pdf.worker.js 1.4 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904429054290642907429084290942910429114291242913429144291542916429174291842919429204292142922429234292442925429264292742928429294293042931429324293342934429354293642937429384293942940429414294242943429444294542946429474294842949429504295142952429534295442955429564295742958429594296042961429624296342964429654296642967429684296942970429714297242973429744297542976429774297842979429804298142982429834298442985429864298742988429894299042991429924299342994429954299642997429984299943000430014300243003430044300543006430074300843009430104301143012430134301443015430164301743018430194302043021430224302343024430254302643027430284302943030430314303243033430344303543036430374303843039430404304143042430434304443045430464304743048430494305043051430524305343054430554305643057430584305943060430614306243063430644306543066430674306843069430704307143072430734307443075430764307743078430794308043081430824308343084430854308643087430884308943090430914309243093430944309543096430974309843099431004310143102431034310443105431064310743108431094311043111431124311343114431154311643117431184311943120431214312243123431244312543126431274312843129431304313143132431334313443135431364313743138431394314043141431424314343144431454314643147431484314943150431514315243153431544315543156431574315843159431604316143162431634316443165431664316743168431694317043171431724317343174431754317643177431784317943180431814318243183431844318543186431874318843189431904319143192431934319443195431964319743198431994320043201432024320343204432054320643207432084320943210432114321243213432144321543216432174321843219432204322143222432234322443225432264322743228432294323043231432324323343234432354323643237432384323943240432414324243243432444324543246432474324843249432504325143252432534325443255432564325743258432594326043261432624326343264432654326643267432684326943270432714327243273432744327543276432774327843279432804328143282432834328443285432864328743288432894329043291432924329343294432954329643297432984329943300433014330243303433044330543306433074330843309433104331143312433134331443315433164331743318433194332043321433224332343324433254332643327433284332943330433314333243333433344333543336433374333843339433404334143342433434334443345433464334743348433494335043351433524335343354433554335643357433584335943360433614336243363433644336543366433674336843369433704337143372433734337443375433764337743378433794338043381433824338343384433854338643387433884338943390433914339243393433944339543396433974339843399434004340143402434034340443405434064340743408434094341043411434124341343414434154341643417434184341943420434214342243423434244342543426434274342843429434304343143432434334343443435434364343743438434394344043441434424344343444434454344643447434484344943450434514345243453434544345543456434574345843459434604346143462434634346443465434664346743468434694347043471434724347343474434754347643477434784347943480434814348243483434844348543486434874348843489434904349143492434934349443495434964349743498434994350043501435024350343504435054350643507435084350943510435114351243513435144351543516435174351843519435204352143522435234352443525435264352743528435294353043531435324353343534435354353643537435384353943540435414354243543435444354543546435474354843549435504355143552435534355443555435564355743558435594356043561435624356343564435654356643567435684356943570435714357243573435744357543576435774357843579435804358143582435834358443585435864358743588435894359043591435924359343594435954359643597435984359943600436014360243603436044360543606436074360843609436104361143612436134361443615436164361743618436194362043621436224362343624436254362643627
  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.210';
  30. var pdfjsBuild = '4ce2356';
  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 = function Util_getInheritableProperty(dict,
  1701. name) {
  1702. while (dict && !dict.has(name)) {
  1703. dict = dict.get('Parent');
  1704. }
  1705. if (!dict) {
  1706. return null;
  1707. }
  1708. return 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['controlNULL'] = 0x0000; // Glyph is missing from Adobe's original list.
  6639. t['controlRS'] = 0x001E;
  6640. t['controlSI'] = 0x000F;
  6641. t['controlSO'] = 0x000E;
  6642. t['controlSOT'] = 0x0002;
  6643. t['controlSTX'] = 0x0001;
  6644. t['controlSUB'] = 0x001A;
  6645. t['controlSYN'] = 0x0016;
  6646. t['controlUS'] = 0x001F;
  6647. t['controlVT'] = 0x000B;
  6648. t['copyright'] = 0x00A9;
  6649. t['copyrightsans'] = 0xF8E9;
  6650. t['copyrightserif'] = 0xF6D9;
  6651. t['cornerbracketleft'] = 0x300C;
  6652. t['cornerbracketlefthalfwidth'] = 0xFF62;
  6653. t['cornerbracketleftvertical'] = 0xFE41;
  6654. t['cornerbracketright'] = 0x300D;
  6655. t['cornerbracketrighthalfwidth'] = 0xFF63;
  6656. t['cornerbracketrightvertical'] = 0xFE42;
  6657. t['corporationsquare'] = 0x337F;
  6658. t['cosquare'] = 0x33C7;
  6659. t['coverkgsquare'] = 0x33C6;
  6660. t['cparen'] = 0x249E;
  6661. t['cruzeiro'] = 0x20A2;
  6662. t['cstretched'] = 0x0297;
  6663. t['curlyand'] = 0x22CF;
  6664. t['curlyor'] = 0x22CE;
  6665. t['currency'] = 0x00A4;
  6666. t['cyrBreve'] = 0xF6D1;
  6667. t['cyrFlex'] = 0xF6D2;
  6668. t['cyrbreve'] = 0xF6D4;
  6669. t['cyrflex'] = 0xF6D5;
  6670. t['d'] = 0x0064;
  6671. t['daarmenian'] = 0x0564;
  6672. t['dabengali'] = 0x09A6;
  6673. t['dadarabic'] = 0x0636;
  6674. t['dadeva'] = 0x0926;
  6675. t['dadfinalarabic'] = 0xFEBE;
  6676. t['dadinitialarabic'] = 0xFEBF;
  6677. t['dadmedialarabic'] = 0xFEC0;
  6678. t['dagesh'] = 0x05BC;
  6679. t['dageshhebrew'] = 0x05BC;
  6680. t['dagger'] = 0x2020;
  6681. t['daggerdbl'] = 0x2021;
  6682. t['dagujarati'] = 0x0AA6;
  6683. t['dagurmukhi'] = 0x0A26;
  6684. t['dahiragana'] = 0x3060;
  6685. t['dakatakana'] = 0x30C0;
  6686. t['dalarabic'] = 0x062F;
  6687. t['dalet'] = 0x05D3;
  6688. t['daletdagesh'] = 0xFB33;
  6689. t['daletdageshhebrew'] = 0xFB33;
  6690. t['dalethebrew'] = 0x05D3;
  6691. t['dalfinalarabic'] = 0xFEAA;
  6692. t['dammaarabic'] = 0x064F;
  6693. t['dammalowarabic'] = 0x064F;
  6694. t['dammatanaltonearabic'] = 0x064C;
  6695. t['dammatanarabic'] = 0x064C;
  6696. t['danda'] = 0x0964;
  6697. t['dargahebrew'] = 0x05A7;
  6698. t['dargalefthebrew'] = 0x05A7;
  6699. t['dasiapneumatacyrilliccmb'] = 0x0485;
  6700. t['dblGrave'] = 0xF6D3;
  6701. t['dblanglebracketleft'] = 0x300A;
  6702. t['dblanglebracketleftvertical'] = 0xFE3D;
  6703. t['dblanglebracketright'] = 0x300B;
  6704. t['dblanglebracketrightvertical'] = 0xFE3E;
  6705. t['dblarchinvertedbelowcmb'] = 0x032B;
  6706. t['dblarrowleft'] = 0x21D4;
  6707. t['dblarrowright'] = 0x21D2;
  6708. t['dbldanda'] = 0x0965;
  6709. t['dblgrave'] = 0xF6D6;
  6710. t['dblgravecmb'] = 0x030F;
  6711. t['dblintegral'] = 0x222C;
  6712. t['dbllowline'] = 0x2017;
  6713. t['dbllowlinecmb'] = 0x0333;
  6714. t['dbloverlinecmb'] = 0x033F;
  6715. t['dblprimemod'] = 0x02BA;
  6716. t['dblverticalbar'] = 0x2016;
  6717. t['dblverticallineabovecmb'] = 0x030E;
  6718. t['dbopomofo'] = 0x3109;
  6719. t['dbsquare'] = 0x33C8;
  6720. t['dcaron'] = 0x010F;
  6721. t['dcedilla'] = 0x1E11;
  6722. t['dcircle'] = 0x24D3;
  6723. t['dcircumflexbelow'] = 0x1E13;
  6724. t['dcroat'] = 0x0111;
  6725. t['ddabengali'] = 0x09A1;
  6726. t['ddadeva'] = 0x0921;
  6727. t['ddagujarati'] = 0x0AA1;
  6728. t['ddagurmukhi'] = 0x0A21;
  6729. t['ddalarabic'] = 0x0688;
  6730. t['ddalfinalarabic'] = 0xFB89;
  6731. t['dddhadeva'] = 0x095C;
  6732. t['ddhabengali'] = 0x09A2;
  6733. t['ddhadeva'] = 0x0922;
  6734. t['ddhagujarati'] = 0x0AA2;
  6735. t['ddhagurmukhi'] = 0x0A22;
  6736. t['ddotaccent'] = 0x1E0B;
  6737. t['ddotbelow'] = 0x1E0D;
  6738. t['decimalseparatorarabic'] = 0x066B;
  6739. t['decimalseparatorpersian'] = 0x066B;
  6740. t['decyrillic'] = 0x0434;
  6741. t['degree'] = 0x00B0;
  6742. t['dehihebrew'] = 0x05AD;
  6743. t['dehiragana'] = 0x3067;
  6744. t['deicoptic'] = 0x03EF;
  6745. t['dekatakana'] = 0x30C7;
  6746. t['deleteleft'] = 0x232B;
  6747. t['deleteright'] = 0x2326;
  6748. t['delta'] = 0x03B4;
  6749. t['deltaturned'] = 0x018D;
  6750. t['denominatorminusonenumeratorbengali'] = 0x09F8;
  6751. t['dezh'] = 0x02A4;
  6752. t['dhabengali'] = 0x09A7;
  6753. t['dhadeva'] = 0x0927;
  6754. t['dhagujarati'] = 0x0AA7;
  6755. t['dhagurmukhi'] = 0x0A27;
  6756. t['dhook'] = 0x0257;
  6757. t['dialytikatonos'] = 0x0385;
  6758. t['dialytikatonoscmb'] = 0x0344;
  6759. t['diamond'] = 0x2666;
  6760. t['diamondsuitwhite'] = 0x2662;
  6761. t['dieresis'] = 0x00A8;
  6762. t['dieresisacute'] = 0xF6D7;
  6763. t['dieresisbelowcmb'] = 0x0324;
  6764. t['dieresiscmb'] = 0x0308;
  6765. t['dieresisgrave'] = 0xF6D8;
  6766. t['dieresistonos'] = 0x0385;
  6767. t['dihiragana'] = 0x3062;
  6768. t['dikatakana'] = 0x30C2;
  6769. t['dittomark'] = 0x3003;
  6770. t['divide'] = 0x00F7;
  6771. t['divides'] = 0x2223;
  6772. t['divisionslash'] = 0x2215;
  6773. t['djecyrillic'] = 0x0452;
  6774. t['dkshade'] = 0x2593;
  6775. t['dlinebelow'] = 0x1E0F;
  6776. t['dlsquare'] = 0x3397;
  6777. t['dmacron'] = 0x0111;
  6778. t['dmonospace'] = 0xFF44;
  6779. t['dnblock'] = 0x2584;
  6780. t['dochadathai'] = 0x0E0E;
  6781. t['dodekthai'] = 0x0E14;
  6782. t['dohiragana'] = 0x3069;
  6783. t['dokatakana'] = 0x30C9;
  6784. t['dollar'] = 0x0024;
  6785. t['dollarinferior'] = 0xF6E3;
  6786. t['dollarmonospace'] = 0xFF04;
  6787. t['dollaroldstyle'] = 0xF724;
  6788. t['dollarsmall'] = 0xFE69;
  6789. t['dollarsuperior'] = 0xF6E4;
  6790. t['dong'] = 0x20AB;
  6791. t['dorusquare'] = 0x3326;
  6792. t['dotaccent'] = 0x02D9;
  6793. t['dotaccentcmb'] = 0x0307;
  6794. t['dotbelowcmb'] = 0x0323;
  6795. t['dotbelowcomb'] = 0x0323;
  6796. t['dotkatakana'] = 0x30FB;
  6797. t['dotlessi'] = 0x0131;
  6798. t['dotlessj'] = 0xF6BE;
  6799. t['dotlessjstrokehook'] = 0x0284;
  6800. t['dotmath'] = 0x22C5;
  6801. t['dottedcircle'] = 0x25CC;
  6802. t['doubleyodpatah'] = 0xFB1F;
  6803. t['doubleyodpatahhebrew'] = 0xFB1F;
  6804. t['downtackbelowcmb'] = 0x031E;
  6805. t['downtackmod'] = 0x02D5;
  6806. t['dparen'] = 0x249F;
  6807. t['dsuperior'] = 0xF6EB;
  6808. t['dtail'] = 0x0256;
  6809. t['dtopbar'] = 0x018C;
  6810. t['duhiragana'] = 0x3065;
  6811. t['dukatakana'] = 0x30C5;
  6812. t['dz'] = 0x01F3;
  6813. t['dzaltone'] = 0x02A3;
  6814. t['dzcaron'] = 0x01C6;
  6815. t['dzcurl'] = 0x02A5;
  6816. t['dzeabkhasiancyrillic'] = 0x04E1;
  6817. t['dzecyrillic'] = 0x0455;
  6818. t['dzhecyrillic'] = 0x045F;
  6819. t['e'] = 0x0065;
  6820. t['eacute'] = 0x00E9;
  6821. t['earth'] = 0x2641;
  6822. t['ebengali'] = 0x098F;
  6823. t['ebopomofo'] = 0x311C;
  6824. t['ebreve'] = 0x0115;
  6825. t['ecandradeva'] = 0x090D;
  6826. t['ecandragujarati'] = 0x0A8D;
  6827. t['ecandravowelsigndeva'] = 0x0945;
  6828. t['ecandravowelsigngujarati'] = 0x0AC5;
  6829. t['ecaron'] = 0x011B;
  6830. t['ecedillabreve'] = 0x1E1D;
  6831. t['echarmenian'] = 0x0565;
  6832. t['echyiwnarmenian'] = 0x0587;
  6833. t['ecircle'] = 0x24D4;
  6834. t['ecircumflex'] = 0x00EA;
  6835. t['ecircumflexacute'] = 0x1EBF;
  6836. t['ecircumflexbelow'] = 0x1E19;
  6837. t['ecircumflexdotbelow'] = 0x1EC7;
  6838. t['ecircumflexgrave'] = 0x1EC1;
  6839. t['ecircumflexhookabove'] = 0x1EC3;
  6840. t['ecircumflextilde'] = 0x1EC5;
  6841. t['ecyrillic'] = 0x0454;
  6842. t['edblgrave'] = 0x0205;
  6843. t['edeva'] = 0x090F;
  6844. t['edieresis'] = 0x00EB;
  6845. t['edot'] = 0x0117;
  6846. t['edotaccent'] = 0x0117;
  6847. t['edotbelow'] = 0x1EB9;
  6848. t['eegurmukhi'] = 0x0A0F;
  6849. t['eematragurmukhi'] = 0x0A47;
  6850. t['efcyrillic'] = 0x0444;
  6851. t['egrave'] = 0x00E8;
  6852. t['egujarati'] = 0x0A8F;
  6853. t['eharmenian'] = 0x0567;
  6854. t['ehbopomofo'] = 0x311D;
  6855. t['ehiragana'] = 0x3048;
  6856. t['ehookabove'] = 0x1EBB;
  6857. t['eibopomofo'] = 0x311F;
  6858. t['eight'] = 0x0038;
  6859. t['eightarabic'] = 0x0668;
  6860. t['eightbengali'] = 0x09EE;
  6861. t['eightcircle'] = 0x2467;
  6862. t['eightcircleinversesansserif'] = 0x2791;
  6863. t['eightdeva'] = 0x096E;
  6864. t['eighteencircle'] = 0x2471;
  6865. t['eighteenparen'] = 0x2485;
  6866. t['eighteenperiod'] = 0x2499;
  6867. t['eightgujarati'] = 0x0AEE;
  6868. t['eightgurmukhi'] = 0x0A6E;
  6869. t['eighthackarabic'] = 0x0668;
  6870. t['eighthangzhou'] = 0x3028;
  6871. t['eighthnotebeamed'] = 0x266B;
  6872. t['eightideographicparen'] = 0x3227;
  6873. t['eightinferior'] = 0x2088;
  6874. t['eightmonospace'] = 0xFF18;
  6875. t['eightoldstyle'] = 0xF738;
  6876. t['eightparen'] = 0x247B;
  6877. t['eightperiod'] = 0x248F;
  6878. t['eightpersian'] = 0x06F8;
  6879. t['eightroman'] = 0x2177;
  6880. t['eightsuperior'] = 0x2078;
  6881. t['eightthai'] = 0x0E58;
  6882. t['einvertedbreve'] = 0x0207;
  6883. t['eiotifiedcyrillic'] = 0x0465;
  6884. t['ekatakana'] = 0x30A8;
  6885. t['ekatakanahalfwidth'] = 0xFF74;
  6886. t['ekonkargurmukhi'] = 0x0A74;
  6887. t['ekorean'] = 0x3154;
  6888. t['elcyrillic'] = 0x043B;
  6889. t['element'] = 0x2208;
  6890. t['elevencircle'] = 0x246A;
  6891. t['elevenparen'] = 0x247E;
  6892. t['elevenperiod'] = 0x2492;
  6893. t['elevenroman'] = 0x217A;
  6894. t['ellipsis'] = 0x2026;
  6895. t['ellipsisvertical'] = 0x22EE;
  6896. t['emacron'] = 0x0113;
  6897. t['emacronacute'] = 0x1E17;
  6898. t['emacrongrave'] = 0x1E15;
  6899. t['emcyrillic'] = 0x043C;
  6900. t['emdash'] = 0x2014;
  6901. t['emdashvertical'] = 0xFE31;
  6902. t['emonospace'] = 0xFF45;
  6903. t['emphasismarkarmenian'] = 0x055B;
  6904. t['emptyset'] = 0x2205;
  6905. t['enbopomofo'] = 0x3123;
  6906. t['encyrillic'] = 0x043D;
  6907. t['endash'] = 0x2013;
  6908. t['endashvertical'] = 0xFE32;
  6909. t['endescendercyrillic'] = 0x04A3;
  6910. t['eng'] = 0x014B;
  6911. t['engbopomofo'] = 0x3125;
  6912. t['enghecyrillic'] = 0x04A5;
  6913. t['enhookcyrillic'] = 0x04C8;
  6914. t['enspace'] = 0x2002;
  6915. t['eogonek'] = 0x0119;
  6916. t['eokorean'] = 0x3153;
  6917. t['eopen'] = 0x025B;
  6918. t['eopenclosed'] = 0x029A;
  6919. t['eopenreversed'] = 0x025C;
  6920. t['eopenreversedclosed'] = 0x025E;
  6921. t['eopenreversedhook'] = 0x025D;
  6922. t['eparen'] = 0x24A0;
  6923. t['epsilon'] = 0x03B5;
  6924. t['epsilontonos'] = 0x03AD;
  6925. t['equal'] = 0x003D;
  6926. t['equalmonospace'] = 0xFF1D;
  6927. t['equalsmall'] = 0xFE66;
  6928. t['equalsuperior'] = 0x207C;
  6929. t['equivalence'] = 0x2261;
  6930. t['erbopomofo'] = 0x3126;
  6931. t['ercyrillic'] = 0x0440;
  6932. t['ereversed'] = 0x0258;
  6933. t['ereversedcyrillic'] = 0x044D;
  6934. t['escyrillic'] = 0x0441;
  6935. t['esdescendercyrillic'] = 0x04AB;
  6936. t['esh'] = 0x0283;
  6937. t['eshcurl'] = 0x0286;
  6938. t['eshortdeva'] = 0x090E;
  6939. t['eshortvowelsigndeva'] = 0x0946;
  6940. t['eshreversedloop'] = 0x01AA;
  6941. t['eshsquatreversed'] = 0x0285;
  6942. t['esmallhiragana'] = 0x3047;
  6943. t['esmallkatakana'] = 0x30A7;
  6944. t['esmallkatakanahalfwidth'] = 0xFF6A;
  6945. t['estimated'] = 0x212E;
  6946. t['esuperior'] = 0xF6EC;
  6947. t['eta'] = 0x03B7;
  6948. t['etarmenian'] = 0x0568;
  6949. t['etatonos'] = 0x03AE;
  6950. t['eth'] = 0x00F0;
  6951. t['etilde'] = 0x1EBD;
  6952. t['etildebelow'] = 0x1E1B;
  6953. t['etnahtafoukhhebrew'] = 0x0591;
  6954. t['etnahtafoukhlefthebrew'] = 0x0591;
  6955. t['etnahtahebrew'] = 0x0591;
  6956. t['etnahtalefthebrew'] = 0x0591;
  6957. t['eturned'] = 0x01DD;
  6958. t['eukorean'] = 0x3161;
  6959. t['euro'] = 0x20AC;
  6960. t['evowelsignbengali'] = 0x09C7;
  6961. t['evowelsigndeva'] = 0x0947;
  6962. t['evowelsigngujarati'] = 0x0AC7;
  6963. t['exclam'] = 0x0021;
  6964. t['exclamarmenian'] = 0x055C;
  6965. t['exclamdbl'] = 0x203C;
  6966. t['exclamdown'] = 0x00A1;
  6967. t['exclamdownsmall'] = 0xF7A1;
  6968. t['exclammonospace'] = 0xFF01;
  6969. t['exclamsmall'] = 0xF721;
  6970. t['existential'] = 0x2203;
  6971. t['ezh'] = 0x0292;
  6972. t['ezhcaron'] = 0x01EF;
  6973. t['ezhcurl'] = 0x0293;
  6974. t['ezhreversed'] = 0x01B9;
  6975. t['ezhtail'] = 0x01BA;
  6976. t['f'] = 0x0066;
  6977. t['fadeva'] = 0x095E;
  6978. t['fagurmukhi'] = 0x0A5E;
  6979. t['fahrenheit'] = 0x2109;
  6980. t['fathaarabic'] = 0x064E;
  6981. t['fathalowarabic'] = 0x064E;
  6982. t['fathatanarabic'] = 0x064B;
  6983. t['fbopomofo'] = 0x3108;
  6984. t['fcircle'] = 0x24D5;
  6985. t['fdotaccent'] = 0x1E1F;
  6986. t['feharabic'] = 0x0641;
  6987. t['feharmenian'] = 0x0586;
  6988. t['fehfinalarabic'] = 0xFED2;
  6989. t['fehinitialarabic'] = 0xFED3;
  6990. t['fehmedialarabic'] = 0xFED4;
  6991. t['feicoptic'] = 0x03E5;
  6992. t['female'] = 0x2640;
  6993. t['ff'] = 0xFB00;
  6994. t['ffi'] = 0xFB03;
  6995. t['ffl'] = 0xFB04;
  6996. t['fi'] = 0xFB01;
  6997. t['fifteencircle'] = 0x246E;
  6998. t['fifteenparen'] = 0x2482;
  6999. t['fifteenperiod'] = 0x2496;
  7000. t['figuredash'] = 0x2012;
  7001. t['filledbox'] = 0x25A0;
  7002. t['filledrect'] = 0x25AC;
  7003. t['finalkaf'] = 0x05DA;
  7004. t['finalkafdagesh'] = 0xFB3A;
  7005. t['finalkafdageshhebrew'] = 0xFB3A;
  7006. t['finalkafhebrew'] = 0x05DA;
  7007. t['finalmem'] = 0x05DD;
  7008. t['finalmemhebrew'] = 0x05DD;
  7009. t['finalnun'] = 0x05DF;
  7010. t['finalnunhebrew'] = 0x05DF;
  7011. t['finalpe'] = 0x05E3;
  7012. t['finalpehebrew'] = 0x05E3;
  7013. t['finaltsadi'] = 0x05E5;
  7014. t['finaltsadihebrew'] = 0x05E5;
  7015. t['firsttonechinese'] = 0x02C9;
  7016. t['fisheye'] = 0x25C9;
  7017. t['fitacyrillic'] = 0x0473;
  7018. t['five'] = 0x0035;
  7019. t['fivearabic'] = 0x0665;
  7020. t['fivebengali'] = 0x09EB;
  7021. t['fivecircle'] = 0x2464;
  7022. t['fivecircleinversesansserif'] = 0x278E;
  7023. t['fivedeva'] = 0x096B;
  7024. t['fiveeighths'] = 0x215D;
  7025. t['fivegujarati'] = 0x0AEB;
  7026. t['fivegurmukhi'] = 0x0A6B;
  7027. t['fivehackarabic'] = 0x0665;
  7028. t['fivehangzhou'] = 0x3025;
  7029. t['fiveideographicparen'] = 0x3224;
  7030. t['fiveinferior'] = 0x2085;
  7031. t['fivemonospace'] = 0xFF15;
  7032. t['fiveoldstyle'] = 0xF735;
  7033. t['fiveparen'] = 0x2478;
  7034. t['fiveperiod'] = 0x248C;
  7035. t['fivepersian'] = 0x06F5;
  7036. t['fiveroman'] = 0x2174;
  7037. t['fivesuperior'] = 0x2075;
  7038. t['fivethai'] = 0x0E55;
  7039. t['fl'] = 0xFB02;
  7040. t['florin'] = 0x0192;
  7041. t['fmonospace'] = 0xFF46;
  7042. t['fmsquare'] = 0x3399;
  7043. t['fofanthai'] = 0x0E1F;
  7044. t['fofathai'] = 0x0E1D;
  7045. t['fongmanthai'] = 0x0E4F;
  7046. t['forall'] = 0x2200;
  7047. t['four'] = 0x0034;
  7048. t['fourarabic'] = 0x0664;
  7049. t['fourbengali'] = 0x09EA;
  7050. t['fourcircle'] = 0x2463;
  7051. t['fourcircleinversesansserif'] = 0x278D;
  7052. t['fourdeva'] = 0x096A;
  7053. t['fourgujarati'] = 0x0AEA;
  7054. t['fourgurmukhi'] = 0x0A6A;
  7055. t['fourhackarabic'] = 0x0664;
  7056. t['fourhangzhou'] = 0x3024;
  7057. t['fourideographicparen'] = 0x3223;
  7058. t['fourinferior'] = 0x2084;
  7059. t['fourmonospace'] = 0xFF14;
  7060. t['fournumeratorbengali'] = 0x09F7;
  7061. t['fouroldstyle'] = 0xF734;
  7062. t['fourparen'] = 0x2477;
  7063. t['fourperiod'] = 0x248B;
  7064. t['fourpersian'] = 0x06F4;
  7065. t['fourroman'] = 0x2173;
  7066. t['foursuperior'] = 0x2074;
  7067. t['fourteencircle'] = 0x246D;
  7068. t['fourteenparen'] = 0x2481;
  7069. t['fourteenperiod'] = 0x2495;
  7070. t['fourthai'] = 0x0E54;
  7071. t['fourthtonechinese'] = 0x02CB;
  7072. t['fparen'] = 0x24A1;
  7073. t['fraction'] = 0x2044;
  7074. t['franc'] = 0x20A3;
  7075. t['g'] = 0x0067;
  7076. t['gabengali'] = 0x0997;
  7077. t['gacute'] = 0x01F5;
  7078. t['gadeva'] = 0x0917;
  7079. t['gafarabic'] = 0x06AF;
  7080. t['gaffinalarabic'] = 0xFB93;
  7081. t['gafinitialarabic'] = 0xFB94;
  7082. t['gafmedialarabic'] = 0xFB95;
  7083. t['gagujarati'] = 0x0A97;
  7084. t['gagurmukhi'] = 0x0A17;
  7085. t['gahiragana'] = 0x304C;
  7086. t['gakatakana'] = 0x30AC;
  7087. t['gamma'] = 0x03B3;
  7088. t['gammalatinsmall'] = 0x0263;
  7089. t['gammasuperior'] = 0x02E0;
  7090. t['gangiacoptic'] = 0x03EB;
  7091. t['gbopomofo'] = 0x310D;
  7092. t['gbreve'] = 0x011F;
  7093. t['gcaron'] = 0x01E7;
  7094. t['gcedilla'] = 0x0123;
  7095. t['gcircle'] = 0x24D6;
  7096. t['gcircumflex'] = 0x011D;
  7097. t['gcommaaccent'] = 0x0123;
  7098. t['gdot'] = 0x0121;
  7099. t['gdotaccent'] = 0x0121;
  7100. t['gecyrillic'] = 0x0433;
  7101. t['gehiragana'] = 0x3052;
  7102. t['gekatakana'] = 0x30B2;
  7103. t['geometricallyequal'] = 0x2251;
  7104. t['gereshaccenthebrew'] = 0x059C;
  7105. t['gereshhebrew'] = 0x05F3;
  7106. t['gereshmuqdamhebrew'] = 0x059D;
  7107. t['germandbls'] = 0x00DF;
  7108. t['gershayimaccenthebrew'] = 0x059E;
  7109. t['gershayimhebrew'] = 0x05F4;
  7110. t['getamark'] = 0x3013;
  7111. t['ghabengali'] = 0x0998;
  7112. t['ghadarmenian'] = 0x0572;
  7113. t['ghadeva'] = 0x0918;
  7114. t['ghagujarati'] = 0x0A98;
  7115. t['ghagurmukhi'] = 0x0A18;
  7116. t['ghainarabic'] = 0x063A;
  7117. t['ghainfinalarabic'] = 0xFECE;
  7118. t['ghaininitialarabic'] = 0xFECF;
  7119. t['ghainmedialarabic'] = 0xFED0;
  7120. t['ghemiddlehookcyrillic'] = 0x0495;
  7121. t['ghestrokecyrillic'] = 0x0493;
  7122. t['gheupturncyrillic'] = 0x0491;
  7123. t['ghhadeva'] = 0x095A;
  7124. t['ghhagurmukhi'] = 0x0A5A;
  7125. t['ghook'] = 0x0260;
  7126. t['ghzsquare'] = 0x3393;
  7127. t['gihiragana'] = 0x304E;
  7128. t['gikatakana'] = 0x30AE;
  7129. t['gimarmenian'] = 0x0563;
  7130. t['gimel'] = 0x05D2;
  7131. t['gimeldagesh'] = 0xFB32;
  7132. t['gimeldageshhebrew'] = 0xFB32;
  7133. t['gimelhebrew'] = 0x05D2;
  7134. t['gjecyrillic'] = 0x0453;
  7135. t['glottalinvertedstroke'] = 0x01BE;
  7136. t['glottalstop'] = 0x0294;
  7137. t['glottalstopinverted'] = 0x0296;
  7138. t['glottalstopmod'] = 0x02C0;
  7139. t['glottalstopreversed'] = 0x0295;
  7140. t['glottalstopreversedmod'] = 0x02C1;
  7141. t['glottalstopreversedsuperior'] = 0x02E4;
  7142. t['glottalstopstroke'] = 0x02A1;
  7143. t['glottalstopstrokereversed'] = 0x02A2;
  7144. t['gmacron'] = 0x1E21;
  7145. t['gmonospace'] = 0xFF47;
  7146. t['gohiragana'] = 0x3054;
  7147. t['gokatakana'] = 0x30B4;
  7148. t['gparen'] = 0x24A2;
  7149. t['gpasquare'] = 0x33AC;
  7150. t['gradient'] = 0x2207;
  7151. t['grave'] = 0x0060;
  7152. t['gravebelowcmb'] = 0x0316;
  7153. t['gravecmb'] = 0x0300;
  7154. t['gravecomb'] = 0x0300;
  7155. t['gravedeva'] = 0x0953;
  7156. t['gravelowmod'] = 0x02CE;
  7157. t['gravemonospace'] = 0xFF40;
  7158. t['gravetonecmb'] = 0x0340;
  7159. t['greater'] = 0x003E;
  7160. t['greaterequal'] = 0x2265;
  7161. t['greaterequalorless'] = 0x22DB;
  7162. t['greatermonospace'] = 0xFF1E;
  7163. t['greaterorequivalent'] = 0x2273;
  7164. t['greaterorless'] = 0x2277;
  7165. t['greateroverequal'] = 0x2267;
  7166. t['greatersmall'] = 0xFE65;
  7167. t['gscript'] = 0x0261;
  7168. t['gstroke'] = 0x01E5;
  7169. t['guhiragana'] = 0x3050;
  7170. t['guillemotleft'] = 0x00AB;
  7171. t['guillemotright'] = 0x00BB;
  7172. t['guilsinglleft'] = 0x2039;
  7173. t['guilsinglright'] = 0x203A;
  7174. t['gukatakana'] = 0x30B0;
  7175. t['guramusquare'] = 0x3318;
  7176. t['gysquare'] = 0x33C9;
  7177. t['h'] = 0x0068;
  7178. t['haabkhasiancyrillic'] = 0x04A9;
  7179. t['haaltonearabic'] = 0x06C1;
  7180. t['habengali'] = 0x09B9;
  7181. t['hadescendercyrillic'] = 0x04B3;
  7182. t['hadeva'] = 0x0939;
  7183. t['hagujarati'] = 0x0AB9;
  7184. t['hagurmukhi'] = 0x0A39;
  7185. t['haharabic'] = 0x062D;
  7186. t['hahfinalarabic'] = 0xFEA2;
  7187. t['hahinitialarabic'] = 0xFEA3;
  7188. t['hahiragana'] = 0x306F;
  7189. t['hahmedialarabic'] = 0xFEA4;
  7190. t['haitusquare'] = 0x332A;
  7191. t['hakatakana'] = 0x30CF;
  7192. t['hakatakanahalfwidth'] = 0xFF8A;
  7193. t['halantgurmukhi'] = 0x0A4D;
  7194. t['hamzaarabic'] = 0x0621;
  7195. t['hamzalowarabic'] = 0x0621;
  7196. t['hangulfiller'] = 0x3164;
  7197. t['hardsigncyrillic'] = 0x044A;
  7198. t['harpoonleftbarbup'] = 0x21BC;
  7199. t['harpoonrightbarbup'] = 0x21C0;
  7200. t['hasquare'] = 0x33CA;
  7201. t['hatafpatah'] = 0x05B2;
  7202. t['hatafpatah16'] = 0x05B2;
  7203. t['hatafpatah23'] = 0x05B2;
  7204. t['hatafpatah2f'] = 0x05B2;
  7205. t['hatafpatahhebrew'] = 0x05B2;
  7206. t['hatafpatahnarrowhebrew'] = 0x05B2;
  7207. t['hatafpatahquarterhebrew'] = 0x05B2;
  7208. t['hatafpatahwidehebrew'] = 0x05B2;
  7209. t['hatafqamats'] = 0x05B3;
  7210. t['hatafqamats1b'] = 0x05B3;
  7211. t['hatafqamats28'] = 0x05B3;
  7212. t['hatafqamats34'] = 0x05B3;
  7213. t['hatafqamatshebrew'] = 0x05B3;
  7214. t['hatafqamatsnarrowhebrew'] = 0x05B3;
  7215. t['hatafqamatsquarterhebrew'] = 0x05B3;
  7216. t['hatafqamatswidehebrew'] = 0x05B3;
  7217. t['hatafsegol'] = 0x05B1;
  7218. t['hatafsegol17'] = 0x05B1;
  7219. t['hatafsegol24'] = 0x05B1;
  7220. t['hatafsegol30'] = 0x05B1;
  7221. t['hatafsegolhebrew'] = 0x05B1;
  7222. t['hatafsegolnarrowhebrew'] = 0x05B1;
  7223. t['hatafsegolquarterhebrew'] = 0x05B1;
  7224. t['hatafsegolwidehebrew'] = 0x05B1;
  7225. t['hbar'] = 0x0127;
  7226. t['hbopomofo'] = 0x310F;
  7227. t['hbrevebelow'] = 0x1E2B;
  7228. t['hcedilla'] = 0x1E29;
  7229. t['hcircle'] = 0x24D7;
  7230. t['hcircumflex'] = 0x0125;
  7231. t['hdieresis'] = 0x1E27;
  7232. t['hdotaccent'] = 0x1E23;
  7233. t['hdotbelow'] = 0x1E25;
  7234. t['he'] = 0x05D4;
  7235. t['heart'] = 0x2665;
  7236. t['heartsuitblack'] = 0x2665;
  7237. t['heartsuitwhite'] = 0x2661;
  7238. t['hedagesh'] = 0xFB34;
  7239. t['hedageshhebrew'] = 0xFB34;
  7240. t['hehaltonearabic'] = 0x06C1;
  7241. t['heharabic'] = 0x0647;
  7242. t['hehebrew'] = 0x05D4;
  7243. t['hehfinalaltonearabic'] = 0xFBA7;
  7244. t['hehfinalalttwoarabic'] = 0xFEEA;
  7245. t['hehfinalarabic'] = 0xFEEA;
  7246. t['hehhamzaabovefinalarabic'] = 0xFBA5;
  7247. t['hehhamzaaboveisolatedarabic'] = 0xFBA4;
  7248. t['hehinitialaltonearabic'] = 0xFBA8;
  7249. t['hehinitialarabic'] = 0xFEEB;
  7250. t['hehiragana'] = 0x3078;
  7251. t['hehmedialaltonearabic'] = 0xFBA9;
  7252. t['hehmedialarabic'] = 0xFEEC;
  7253. t['heiseierasquare'] = 0x337B;
  7254. t['hekatakana'] = 0x30D8;
  7255. t['hekatakanahalfwidth'] = 0xFF8D;
  7256. t['hekutaarusquare'] = 0x3336;
  7257. t['henghook'] = 0x0267;
  7258. t['herutusquare'] = 0x3339;
  7259. t['het'] = 0x05D7;
  7260. t['hethebrew'] = 0x05D7;
  7261. t['hhook'] = 0x0266;
  7262. t['hhooksuperior'] = 0x02B1;
  7263. t['hieuhacirclekorean'] = 0x327B;
  7264. t['hieuhaparenkorean'] = 0x321B;
  7265. t['hieuhcirclekorean'] = 0x326D;
  7266. t['hieuhkorean'] = 0x314E;
  7267. t['hieuhparenkorean'] = 0x320D;
  7268. t['hihiragana'] = 0x3072;
  7269. t['hikatakana'] = 0x30D2;
  7270. t['hikatakanahalfwidth'] = 0xFF8B;
  7271. t['hiriq'] = 0x05B4;
  7272. t['hiriq14'] = 0x05B4;
  7273. t['hiriq21'] = 0x05B4;
  7274. t['hiriq2d'] = 0x05B4;
  7275. t['hiriqhebrew'] = 0x05B4;
  7276. t['hiriqnarrowhebrew'] = 0x05B4;
  7277. t['hiriqquarterhebrew'] = 0x05B4;
  7278. t['hiriqwidehebrew'] = 0x05B4;
  7279. t['hlinebelow'] = 0x1E96;
  7280. t['hmonospace'] = 0xFF48;
  7281. t['hoarmenian'] = 0x0570;
  7282. t['hohipthai'] = 0x0E2B;
  7283. t['hohiragana'] = 0x307B;
  7284. t['hokatakana'] = 0x30DB;
  7285. t['hokatakanahalfwidth'] = 0xFF8E;
  7286. t['holam'] = 0x05B9;
  7287. t['holam19'] = 0x05B9;
  7288. t['holam26'] = 0x05B9;
  7289. t['holam32'] = 0x05B9;
  7290. t['holamhebrew'] = 0x05B9;
  7291. t['holamnarrowhebrew'] = 0x05B9;
  7292. t['holamquarterhebrew'] = 0x05B9;
  7293. t['holamwidehebrew'] = 0x05B9;
  7294. t['honokhukthai'] = 0x0E2E;
  7295. t['hookabovecomb'] = 0x0309;
  7296. t['hookcmb'] = 0x0309;
  7297. t['hookpalatalizedbelowcmb'] = 0x0321;
  7298. t['hookretroflexbelowcmb'] = 0x0322;
  7299. t['hoonsquare'] = 0x3342;
  7300. t['horicoptic'] = 0x03E9;
  7301. t['horizontalbar'] = 0x2015;
  7302. t['horncmb'] = 0x031B;
  7303. t['hotsprings'] = 0x2668;
  7304. t['house'] = 0x2302;
  7305. t['hparen'] = 0x24A3;
  7306. t['hsuperior'] = 0x02B0;
  7307. t['hturned'] = 0x0265;
  7308. t['huhiragana'] = 0x3075;
  7309. t['huiitosquare'] = 0x3333;
  7310. t['hukatakana'] = 0x30D5;
  7311. t['hukatakanahalfwidth'] = 0xFF8C;
  7312. t['hungarumlaut'] = 0x02DD;
  7313. t['hungarumlautcmb'] = 0x030B;
  7314. t['hv'] = 0x0195;
  7315. t['hyphen'] = 0x002D;
  7316. t['hypheninferior'] = 0xF6E5;
  7317. t['hyphenmonospace'] = 0xFF0D;
  7318. t['hyphensmall'] = 0xFE63;
  7319. t['hyphensuperior'] = 0xF6E6;
  7320. t['hyphentwo'] = 0x2010;
  7321. t['i'] = 0x0069;
  7322. t['iacute'] = 0x00ED;
  7323. t['iacyrillic'] = 0x044F;
  7324. t['ibengali'] = 0x0987;
  7325. t['ibopomofo'] = 0x3127;
  7326. t['ibreve'] = 0x012D;
  7327. t['icaron'] = 0x01D0;
  7328. t['icircle'] = 0x24D8;
  7329. t['icircumflex'] = 0x00EE;
  7330. t['icyrillic'] = 0x0456;
  7331. t['idblgrave'] = 0x0209;
  7332. t['ideographearthcircle'] = 0x328F;
  7333. t['ideographfirecircle'] = 0x328B;
  7334. t['ideographicallianceparen'] = 0x323F;
  7335. t['ideographiccallparen'] = 0x323A;
  7336. t['ideographiccentrecircle'] = 0x32A5;
  7337. t['ideographicclose'] = 0x3006;
  7338. t['ideographiccomma'] = 0x3001;
  7339. t['ideographiccommaleft'] = 0xFF64;
  7340. t['ideographiccongratulationparen'] = 0x3237;
  7341. t['ideographiccorrectcircle'] = 0x32A3;
  7342. t['ideographicearthparen'] = 0x322F;
  7343. t['ideographicenterpriseparen'] = 0x323D;
  7344. t['ideographicexcellentcircle'] = 0x329D;
  7345. t['ideographicfestivalparen'] = 0x3240;
  7346. t['ideographicfinancialcircle'] = 0x3296;
  7347. t['ideographicfinancialparen'] = 0x3236;
  7348. t['ideographicfireparen'] = 0x322B;
  7349. t['ideographichaveparen'] = 0x3232;
  7350. t['ideographichighcircle'] = 0x32A4;
  7351. t['ideographiciterationmark'] = 0x3005;
  7352. t['ideographiclaborcircle'] = 0x3298;
  7353. t['ideographiclaborparen'] = 0x3238;
  7354. t['ideographicleftcircle'] = 0x32A7;
  7355. t['ideographiclowcircle'] = 0x32A6;
  7356. t['ideographicmedicinecircle'] = 0x32A9;
  7357. t['ideographicmetalparen'] = 0x322E;
  7358. t['ideographicmoonparen'] = 0x322A;
  7359. t['ideographicnameparen'] = 0x3234;
  7360. t['ideographicperiod'] = 0x3002;
  7361. t['ideographicprintcircle'] = 0x329E;
  7362. t['ideographicreachparen'] = 0x3243;
  7363. t['ideographicrepresentparen'] = 0x3239;
  7364. t['ideographicresourceparen'] = 0x323E;
  7365. t['ideographicrightcircle'] = 0x32A8;
  7366. t['ideographicsecretcircle'] = 0x3299;
  7367. t['ideographicselfparen'] = 0x3242;
  7368. t['ideographicsocietyparen'] = 0x3233;
  7369. t['ideographicspace'] = 0x3000;
  7370. t['ideographicspecialparen'] = 0x3235;
  7371. t['ideographicstockparen'] = 0x3231;
  7372. t['ideographicstudyparen'] = 0x323B;
  7373. t['ideographicsunparen'] = 0x3230;
  7374. t['ideographicsuperviseparen'] = 0x323C;
  7375. t['ideographicwaterparen'] = 0x322C;
  7376. t['ideographicwoodparen'] = 0x322D;
  7377. t['ideographiczero'] = 0x3007;
  7378. t['ideographmetalcircle'] = 0x328E;
  7379. t['ideographmooncircle'] = 0x328A;
  7380. t['ideographnamecircle'] = 0x3294;
  7381. t['ideographsuncircle'] = 0x3290;
  7382. t['ideographwatercircle'] = 0x328C;
  7383. t['ideographwoodcircle'] = 0x328D;
  7384. t['ideva'] = 0x0907;
  7385. t['idieresis'] = 0x00EF;
  7386. t['idieresisacute'] = 0x1E2F;
  7387. t['idieresiscyrillic'] = 0x04E5;
  7388. t['idotbelow'] = 0x1ECB;
  7389. t['iebrevecyrillic'] = 0x04D7;
  7390. t['iecyrillic'] = 0x0435;
  7391. t['ieungacirclekorean'] = 0x3275;
  7392. t['ieungaparenkorean'] = 0x3215;
  7393. t['ieungcirclekorean'] = 0x3267;
  7394. t['ieungkorean'] = 0x3147;
  7395. t['ieungparenkorean'] = 0x3207;
  7396. t['igrave'] = 0x00EC;
  7397. t['igujarati'] = 0x0A87;
  7398. t['igurmukhi'] = 0x0A07;
  7399. t['ihiragana'] = 0x3044;
  7400. t['ihookabove'] = 0x1EC9;
  7401. t['iibengali'] = 0x0988;
  7402. t['iicyrillic'] = 0x0438;
  7403. t['iideva'] = 0x0908;
  7404. t['iigujarati'] = 0x0A88;
  7405. t['iigurmukhi'] = 0x0A08;
  7406. t['iimatragurmukhi'] = 0x0A40;
  7407. t['iinvertedbreve'] = 0x020B;
  7408. t['iishortcyrillic'] = 0x0439;
  7409. t['iivowelsignbengali'] = 0x09C0;
  7410. t['iivowelsigndeva'] = 0x0940;
  7411. t['iivowelsigngujarati'] = 0x0AC0;
  7412. t['ij'] = 0x0133;
  7413. t['ikatakana'] = 0x30A4;
  7414. t['ikatakanahalfwidth'] = 0xFF72;
  7415. t['ikorean'] = 0x3163;
  7416. t['ilde'] = 0x02DC;
  7417. t['iluyhebrew'] = 0x05AC;
  7418. t['imacron'] = 0x012B;
  7419. t['imacroncyrillic'] = 0x04E3;
  7420. t['imageorapproximatelyequal'] = 0x2253;
  7421. t['imatragurmukhi'] = 0x0A3F;
  7422. t['imonospace'] = 0xFF49;
  7423. t['increment'] = 0x2206;
  7424. t['infinity'] = 0x221E;
  7425. t['iniarmenian'] = 0x056B;
  7426. t['integral'] = 0x222B;
  7427. t['integralbottom'] = 0x2321;
  7428. t['integralbt'] = 0x2321;
  7429. t['integralex'] = 0xF8F5;
  7430. t['integraltop'] = 0x2320;
  7431. t['integraltp'] = 0x2320;
  7432. t['intersection'] = 0x2229;
  7433. t['intisquare'] = 0x3305;
  7434. t['invbullet'] = 0x25D8;
  7435. t['invcircle'] = 0x25D9;
  7436. t['invsmileface'] = 0x263B;
  7437. t['iocyrillic'] = 0x0451;
  7438. t['iogonek'] = 0x012F;
  7439. t['iota'] = 0x03B9;
  7440. t['iotadieresis'] = 0x03CA;
  7441. t['iotadieresistonos'] = 0x0390;
  7442. t['iotalatin'] = 0x0269;
  7443. t['iotatonos'] = 0x03AF;
  7444. t['iparen'] = 0x24A4;
  7445. t['irigurmukhi'] = 0x0A72;
  7446. t['ismallhiragana'] = 0x3043;
  7447. t['ismallkatakana'] = 0x30A3;
  7448. t['ismallkatakanahalfwidth'] = 0xFF68;
  7449. t['issharbengali'] = 0x09FA;
  7450. t['istroke'] = 0x0268;
  7451. t['isuperior'] = 0xF6ED;
  7452. t['iterationhiragana'] = 0x309D;
  7453. t['iterationkatakana'] = 0x30FD;
  7454. t['itilde'] = 0x0129;
  7455. t['itildebelow'] = 0x1E2D;
  7456. t['iubopomofo'] = 0x3129;
  7457. t['iucyrillic'] = 0x044E;
  7458. t['ivowelsignbengali'] = 0x09BF;
  7459. t['ivowelsigndeva'] = 0x093F;
  7460. t['ivowelsigngujarati'] = 0x0ABF;
  7461. t['izhitsacyrillic'] = 0x0475;
  7462. t['izhitsadblgravecyrillic'] = 0x0477;
  7463. t['j'] = 0x006A;
  7464. t['jaarmenian'] = 0x0571;
  7465. t['jabengali'] = 0x099C;
  7466. t['jadeva'] = 0x091C;
  7467. t['jagujarati'] = 0x0A9C;
  7468. t['jagurmukhi'] = 0x0A1C;
  7469. t['jbopomofo'] = 0x3110;
  7470. t['jcaron'] = 0x01F0;
  7471. t['jcircle'] = 0x24D9;
  7472. t['jcircumflex'] = 0x0135;
  7473. t['jcrossedtail'] = 0x029D;
  7474. t['jdotlessstroke'] = 0x025F;
  7475. t['jecyrillic'] = 0x0458;
  7476. t['jeemarabic'] = 0x062C;
  7477. t['jeemfinalarabic'] = 0xFE9E;
  7478. t['jeeminitialarabic'] = 0xFE9F;
  7479. t['jeemmedialarabic'] = 0xFEA0;
  7480. t['jeharabic'] = 0x0698;
  7481. t['jehfinalarabic'] = 0xFB8B;
  7482. t['jhabengali'] = 0x099D;
  7483. t['jhadeva'] = 0x091D;
  7484. t['jhagujarati'] = 0x0A9D;
  7485. t['jhagurmukhi'] = 0x0A1D;
  7486. t['jheharmenian'] = 0x057B;
  7487. t['jis'] = 0x3004;
  7488. t['jmonospace'] = 0xFF4A;
  7489. t['jparen'] = 0x24A5;
  7490. t['jsuperior'] = 0x02B2;
  7491. t['k'] = 0x006B;
  7492. t['kabashkircyrillic'] = 0x04A1;
  7493. t['kabengali'] = 0x0995;
  7494. t['kacute'] = 0x1E31;
  7495. t['kacyrillic'] = 0x043A;
  7496. t['kadescendercyrillic'] = 0x049B;
  7497. t['kadeva'] = 0x0915;
  7498. t['kaf'] = 0x05DB;
  7499. t['kafarabic'] = 0x0643;
  7500. t['kafdagesh'] = 0xFB3B;
  7501. t['kafdageshhebrew'] = 0xFB3B;
  7502. t['kaffinalarabic'] = 0xFEDA;
  7503. t['kafhebrew'] = 0x05DB;
  7504. t['kafinitialarabic'] = 0xFEDB;
  7505. t['kafmedialarabic'] = 0xFEDC;
  7506. t['kafrafehebrew'] = 0xFB4D;
  7507. t['kagujarati'] = 0x0A95;
  7508. t['kagurmukhi'] = 0x0A15;
  7509. t['kahiragana'] = 0x304B;
  7510. t['kahookcyrillic'] = 0x04C4;
  7511. t['kakatakana'] = 0x30AB;
  7512. t['kakatakanahalfwidth'] = 0xFF76;
  7513. t['kappa'] = 0x03BA;
  7514. t['kappasymbolgreek'] = 0x03F0;
  7515. t['kapyeounmieumkorean'] = 0x3171;
  7516. t['kapyeounphieuphkorean'] = 0x3184;
  7517. t['kapyeounpieupkorean'] = 0x3178;
  7518. t['kapyeounssangpieupkorean'] = 0x3179;
  7519. t['karoriisquare'] = 0x330D;
  7520. t['kashidaautoarabic'] = 0x0640;
  7521. t['kashidaautonosidebearingarabic'] = 0x0640;
  7522. t['kasmallkatakana'] = 0x30F5;
  7523. t['kasquare'] = 0x3384;
  7524. t['kasraarabic'] = 0x0650;
  7525. t['kasratanarabic'] = 0x064D;
  7526. t['kastrokecyrillic'] = 0x049F;
  7527. t['katahiraprolongmarkhalfwidth'] = 0xFF70;
  7528. t['kaverticalstrokecyrillic'] = 0x049D;
  7529. t['kbopomofo'] = 0x310E;
  7530. t['kcalsquare'] = 0x3389;
  7531. t['kcaron'] = 0x01E9;
  7532. t['kcedilla'] = 0x0137;
  7533. t['kcircle'] = 0x24DA;
  7534. t['kcommaaccent'] = 0x0137;
  7535. t['kdotbelow'] = 0x1E33;
  7536. t['keharmenian'] = 0x0584;
  7537. t['kehiragana'] = 0x3051;
  7538. t['kekatakana'] = 0x30B1;
  7539. t['kekatakanahalfwidth'] = 0xFF79;
  7540. t['kenarmenian'] = 0x056F;
  7541. t['kesmallkatakana'] = 0x30F6;
  7542. t['kgreenlandic'] = 0x0138;
  7543. t['khabengali'] = 0x0996;
  7544. t['khacyrillic'] = 0x0445;
  7545. t['khadeva'] = 0x0916;
  7546. t['khagujarati'] = 0x0A96;
  7547. t['khagurmukhi'] = 0x0A16;
  7548. t['khaharabic'] = 0x062E;
  7549. t['khahfinalarabic'] = 0xFEA6;
  7550. t['khahinitialarabic'] = 0xFEA7;
  7551. t['khahmedialarabic'] = 0xFEA8;
  7552. t['kheicoptic'] = 0x03E7;
  7553. t['khhadeva'] = 0x0959;
  7554. t['khhagurmukhi'] = 0x0A59;
  7555. t['khieukhacirclekorean'] = 0x3278;
  7556. t['khieukhaparenkorean'] = 0x3218;
  7557. t['khieukhcirclekorean'] = 0x326A;
  7558. t['khieukhkorean'] = 0x314B;
  7559. t['khieukhparenkorean'] = 0x320A;
  7560. t['khokhaithai'] = 0x0E02;
  7561. t['khokhonthai'] = 0x0E05;
  7562. t['khokhuatthai'] = 0x0E03;
  7563. t['khokhwaithai'] = 0x0E04;
  7564. t['khomutthai'] = 0x0E5B;
  7565. t['khook'] = 0x0199;
  7566. t['khorakhangthai'] = 0x0E06;
  7567. t['khzsquare'] = 0x3391;
  7568. t['kihiragana'] = 0x304D;
  7569. t['kikatakana'] = 0x30AD;
  7570. t['kikatakanahalfwidth'] = 0xFF77;
  7571. t['kiroguramusquare'] = 0x3315;
  7572. t['kiromeetorusquare'] = 0x3316;
  7573. t['kirosquare'] = 0x3314;
  7574. t['kiyeokacirclekorean'] = 0x326E;
  7575. t['kiyeokaparenkorean'] = 0x320E;
  7576. t['kiyeokcirclekorean'] = 0x3260;
  7577. t['kiyeokkorean'] = 0x3131;
  7578. t['kiyeokparenkorean'] = 0x3200;
  7579. t['kiyeoksioskorean'] = 0x3133;
  7580. t['kjecyrillic'] = 0x045C;
  7581. t['klinebelow'] = 0x1E35;
  7582. t['klsquare'] = 0x3398;
  7583. t['kmcubedsquare'] = 0x33A6;
  7584. t['kmonospace'] = 0xFF4B;
  7585. t['kmsquaredsquare'] = 0x33A2;
  7586. t['kohiragana'] = 0x3053;
  7587. t['kohmsquare'] = 0x33C0;
  7588. t['kokaithai'] = 0x0E01;
  7589. t['kokatakana'] = 0x30B3;
  7590. t['kokatakanahalfwidth'] = 0xFF7A;
  7591. t['kooposquare'] = 0x331E;
  7592. t['koppacyrillic'] = 0x0481;
  7593. t['koreanstandardsymbol'] = 0x327F;
  7594. t['koroniscmb'] = 0x0343;
  7595. t['kparen'] = 0x24A6;
  7596. t['kpasquare'] = 0x33AA;
  7597. t['ksicyrillic'] = 0x046F;
  7598. t['ktsquare'] = 0x33CF;
  7599. t['kturned'] = 0x029E;
  7600. t['kuhiragana'] = 0x304F;
  7601. t['kukatakana'] = 0x30AF;
  7602. t['kukatakanahalfwidth'] = 0xFF78;
  7603. t['kvsquare'] = 0x33B8;
  7604. t['kwsquare'] = 0x33BE;
  7605. t['l'] = 0x006C;
  7606. t['labengali'] = 0x09B2;
  7607. t['lacute'] = 0x013A;
  7608. t['ladeva'] = 0x0932;
  7609. t['lagujarati'] = 0x0AB2;
  7610. t['lagurmukhi'] = 0x0A32;
  7611. t['lakkhangyaothai'] = 0x0E45;
  7612. t['lamaleffinalarabic'] = 0xFEFC;
  7613. t['lamalefhamzaabovefinalarabic'] = 0xFEF8;
  7614. t['lamalefhamzaaboveisolatedarabic'] = 0xFEF7;
  7615. t['lamalefhamzabelowfinalarabic'] = 0xFEFA;
  7616. t['lamalefhamzabelowisolatedarabic'] = 0xFEF9;
  7617. t['lamalefisolatedarabic'] = 0xFEFB;
  7618. t['lamalefmaddaabovefinalarabic'] = 0xFEF6;
  7619. t['lamalefmaddaaboveisolatedarabic'] = 0xFEF5;
  7620. t['lamarabic'] = 0x0644;
  7621. t['lambda'] = 0x03BB;
  7622. t['lambdastroke'] = 0x019B;
  7623. t['lamed'] = 0x05DC;
  7624. t['lameddagesh'] = 0xFB3C;
  7625. t['lameddageshhebrew'] = 0xFB3C;
  7626. t['lamedhebrew'] = 0x05DC;
  7627. t['lamfinalarabic'] = 0xFEDE;
  7628. t['lamhahinitialarabic'] = 0xFCCA;
  7629. t['laminitialarabic'] = 0xFEDF;
  7630. t['lamjeeminitialarabic'] = 0xFCC9;
  7631. t['lamkhahinitialarabic'] = 0xFCCB;
  7632. t['lamlamhehisolatedarabic'] = 0xFDF2;
  7633. t['lammedialarabic'] = 0xFEE0;
  7634. t['lammeemhahinitialarabic'] = 0xFD88;
  7635. t['lammeeminitialarabic'] = 0xFCCC;
  7636. t['largecircle'] = 0x25EF;
  7637. t['lbar'] = 0x019A;
  7638. t['lbelt'] = 0x026C;
  7639. t['lbopomofo'] = 0x310C;
  7640. t['lcaron'] = 0x013E;
  7641. t['lcedilla'] = 0x013C;
  7642. t['lcircle'] = 0x24DB;
  7643. t['lcircumflexbelow'] = 0x1E3D;
  7644. t['lcommaaccent'] = 0x013C;
  7645. t['ldot'] = 0x0140;
  7646. t['ldotaccent'] = 0x0140;
  7647. t['ldotbelow'] = 0x1E37;
  7648. t['ldotbelowmacron'] = 0x1E39;
  7649. t['leftangleabovecmb'] = 0x031A;
  7650. t['lefttackbelowcmb'] = 0x0318;
  7651. t['less'] = 0x003C;
  7652. t['lessequal'] = 0x2264;
  7653. t['lessequalorgreater'] = 0x22DA;
  7654. t['lessmonospace'] = 0xFF1C;
  7655. t['lessorequivalent'] = 0x2272;
  7656. t['lessorgreater'] = 0x2276;
  7657. t['lessoverequal'] = 0x2266;
  7658. t['lesssmall'] = 0xFE64;
  7659. t['lezh'] = 0x026E;
  7660. t['lfblock'] = 0x258C;
  7661. t['lhookretroflex'] = 0x026D;
  7662. t['lira'] = 0x20A4;
  7663. t['liwnarmenian'] = 0x056C;
  7664. t['lj'] = 0x01C9;
  7665. t['ljecyrillic'] = 0x0459;
  7666. t['ll'] = 0xF6C0;
  7667. t['lladeva'] = 0x0933;
  7668. t['llagujarati'] = 0x0AB3;
  7669. t['llinebelow'] = 0x1E3B;
  7670. t['llladeva'] = 0x0934;
  7671. t['llvocalicbengali'] = 0x09E1;
  7672. t['llvocalicdeva'] = 0x0961;
  7673. t['llvocalicvowelsignbengali'] = 0x09E3;
  7674. t['llvocalicvowelsigndeva'] = 0x0963;
  7675. t['lmiddletilde'] = 0x026B;
  7676. t['lmonospace'] = 0xFF4C;
  7677. t['lmsquare'] = 0x33D0;
  7678. t['lochulathai'] = 0x0E2C;
  7679. t['logicaland'] = 0x2227;
  7680. t['logicalnot'] = 0x00AC;
  7681. t['logicalnotreversed'] = 0x2310;
  7682. t['logicalor'] = 0x2228;
  7683. t['lolingthai'] = 0x0E25;
  7684. t['longs'] = 0x017F;
  7685. t['lowlinecenterline'] = 0xFE4E;
  7686. t['lowlinecmb'] = 0x0332;
  7687. t['lowlinedashed'] = 0xFE4D;
  7688. t['lozenge'] = 0x25CA;
  7689. t['lparen'] = 0x24A7;
  7690. t['lslash'] = 0x0142;
  7691. t['lsquare'] = 0x2113;
  7692. t['lsuperior'] = 0xF6EE;
  7693. t['ltshade'] = 0x2591;
  7694. t['luthai'] = 0x0E26;
  7695. t['lvocalicbengali'] = 0x098C;
  7696. t['lvocalicdeva'] = 0x090C;
  7697. t['lvocalicvowelsignbengali'] = 0x09E2;
  7698. t['lvocalicvowelsigndeva'] = 0x0962;
  7699. t['lxsquare'] = 0x33D3;
  7700. t['m'] = 0x006D;
  7701. t['mabengali'] = 0x09AE;
  7702. t['macron'] = 0x00AF;
  7703. t['macronbelowcmb'] = 0x0331;
  7704. t['macroncmb'] = 0x0304;
  7705. t['macronlowmod'] = 0x02CD;
  7706. t['macronmonospace'] = 0xFFE3;
  7707. t['macute'] = 0x1E3F;
  7708. t['madeva'] = 0x092E;
  7709. t['magujarati'] = 0x0AAE;
  7710. t['magurmukhi'] = 0x0A2E;
  7711. t['mahapakhhebrew'] = 0x05A4;
  7712. t['mahapakhlefthebrew'] = 0x05A4;
  7713. t['mahiragana'] = 0x307E;
  7714. t['maichattawalowleftthai'] = 0xF895;
  7715. t['maichattawalowrightthai'] = 0xF894;
  7716. t['maichattawathai'] = 0x0E4B;
  7717. t['maichattawaupperleftthai'] = 0xF893;
  7718. t['maieklowleftthai'] = 0xF88C;
  7719. t['maieklowrightthai'] = 0xF88B;
  7720. t['maiekthai'] = 0x0E48;
  7721. t['maiekupperleftthai'] = 0xF88A;
  7722. t['maihanakatleftthai'] = 0xF884;
  7723. t['maihanakatthai'] = 0x0E31;
  7724. t['maitaikhuleftthai'] = 0xF889;
  7725. t['maitaikhuthai'] = 0x0E47;
  7726. t['maitholowleftthai'] = 0xF88F;
  7727. t['maitholowrightthai'] = 0xF88E;
  7728. t['maithothai'] = 0x0E49;
  7729. t['maithoupperleftthai'] = 0xF88D;
  7730. t['maitrilowleftthai'] = 0xF892;
  7731. t['maitrilowrightthai'] = 0xF891;
  7732. t['maitrithai'] = 0x0E4A;
  7733. t['maitriupperleftthai'] = 0xF890;
  7734. t['maiyamokthai'] = 0x0E46;
  7735. t['makatakana'] = 0x30DE;
  7736. t['makatakanahalfwidth'] = 0xFF8F;
  7737. t['male'] = 0x2642;
  7738. t['mansyonsquare'] = 0x3347;
  7739. t['maqafhebrew'] = 0x05BE;
  7740. t['mars'] = 0x2642;
  7741. t['masoracirclehebrew'] = 0x05AF;
  7742. t['masquare'] = 0x3383;
  7743. t['mbopomofo'] = 0x3107;
  7744. t['mbsquare'] = 0x33D4;
  7745. t['mcircle'] = 0x24DC;
  7746. t['mcubedsquare'] = 0x33A5;
  7747. t['mdotaccent'] = 0x1E41;
  7748. t['mdotbelow'] = 0x1E43;
  7749. t['meemarabic'] = 0x0645;
  7750. t['meemfinalarabic'] = 0xFEE2;
  7751. t['meeminitialarabic'] = 0xFEE3;
  7752. t['meemmedialarabic'] = 0xFEE4;
  7753. t['meemmeeminitialarabic'] = 0xFCD1;
  7754. t['meemmeemisolatedarabic'] = 0xFC48;
  7755. t['meetorusquare'] = 0x334D;
  7756. t['mehiragana'] = 0x3081;
  7757. t['meizierasquare'] = 0x337E;
  7758. t['mekatakana'] = 0x30E1;
  7759. t['mekatakanahalfwidth'] = 0xFF92;
  7760. t['mem'] = 0x05DE;
  7761. t['memdagesh'] = 0xFB3E;
  7762. t['memdageshhebrew'] = 0xFB3E;
  7763. t['memhebrew'] = 0x05DE;
  7764. t['menarmenian'] = 0x0574;
  7765. t['merkhahebrew'] = 0x05A5;
  7766. t['merkhakefulahebrew'] = 0x05A6;
  7767. t['merkhakefulalefthebrew'] = 0x05A6;
  7768. t['merkhalefthebrew'] = 0x05A5;
  7769. t['mhook'] = 0x0271;
  7770. t['mhzsquare'] = 0x3392;
  7771. t['middledotkatakanahalfwidth'] = 0xFF65;
  7772. t['middot'] = 0x00B7;
  7773. t['mieumacirclekorean'] = 0x3272;
  7774. t['mieumaparenkorean'] = 0x3212;
  7775. t['mieumcirclekorean'] = 0x3264;
  7776. t['mieumkorean'] = 0x3141;
  7777. t['mieumpansioskorean'] = 0x3170;
  7778. t['mieumparenkorean'] = 0x3204;
  7779. t['mieumpieupkorean'] = 0x316E;
  7780. t['mieumsioskorean'] = 0x316F;
  7781. t['mihiragana'] = 0x307F;
  7782. t['mikatakana'] = 0x30DF;
  7783. t['mikatakanahalfwidth'] = 0xFF90;
  7784. t['minus'] = 0x2212;
  7785. t['minusbelowcmb'] = 0x0320;
  7786. t['minuscircle'] = 0x2296;
  7787. t['minusmod'] = 0x02D7;
  7788. t['minusplus'] = 0x2213;
  7789. t['minute'] = 0x2032;
  7790. t['miribaarusquare'] = 0x334A;
  7791. t['mirisquare'] = 0x3349;
  7792. t['mlonglegturned'] = 0x0270;
  7793. t['mlsquare'] = 0x3396;
  7794. t['mmcubedsquare'] = 0x33A3;
  7795. t['mmonospace'] = 0xFF4D;
  7796. t['mmsquaredsquare'] = 0x339F;
  7797. t['mohiragana'] = 0x3082;
  7798. t['mohmsquare'] = 0x33C1;
  7799. t['mokatakana'] = 0x30E2;
  7800. t['mokatakanahalfwidth'] = 0xFF93;
  7801. t['molsquare'] = 0x33D6;
  7802. t['momathai'] = 0x0E21;
  7803. t['moverssquare'] = 0x33A7;
  7804. t['moverssquaredsquare'] = 0x33A8;
  7805. t['mparen'] = 0x24A8;
  7806. t['mpasquare'] = 0x33AB;
  7807. t['mssquare'] = 0x33B3;
  7808. t['msuperior'] = 0xF6EF;
  7809. t['mturned'] = 0x026F;
  7810. t['mu'] = 0x00B5;
  7811. t['mu1'] = 0x00B5;
  7812. t['muasquare'] = 0x3382;
  7813. t['muchgreater'] = 0x226B;
  7814. t['muchless'] = 0x226A;
  7815. t['mufsquare'] = 0x338C;
  7816. t['mugreek'] = 0x03BC;
  7817. t['mugsquare'] = 0x338D;
  7818. t['muhiragana'] = 0x3080;
  7819. t['mukatakana'] = 0x30E0;
  7820. t['mukatakanahalfwidth'] = 0xFF91;
  7821. t['mulsquare'] = 0x3395;
  7822. t['multiply'] = 0x00D7;
  7823. t['mumsquare'] = 0x339B;
  7824. t['munahhebrew'] = 0x05A3;
  7825. t['munahlefthebrew'] = 0x05A3;
  7826. t['musicalnote'] = 0x266A;
  7827. t['musicalnotedbl'] = 0x266B;
  7828. t['musicflatsign'] = 0x266D;
  7829. t['musicsharpsign'] = 0x266F;
  7830. t['mussquare'] = 0x33B2;
  7831. t['muvsquare'] = 0x33B6;
  7832. t['muwsquare'] = 0x33BC;
  7833. t['mvmegasquare'] = 0x33B9;
  7834. t['mvsquare'] = 0x33B7;
  7835. t['mwmegasquare'] = 0x33BF;
  7836. t['mwsquare'] = 0x33BD;
  7837. t['n'] = 0x006E;
  7838. t['nabengali'] = 0x09A8;
  7839. t['nabla'] = 0x2207;
  7840. t['nacute'] = 0x0144;
  7841. t['nadeva'] = 0x0928;
  7842. t['nagujarati'] = 0x0AA8;
  7843. t['nagurmukhi'] = 0x0A28;
  7844. t['nahiragana'] = 0x306A;
  7845. t['nakatakana'] = 0x30CA;
  7846. t['nakatakanahalfwidth'] = 0xFF85;
  7847. t['napostrophe'] = 0x0149;
  7848. t['nasquare'] = 0x3381;
  7849. t['nbopomofo'] = 0x310B;
  7850. t['nbspace'] = 0x00A0;
  7851. t['ncaron'] = 0x0148;
  7852. t['ncedilla'] = 0x0146;
  7853. t['ncircle'] = 0x24DD;
  7854. t['ncircumflexbelow'] = 0x1E4B;
  7855. t['ncommaaccent'] = 0x0146;
  7856. t['ndotaccent'] = 0x1E45;
  7857. t['ndotbelow'] = 0x1E47;
  7858. t['nehiragana'] = 0x306D;
  7859. t['nekatakana'] = 0x30CD;
  7860. t['nekatakanahalfwidth'] = 0xFF88;
  7861. t['newsheqelsign'] = 0x20AA;
  7862. t['nfsquare'] = 0x338B;
  7863. t['ngabengali'] = 0x0999;
  7864. t['ngadeva'] = 0x0919;
  7865. t['ngagujarati'] = 0x0A99;
  7866. t['ngagurmukhi'] = 0x0A19;
  7867. t['ngonguthai'] = 0x0E07;
  7868. t['nhiragana'] = 0x3093;
  7869. t['nhookleft'] = 0x0272;
  7870. t['nhookretroflex'] = 0x0273;
  7871. t['nieunacirclekorean'] = 0x326F;
  7872. t['nieunaparenkorean'] = 0x320F;
  7873. t['nieuncieuckorean'] = 0x3135;
  7874. t['nieuncirclekorean'] = 0x3261;
  7875. t['nieunhieuhkorean'] = 0x3136;
  7876. t['nieunkorean'] = 0x3134;
  7877. t['nieunpansioskorean'] = 0x3168;
  7878. t['nieunparenkorean'] = 0x3201;
  7879. t['nieunsioskorean'] = 0x3167;
  7880. t['nieuntikeutkorean'] = 0x3166;
  7881. t['nihiragana'] = 0x306B;
  7882. t['nikatakana'] = 0x30CB;
  7883. t['nikatakanahalfwidth'] = 0xFF86;
  7884. t['nikhahitleftthai'] = 0xF899;
  7885. t['nikhahitthai'] = 0x0E4D;
  7886. t['nine'] = 0x0039;
  7887. t['ninearabic'] = 0x0669;
  7888. t['ninebengali'] = 0x09EF;
  7889. t['ninecircle'] = 0x2468;
  7890. t['ninecircleinversesansserif'] = 0x2792;
  7891. t['ninedeva'] = 0x096F;
  7892. t['ninegujarati'] = 0x0AEF;
  7893. t['ninegurmukhi'] = 0x0A6F;
  7894. t['ninehackarabic'] = 0x0669;
  7895. t['ninehangzhou'] = 0x3029;
  7896. t['nineideographicparen'] = 0x3228;
  7897. t['nineinferior'] = 0x2089;
  7898. t['ninemonospace'] = 0xFF19;
  7899. t['nineoldstyle'] = 0xF739;
  7900. t['nineparen'] = 0x247C;
  7901. t['nineperiod'] = 0x2490;
  7902. t['ninepersian'] = 0x06F9;
  7903. t['nineroman'] = 0x2178;
  7904. t['ninesuperior'] = 0x2079;
  7905. t['nineteencircle'] = 0x2472;
  7906. t['nineteenparen'] = 0x2486;
  7907. t['nineteenperiod'] = 0x249A;
  7908. t['ninethai'] = 0x0E59;
  7909. t['nj'] = 0x01CC;
  7910. t['njecyrillic'] = 0x045A;
  7911. t['nkatakana'] = 0x30F3;
  7912. t['nkatakanahalfwidth'] = 0xFF9D;
  7913. t['nlegrightlong'] = 0x019E;
  7914. t['nlinebelow'] = 0x1E49;
  7915. t['nmonospace'] = 0xFF4E;
  7916. t['nmsquare'] = 0x339A;
  7917. t['nnabengali'] = 0x09A3;
  7918. t['nnadeva'] = 0x0923;
  7919. t['nnagujarati'] = 0x0AA3;
  7920. t['nnagurmukhi'] = 0x0A23;
  7921. t['nnnadeva'] = 0x0929;
  7922. t['nohiragana'] = 0x306E;
  7923. t['nokatakana'] = 0x30CE;
  7924. t['nokatakanahalfwidth'] = 0xFF89;
  7925. t['nonbreakingspace'] = 0x00A0;
  7926. t['nonenthai'] = 0x0E13;
  7927. t['nonuthai'] = 0x0E19;
  7928. t['noonarabic'] = 0x0646;
  7929. t['noonfinalarabic'] = 0xFEE6;
  7930. t['noonghunnaarabic'] = 0x06BA;
  7931. t['noonghunnafinalarabic'] = 0xFB9F;
  7932. t['nooninitialarabic'] = 0xFEE7;
  7933. t['noonjeeminitialarabic'] = 0xFCD2;
  7934. t['noonjeemisolatedarabic'] = 0xFC4B;
  7935. t['noonmedialarabic'] = 0xFEE8;
  7936. t['noonmeeminitialarabic'] = 0xFCD5;
  7937. t['noonmeemisolatedarabic'] = 0xFC4E;
  7938. t['noonnoonfinalarabic'] = 0xFC8D;
  7939. t['notcontains'] = 0x220C;
  7940. t['notelement'] = 0x2209;
  7941. t['notelementof'] = 0x2209;
  7942. t['notequal'] = 0x2260;
  7943. t['notgreater'] = 0x226F;
  7944. t['notgreaternorequal'] = 0x2271;
  7945. t['notgreaternorless'] = 0x2279;
  7946. t['notidentical'] = 0x2262;
  7947. t['notless'] = 0x226E;
  7948. t['notlessnorequal'] = 0x2270;
  7949. t['notparallel'] = 0x2226;
  7950. t['notprecedes'] = 0x2280;
  7951. t['notsubset'] = 0x2284;
  7952. t['notsucceeds'] = 0x2281;
  7953. t['notsuperset'] = 0x2285;
  7954. t['nowarmenian'] = 0x0576;
  7955. t['nparen'] = 0x24A9;
  7956. t['nssquare'] = 0x33B1;
  7957. t['nsuperior'] = 0x207F;
  7958. t['ntilde'] = 0x00F1;
  7959. t['nu'] = 0x03BD;
  7960. t['nuhiragana'] = 0x306C;
  7961. t['nukatakana'] = 0x30CC;
  7962. t['nukatakanahalfwidth'] = 0xFF87;
  7963. t['nuktabengali'] = 0x09BC;
  7964. t['nuktadeva'] = 0x093C;
  7965. t['nuktagujarati'] = 0x0ABC;
  7966. t['nuktagurmukhi'] = 0x0A3C;
  7967. t['numbersign'] = 0x0023;
  7968. t['numbersignmonospace'] = 0xFF03;
  7969. t['numbersignsmall'] = 0xFE5F;
  7970. t['numeralsigngreek'] = 0x0374;
  7971. t['numeralsignlowergreek'] = 0x0375;
  7972. t['numero'] = 0x2116;
  7973. t['nun'] = 0x05E0;
  7974. t['nundagesh'] = 0xFB40;
  7975. t['nundageshhebrew'] = 0xFB40;
  7976. t['nunhebrew'] = 0x05E0;
  7977. t['nvsquare'] = 0x33B5;
  7978. t['nwsquare'] = 0x33BB;
  7979. t['nyabengali'] = 0x099E;
  7980. t['nyadeva'] = 0x091E;
  7981. t['nyagujarati'] = 0x0A9E;
  7982. t['nyagurmukhi'] = 0x0A1E;
  7983. t['o'] = 0x006F;
  7984. t['oacute'] = 0x00F3;
  7985. t['oangthai'] = 0x0E2D;
  7986. t['obarred'] = 0x0275;
  7987. t['obarredcyrillic'] = 0x04E9;
  7988. t['obarreddieresiscyrillic'] = 0x04EB;
  7989. t['obengali'] = 0x0993;
  7990. t['obopomofo'] = 0x311B;
  7991. t['obreve'] = 0x014F;
  7992. t['ocandradeva'] = 0x0911;
  7993. t['ocandragujarati'] = 0x0A91;
  7994. t['ocandravowelsigndeva'] = 0x0949;
  7995. t['ocandravowelsigngujarati'] = 0x0AC9;
  7996. t['ocaron'] = 0x01D2;
  7997. t['ocircle'] = 0x24DE;
  7998. t['ocircumflex'] = 0x00F4;
  7999. t['ocircumflexacute'] = 0x1ED1;
  8000. t['ocircumflexdotbelow'] = 0x1ED9;
  8001. t['ocircumflexgrave'] = 0x1ED3;
  8002. t['ocircumflexhookabove'] = 0x1ED5;
  8003. t['ocircumflextilde'] = 0x1ED7;
  8004. t['ocyrillic'] = 0x043E;
  8005. t['odblacute'] = 0x0151;
  8006. t['odblgrave'] = 0x020D;
  8007. t['odeva'] = 0x0913;
  8008. t['odieresis'] = 0x00F6;
  8009. t['odieresiscyrillic'] = 0x04E7;
  8010. t['odotbelow'] = 0x1ECD;
  8011. t['oe'] = 0x0153;
  8012. t['oekorean'] = 0x315A;
  8013. t['ogonek'] = 0x02DB;
  8014. t['ogonekcmb'] = 0x0328;
  8015. t['ograve'] = 0x00F2;
  8016. t['ogujarati'] = 0x0A93;
  8017. t['oharmenian'] = 0x0585;
  8018. t['ohiragana'] = 0x304A;
  8019. t['ohookabove'] = 0x1ECF;
  8020. t['ohorn'] = 0x01A1;
  8021. t['ohornacute'] = 0x1EDB;
  8022. t['ohorndotbelow'] = 0x1EE3;
  8023. t['ohorngrave'] = 0x1EDD;
  8024. t['ohornhookabove'] = 0x1EDF;
  8025. t['ohorntilde'] = 0x1EE1;
  8026. t['ohungarumlaut'] = 0x0151;
  8027. t['oi'] = 0x01A3;
  8028. t['oinvertedbreve'] = 0x020F;
  8029. t['okatakana'] = 0x30AA;
  8030. t['okatakanahalfwidth'] = 0xFF75;
  8031. t['okorean'] = 0x3157;
  8032. t['olehebrew'] = 0x05AB;
  8033. t['omacron'] = 0x014D;
  8034. t['omacronacute'] = 0x1E53;
  8035. t['omacrongrave'] = 0x1E51;
  8036. t['omdeva'] = 0x0950;
  8037. t['omega'] = 0x03C9;
  8038. t['omega1'] = 0x03D6;
  8039. t['omegacyrillic'] = 0x0461;
  8040. t['omegalatinclosed'] = 0x0277;
  8041. t['omegaroundcyrillic'] = 0x047B;
  8042. t['omegatitlocyrillic'] = 0x047D;
  8043. t['omegatonos'] = 0x03CE;
  8044. t['omgujarati'] = 0x0AD0;
  8045. t['omicron'] = 0x03BF;
  8046. t['omicrontonos'] = 0x03CC;
  8047. t['omonospace'] = 0xFF4F;
  8048. t['one'] = 0x0031;
  8049. t['onearabic'] = 0x0661;
  8050. t['onebengali'] = 0x09E7;
  8051. t['onecircle'] = 0x2460;
  8052. t['onecircleinversesansserif'] = 0x278A;
  8053. t['onedeva'] = 0x0967;
  8054. t['onedotenleader'] = 0x2024;
  8055. t['oneeighth'] = 0x215B;
  8056. t['onefitted'] = 0xF6DC;
  8057. t['onegujarati'] = 0x0AE7;
  8058. t['onegurmukhi'] = 0x0A67;
  8059. t['onehackarabic'] = 0x0661;
  8060. t['onehalf'] = 0x00BD;
  8061. t['onehangzhou'] = 0x3021;
  8062. t['oneideographicparen'] = 0x3220;
  8063. t['oneinferior'] = 0x2081;
  8064. t['onemonospace'] = 0xFF11;
  8065. t['onenumeratorbengali'] = 0x09F4;
  8066. t['oneoldstyle'] = 0xF731;
  8067. t['oneparen'] = 0x2474;
  8068. t['oneperiod'] = 0x2488;
  8069. t['onepersian'] = 0x06F1;
  8070. t['onequarter'] = 0x00BC;
  8071. t['oneroman'] = 0x2170;
  8072. t['onesuperior'] = 0x00B9;
  8073. t['onethai'] = 0x0E51;
  8074. t['onethird'] = 0x2153;
  8075. t['oogonek'] = 0x01EB;
  8076. t['oogonekmacron'] = 0x01ED;
  8077. t['oogurmukhi'] = 0x0A13;
  8078. t['oomatragurmukhi'] = 0x0A4B;
  8079. t['oopen'] = 0x0254;
  8080. t['oparen'] = 0x24AA;
  8081. t['openbullet'] = 0x25E6;
  8082. t['option'] = 0x2325;
  8083. t['ordfeminine'] = 0x00AA;
  8084. t['ordmasculine'] = 0x00BA;
  8085. t['orthogonal'] = 0x221F;
  8086. t['oshortdeva'] = 0x0912;
  8087. t['oshortvowelsigndeva'] = 0x094A;
  8088. t['oslash'] = 0x00F8;
  8089. t['oslashacute'] = 0x01FF;
  8090. t['osmallhiragana'] = 0x3049;
  8091. t['osmallkatakana'] = 0x30A9;
  8092. t['osmallkatakanahalfwidth'] = 0xFF6B;
  8093. t['ostrokeacute'] = 0x01FF;
  8094. t['osuperior'] = 0xF6F0;
  8095. t['otcyrillic'] = 0x047F;
  8096. t['otilde'] = 0x00F5;
  8097. t['otildeacute'] = 0x1E4D;
  8098. t['otildedieresis'] = 0x1E4F;
  8099. t['oubopomofo'] = 0x3121;
  8100. t['overline'] = 0x203E;
  8101. t['overlinecenterline'] = 0xFE4A;
  8102. t['overlinecmb'] = 0x0305;
  8103. t['overlinedashed'] = 0xFE49;
  8104. t['overlinedblwavy'] = 0xFE4C;
  8105. t['overlinewavy'] = 0xFE4B;
  8106. t['overscore'] = 0x00AF;
  8107. t['ovowelsignbengali'] = 0x09CB;
  8108. t['ovowelsigndeva'] = 0x094B;
  8109. t['ovowelsigngujarati'] = 0x0ACB;
  8110. t['p'] = 0x0070;
  8111. t['paampssquare'] = 0x3380;
  8112. t['paasentosquare'] = 0x332B;
  8113. t['pabengali'] = 0x09AA;
  8114. t['pacute'] = 0x1E55;
  8115. t['padeva'] = 0x092A;
  8116. t['pagedown'] = 0x21DF;
  8117. t['pageup'] = 0x21DE;
  8118. t['pagujarati'] = 0x0AAA;
  8119. t['pagurmukhi'] = 0x0A2A;
  8120. t['pahiragana'] = 0x3071;
  8121. t['paiyannoithai'] = 0x0E2F;
  8122. t['pakatakana'] = 0x30D1;
  8123. t['palatalizationcyrilliccmb'] = 0x0484;
  8124. t['palochkacyrillic'] = 0x04C0;
  8125. t['pansioskorean'] = 0x317F;
  8126. t['paragraph'] = 0x00B6;
  8127. t['parallel'] = 0x2225;
  8128. t['parenleft'] = 0x0028;
  8129. t['parenleftaltonearabic'] = 0xFD3E;
  8130. t['parenleftbt'] = 0xF8ED;
  8131. t['parenleftex'] = 0xF8EC;
  8132. t['parenleftinferior'] = 0x208D;
  8133. t['parenleftmonospace'] = 0xFF08;
  8134. t['parenleftsmall'] = 0xFE59;
  8135. t['parenleftsuperior'] = 0x207D;
  8136. t['parenlefttp'] = 0xF8EB;
  8137. t['parenleftvertical'] = 0xFE35;
  8138. t['parenright'] = 0x0029;
  8139. t['parenrightaltonearabic'] = 0xFD3F;
  8140. t['parenrightbt'] = 0xF8F8;
  8141. t['parenrightex'] = 0xF8F7;
  8142. t['parenrightinferior'] = 0x208E;
  8143. t['parenrightmonospace'] = 0xFF09;
  8144. t['parenrightsmall'] = 0xFE5A;
  8145. t['parenrightsuperior'] = 0x207E;
  8146. t['parenrighttp'] = 0xF8F6;
  8147. t['parenrightvertical'] = 0xFE36;
  8148. t['partialdiff'] = 0x2202;
  8149. t['paseqhebrew'] = 0x05C0;
  8150. t['pashtahebrew'] = 0x0599;
  8151. t['pasquare'] = 0x33A9;
  8152. t['patah'] = 0x05B7;
  8153. t['patah11'] = 0x05B7;
  8154. t['patah1d'] = 0x05B7;
  8155. t['patah2a'] = 0x05B7;
  8156. t['patahhebrew'] = 0x05B7;
  8157. t['patahnarrowhebrew'] = 0x05B7;
  8158. t['patahquarterhebrew'] = 0x05B7;
  8159. t['patahwidehebrew'] = 0x05B7;
  8160. t['pazerhebrew'] = 0x05A1;
  8161. t['pbopomofo'] = 0x3106;
  8162. t['pcircle'] = 0x24DF;
  8163. t['pdotaccent'] = 0x1E57;
  8164. t['pe'] = 0x05E4;
  8165. t['pecyrillic'] = 0x043F;
  8166. t['pedagesh'] = 0xFB44;
  8167. t['pedageshhebrew'] = 0xFB44;
  8168. t['peezisquare'] = 0x333B;
  8169. t['pefinaldageshhebrew'] = 0xFB43;
  8170. t['peharabic'] = 0x067E;
  8171. t['peharmenian'] = 0x057A;
  8172. t['pehebrew'] = 0x05E4;
  8173. t['pehfinalarabic'] = 0xFB57;
  8174. t['pehinitialarabic'] = 0xFB58;
  8175. t['pehiragana'] = 0x307A;
  8176. t['pehmedialarabic'] = 0xFB59;
  8177. t['pekatakana'] = 0x30DA;
  8178. t['pemiddlehookcyrillic'] = 0x04A7;
  8179. t['perafehebrew'] = 0xFB4E;
  8180. t['percent'] = 0x0025;
  8181. t['percentarabic'] = 0x066A;
  8182. t['percentmonospace'] = 0xFF05;
  8183. t['percentsmall'] = 0xFE6A;
  8184. t['period'] = 0x002E;
  8185. t['periodarmenian'] = 0x0589;
  8186. t['periodcentered'] = 0x00B7;
  8187. t['periodhalfwidth'] = 0xFF61;
  8188. t['periodinferior'] = 0xF6E7;
  8189. t['periodmonospace'] = 0xFF0E;
  8190. t['periodsmall'] = 0xFE52;
  8191. t['periodsuperior'] = 0xF6E8;
  8192. t['perispomenigreekcmb'] = 0x0342;
  8193. t['perpendicular'] = 0x22A5;
  8194. t['perthousand'] = 0x2030;
  8195. t['peseta'] = 0x20A7;
  8196. t['pfsquare'] = 0x338A;
  8197. t['phabengali'] = 0x09AB;
  8198. t['phadeva'] = 0x092B;
  8199. t['phagujarati'] = 0x0AAB;
  8200. t['phagurmukhi'] = 0x0A2B;
  8201. t['phi'] = 0x03C6;
  8202. t['phi1'] = 0x03D5;
  8203. t['phieuphacirclekorean'] = 0x327A;
  8204. t['phieuphaparenkorean'] = 0x321A;
  8205. t['phieuphcirclekorean'] = 0x326C;
  8206. t['phieuphkorean'] = 0x314D;
  8207. t['phieuphparenkorean'] = 0x320C;
  8208. t['philatin'] = 0x0278;
  8209. t['phinthuthai'] = 0x0E3A;
  8210. t['phisymbolgreek'] = 0x03D5;
  8211. t['phook'] = 0x01A5;
  8212. t['phophanthai'] = 0x0E1E;
  8213. t['phophungthai'] = 0x0E1C;
  8214. t['phosamphaothai'] = 0x0E20;
  8215. t['pi'] = 0x03C0;
  8216. t['pieupacirclekorean'] = 0x3273;
  8217. t['pieupaparenkorean'] = 0x3213;
  8218. t['pieupcieuckorean'] = 0x3176;
  8219. t['pieupcirclekorean'] = 0x3265;
  8220. t['pieupkiyeokkorean'] = 0x3172;
  8221. t['pieupkorean'] = 0x3142;
  8222. t['pieupparenkorean'] = 0x3205;
  8223. t['pieupsioskiyeokkorean'] = 0x3174;
  8224. t['pieupsioskorean'] = 0x3144;
  8225. t['pieupsiostikeutkorean'] = 0x3175;
  8226. t['pieupthieuthkorean'] = 0x3177;
  8227. t['pieuptikeutkorean'] = 0x3173;
  8228. t['pihiragana'] = 0x3074;
  8229. t['pikatakana'] = 0x30D4;
  8230. t['pisymbolgreek'] = 0x03D6;
  8231. t['piwrarmenian'] = 0x0583;
  8232. t['plus'] = 0x002B;
  8233. t['plusbelowcmb'] = 0x031F;
  8234. t['pluscircle'] = 0x2295;
  8235. t['plusminus'] = 0x00B1;
  8236. t['plusmod'] = 0x02D6;
  8237. t['plusmonospace'] = 0xFF0B;
  8238. t['plussmall'] = 0xFE62;
  8239. t['plussuperior'] = 0x207A;
  8240. t['pmonospace'] = 0xFF50;
  8241. t['pmsquare'] = 0x33D8;
  8242. t['pohiragana'] = 0x307D;
  8243. t['pointingindexdownwhite'] = 0x261F;
  8244. t['pointingindexleftwhite'] = 0x261C;
  8245. t['pointingindexrightwhite'] = 0x261E;
  8246. t['pointingindexupwhite'] = 0x261D;
  8247. t['pokatakana'] = 0x30DD;
  8248. t['poplathai'] = 0x0E1B;
  8249. t['postalmark'] = 0x3012;
  8250. t['postalmarkface'] = 0x3020;
  8251. t['pparen'] = 0x24AB;
  8252. t['precedes'] = 0x227A;
  8253. t['prescription'] = 0x211E;
  8254. t['primemod'] = 0x02B9;
  8255. t['primereversed'] = 0x2035;
  8256. t['product'] = 0x220F;
  8257. t['projective'] = 0x2305;
  8258. t['prolongedkana'] = 0x30FC;
  8259. t['propellor'] = 0x2318;
  8260. t['propersubset'] = 0x2282;
  8261. t['propersuperset'] = 0x2283;
  8262. t['proportion'] = 0x2237;
  8263. t['proportional'] = 0x221D;
  8264. t['psi'] = 0x03C8;
  8265. t['psicyrillic'] = 0x0471;
  8266. t['psilipneumatacyrilliccmb'] = 0x0486;
  8267. t['pssquare'] = 0x33B0;
  8268. t['puhiragana'] = 0x3077;
  8269. t['pukatakana'] = 0x30D7;
  8270. t['pvsquare'] = 0x33B4;
  8271. t['pwsquare'] = 0x33BA;
  8272. t['q'] = 0x0071;
  8273. t['qadeva'] = 0x0958;
  8274. t['qadmahebrew'] = 0x05A8;
  8275. t['qafarabic'] = 0x0642;
  8276. t['qaffinalarabic'] = 0xFED6;
  8277. t['qafinitialarabic'] = 0xFED7;
  8278. t['qafmedialarabic'] = 0xFED8;
  8279. t['qamats'] = 0x05B8;
  8280. t['qamats10'] = 0x05B8;
  8281. t['qamats1a'] = 0x05B8;
  8282. t['qamats1c'] = 0x05B8;
  8283. t['qamats27'] = 0x05B8;
  8284. t['qamats29'] = 0x05B8;
  8285. t['qamats33'] = 0x05B8;
  8286. t['qamatsde'] = 0x05B8;
  8287. t['qamatshebrew'] = 0x05B8;
  8288. t['qamatsnarrowhebrew'] = 0x05B8;
  8289. t['qamatsqatanhebrew'] = 0x05B8;
  8290. t['qamatsqatannarrowhebrew'] = 0x05B8;
  8291. t['qamatsqatanquarterhebrew'] = 0x05B8;
  8292. t['qamatsqatanwidehebrew'] = 0x05B8;
  8293. t['qamatsquarterhebrew'] = 0x05B8;
  8294. t['qamatswidehebrew'] = 0x05B8;
  8295. t['qarneyparahebrew'] = 0x059F;
  8296. t['qbopomofo'] = 0x3111;
  8297. t['qcircle'] = 0x24E0;
  8298. t['qhook'] = 0x02A0;
  8299. t['qmonospace'] = 0xFF51;
  8300. t['qof'] = 0x05E7;
  8301. t['qofdagesh'] = 0xFB47;
  8302. t['qofdageshhebrew'] = 0xFB47;
  8303. t['qofhebrew'] = 0x05E7;
  8304. t['qparen'] = 0x24AC;
  8305. t['quarternote'] = 0x2669;
  8306. t['qubuts'] = 0x05BB;
  8307. t['qubuts18'] = 0x05BB;
  8308. t['qubuts25'] = 0x05BB;
  8309. t['qubuts31'] = 0x05BB;
  8310. t['qubutshebrew'] = 0x05BB;
  8311. t['qubutsnarrowhebrew'] = 0x05BB;
  8312. t['qubutsquarterhebrew'] = 0x05BB;
  8313. t['qubutswidehebrew'] = 0x05BB;
  8314. t['question'] = 0x003F;
  8315. t['questionarabic'] = 0x061F;
  8316. t['questionarmenian'] = 0x055E;
  8317. t['questiondown'] = 0x00BF;
  8318. t['questiondownsmall'] = 0xF7BF;
  8319. t['questiongreek'] = 0x037E;
  8320. t['questionmonospace'] = 0xFF1F;
  8321. t['questionsmall'] = 0xF73F;
  8322. t['quotedbl'] = 0x0022;
  8323. t['quotedblbase'] = 0x201E;
  8324. t['quotedblleft'] = 0x201C;
  8325. t['quotedblmonospace'] = 0xFF02;
  8326. t['quotedblprime'] = 0x301E;
  8327. t['quotedblprimereversed'] = 0x301D;
  8328. t['quotedblright'] = 0x201D;
  8329. t['quoteleft'] = 0x2018;
  8330. t['quoteleftreversed'] = 0x201B;
  8331. t['quotereversed'] = 0x201B;
  8332. t['quoteright'] = 0x2019;
  8333. t['quoterightn'] = 0x0149;
  8334. t['quotesinglbase'] = 0x201A;
  8335. t['quotesingle'] = 0x0027;
  8336. t['quotesinglemonospace'] = 0xFF07;
  8337. t['r'] = 0x0072;
  8338. t['raarmenian'] = 0x057C;
  8339. t['rabengali'] = 0x09B0;
  8340. t['racute'] = 0x0155;
  8341. t['radeva'] = 0x0930;
  8342. t['radical'] = 0x221A;
  8343. t['radicalex'] = 0xF8E5;
  8344. t['radoverssquare'] = 0x33AE;
  8345. t['radoverssquaredsquare'] = 0x33AF;
  8346. t['radsquare'] = 0x33AD;
  8347. t['rafe'] = 0x05BF;
  8348. t['rafehebrew'] = 0x05BF;
  8349. t['ragujarati'] = 0x0AB0;
  8350. t['ragurmukhi'] = 0x0A30;
  8351. t['rahiragana'] = 0x3089;
  8352. t['rakatakana'] = 0x30E9;
  8353. t['rakatakanahalfwidth'] = 0xFF97;
  8354. t['ralowerdiagonalbengali'] = 0x09F1;
  8355. t['ramiddlediagonalbengali'] = 0x09F0;
  8356. t['ramshorn'] = 0x0264;
  8357. t['ratio'] = 0x2236;
  8358. t['rbopomofo'] = 0x3116;
  8359. t['rcaron'] = 0x0159;
  8360. t['rcedilla'] = 0x0157;
  8361. t['rcircle'] = 0x24E1;
  8362. t['rcommaaccent'] = 0x0157;
  8363. t['rdblgrave'] = 0x0211;
  8364. t['rdotaccent'] = 0x1E59;
  8365. t['rdotbelow'] = 0x1E5B;
  8366. t['rdotbelowmacron'] = 0x1E5D;
  8367. t['referencemark'] = 0x203B;
  8368. t['reflexsubset'] = 0x2286;
  8369. t['reflexsuperset'] = 0x2287;
  8370. t['registered'] = 0x00AE;
  8371. t['registersans'] = 0xF8E8;
  8372. t['registerserif'] = 0xF6DA;
  8373. t['reharabic'] = 0x0631;
  8374. t['reharmenian'] = 0x0580;
  8375. t['rehfinalarabic'] = 0xFEAE;
  8376. t['rehiragana'] = 0x308C;
  8377. t['rekatakana'] = 0x30EC;
  8378. t['rekatakanahalfwidth'] = 0xFF9A;
  8379. t['resh'] = 0x05E8;
  8380. t['reshdageshhebrew'] = 0xFB48;
  8381. t['reshhebrew'] = 0x05E8;
  8382. t['reversedtilde'] = 0x223D;
  8383. t['reviahebrew'] = 0x0597;
  8384. t['reviamugrashhebrew'] = 0x0597;
  8385. t['revlogicalnot'] = 0x2310;
  8386. t['rfishhook'] = 0x027E;
  8387. t['rfishhookreversed'] = 0x027F;
  8388. t['rhabengali'] = 0x09DD;
  8389. t['rhadeva'] = 0x095D;
  8390. t['rho'] = 0x03C1;
  8391. t['rhook'] = 0x027D;
  8392. t['rhookturned'] = 0x027B;
  8393. t['rhookturnedsuperior'] = 0x02B5;
  8394. t['rhosymbolgreek'] = 0x03F1;
  8395. t['rhotichookmod'] = 0x02DE;
  8396. t['rieulacirclekorean'] = 0x3271;
  8397. t['rieulaparenkorean'] = 0x3211;
  8398. t['rieulcirclekorean'] = 0x3263;
  8399. t['rieulhieuhkorean'] = 0x3140;
  8400. t['rieulkiyeokkorean'] = 0x313A;
  8401. t['rieulkiyeoksioskorean'] = 0x3169;
  8402. t['rieulkorean'] = 0x3139;
  8403. t['rieulmieumkorean'] = 0x313B;
  8404. t['rieulpansioskorean'] = 0x316C;
  8405. t['rieulparenkorean'] = 0x3203;
  8406. t['rieulphieuphkorean'] = 0x313F;
  8407. t['rieulpieupkorean'] = 0x313C;
  8408. t['rieulpieupsioskorean'] = 0x316B;
  8409. t['rieulsioskorean'] = 0x313D;
  8410. t['rieulthieuthkorean'] = 0x313E;
  8411. t['rieultikeutkorean'] = 0x316A;
  8412. t['rieulyeorinhieuhkorean'] = 0x316D;
  8413. t['rightangle'] = 0x221F;
  8414. t['righttackbelowcmb'] = 0x0319;
  8415. t['righttriangle'] = 0x22BF;
  8416. t['rihiragana'] = 0x308A;
  8417. t['rikatakana'] = 0x30EA;
  8418. t['rikatakanahalfwidth'] = 0xFF98;
  8419. t['ring'] = 0x02DA;
  8420. t['ringbelowcmb'] = 0x0325;
  8421. t['ringcmb'] = 0x030A;
  8422. t['ringhalfleft'] = 0x02BF;
  8423. t['ringhalfleftarmenian'] = 0x0559;
  8424. t['ringhalfleftbelowcmb'] = 0x031C;
  8425. t['ringhalfleftcentered'] = 0x02D3;
  8426. t['ringhalfright'] = 0x02BE;
  8427. t['ringhalfrightbelowcmb'] = 0x0339;
  8428. t['ringhalfrightcentered'] = 0x02D2;
  8429. t['rinvertedbreve'] = 0x0213;
  8430. t['rittorusquare'] = 0x3351;
  8431. t['rlinebelow'] = 0x1E5F;
  8432. t['rlongleg'] = 0x027C;
  8433. t['rlonglegturned'] = 0x027A;
  8434. t['rmonospace'] = 0xFF52;
  8435. t['rohiragana'] = 0x308D;
  8436. t['rokatakana'] = 0x30ED;
  8437. t['rokatakanahalfwidth'] = 0xFF9B;
  8438. t['roruathai'] = 0x0E23;
  8439. t['rparen'] = 0x24AD;
  8440. t['rrabengali'] = 0x09DC;
  8441. t['rradeva'] = 0x0931;
  8442. t['rragurmukhi'] = 0x0A5C;
  8443. t['rreharabic'] = 0x0691;
  8444. t['rrehfinalarabic'] = 0xFB8D;
  8445. t['rrvocalicbengali'] = 0x09E0;
  8446. t['rrvocalicdeva'] = 0x0960;
  8447. t['rrvocalicgujarati'] = 0x0AE0;
  8448. t['rrvocalicvowelsignbengali'] = 0x09C4;
  8449. t['rrvocalicvowelsigndeva'] = 0x0944;
  8450. t['rrvocalicvowelsigngujarati'] = 0x0AC4;
  8451. t['rsuperior'] = 0xF6F1;
  8452. t['rtblock'] = 0x2590;
  8453. t['rturned'] = 0x0279;
  8454. t['rturnedsuperior'] = 0x02B4;
  8455. t['ruhiragana'] = 0x308B;
  8456. t['rukatakana'] = 0x30EB;
  8457. t['rukatakanahalfwidth'] = 0xFF99;
  8458. t['rupeemarkbengali'] = 0x09F2;
  8459. t['rupeesignbengali'] = 0x09F3;
  8460. t['rupiah'] = 0xF6DD;
  8461. t['ruthai'] = 0x0E24;
  8462. t['rvocalicbengali'] = 0x098B;
  8463. t['rvocalicdeva'] = 0x090B;
  8464. t['rvocalicgujarati'] = 0x0A8B;
  8465. t['rvocalicvowelsignbengali'] = 0x09C3;
  8466. t['rvocalicvowelsigndeva'] = 0x0943;
  8467. t['rvocalicvowelsigngujarati'] = 0x0AC3;
  8468. t['s'] = 0x0073;
  8469. t['sabengali'] = 0x09B8;
  8470. t['sacute'] = 0x015B;
  8471. t['sacutedotaccent'] = 0x1E65;
  8472. t['sadarabic'] = 0x0635;
  8473. t['sadeva'] = 0x0938;
  8474. t['sadfinalarabic'] = 0xFEBA;
  8475. t['sadinitialarabic'] = 0xFEBB;
  8476. t['sadmedialarabic'] = 0xFEBC;
  8477. t['sagujarati'] = 0x0AB8;
  8478. t['sagurmukhi'] = 0x0A38;
  8479. t['sahiragana'] = 0x3055;
  8480. t['sakatakana'] = 0x30B5;
  8481. t['sakatakanahalfwidth'] = 0xFF7B;
  8482. t['sallallahoualayhewasallamarabic'] = 0xFDFA;
  8483. t['samekh'] = 0x05E1;
  8484. t['samekhdagesh'] = 0xFB41;
  8485. t['samekhdageshhebrew'] = 0xFB41;
  8486. t['samekhhebrew'] = 0x05E1;
  8487. t['saraaathai'] = 0x0E32;
  8488. t['saraaethai'] = 0x0E41;
  8489. t['saraaimaimalaithai'] = 0x0E44;
  8490. t['saraaimaimuanthai'] = 0x0E43;
  8491. t['saraamthai'] = 0x0E33;
  8492. t['saraathai'] = 0x0E30;
  8493. t['saraethai'] = 0x0E40;
  8494. t['saraiileftthai'] = 0xF886;
  8495. t['saraiithai'] = 0x0E35;
  8496. t['saraileftthai'] = 0xF885;
  8497. t['saraithai'] = 0x0E34;
  8498. t['saraothai'] = 0x0E42;
  8499. t['saraueeleftthai'] = 0xF888;
  8500. t['saraueethai'] = 0x0E37;
  8501. t['saraueleftthai'] = 0xF887;
  8502. t['sarauethai'] = 0x0E36;
  8503. t['sarauthai'] = 0x0E38;
  8504. t['sarauuthai'] = 0x0E39;
  8505. t['sbopomofo'] = 0x3119;
  8506. t['scaron'] = 0x0161;
  8507. t['scarondotaccent'] = 0x1E67;
  8508. t['scedilla'] = 0x015F;
  8509. t['schwa'] = 0x0259;
  8510. t['schwacyrillic'] = 0x04D9;
  8511. t['schwadieresiscyrillic'] = 0x04DB;
  8512. t['schwahook'] = 0x025A;
  8513. t['scircle'] = 0x24E2;
  8514. t['scircumflex'] = 0x015D;
  8515. t['scommaaccent'] = 0x0219;
  8516. t['sdotaccent'] = 0x1E61;
  8517. t['sdotbelow'] = 0x1E63;
  8518. t['sdotbelowdotaccent'] = 0x1E69;
  8519. t['seagullbelowcmb'] = 0x033C;
  8520. t['second'] = 0x2033;
  8521. t['secondtonechinese'] = 0x02CA;
  8522. t['section'] = 0x00A7;
  8523. t['seenarabic'] = 0x0633;
  8524. t['seenfinalarabic'] = 0xFEB2;
  8525. t['seeninitialarabic'] = 0xFEB3;
  8526. t['seenmedialarabic'] = 0xFEB4;
  8527. t['segol'] = 0x05B6;
  8528. t['segol13'] = 0x05B6;
  8529. t['segol1f'] = 0x05B6;
  8530. t['segol2c'] = 0x05B6;
  8531. t['segolhebrew'] = 0x05B6;
  8532. t['segolnarrowhebrew'] = 0x05B6;
  8533. t['segolquarterhebrew'] = 0x05B6;
  8534. t['segoltahebrew'] = 0x0592;
  8535. t['segolwidehebrew'] = 0x05B6;
  8536. t['seharmenian'] = 0x057D;
  8537. t['sehiragana'] = 0x305B;
  8538. t['sekatakana'] = 0x30BB;
  8539. t['sekatakanahalfwidth'] = 0xFF7E;
  8540. t['semicolon'] = 0x003B;
  8541. t['semicolonarabic'] = 0x061B;
  8542. t['semicolonmonospace'] = 0xFF1B;
  8543. t['semicolonsmall'] = 0xFE54;
  8544. t['semivoicedmarkkana'] = 0x309C;
  8545. t['semivoicedmarkkanahalfwidth'] = 0xFF9F;
  8546. t['sentisquare'] = 0x3322;
  8547. t['sentosquare'] = 0x3323;
  8548. t['seven'] = 0x0037;
  8549. t['sevenarabic'] = 0x0667;
  8550. t['sevenbengali'] = 0x09ED;
  8551. t['sevencircle'] = 0x2466;
  8552. t['sevencircleinversesansserif'] = 0x2790;
  8553. t['sevendeva'] = 0x096D;
  8554. t['seveneighths'] = 0x215E;
  8555. t['sevengujarati'] = 0x0AED;
  8556. t['sevengurmukhi'] = 0x0A6D;
  8557. t['sevenhackarabic'] = 0x0667;
  8558. t['sevenhangzhou'] = 0x3027;
  8559. t['sevenideographicparen'] = 0x3226;
  8560. t['seveninferior'] = 0x2087;
  8561. t['sevenmonospace'] = 0xFF17;
  8562. t['sevenoldstyle'] = 0xF737;
  8563. t['sevenparen'] = 0x247A;
  8564. t['sevenperiod'] = 0x248E;
  8565. t['sevenpersian'] = 0x06F7;
  8566. t['sevenroman'] = 0x2176;
  8567. t['sevensuperior'] = 0x2077;
  8568. t['seventeencircle'] = 0x2470;
  8569. t['seventeenparen'] = 0x2484;
  8570. t['seventeenperiod'] = 0x2498;
  8571. t['seventhai'] = 0x0E57;
  8572. t['sfthyphen'] = 0x00AD;
  8573. t['shaarmenian'] = 0x0577;
  8574. t['shabengali'] = 0x09B6;
  8575. t['shacyrillic'] = 0x0448;
  8576. t['shaddaarabic'] = 0x0651;
  8577. t['shaddadammaarabic'] = 0xFC61;
  8578. t['shaddadammatanarabic'] = 0xFC5E;
  8579. t['shaddafathaarabic'] = 0xFC60;
  8580. t['shaddakasraarabic'] = 0xFC62;
  8581. t['shaddakasratanarabic'] = 0xFC5F;
  8582. t['shade'] = 0x2592;
  8583. t['shadedark'] = 0x2593;
  8584. t['shadelight'] = 0x2591;
  8585. t['shademedium'] = 0x2592;
  8586. t['shadeva'] = 0x0936;
  8587. t['shagujarati'] = 0x0AB6;
  8588. t['shagurmukhi'] = 0x0A36;
  8589. t['shalshelethebrew'] = 0x0593;
  8590. t['shbopomofo'] = 0x3115;
  8591. t['shchacyrillic'] = 0x0449;
  8592. t['sheenarabic'] = 0x0634;
  8593. t['sheenfinalarabic'] = 0xFEB6;
  8594. t['sheeninitialarabic'] = 0xFEB7;
  8595. t['sheenmedialarabic'] = 0xFEB8;
  8596. t['sheicoptic'] = 0x03E3;
  8597. t['sheqel'] = 0x20AA;
  8598. t['sheqelhebrew'] = 0x20AA;
  8599. t['sheva'] = 0x05B0;
  8600. t['sheva115'] = 0x05B0;
  8601. t['sheva15'] = 0x05B0;
  8602. t['sheva22'] = 0x05B0;
  8603. t['sheva2e'] = 0x05B0;
  8604. t['shevahebrew'] = 0x05B0;
  8605. t['shevanarrowhebrew'] = 0x05B0;
  8606. t['shevaquarterhebrew'] = 0x05B0;
  8607. t['shevawidehebrew'] = 0x05B0;
  8608. t['shhacyrillic'] = 0x04BB;
  8609. t['shimacoptic'] = 0x03ED;
  8610. t['shin'] = 0x05E9;
  8611. t['shindagesh'] = 0xFB49;
  8612. t['shindageshhebrew'] = 0xFB49;
  8613. t['shindageshshindot'] = 0xFB2C;
  8614. t['shindageshshindothebrew'] = 0xFB2C;
  8615. t['shindageshsindot'] = 0xFB2D;
  8616. t['shindageshsindothebrew'] = 0xFB2D;
  8617. t['shindothebrew'] = 0x05C1;
  8618. t['shinhebrew'] = 0x05E9;
  8619. t['shinshindot'] = 0xFB2A;
  8620. t['shinshindothebrew'] = 0xFB2A;
  8621. t['shinsindot'] = 0xFB2B;
  8622. t['shinsindothebrew'] = 0xFB2B;
  8623. t['shook'] = 0x0282;
  8624. t['sigma'] = 0x03C3;
  8625. t['sigma1'] = 0x03C2;
  8626. t['sigmafinal'] = 0x03C2;
  8627. t['sigmalunatesymbolgreek'] = 0x03F2;
  8628. t['sihiragana'] = 0x3057;
  8629. t['sikatakana'] = 0x30B7;
  8630. t['sikatakanahalfwidth'] = 0xFF7C;
  8631. t['siluqhebrew'] = 0x05BD;
  8632. t['siluqlefthebrew'] = 0x05BD;
  8633. t['similar'] = 0x223C;
  8634. t['sindothebrew'] = 0x05C2;
  8635. t['siosacirclekorean'] = 0x3274;
  8636. t['siosaparenkorean'] = 0x3214;
  8637. t['sioscieuckorean'] = 0x317E;
  8638. t['sioscirclekorean'] = 0x3266;
  8639. t['sioskiyeokkorean'] = 0x317A;
  8640. t['sioskorean'] = 0x3145;
  8641. t['siosnieunkorean'] = 0x317B;
  8642. t['siosparenkorean'] = 0x3206;
  8643. t['siospieupkorean'] = 0x317D;
  8644. t['siostikeutkorean'] = 0x317C;
  8645. t['six'] = 0x0036;
  8646. t['sixarabic'] = 0x0666;
  8647. t['sixbengali'] = 0x09EC;
  8648. t['sixcircle'] = 0x2465;
  8649. t['sixcircleinversesansserif'] = 0x278F;
  8650. t['sixdeva'] = 0x096C;
  8651. t['sixgujarati'] = 0x0AEC;
  8652. t['sixgurmukhi'] = 0x0A6C;
  8653. t['sixhackarabic'] = 0x0666;
  8654. t['sixhangzhou'] = 0x3026;
  8655. t['sixideographicparen'] = 0x3225;
  8656. t['sixinferior'] = 0x2086;
  8657. t['sixmonospace'] = 0xFF16;
  8658. t['sixoldstyle'] = 0xF736;
  8659. t['sixparen'] = 0x2479;
  8660. t['sixperiod'] = 0x248D;
  8661. t['sixpersian'] = 0x06F6;
  8662. t['sixroman'] = 0x2175;
  8663. t['sixsuperior'] = 0x2076;
  8664. t['sixteencircle'] = 0x246F;
  8665. t['sixteencurrencydenominatorbengali'] = 0x09F9;
  8666. t['sixteenparen'] = 0x2483;
  8667. t['sixteenperiod'] = 0x2497;
  8668. t['sixthai'] = 0x0E56;
  8669. t['slash'] = 0x002F;
  8670. t['slashmonospace'] = 0xFF0F;
  8671. t['slong'] = 0x017F;
  8672. t['slongdotaccent'] = 0x1E9B;
  8673. t['smileface'] = 0x263A;
  8674. t['smonospace'] = 0xFF53;
  8675. t['sofpasuqhebrew'] = 0x05C3;
  8676. t['softhyphen'] = 0x00AD;
  8677. t['softsigncyrillic'] = 0x044C;
  8678. t['sohiragana'] = 0x305D;
  8679. t['sokatakana'] = 0x30BD;
  8680. t['sokatakanahalfwidth'] = 0xFF7F;
  8681. t['soliduslongoverlaycmb'] = 0x0338;
  8682. t['solidusshortoverlaycmb'] = 0x0337;
  8683. t['sorusithai'] = 0x0E29;
  8684. t['sosalathai'] = 0x0E28;
  8685. t['sosothai'] = 0x0E0B;
  8686. t['sosuathai'] = 0x0E2A;
  8687. t['space'] = 0x0020;
  8688. t['spacehackarabic'] = 0x0020;
  8689. t['spade'] = 0x2660;
  8690. t['spadesuitblack'] = 0x2660;
  8691. t['spadesuitwhite'] = 0x2664;
  8692. t['sparen'] = 0x24AE;
  8693. t['squarebelowcmb'] = 0x033B;
  8694. t['squarecc'] = 0x33C4;
  8695. t['squarecm'] = 0x339D;
  8696. t['squarediagonalcrosshatchfill'] = 0x25A9;
  8697. t['squarehorizontalfill'] = 0x25A4;
  8698. t['squarekg'] = 0x338F;
  8699. t['squarekm'] = 0x339E;
  8700. t['squarekmcapital'] = 0x33CE;
  8701. t['squareln'] = 0x33D1;
  8702. t['squarelog'] = 0x33D2;
  8703. t['squaremg'] = 0x338E;
  8704. t['squaremil'] = 0x33D5;
  8705. t['squaremm'] = 0x339C;
  8706. t['squaremsquared'] = 0x33A1;
  8707. t['squareorthogonalcrosshatchfill'] = 0x25A6;
  8708. t['squareupperlefttolowerrightfill'] = 0x25A7;
  8709. t['squareupperrighttolowerleftfill'] = 0x25A8;
  8710. t['squareverticalfill'] = 0x25A5;
  8711. t['squarewhitewithsmallblack'] = 0x25A3;
  8712. t['srsquare'] = 0x33DB;
  8713. t['ssabengali'] = 0x09B7;
  8714. t['ssadeva'] = 0x0937;
  8715. t['ssagujarati'] = 0x0AB7;
  8716. t['ssangcieuckorean'] = 0x3149;
  8717. t['ssanghieuhkorean'] = 0x3185;
  8718. t['ssangieungkorean'] = 0x3180;
  8719. t['ssangkiyeokkorean'] = 0x3132;
  8720. t['ssangnieunkorean'] = 0x3165;
  8721. t['ssangpieupkorean'] = 0x3143;
  8722. t['ssangsioskorean'] = 0x3146;
  8723. t['ssangtikeutkorean'] = 0x3138;
  8724. t['ssuperior'] = 0xF6F2;
  8725. t['sterling'] = 0x00A3;
  8726. t['sterlingmonospace'] = 0xFFE1;
  8727. t['strokelongoverlaycmb'] = 0x0336;
  8728. t['strokeshortoverlaycmb'] = 0x0335;
  8729. t['subset'] = 0x2282;
  8730. t['subsetnotequal'] = 0x228A;
  8731. t['subsetorequal'] = 0x2286;
  8732. t['succeeds'] = 0x227B;
  8733. t['suchthat'] = 0x220B;
  8734. t['suhiragana'] = 0x3059;
  8735. t['sukatakana'] = 0x30B9;
  8736. t['sukatakanahalfwidth'] = 0xFF7D;
  8737. t['sukunarabic'] = 0x0652;
  8738. t['summation'] = 0x2211;
  8739. t['sun'] = 0x263C;
  8740. t['superset'] = 0x2283;
  8741. t['supersetnotequal'] = 0x228B;
  8742. t['supersetorequal'] = 0x2287;
  8743. t['svsquare'] = 0x33DC;
  8744. t['syouwaerasquare'] = 0x337C;
  8745. t['t'] = 0x0074;
  8746. t['tabengali'] = 0x09A4;
  8747. t['tackdown'] = 0x22A4;
  8748. t['tackleft'] = 0x22A3;
  8749. t['tadeva'] = 0x0924;
  8750. t['tagujarati'] = 0x0AA4;
  8751. t['tagurmukhi'] = 0x0A24;
  8752. t['taharabic'] = 0x0637;
  8753. t['tahfinalarabic'] = 0xFEC2;
  8754. t['tahinitialarabic'] = 0xFEC3;
  8755. t['tahiragana'] = 0x305F;
  8756. t['tahmedialarabic'] = 0xFEC4;
  8757. t['taisyouerasquare'] = 0x337D;
  8758. t['takatakana'] = 0x30BF;
  8759. t['takatakanahalfwidth'] = 0xFF80;
  8760. t['tatweelarabic'] = 0x0640;
  8761. t['tau'] = 0x03C4;
  8762. t['tav'] = 0x05EA;
  8763. t['tavdages'] = 0xFB4A;
  8764. t['tavdagesh'] = 0xFB4A;
  8765. t['tavdageshhebrew'] = 0xFB4A;
  8766. t['tavhebrew'] = 0x05EA;
  8767. t['tbar'] = 0x0167;
  8768. t['tbopomofo'] = 0x310A;
  8769. t['tcaron'] = 0x0165;
  8770. t['tccurl'] = 0x02A8;
  8771. t['tcedilla'] = 0x0163;
  8772. t['tcheharabic'] = 0x0686;
  8773. t['tchehfinalarabic'] = 0xFB7B;
  8774. t['tchehinitialarabic'] = 0xFB7C;
  8775. t['tchehmedialarabic'] = 0xFB7D;
  8776. t['tcircle'] = 0x24E3;
  8777. t['tcircumflexbelow'] = 0x1E71;
  8778. t['tcommaaccent'] = 0x0163;
  8779. t['tdieresis'] = 0x1E97;
  8780. t['tdotaccent'] = 0x1E6B;
  8781. t['tdotbelow'] = 0x1E6D;
  8782. t['tecyrillic'] = 0x0442;
  8783. t['tedescendercyrillic'] = 0x04AD;
  8784. t['teharabic'] = 0x062A;
  8785. t['tehfinalarabic'] = 0xFE96;
  8786. t['tehhahinitialarabic'] = 0xFCA2;
  8787. t['tehhahisolatedarabic'] = 0xFC0C;
  8788. t['tehinitialarabic'] = 0xFE97;
  8789. t['tehiragana'] = 0x3066;
  8790. t['tehjeeminitialarabic'] = 0xFCA1;
  8791. t['tehjeemisolatedarabic'] = 0xFC0B;
  8792. t['tehmarbutaarabic'] = 0x0629;
  8793. t['tehmarbutafinalarabic'] = 0xFE94;
  8794. t['tehmedialarabic'] = 0xFE98;
  8795. t['tehmeeminitialarabic'] = 0xFCA4;
  8796. t['tehmeemisolatedarabic'] = 0xFC0E;
  8797. t['tehnoonfinalarabic'] = 0xFC73;
  8798. t['tekatakana'] = 0x30C6;
  8799. t['tekatakanahalfwidth'] = 0xFF83;
  8800. t['telephone'] = 0x2121;
  8801. t['telephoneblack'] = 0x260E;
  8802. t['telishagedolahebrew'] = 0x05A0;
  8803. t['telishaqetanahebrew'] = 0x05A9;
  8804. t['tencircle'] = 0x2469;
  8805. t['tenideographicparen'] = 0x3229;
  8806. t['tenparen'] = 0x247D;
  8807. t['tenperiod'] = 0x2491;
  8808. t['tenroman'] = 0x2179;
  8809. t['tesh'] = 0x02A7;
  8810. t['tet'] = 0x05D8;
  8811. t['tetdagesh'] = 0xFB38;
  8812. t['tetdageshhebrew'] = 0xFB38;
  8813. t['tethebrew'] = 0x05D8;
  8814. t['tetsecyrillic'] = 0x04B5;
  8815. t['tevirhebrew'] = 0x059B;
  8816. t['tevirlefthebrew'] = 0x059B;
  8817. t['thabengali'] = 0x09A5;
  8818. t['thadeva'] = 0x0925;
  8819. t['thagujarati'] = 0x0AA5;
  8820. t['thagurmukhi'] = 0x0A25;
  8821. t['thalarabic'] = 0x0630;
  8822. t['thalfinalarabic'] = 0xFEAC;
  8823. t['thanthakhatlowleftthai'] = 0xF898;
  8824. t['thanthakhatlowrightthai'] = 0xF897;
  8825. t['thanthakhatthai'] = 0x0E4C;
  8826. t['thanthakhatupperleftthai'] = 0xF896;
  8827. t['theharabic'] = 0x062B;
  8828. t['thehfinalarabic'] = 0xFE9A;
  8829. t['thehinitialarabic'] = 0xFE9B;
  8830. t['thehmedialarabic'] = 0xFE9C;
  8831. t['thereexists'] = 0x2203;
  8832. t['therefore'] = 0x2234;
  8833. t['theta'] = 0x03B8;
  8834. t['theta1'] = 0x03D1;
  8835. t['thetasymbolgreek'] = 0x03D1;
  8836. t['thieuthacirclekorean'] = 0x3279;
  8837. t['thieuthaparenkorean'] = 0x3219;
  8838. t['thieuthcirclekorean'] = 0x326B;
  8839. t['thieuthkorean'] = 0x314C;
  8840. t['thieuthparenkorean'] = 0x320B;
  8841. t['thirteencircle'] = 0x246C;
  8842. t['thirteenparen'] = 0x2480;
  8843. t['thirteenperiod'] = 0x2494;
  8844. t['thonangmonthothai'] = 0x0E11;
  8845. t['thook'] = 0x01AD;
  8846. t['thophuthaothai'] = 0x0E12;
  8847. t['thorn'] = 0x00FE;
  8848. t['thothahanthai'] = 0x0E17;
  8849. t['thothanthai'] = 0x0E10;
  8850. t['thothongthai'] = 0x0E18;
  8851. t['thothungthai'] = 0x0E16;
  8852. t['thousandcyrillic'] = 0x0482;
  8853. t['thousandsseparatorarabic'] = 0x066C;
  8854. t['thousandsseparatorpersian'] = 0x066C;
  8855. t['three'] = 0x0033;
  8856. t['threearabic'] = 0x0663;
  8857. t['threebengali'] = 0x09E9;
  8858. t['threecircle'] = 0x2462;
  8859. t['threecircleinversesansserif'] = 0x278C;
  8860. t['threedeva'] = 0x0969;
  8861. t['threeeighths'] = 0x215C;
  8862. t['threegujarati'] = 0x0AE9;
  8863. t['threegurmukhi'] = 0x0A69;
  8864. t['threehackarabic'] = 0x0663;
  8865. t['threehangzhou'] = 0x3023;
  8866. t['threeideographicparen'] = 0x3222;
  8867. t['threeinferior'] = 0x2083;
  8868. t['threemonospace'] = 0xFF13;
  8869. t['threenumeratorbengali'] = 0x09F6;
  8870. t['threeoldstyle'] = 0xF733;
  8871. t['threeparen'] = 0x2476;
  8872. t['threeperiod'] = 0x248A;
  8873. t['threepersian'] = 0x06F3;
  8874. t['threequarters'] = 0x00BE;
  8875. t['threequartersemdash'] = 0xF6DE;
  8876. t['threeroman'] = 0x2172;
  8877. t['threesuperior'] = 0x00B3;
  8878. t['threethai'] = 0x0E53;
  8879. t['thzsquare'] = 0x3394;
  8880. t['tihiragana'] = 0x3061;
  8881. t['tikatakana'] = 0x30C1;
  8882. t['tikatakanahalfwidth'] = 0xFF81;
  8883. t['tikeutacirclekorean'] = 0x3270;
  8884. t['tikeutaparenkorean'] = 0x3210;
  8885. t['tikeutcirclekorean'] = 0x3262;
  8886. t['tikeutkorean'] = 0x3137;
  8887. t['tikeutparenkorean'] = 0x3202;
  8888. t['tilde'] = 0x02DC;
  8889. t['tildebelowcmb'] = 0x0330;
  8890. t['tildecmb'] = 0x0303;
  8891. t['tildecomb'] = 0x0303;
  8892. t['tildedoublecmb'] = 0x0360;
  8893. t['tildeoperator'] = 0x223C;
  8894. t['tildeoverlaycmb'] = 0x0334;
  8895. t['tildeverticalcmb'] = 0x033E;
  8896. t['timescircle'] = 0x2297;
  8897. t['tipehahebrew'] = 0x0596;
  8898. t['tipehalefthebrew'] = 0x0596;
  8899. t['tippigurmukhi'] = 0x0A70;
  8900. t['titlocyrilliccmb'] = 0x0483;
  8901. t['tiwnarmenian'] = 0x057F;
  8902. t['tlinebelow'] = 0x1E6F;
  8903. t['tmonospace'] = 0xFF54;
  8904. t['toarmenian'] = 0x0569;
  8905. t['tohiragana'] = 0x3068;
  8906. t['tokatakana'] = 0x30C8;
  8907. t['tokatakanahalfwidth'] = 0xFF84;
  8908. t['tonebarextrahighmod'] = 0x02E5;
  8909. t['tonebarextralowmod'] = 0x02E9;
  8910. t['tonebarhighmod'] = 0x02E6;
  8911. t['tonebarlowmod'] = 0x02E8;
  8912. t['tonebarmidmod'] = 0x02E7;
  8913. t['tonefive'] = 0x01BD;
  8914. t['tonesix'] = 0x0185;
  8915. t['tonetwo'] = 0x01A8;
  8916. t['tonos'] = 0x0384;
  8917. t['tonsquare'] = 0x3327;
  8918. t['topatakthai'] = 0x0E0F;
  8919. t['tortoiseshellbracketleft'] = 0x3014;
  8920. t['tortoiseshellbracketleftsmall'] = 0xFE5D;
  8921. t['tortoiseshellbracketleftvertical'] = 0xFE39;
  8922. t['tortoiseshellbracketright'] = 0x3015;
  8923. t['tortoiseshellbracketrightsmall'] = 0xFE5E;
  8924. t['tortoiseshellbracketrightvertical'] = 0xFE3A;
  8925. t['totaothai'] = 0x0E15;
  8926. t['tpalatalhook'] = 0x01AB;
  8927. t['tparen'] = 0x24AF;
  8928. t['trademark'] = 0x2122;
  8929. t['trademarksans'] = 0xF8EA;
  8930. t['trademarkserif'] = 0xF6DB;
  8931. t['tretroflexhook'] = 0x0288;
  8932. t['triagdn'] = 0x25BC;
  8933. t['triaglf'] = 0x25C4;
  8934. t['triagrt'] = 0x25BA;
  8935. t['triagup'] = 0x25B2;
  8936. t['ts'] = 0x02A6;
  8937. t['tsadi'] = 0x05E6;
  8938. t['tsadidagesh'] = 0xFB46;
  8939. t['tsadidageshhebrew'] = 0xFB46;
  8940. t['tsadihebrew'] = 0x05E6;
  8941. t['tsecyrillic'] = 0x0446;
  8942. t['tsere'] = 0x05B5;
  8943. t['tsere12'] = 0x05B5;
  8944. t['tsere1e'] = 0x05B5;
  8945. t['tsere2b'] = 0x05B5;
  8946. t['tserehebrew'] = 0x05B5;
  8947. t['tserenarrowhebrew'] = 0x05B5;
  8948. t['tserequarterhebrew'] = 0x05B5;
  8949. t['tserewidehebrew'] = 0x05B5;
  8950. t['tshecyrillic'] = 0x045B;
  8951. t['tsuperior'] = 0xF6F3;
  8952. t['ttabengali'] = 0x099F;
  8953. t['ttadeva'] = 0x091F;
  8954. t['ttagujarati'] = 0x0A9F;
  8955. t['ttagurmukhi'] = 0x0A1F;
  8956. t['tteharabic'] = 0x0679;
  8957. t['ttehfinalarabic'] = 0xFB67;
  8958. t['ttehinitialarabic'] = 0xFB68;
  8959. t['ttehmedialarabic'] = 0xFB69;
  8960. t['tthabengali'] = 0x09A0;
  8961. t['tthadeva'] = 0x0920;
  8962. t['tthagujarati'] = 0x0AA0;
  8963. t['tthagurmukhi'] = 0x0A20;
  8964. t['tturned'] = 0x0287;
  8965. t['tuhiragana'] = 0x3064;
  8966. t['tukatakana'] = 0x30C4;
  8967. t['tukatakanahalfwidth'] = 0xFF82;
  8968. t['tusmallhiragana'] = 0x3063;
  8969. t['tusmallkatakana'] = 0x30C3;
  8970. t['tusmallkatakanahalfwidth'] = 0xFF6F;
  8971. t['twelvecircle'] = 0x246B;
  8972. t['twelveparen'] = 0x247F;
  8973. t['twelveperiod'] = 0x2493;
  8974. t['twelveroman'] = 0x217B;
  8975. t['twentycircle'] = 0x2473;
  8976. t['twentyhangzhou'] = 0x5344;
  8977. t['twentyparen'] = 0x2487;
  8978. t['twentyperiod'] = 0x249B;
  8979. t['two'] = 0x0032;
  8980. t['twoarabic'] = 0x0662;
  8981. t['twobengali'] = 0x09E8;
  8982. t['twocircle'] = 0x2461;
  8983. t['twocircleinversesansserif'] = 0x278B;
  8984. t['twodeva'] = 0x0968;
  8985. t['twodotenleader'] = 0x2025;
  8986. t['twodotleader'] = 0x2025;
  8987. t['twodotleadervertical'] = 0xFE30;
  8988. t['twogujarati'] = 0x0AE8;
  8989. t['twogurmukhi'] = 0x0A68;
  8990. t['twohackarabic'] = 0x0662;
  8991. t['twohangzhou'] = 0x3022;
  8992. t['twoideographicparen'] = 0x3221;
  8993. t['twoinferior'] = 0x2082;
  8994. t['twomonospace'] = 0xFF12;
  8995. t['twonumeratorbengali'] = 0x09F5;
  8996. t['twooldstyle'] = 0xF732;
  8997. t['twoparen'] = 0x2475;
  8998. t['twoperiod'] = 0x2489;
  8999. t['twopersian'] = 0x06F2;
  9000. t['tworoman'] = 0x2171;
  9001. t['twostroke'] = 0x01BB;
  9002. t['twosuperior'] = 0x00B2;
  9003. t['twothai'] = 0x0E52;
  9004. t['twothirds'] = 0x2154;
  9005. t['u'] = 0x0075;
  9006. t['uacute'] = 0x00FA;
  9007. t['ubar'] = 0x0289;
  9008. t['ubengali'] = 0x0989;
  9009. t['ubopomofo'] = 0x3128;
  9010. t['ubreve'] = 0x016D;
  9011. t['ucaron'] = 0x01D4;
  9012. t['ucircle'] = 0x24E4;
  9013. t['ucircumflex'] = 0x00FB;
  9014. t['ucircumflexbelow'] = 0x1E77;
  9015. t['ucyrillic'] = 0x0443;
  9016. t['udattadeva'] = 0x0951;
  9017. t['udblacute'] = 0x0171;
  9018. t['udblgrave'] = 0x0215;
  9019. t['udeva'] = 0x0909;
  9020. t['udieresis'] = 0x00FC;
  9021. t['udieresisacute'] = 0x01D8;
  9022. t['udieresisbelow'] = 0x1E73;
  9023. t['udieresiscaron'] = 0x01DA;
  9024. t['udieresiscyrillic'] = 0x04F1;
  9025. t['udieresisgrave'] = 0x01DC;
  9026. t['udieresismacron'] = 0x01D6;
  9027. t['udotbelow'] = 0x1EE5;
  9028. t['ugrave'] = 0x00F9;
  9029. t['ugujarati'] = 0x0A89;
  9030. t['ugurmukhi'] = 0x0A09;
  9031. t['uhiragana'] = 0x3046;
  9032. t['uhookabove'] = 0x1EE7;
  9033. t['uhorn'] = 0x01B0;
  9034. t['uhornacute'] = 0x1EE9;
  9035. t['uhorndotbelow'] = 0x1EF1;
  9036. t['uhorngrave'] = 0x1EEB;
  9037. t['uhornhookabove'] = 0x1EED;
  9038. t['uhorntilde'] = 0x1EEF;
  9039. t['uhungarumlaut'] = 0x0171;
  9040. t['uhungarumlautcyrillic'] = 0x04F3;
  9041. t['uinvertedbreve'] = 0x0217;
  9042. t['ukatakana'] = 0x30A6;
  9043. t['ukatakanahalfwidth'] = 0xFF73;
  9044. t['ukcyrillic'] = 0x0479;
  9045. t['ukorean'] = 0x315C;
  9046. t['umacron'] = 0x016B;
  9047. t['umacroncyrillic'] = 0x04EF;
  9048. t['umacrondieresis'] = 0x1E7B;
  9049. t['umatragurmukhi'] = 0x0A41;
  9050. t['umonospace'] = 0xFF55;
  9051. t['underscore'] = 0x005F;
  9052. t['underscoredbl'] = 0x2017;
  9053. t['underscoremonospace'] = 0xFF3F;
  9054. t['underscorevertical'] = 0xFE33;
  9055. t['underscorewavy'] = 0xFE4F;
  9056. t['union'] = 0x222A;
  9057. t['universal'] = 0x2200;
  9058. t['uogonek'] = 0x0173;
  9059. t['uparen'] = 0x24B0;
  9060. t['upblock'] = 0x2580;
  9061. t['upperdothebrew'] = 0x05C4;
  9062. t['upsilon'] = 0x03C5;
  9063. t['upsilondieresis'] = 0x03CB;
  9064. t['upsilondieresistonos'] = 0x03B0;
  9065. t['upsilonlatin'] = 0x028A;
  9066. t['upsilontonos'] = 0x03CD;
  9067. t['uptackbelowcmb'] = 0x031D;
  9068. t['uptackmod'] = 0x02D4;
  9069. t['uragurmukhi'] = 0x0A73;
  9070. t['uring'] = 0x016F;
  9071. t['ushortcyrillic'] = 0x045E;
  9072. t['usmallhiragana'] = 0x3045;
  9073. t['usmallkatakana'] = 0x30A5;
  9074. t['usmallkatakanahalfwidth'] = 0xFF69;
  9075. t['ustraightcyrillic'] = 0x04AF;
  9076. t['ustraightstrokecyrillic'] = 0x04B1;
  9077. t['utilde'] = 0x0169;
  9078. t['utildeacute'] = 0x1E79;
  9079. t['utildebelow'] = 0x1E75;
  9080. t['uubengali'] = 0x098A;
  9081. t['uudeva'] = 0x090A;
  9082. t['uugujarati'] = 0x0A8A;
  9083. t['uugurmukhi'] = 0x0A0A;
  9084. t['uumatragurmukhi'] = 0x0A42;
  9085. t['uuvowelsignbengali'] = 0x09C2;
  9086. t['uuvowelsigndeva'] = 0x0942;
  9087. t['uuvowelsigngujarati'] = 0x0AC2;
  9088. t['uvowelsignbengali'] = 0x09C1;
  9089. t['uvowelsigndeva'] = 0x0941;
  9090. t['uvowelsigngujarati'] = 0x0AC1;
  9091. t['v'] = 0x0076;
  9092. t['vadeva'] = 0x0935;
  9093. t['vagujarati'] = 0x0AB5;
  9094. t['vagurmukhi'] = 0x0A35;
  9095. t['vakatakana'] = 0x30F7;
  9096. t['vav'] = 0x05D5;
  9097. t['vavdagesh'] = 0xFB35;
  9098. t['vavdagesh65'] = 0xFB35;
  9099. t['vavdageshhebrew'] = 0xFB35;
  9100. t['vavhebrew'] = 0x05D5;
  9101. t['vavholam'] = 0xFB4B;
  9102. t['vavholamhebrew'] = 0xFB4B;
  9103. t['vavvavhebrew'] = 0x05F0;
  9104. t['vavyodhebrew'] = 0x05F1;
  9105. t['vcircle'] = 0x24E5;
  9106. t['vdotbelow'] = 0x1E7F;
  9107. t['vecyrillic'] = 0x0432;
  9108. t['veharabic'] = 0x06A4;
  9109. t['vehfinalarabic'] = 0xFB6B;
  9110. t['vehinitialarabic'] = 0xFB6C;
  9111. t['vehmedialarabic'] = 0xFB6D;
  9112. t['vekatakana'] = 0x30F9;
  9113. t['venus'] = 0x2640;
  9114. t['verticalbar'] = 0x007C;
  9115. t['verticallineabovecmb'] = 0x030D;
  9116. t['verticallinebelowcmb'] = 0x0329;
  9117. t['verticallinelowmod'] = 0x02CC;
  9118. t['verticallinemod'] = 0x02C8;
  9119. t['vewarmenian'] = 0x057E;
  9120. t['vhook'] = 0x028B;
  9121. t['vikatakana'] = 0x30F8;
  9122. t['viramabengali'] = 0x09CD;
  9123. t['viramadeva'] = 0x094D;
  9124. t['viramagujarati'] = 0x0ACD;
  9125. t['visargabengali'] = 0x0983;
  9126. t['visargadeva'] = 0x0903;
  9127. t['visargagujarati'] = 0x0A83;
  9128. t['vmonospace'] = 0xFF56;
  9129. t['voarmenian'] = 0x0578;
  9130. t['voicediterationhiragana'] = 0x309E;
  9131. t['voicediterationkatakana'] = 0x30FE;
  9132. t['voicedmarkkana'] = 0x309B;
  9133. t['voicedmarkkanahalfwidth'] = 0xFF9E;
  9134. t['vokatakana'] = 0x30FA;
  9135. t['vparen'] = 0x24B1;
  9136. t['vtilde'] = 0x1E7D;
  9137. t['vturned'] = 0x028C;
  9138. t['vuhiragana'] = 0x3094;
  9139. t['vukatakana'] = 0x30F4;
  9140. t['w'] = 0x0077;
  9141. t['wacute'] = 0x1E83;
  9142. t['waekorean'] = 0x3159;
  9143. t['wahiragana'] = 0x308F;
  9144. t['wakatakana'] = 0x30EF;
  9145. t['wakatakanahalfwidth'] = 0xFF9C;
  9146. t['wakorean'] = 0x3158;
  9147. t['wasmallhiragana'] = 0x308E;
  9148. t['wasmallkatakana'] = 0x30EE;
  9149. t['wattosquare'] = 0x3357;
  9150. t['wavedash'] = 0x301C;
  9151. t['wavyunderscorevertical'] = 0xFE34;
  9152. t['wawarabic'] = 0x0648;
  9153. t['wawfinalarabic'] = 0xFEEE;
  9154. t['wawhamzaabovearabic'] = 0x0624;
  9155. t['wawhamzaabovefinalarabic'] = 0xFE86;
  9156. t['wbsquare'] = 0x33DD;
  9157. t['wcircle'] = 0x24E6;
  9158. t['wcircumflex'] = 0x0175;
  9159. t['wdieresis'] = 0x1E85;
  9160. t['wdotaccent'] = 0x1E87;
  9161. t['wdotbelow'] = 0x1E89;
  9162. t['wehiragana'] = 0x3091;
  9163. t['weierstrass'] = 0x2118;
  9164. t['wekatakana'] = 0x30F1;
  9165. t['wekorean'] = 0x315E;
  9166. t['weokorean'] = 0x315D;
  9167. t['wgrave'] = 0x1E81;
  9168. t['whitebullet'] = 0x25E6;
  9169. t['whitecircle'] = 0x25CB;
  9170. t['whitecircleinverse'] = 0x25D9;
  9171. t['whitecornerbracketleft'] = 0x300E;
  9172. t['whitecornerbracketleftvertical'] = 0xFE43;
  9173. t['whitecornerbracketright'] = 0x300F;
  9174. t['whitecornerbracketrightvertical'] = 0xFE44;
  9175. t['whitediamond'] = 0x25C7;
  9176. t['whitediamondcontainingblacksmalldiamond'] = 0x25C8;
  9177. t['whitedownpointingsmalltriangle'] = 0x25BF;
  9178. t['whitedownpointingtriangle'] = 0x25BD;
  9179. t['whiteleftpointingsmalltriangle'] = 0x25C3;
  9180. t['whiteleftpointingtriangle'] = 0x25C1;
  9181. t['whitelenticularbracketleft'] = 0x3016;
  9182. t['whitelenticularbracketright'] = 0x3017;
  9183. t['whiterightpointingsmalltriangle'] = 0x25B9;
  9184. t['whiterightpointingtriangle'] = 0x25B7;
  9185. t['whitesmallsquare'] = 0x25AB;
  9186. t['whitesmilingface'] = 0x263A;
  9187. t['whitesquare'] = 0x25A1;
  9188. t['whitestar'] = 0x2606;
  9189. t['whitetelephone'] = 0x260F;
  9190. t['whitetortoiseshellbracketleft'] = 0x3018;
  9191. t['whitetortoiseshellbracketright'] = 0x3019;
  9192. t['whiteuppointingsmalltriangle'] = 0x25B5;
  9193. t['whiteuppointingtriangle'] = 0x25B3;
  9194. t['wihiragana'] = 0x3090;
  9195. t['wikatakana'] = 0x30F0;
  9196. t['wikorean'] = 0x315F;
  9197. t['wmonospace'] = 0xFF57;
  9198. t['wohiragana'] = 0x3092;
  9199. t['wokatakana'] = 0x30F2;
  9200. t['wokatakanahalfwidth'] = 0xFF66;
  9201. t['won'] = 0x20A9;
  9202. t['wonmonospace'] = 0xFFE6;
  9203. t['wowaenthai'] = 0x0E27;
  9204. t['wparen'] = 0x24B2;
  9205. t['wring'] = 0x1E98;
  9206. t['wsuperior'] = 0x02B7;
  9207. t['wturned'] = 0x028D;
  9208. t['wynn'] = 0x01BF;
  9209. t['x'] = 0x0078;
  9210. t['xabovecmb'] = 0x033D;
  9211. t['xbopomofo'] = 0x3112;
  9212. t['xcircle'] = 0x24E7;
  9213. t['xdieresis'] = 0x1E8D;
  9214. t['xdotaccent'] = 0x1E8B;
  9215. t['xeharmenian'] = 0x056D;
  9216. t['xi'] = 0x03BE;
  9217. t['xmonospace'] = 0xFF58;
  9218. t['xparen'] = 0x24B3;
  9219. t['xsuperior'] = 0x02E3;
  9220. t['y'] = 0x0079;
  9221. t['yaadosquare'] = 0x334E;
  9222. t['yabengali'] = 0x09AF;
  9223. t['yacute'] = 0x00FD;
  9224. t['yadeva'] = 0x092F;
  9225. t['yaekorean'] = 0x3152;
  9226. t['yagujarati'] = 0x0AAF;
  9227. t['yagurmukhi'] = 0x0A2F;
  9228. t['yahiragana'] = 0x3084;
  9229. t['yakatakana'] = 0x30E4;
  9230. t['yakatakanahalfwidth'] = 0xFF94;
  9231. t['yakorean'] = 0x3151;
  9232. t['yamakkanthai'] = 0x0E4E;
  9233. t['yasmallhiragana'] = 0x3083;
  9234. t['yasmallkatakana'] = 0x30E3;
  9235. t['yasmallkatakanahalfwidth'] = 0xFF6C;
  9236. t['yatcyrillic'] = 0x0463;
  9237. t['ycircle'] = 0x24E8;
  9238. t['ycircumflex'] = 0x0177;
  9239. t['ydieresis'] = 0x00FF;
  9240. t['ydotaccent'] = 0x1E8F;
  9241. t['ydotbelow'] = 0x1EF5;
  9242. t['yeharabic'] = 0x064A;
  9243. t['yehbarreearabic'] = 0x06D2;
  9244. t['yehbarreefinalarabic'] = 0xFBAF;
  9245. t['yehfinalarabic'] = 0xFEF2;
  9246. t['yehhamzaabovearabic'] = 0x0626;
  9247. t['yehhamzaabovefinalarabic'] = 0xFE8A;
  9248. t['yehhamzaaboveinitialarabic'] = 0xFE8B;
  9249. t['yehhamzaabovemedialarabic'] = 0xFE8C;
  9250. t['yehinitialarabic'] = 0xFEF3;
  9251. t['yehmedialarabic'] = 0xFEF4;
  9252. t['yehmeeminitialarabic'] = 0xFCDD;
  9253. t['yehmeemisolatedarabic'] = 0xFC58;
  9254. t['yehnoonfinalarabic'] = 0xFC94;
  9255. t['yehthreedotsbelowarabic'] = 0x06D1;
  9256. t['yekorean'] = 0x3156;
  9257. t['yen'] = 0x00A5;
  9258. t['yenmonospace'] = 0xFFE5;
  9259. t['yeokorean'] = 0x3155;
  9260. t['yeorinhieuhkorean'] = 0x3186;
  9261. t['yerahbenyomohebrew'] = 0x05AA;
  9262. t['yerahbenyomolefthebrew'] = 0x05AA;
  9263. t['yericyrillic'] = 0x044B;
  9264. t['yerudieresiscyrillic'] = 0x04F9;
  9265. t['yesieungkorean'] = 0x3181;
  9266. t['yesieungpansioskorean'] = 0x3183;
  9267. t['yesieungsioskorean'] = 0x3182;
  9268. t['yetivhebrew'] = 0x059A;
  9269. t['ygrave'] = 0x1EF3;
  9270. t['yhook'] = 0x01B4;
  9271. t['yhookabove'] = 0x1EF7;
  9272. t['yiarmenian'] = 0x0575;
  9273. t['yicyrillic'] = 0x0457;
  9274. t['yikorean'] = 0x3162;
  9275. t['yinyang'] = 0x262F;
  9276. t['yiwnarmenian'] = 0x0582;
  9277. t['ymonospace'] = 0xFF59;
  9278. t['yod'] = 0x05D9;
  9279. t['yoddagesh'] = 0xFB39;
  9280. t['yoddageshhebrew'] = 0xFB39;
  9281. t['yodhebrew'] = 0x05D9;
  9282. t['yodyodhebrew'] = 0x05F2;
  9283. t['yodyodpatahhebrew'] = 0xFB1F;
  9284. t['yohiragana'] = 0x3088;
  9285. t['yoikorean'] = 0x3189;
  9286. t['yokatakana'] = 0x30E8;
  9287. t['yokatakanahalfwidth'] = 0xFF96;
  9288. t['yokorean'] = 0x315B;
  9289. t['yosmallhiragana'] = 0x3087;
  9290. t['yosmallkatakana'] = 0x30E7;
  9291. t['yosmallkatakanahalfwidth'] = 0xFF6E;
  9292. t['yotgreek'] = 0x03F3;
  9293. t['yoyaekorean'] = 0x3188;
  9294. t['yoyakorean'] = 0x3187;
  9295. t['yoyakthai'] = 0x0E22;
  9296. t['yoyingthai'] = 0x0E0D;
  9297. t['yparen'] = 0x24B4;
  9298. t['ypogegrammeni'] = 0x037A;
  9299. t['ypogegrammenigreekcmb'] = 0x0345;
  9300. t['yr'] = 0x01A6;
  9301. t['yring'] = 0x1E99;
  9302. t['ysuperior'] = 0x02B8;
  9303. t['ytilde'] = 0x1EF9;
  9304. t['yturned'] = 0x028E;
  9305. t['yuhiragana'] = 0x3086;
  9306. t['yuikorean'] = 0x318C;
  9307. t['yukatakana'] = 0x30E6;
  9308. t['yukatakanahalfwidth'] = 0xFF95;
  9309. t['yukorean'] = 0x3160;
  9310. t['yusbigcyrillic'] = 0x046B;
  9311. t['yusbigiotifiedcyrillic'] = 0x046D;
  9312. t['yuslittlecyrillic'] = 0x0467;
  9313. t['yuslittleiotifiedcyrillic'] = 0x0469;
  9314. t['yusmallhiragana'] = 0x3085;
  9315. t['yusmallkatakana'] = 0x30E5;
  9316. t['yusmallkatakanahalfwidth'] = 0xFF6D;
  9317. t['yuyekorean'] = 0x318B;
  9318. t['yuyeokorean'] = 0x318A;
  9319. t['yyabengali'] = 0x09DF;
  9320. t['yyadeva'] = 0x095F;
  9321. t['z'] = 0x007A;
  9322. t['zaarmenian'] = 0x0566;
  9323. t['zacute'] = 0x017A;
  9324. t['zadeva'] = 0x095B;
  9325. t['zagurmukhi'] = 0x0A5B;
  9326. t['zaharabic'] = 0x0638;
  9327. t['zahfinalarabic'] = 0xFEC6;
  9328. t['zahinitialarabic'] = 0xFEC7;
  9329. t['zahiragana'] = 0x3056;
  9330. t['zahmedialarabic'] = 0xFEC8;
  9331. t['zainarabic'] = 0x0632;
  9332. t['zainfinalarabic'] = 0xFEB0;
  9333. t['zakatakana'] = 0x30B6;
  9334. t['zaqefgadolhebrew'] = 0x0595;
  9335. t['zaqefqatanhebrew'] = 0x0594;
  9336. t['zarqahebrew'] = 0x0598;
  9337. t['zayin'] = 0x05D6;
  9338. t['zayindagesh'] = 0xFB36;
  9339. t['zayindageshhebrew'] = 0xFB36;
  9340. t['zayinhebrew'] = 0x05D6;
  9341. t['zbopomofo'] = 0x3117;
  9342. t['zcaron'] = 0x017E;
  9343. t['zcircle'] = 0x24E9;
  9344. t['zcircumflex'] = 0x1E91;
  9345. t['zcurl'] = 0x0291;
  9346. t['zdot'] = 0x017C;
  9347. t['zdotaccent'] = 0x017C;
  9348. t['zdotbelow'] = 0x1E93;
  9349. t['zecyrillic'] = 0x0437;
  9350. t['zedescendercyrillic'] = 0x0499;
  9351. t['zedieresiscyrillic'] = 0x04DF;
  9352. t['zehiragana'] = 0x305C;
  9353. t['zekatakana'] = 0x30BC;
  9354. t['zero'] = 0x0030;
  9355. t['zeroarabic'] = 0x0660;
  9356. t['zerobengali'] = 0x09E6;
  9357. t['zerodeva'] = 0x0966;
  9358. t['zerogujarati'] = 0x0AE6;
  9359. t['zerogurmukhi'] = 0x0A66;
  9360. t['zerohackarabic'] = 0x0660;
  9361. t['zeroinferior'] = 0x2080;
  9362. t['zeromonospace'] = 0xFF10;
  9363. t['zerooldstyle'] = 0xF730;
  9364. t['zeropersian'] = 0x06F0;
  9365. t['zerosuperior'] = 0x2070;
  9366. t['zerothai'] = 0x0E50;
  9367. t['zerowidthjoiner'] = 0xFEFF;
  9368. t['zerowidthnonjoiner'] = 0x200C;
  9369. t['zerowidthspace'] = 0x200B;
  9370. t['zeta'] = 0x03B6;
  9371. t['zhbopomofo'] = 0x3113;
  9372. t['zhearmenian'] = 0x056A;
  9373. t['zhebrevecyrillic'] = 0x04C2;
  9374. t['zhecyrillic'] = 0x0436;
  9375. t['zhedescendercyrillic'] = 0x0497;
  9376. t['zhedieresiscyrillic'] = 0x04DD;
  9377. t['zihiragana'] = 0x3058;
  9378. t['zikatakana'] = 0x30B8;
  9379. t['zinorhebrew'] = 0x05AE;
  9380. t['zlinebelow'] = 0x1E95;
  9381. t['zmonospace'] = 0xFF5A;
  9382. t['zohiragana'] = 0x305E;
  9383. t['zokatakana'] = 0x30BE;
  9384. t['zparen'] = 0x24B5;
  9385. t['zretroflexhook'] = 0x0290;
  9386. t['zstroke'] = 0x01B6;
  9387. t['zuhiragana'] = 0x305A;
  9388. t['zukatakana'] = 0x30BA;
  9389. t['.notdef'] = 0x0000;
  9390. // TeX-specific glyph names.
  9391. t['angbracketleftbig'] = 0x2329;
  9392. t['angbracketleftBig'] = 0x2329;
  9393. t['angbracketleftbigg'] = 0x2329;
  9394. t['angbracketleftBigg'] = 0x2329;
  9395. t['angbracketrightBig'] = 0x232A;
  9396. t['angbracketrightbig'] = 0x232A;
  9397. t['angbracketrightBigg'] = 0x232A;
  9398. t['angbracketrightbigg'] = 0x232A;
  9399. t['arrowhookleft'] = 0x21AA;
  9400. t['arrowhookright'] = 0x21A9;
  9401. t['arrowlefttophalf'] = 0x21BC;
  9402. t['arrowleftbothalf'] = 0x21BD;
  9403. t['arrownortheast'] = 0x2197;
  9404. t['arrownorthwest'] = 0x2196;
  9405. t['arrowrighttophalf'] = 0x21C0;
  9406. t['arrowrightbothalf'] = 0x21C1;
  9407. t['arrowsoutheast'] = 0x2198;
  9408. t['arrowsouthwest'] = 0x2199;
  9409. t['backslashbig'] = 0x2216;
  9410. t['backslashBig'] = 0x2216;
  9411. t['backslashBigg'] = 0x2216;
  9412. t['backslashbigg'] = 0x2216;
  9413. t['bardbl'] = 0x2016;
  9414. t['bracehtipdownleft'] = 0xFE37;
  9415. t['bracehtipdownright'] = 0xFE37;
  9416. t['bracehtipupleft'] = 0xFE38;
  9417. t['bracehtipupright'] = 0xFE38;
  9418. t['braceleftBig'] = 0x007B;
  9419. t['braceleftbig'] = 0x007B;
  9420. t['braceleftbigg'] = 0x007B;
  9421. t['braceleftBigg'] = 0x007B;
  9422. t['bracerightBig'] = 0x007D;
  9423. t['bracerightbig'] = 0x007D;
  9424. t['bracerightbigg'] = 0x007D;
  9425. t['bracerightBigg'] = 0x007D;
  9426. t['bracketleftbig'] = 0x005B;
  9427. t['bracketleftBig'] = 0x005B;
  9428. t['bracketleftbigg'] = 0x005B;
  9429. t['bracketleftBigg'] = 0x005B;
  9430. t['bracketrightBig'] = 0x005D;
  9431. t['bracketrightbig'] = 0x005D;
  9432. t['bracketrightbigg'] = 0x005D;
  9433. t['bracketrightBigg'] = 0x005D;
  9434. t['ceilingleftbig'] = 0x2308;
  9435. t['ceilingleftBig'] = 0x2308;
  9436. t['ceilingleftBigg'] = 0x2308;
  9437. t['ceilingleftbigg'] = 0x2308;
  9438. t['ceilingrightbig'] = 0x2309;
  9439. t['ceilingrightBig'] = 0x2309;
  9440. t['ceilingrightbigg'] = 0x2309;
  9441. t['ceilingrightBigg'] = 0x2309;
  9442. t['circledotdisplay'] = 0x2299;
  9443. t['circledottext'] = 0x2299;
  9444. t['circlemultiplydisplay'] = 0x2297;
  9445. t['circlemultiplytext'] = 0x2297;
  9446. t['circleplusdisplay'] = 0x2295;
  9447. t['circleplustext'] = 0x2295;
  9448. t['contintegraldisplay'] = 0x222E;
  9449. t['contintegraltext'] = 0x222E;
  9450. t['coproductdisplay'] = 0x2210;
  9451. t['coproducttext'] = 0x2210;
  9452. t['floorleftBig'] = 0x230A;
  9453. t['floorleftbig'] = 0x230A;
  9454. t['floorleftbigg'] = 0x230A;
  9455. t['floorleftBigg'] = 0x230A;
  9456. t['floorrightbig'] = 0x230B;
  9457. t['floorrightBig'] = 0x230B;
  9458. t['floorrightBigg'] = 0x230B;
  9459. t['floorrightbigg'] = 0x230B;
  9460. t['hatwide'] = 0x0302;
  9461. t['hatwider'] = 0x0302;
  9462. t['hatwidest'] = 0x0302;
  9463. t['intercal'] = 0x1D40;
  9464. t['integraldisplay'] = 0x222B;
  9465. t['integraltext'] = 0x222B;
  9466. t['intersectiondisplay'] = 0x22C2;
  9467. t['intersectiontext'] = 0x22C2;
  9468. t['logicalanddisplay'] = 0x2227;
  9469. t['logicalandtext'] = 0x2227;
  9470. t['logicalordisplay'] = 0x2228;
  9471. t['logicalortext'] = 0x2228;
  9472. t['parenleftBig'] = 0x0028;
  9473. t['parenleftbig'] = 0x0028;
  9474. t['parenleftBigg'] = 0x0028;
  9475. t['parenleftbigg'] = 0x0028;
  9476. t['parenrightBig'] = 0x0029;
  9477. t['parenrightbig'] = 0x0029;
  9478. t['parenrightBigg'] = 0x0029;
  9479. t['parenrightbigg'] = 0x0029;
  9480. t['prime'] = 0x2032;
  9481. t['productdisplay'] = 0x220F;
  9482. t['producttext'] = 0x220F;
  9483. t['radicalbig'] = 0x221A;
  9484. t['radicalBig'] = 0x221A;
  9485. t['radicalBigg'] = 0x221A;
  9486. t['radicalbigg'] = 0x221A;
  9487. t['radicalbt'] = 0x221A;
  9488. t['radicaltp'] = 0x221A;
  9489. t['radicalvertex'] = 0x221A;
  9490. t['slashbig'] = 0x002F;
  9491. t['slashBig'] = 0x002F;
  9492. t['slashBigg'] = 0x002F;
  9493. t['slashbigg'] = 0x002F;
  9494. t['summationdisplay'] = 0x2211;
  9495. t['summationtext'] = 0x2211;
  9496. t['tildewide'] = 0x02DC;
  9497. t['tildewider'] = 0x02DC;
  9498. t['tildewidest'] = 0x02DC;
  9499. t['uniondisplay'] = 0x22C3;
  9500. t['unionmultidisplay'] = 0x228E;
  9501. t['unionmultitext'] = 0x228E;
  9502. t['unionsqdisplay'] = 0x2294;
  9503. t['unionsqtext'] = 0x2294;
  9504. t['uniontext'] = 0x22C3;
  9505. t['vextenddouble'] = 0x2225;
  9506. t['vextendsingle'] = 0x2223;
  9507. });
  9508. var getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) {
  9509. t['space'] = 0x0020;
  9510. t['a1'] = 0x2701;
  9511. t['a2'] = 0x2702;
  9512. t['a202'] = 0x2703;
  9513. t['a3'] = 0x2704;
  9514. t['a4'] = 0x260E;
  9515. t['a5'] = 0x2706;
  9516. t['a119'] = 0x2707;
  9517. t['a118'] = 0x2708;
  9518. t['a117'] = 0x2709;
  9519. t['a11'] = 0x261B;
  9520. t['a12'] = 0x261E;
  9521. t['a13'] = 0x270C;
  9522. t['a14'] = 0x270D;
  9523. t['a15'] = 0x270E;
  9524. t['a16'] = 0x270F;
  9525. t['a105'] = 0x2710;
  9526. t['a17'] = 0x2711;
  9527. t['a18'] = 0x2712;
  9528. t['a19'] = 0x2713;
  9529. t['a20'] = 0x2714;
  9530. t['a21'] = 0x2715;
  9531. t['a22'] = 0x2716;
  9532. t['a23'] = 0x2717;
  9533. t['a24'] = 0x2718;
  9534. t['a25'] = 0x2719;
  9535. t['a26'] = 0x271A;
  9536. t['a27'] = 0x271B;
  9537. t['a28'] = 0x271C;
  9538. t['a6'] = 0x271D;
  9539. t['a7'] = 0x271E;
  9540. t['a8'] = 0x271F;
  9541. t['a9'] = 0x2720;
  9542. t['a10'] = 0x2721;
  9543. t['a29'] = 0x2722;
  9544. t['a30'] = 0x2723;
  9545. t['a31'] = 0x2724;
  9546. t['a32'] = 0x2725;
  9547. t['a33'] = 0x2726;
  9548. t['a34'] = 0x2727;
  9549. t['a35'] = 0x2605;
  9550. t['a36'] = 0x2729;
  9551. t['a37'] = 0x272A;
  9552. t['a38'] = 0x272B;
  9553. t['a39'] = 0x272C;
  9554. t['a40'] = 0x272D;
  9555. t['a41'] = 0x272E;
  9556. t['a42'] = 0x272F;
  9557. t['a43'] = 0x2730;
  9558. t['a44'] = 0x2731;
  9559. t['a45'] = 0x2732;
  9560. t['a46'] = 0x2733;
  9561. t['a47'] = 0x2734;
  9562. t['a48'] = 0x2735;
  9563. t['a49'] = 0x2736;
  9564. t['a50'] = 0x2737;
  9565. t['a51'] = 0x2738;
  9566. t['a52'] = 0x2739;
  9567. t['a53'] = 0x273A;
  9568. t['a54'] = 0x273B;
  9569. t['a55'] = 0x273C;
  9570. t['a56'] = 0x273D;
  9571. t['a57'] = 0x273E;
  9572. t['a58'] = 0x273F;
  9573. t['a59'] = 0x2740;
  9574. t['a60'] = 0x2741;
  9575. t['a61'] = 0x2742;
  9576. t['a62'] = 0x2743;
  9577. t['a63'] = 0x2744;
  9578. t['a64'] = 0x2745;
  9579. t['a65'] = 0x2746;
  9580. t['a66'] = 0x2747;
  9581. t['a67'] = 0x2748;
  9582. t['a68'] = 0x2749;
  9583. t['a69'] = 0x274A;
  9584. t['a70'] = 0x274B;
  9585. t['a71'] = 0x25CF;
  9586. t['a72'] = 0x274D;
  9587. t['a73'] = 0x25A0;
  9588. t['a74'] = 0x274F;
  9589. t['a203'] = 0x2750;
  9590. t['a75'] = 0x2751;
  9591. t['a204'] = 0x2752;
  9592. t['a76'] = 0x25B2;
  9593. t['a77'] = 0x25BC;
  9594. t['a78'] = 0x25C6;
  9595. t['a79'] = 0x2756;
  9596. t['a81'] = 0x25D7;
  9597. t['a82'] = 0x2758;
  9598. t['a83'] = 0x2759;
  9599. t['a84'] = 0x275A;
  9600. t['a97'] = 0x275B;
  9601. t['a98'] = 0x275C;
  9602. t['a99'] = 0x275D;
  9603. t['a100'] = 0x275E;
  9604. t['a101'] = 0x2761;
  9605. t['a102'] = 0x2762;
  9606. t['a103'] = 0x2763;
  9607. t['a104'] = 0x2764;
  9608. t['a106'] = 0x2765;
  9609. t['a107'] = 0x2766;
  9610. t['a108'] = 0x2767;
  9611. t['a112'] = 0x2663;
  9612. t['a111'] = 0x2666;
  9613. t['a110'] = 0x2665;
  9614. t['a109'] = 0x2660;
  9615. t['a120'] = 0x2460;
  9616. t['a121'] = 0x2461;
  9617. t['a122'] = 0x2462;
  9618. t['a123'] = 0x2463;
  9619. t['a124'] = 0x2464;
  9620. t['a125'] = 0x2465;
  9621. t['a126'] = 0x2466;
  9622. t['a127'] = 0x2467;
  9623. t['a128'] = 0x2468;
  9624. t['a129'] = 0x2469;
  9625. t['a130'] = 0x2776;
  9626. t['a131'] = 0x2777;
  9627. t['a132'] = 0x2778;
  9628. t['a133'] = 0x2779;
  9629. t['a134'] = 0x277A;
  9630. t['a135'] = 0x277B;
  9631. t['a136'] = 0x277C;
  9632. t['a137'] = 0x277D;
  9633. t['a138'] = 0x277E;
  9634. t['a139'] = 0x277F;
  9635. t['a140'] = 0x2780;
  9636. t['a141'] = 0x2781;
  9637. t['a142'] = 0x2782;
  9638. t['a143'] = 0x2783;
  9639. t['a144'] = 0x2784;
  9640. t['a145'] = 0x2785;
  9641. t['a146'] = 0x2786;
  9642. t['a147'] = 0x2787;
  9643. t['a148'] = 0x2788;
  9644. t['a149'] = 0x2789;
  9645. t['a150'] = 0x278A;
  9646. t['a151'] = 0x278B;
  9647. t['a152'] = 0x278C;
  9648. t['a153'] = 0x278D;
  9649. t['a154'] = 0x278E;
  9650. t['a155'] = 0x278F;
  9651. t['a156'] = 0x2790;
  9652. t['a157'] = 0x2791;
  9653. t['a158'] = 0x2792;
  9654. t['a159'] = 0x2793;
  9655. t['a160'] = 0x2794;
  9656. t['a161'] = 0x2192;
  9657. t['a163'] = 0x2194;
  9658. t['a164'] = 0x2195;
  9659. t['a196'] = 0x2798;
  9660. t['a165'] = 0x2799;
  9661. t['a192'] = 0x279A;
  9662. t['a166'] = 0x279B;
  9663. t['a167'] = 0x279C;
  9664. t['a168'] = 0x279D;
  9665. t['a169'] = 0x279E;
  9666. t['a170'] = 0x279F;
  9667. t['a171'] = 0x27A0;
  9668. t['a172'] = 0x27A1;
  9669. t['a173'] = 0x27A2;
  9670. t['a162'] = 0x27A3;
  9671. t['a174'] = 0x27A4;
  9672. t['a175'] = 0x27A5;
  9673. t['a176'] = 0x27A6;
  9674. t['a177'] = 0x27A7;
  9675. t['a178'] = 0x27A8;
  9676. t['a179'] = 0x27A9;
  9677. t['a193'] = 0x27AA;
  9678. t['a180'] = 0x27AB;
  9679. t['a199'] = 0x27AC;
  9680. t['a181'] = 0x27AD;
  9681. t['a200'] = 0x27AE;
  9682. t['a182'] = 0x27AF;
  9683. t['a201'] = 0x27B1;
  9684. t['a183'] = 0x27B2;
  9685. t['a184'] = 0x27B3;
  9686. t['a197'] = 0x27B4;
  9687. t['a185'] = 0x27B5;
  9688. t['a194'] = 0x27B6;
  9689. t['a198'] = 0x27B7;
  9690. t['a186'] = 0x27B8;
  9691. t['a195'] = 0x27B9;
  9692. t['a187'] = 0x27BA;
  9693. t['a188'] = 0x27BB;
  9694. t['a189'] = 0x27BC;
  9695. t['a190'] = 0x27BD;
  9696. t['a191'] = 0x27BE;
  9697. t['a89'] = 0x2768; // 0xF8D7
  9698. t['a90'] = 0x2769; // 0xF8D8
  9699. t['a93'] = 0x276A; // 0xF8D9
  9700. t['a94'] = 0x276B; // 0xF8DA
  9701. t['a91'] = 0x276C; // 0xF8DB
  9702. t['a92'] = 0x276D; // 0xF8DC
  9703. t['a205'] = 0x276E; // 0xF8DD
  9704. t['a85'] = 0x276F; // 0xF8DE
  9705. t['a206'] = 0x2770; // 0xF8DF
  9706. t['a86'] = 0x2771; // 0xF8E0
  9707. t['a87'] = 0x2772; // 0xF8E1
  9708. t['a88'] = 0x2773; // 0xF8E2
  9709. t['a95'] = 0x2774; // 0xF8E3
  9710. t['a96'] = 0x2775; // 0xF8E4
  9711. t['.notdef'] = 0x0000;
  9712. });
  9713. exports.getGlyphsUnicode = getGlyphsUnicode;
  9714. exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode;
  9715. }));
  9716. (function (root, factory) {
  9717. {
  9718. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  9719. root.pdfjsCoreArithmeticDecoder);
  9720. }
  9721. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  9722. var error = sharedUtil.error;
  9723. var log2 = sharedUtil.log2;
  9724. var readInt8 = sharedUtil.readInt8;
  9725. var readUint16 = sharedUtil.readUint16;
  9726. var readUint32 = sharedUtil.readUint32;
  9727. var shadow = sharedUtil.shadow;
  9728. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  9729. var Jbig2Image = (function Jbig2ImageClosure() {
  9730. // Utility data structures
  9731. function ContextCache() {}
  9732. ContextCache.prototype = {
  9733. getContexts: function(id) {
  9734. if (id in this) {
  9735. return this[id];
  9736. }
  9737. return (this[id] = new Int8Array(1 << 16));
  9738. }
  9739. };
  9740. function DecodingContext(data, start, end) {
  9741. this.data = data;
  9742. this.start = start;
  9743. this.end = end;
  9744. }
  9745. DecodingContext.prototype = {
  9746. get decoder() {
  9747. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  9748. return shadow(this, 'decoder', decoder);
  9749. },
  9750. get contextCache() {
  9751. var cache = new ContextCache();
  9752. return shadow(this, 'contextCache', cache);
  9753. }
  9754. };
  9755. // Annex A. Arithmetic Integer Decoding Procedure
  9756. // A.2 Procedure for decoding values
  9757. function decodeInteger(contextCache, procedure, decoder) {
  9758. var contexts = contextCache.getContexts(procedure);
  9759. var prev = 1;
  9760. function readBits(length) {
  9761. var v = 0;
  9762. for (var i = 0; i < length; i++) {
  9763. var bit = decoder.readBit(contexts, prev);
  9764. prev = (prev < 256 ? (prev << 1) | bit :
  9765. (((prev << 1) | bit) & 511) | 256);
  9766. v = (v << 1) | bit;
  9767. }
  9768. return v >>> 0;
  9769. }
  9770. var sign = readBits(1);
  9771. var value = readBits(1) ?
  9772. (readBits(1) ?
  9773. (readBits(1) ?
  9774. (readBits(1) ?
  9775. (readBits(1) ?
  9776. (readBits(32) + 4436) :
  9777. readBits(12) + 340) :
  9778. readBits(8) + 84) :
  9779. readBits(6) + 20) :
  9780. readBits(4) + 4) :
  9781. readBits(2);
  9782. return (sign === 0 ? value : (value > 0 ? -value : null));
  9783. }
  9784. // A.3 The IAID decoding procedure
  9785. function decodeIAID(contextCache, decoder, codeLength) {
  9786. var contexts = contextCache.getContexts('IAID');
  9787. var prev = 1;
  9788. for (var i = 0; i < codeLength; i++) {
  9789. var bit = decoder.readBit(contexts, prev);
  9790. prev = (prev << 1) | bit;
  9791. }
  9792. if (codeLength < 31) {
  9793. return prev & ((1 << codeLength) - 1);
  9794. }
  9795. return prev & 0x7FFFFFFF;
  9796. }
  9797. // 7.3 Segment types
  9798. var SegmentTypes = [
  9799. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  9800. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  9801. null, null, null, null, null, 'patternDictionary', null, null, null,
  9802. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  9803. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  9804. null, null, null, null, null, 'IntermediateGenericRegion', null,
  9805. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  9806. 'IntermediateGenericRefinementRegion', null,
  9807. 'ImmediateGenericRefinementRegion',
  9808. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  9809. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  9810. 'Tables', null, null, null, null, null, null, null, null,
  9811. 'Extension'
  9812. ];
  9813. var CodingTemplates = [
  9814. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  9815. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  9816. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  9817. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  9818. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  9819. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  9820. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  9821. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  9822. {x: -1, y: 0}],
  9823. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  9824. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  9825. ];
  9826. var RefinementTemplates = [
  9827. {
  9828. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  9829. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  9830. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  9831. },
  9832. {
  9833. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  9834. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  9835. {x: 0, y: 1}, {x: 1, y: 1}]
  9836. }
  9837. ];
  9838. // See 6.2.5.7 Decoding the bitmap.
  9839. var ReusedContexts = [
  9840. 0x9B25, // 10011 0110010 0101
  9841. 0x0795, // 0011 110010 101
  9842. 0x00E5, // 001 11001 01
  9843. 0x0195 // 011001 0101
  9844. ];
  9845. var RefinementReusedContexts = [
  9846. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  9847. 0x0008 // '0000' + '001000'
  9848. ];
  9849. function decodeBitmapTemplate0(width, height, decodingContext) {
  9850. var decoder = decodingContext.decoder;
  9851. var contexts = decodingContext.contextCache.getContexts('GB');
  9852. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  9853. // ...ooooo....
  9854. // ..ooooooo... Context template for current pixel (X)
  9855. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  9856. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  9857. for (i = 0; i < height; i++) {
  9858. row = bitmap[i] = new Uint8Array(width);
  9859. row1 = (i < 1) ? row : bitmap[i - 1];
  9860. row2 = (i < 2) ? row : bitmap[i - 2];
  9861. // At the beginning of each row:
  9862. // Fill contextLabel with pixels that are above/right of (X)
  9863. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  9864. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  9865. (row1[3] << 4);
  9866. for (j = 0; j < width; j++) {
  9867. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  9868. // At each pixel: Clear contextLabel pixels that are shifted
  9869. // out of the context, then add new ones.
  9870. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  9871. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  9872. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  9873. }
  9874. }
  9875. return bitmap;
  9876. }
  9877. // 6.2 Generic Region Decoding Procedure
  9878. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  9879. decodingContext) {
  9880. if (mmr) {
  9881. error('JBIG2 error: MMR encoding is not supported');
  9882. }
  9883. // Use optimized version for the most common case
  9884. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  9885. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  9886. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  9887. return decodeBitmapTemplate0(width, height, decodingContext);
  9888. }
  9889. var useskip = !!skip;
  9890. var template = CodingTemplates[templateIndex].concat(at);
  9891. // Sorting is non-standard, and it is not required. But sorting increases
  9892. // the number of template bits that can be reused from the previous
  9893. // contextLabel in the main loop.
  9894. template.sort(function (a, b) {
  9895. return (a.y - b.y) || (a.x - b.x);
  9896. });
  9897. var templateLength = template.length;
  9898. var templateX = new Int8Array(templateLength);
  9899. var templateY = new Int8Array(templateLength);
  9900. var changingTemplateEntries = [];
  9901. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  9902. var c, k;
  9903. for (k = 0; k < templateLength; k++) {
  9904. templateX[k] = template[k].x;
  9905. templateY[k] = template[k].y;
  9906. minX = Math.min(minX, template[k].x);
  9907. maxX = Math.max(maxX, template[k].x);
  9908. minY = Math.min(minY, template[k].y);
  9909. // Check if the template pixel appears in two consecutive context labels,
  9910. // so it can be reused. Otherwise, we add it to the list of changing
  9911. // template entries.
  9912. if (k < templateLength - 1 &&
  9913. template[k].y === template[k + 1].y &&
  9914. template[k].x === template[k + 1].x - 1) {
  9915. reuseMask |= 1 << (templateLength - 1 - k);
  9916. } else {
  9917. changingTemplateEntries.push(k);
  9918. }
  9919. }
  9920. var changingEntriesLength = changingTemplateEntries.length;
  9921. var changingTemplateX = new Int8Array(changingEntriesLength);
  9922. var changingTemplateY = new Int8Array(changingEntriesLength);
  9923. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  9924. for (c = 0; c < changingEntriesLength; c++) {
  9925. k = changingTemplateEntries[c];
  9926. changingTemplateX[c] = template[k].x;
  9927. changingTemplateY[c] = template[k].y;
  9928. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  9929. }
  9930. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  9931. var sbb_left = -minX;
  9932. var sbb_top = -minY;
  9933. var sbb_right = width - maxX;
  9934. var pseudoPixelContext = ReusedContexts[templateIndex];
  9935. var row = new Uint8Array(width);
  9936. var bitmap = [];
  9937. var decoder = decodingContext.decoder;
  9938. var contexts = decodingContext.contextCache.getContexts('GB');
  9939. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  9940. for (var i = 0; i < height; i++) {
  9941. if (prediction) {
  9942. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  9943. ltp ^= sltp;
  9944. if (ltp) {
  9945. bitmap.push(row); // duplicate previous row
  9946. continue;
  9947. }
  9948. }
  9949. row = new Uint8Array(row);
  9950. bitmap.push(row);
  9951. for (j = 0; j < width; j++) {
  9952. if (useskip && skip[i][j]) {
  9953. row[j] = 0;
  9954. continue;
  9955. }
  9956. // Are we in the middle of a scanline, so we can reuse contextLabel
  9957. // bits?
  9958. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  9959. // If yes, we can just shift the bits that are reusable and only
  9960. // fetch the remaining ones.
  9961. contextLabel = (contextLabel << 1) & reuseMask;
  9962. for (k = 0; k < changingEntriesLength; k++) {
  9963. i0 = i + changingTemplateY[k];
  9964. j0 = j + changingTemplateX[k];
  9965. bit = bitmap[i0][j0];
  9966. if (bit) {
  9967. bit = changingTemplateBit[k];
  9968. contextLabel |= bit;
  9969. }
  9970. }
  9971. } else {
  9972. // compute the contextLabel from scratch
  9973. contextLabel = 0;
  9974. shift = templateLength - 1;
  9975. for (k = 0; k < templateLength; k++, shift--) {
  9976. j0 = j + templateX[k];
  9977. if (j0 >= 0 && j0 < width) {
  9978. i0 = i + templateY[k];
  9979. if (i0 >= 0) {
  9980. bit = bitmap[i0][j0];
  9981. if (bit) {
  9982. contextLabel |= bit << shift;
  9983. }
  9984. }
  9985. }
  9986. }
  9987. }
  9988. var pixel = decoder.readBit(contexts, contextLabel);
  9989. row[j] = pixel;
  9990. }
  9991. }
  9992. return bitmap;
  9993. }
  9994. // 6.3.2 Generic Refinement Region Decoding Procedure
  9995. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  9996. offsetX, offsetY, prediction, at,
  9997. decodingContext) {
  9998. var codingTemplate = RefinementTemplates[templateIndex].coding;
  9999. if (templateIndex === 0) {
  10000. codingTemplate = codingTemplate.concat([at[0]]);
  10001. }
  10002. var codingTemplateLength = codingTemplate.length;
  10003. var codingTemplateX = new Int32Array(codingTemplateLength);
  10004. var codingTemplateY = new Int32Array(codingTemplateLength);
  10005. var k;
  10006. for (k = 0; k < codingTemplateLength; k++) {
  10007. codingTemplateX[k] = codingTemplate[k].x;
  10008. codingTemplateY[k] = codingTemplate[k].y;
  10009. }
  10010. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  10011. if (templateIndex === 0) {
  10012. referenceTemplate = referenceTemplate.concat([at[1]]);
  10013. }
  10014. var referenceTemplateLength = referenceTemplate.length;
  10015. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  10016. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  10017. for (k = 0; k < referenceTemplateLength; k++) {
  10018. referenceTemplateX[k] = referenceTemplate[k].x;
  10019. referenceTemplateY[k] = referenceTemplate[k].y;
  10020. }
  10021. var referenceWidth = referenceBitmap[0].length;
  10022. var referenceHeight = referenceBitmap.length;
  10023. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  10024. var bitmap = [];
  10025. var decoder = decodingContext.decoder;
  10026. var contexts = decodingContext.contextCache.getContexts('GR');
  10027. var ltp = 0;
  10028. for (var i = 0; i < height; i++) {
  10029. if (prediction) {
  10030. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  10031. ltp ^= sltp;
  10032. if (ltp) {
  10033. error('JBIG2 error: prediction is not supported');
  10034. }
  10035. }
  10036. var row = new Uint8Array(width);
  10037. bitmap.push(row);
  10038. for (var j = 0; j < width; j++) {
  10039. var i0, j0;
  10040. var contextLabel = 0;
  10041. for (k = 0; k < codingTemplateLength; k++) {
  10042. i0 = i + codingTemplateY[k];
  10043. j0 = j + codingTemplateX[k];
  10044. if (i0 < 0 || j0 < 0 || j0 >= width) {
  10045. contextLabel <<= 1; // out of bound pixel
  10046. } else {
  10047. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  10048. }
  10049. }
  10050. for (k = 0; k < referenceTemplateLength; k++) {
  10051. i0 = i + referenceTemplateY[k] + offsetY;
  10052. j0 = j + referenceTemplateX[k] + offsetX;
  10053. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  10054. j0 >= referenceWidth) {
  10055. contextLabel <<= 1; // out of bound pixel
  10056. } else {
  10057. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  10058. }
  10059. }
  10060. var pixel = decoder.readBit(contexts, contextLabel);
  10061. row[j] = pixel;
  10062. }
  10063. }
  10064. return bitmap;
  10065. }
  10066. // 6.5.5 Decoding the symbol dictionary
  10067. function decodeSymbolDictionary(huffman, refinement, symbols,
  10068. numberOfNewSymbols, numberOfExportedSymbols,
  10069. huffmanTables, templateIndex, at,
  10070. refinementTemplateIndex, refinementAt,
  10071. decodingContext) {
  10072. if (huffman) {
  10073. error('JBIG2 error: huffman is not supported');
  10074. }
  10075. var newSymbols = [];
  10076. var currentHeight = 0;
  10077. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  10078. var decoder = decodingContext.decoder;
  10079. var contextCache = decodingContext.contextCache;
  10080. while (newSymbols.length < numberOfNewSymbols) {
  10081. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  10082. currentHeight += deltaHeight;
  10083. var currentWidth = 0;
  10084. var totalWidth = 0;
  10085. while (true) {
  10086. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  10087. if (deltaWidth === null) {
  10088. break; // OOB
  10089. }
  10090. currentWidth += deltaWidth;
  10091. totalWidth += currentWidth;
  10092. var bitmap;
  10093. if (refinement) {
  10094. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  10095. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  10096. if (numberOfInstances > 1) {
  10097. bitmap = decodeTextRegion(huffman, refinement,
  10098. currentWidth, currentHeight, 0,
  10099. numberOfInstances, 1, //strip size
  10100. symbols.concat(newSymbols),
  10101. symbolCodeLength,
  10102. 0, //transposed
  10103. 0, //ds offset
  10104. 1, //top left 7.4.3.1.1
  10105. 0, //OR operator
  10106. huffmanTables,
  10107. refinementTemplateIndex, refinementAt,
  10108. decodingContext);
  10109. } else {
  10110. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  10111. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  10112. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  10113. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  10114. newSymbols[symbolId - symbols.length]);
  10115. bitmap = decodeRefinement(currentWidth, currentHeight,
  10116. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  10117. decodingContext);
  10118. }
  10119. } else {
  10120. // 6.5.8.1 Direct-coded symbol bitmap
  10121. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  10122. templateIndex, false, null, at, decodingContext);
  10123. }
  10124. newSymbols.push(bitmap);
  10125. }
  10126. }
  10127. // 6.5.10 Exported symbols
  10128. var exportedSymbols = [];
  10129. var flags = [], currentFlag = false;
  10130. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  10131. while (flags.length < totalSymbolsLength) {
  10132. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  10133. while (runLength--) {
  10134. flags.push(currentFlag);
  10135. }
  10136. currentFlag = !currentFlag;
  10137. }
  10138. for (var i = 0, ii = symbols.length; i < ii; i++) {
  10139. if (flags[i]) {
  10140. exportedSymbols.push(symbols[i]);
  10141. }
  10142. }
  10143. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  10144. if (flags[i]) {
  10145. exportedSymbols.push(newSymbols[j]);
  10146. }
  10147. }
  10148. return exportedSymbols;
  10149. }
  10150. function decodeTextRegion(huffman, refinement, width, height,
  10151. defaultPixelValue, numberOfSymbolInstances,
  10152. stripSize, inputSymbols, symbolCodeLength,
  10153. transposed, dsOffset, referenceCorner,
  10154. combinationOperator, huffmanTables,
  10155. refinementTemplateIndex, refinementAt,
  10156. decodingContext) {
  10157. if (huffman) {
  10158. error('JBIG2 error: huffman is not supported');
  10159. }
  10160. // Prepare bitmap
  10161. var bitmap = [];
  10162. var i, row;
  10163. for (i = 0; i < height; i++) {
  10164. row = new Uint8Array(width);
  10165. if (defaultPixelValue) {
  10166. for (var j = 0; j < width; j++) {
  10167. row[j] = defaultPixelValue;
  10168. }
  10169. }
  10170. bitmap.push(row);
  10171. }
  10172. var decoder = decodingContext.decoder;
  10173. var contextCache = decodingContext.contextCache;
  10174. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  10175. var firstS = 0;
  10176. i = 0;
  10177. while (i < numberOfSymbolInstances) {
  10178. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  10179. stripT += deltaT;
  10180. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  10181. firstS += deltaFirstS;
  10182. var currentS = firstS;
  10183. do {
  10184. var currentT = (stripSize === 1 ? 0 :
  10185. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  10186. var t = stripSize * stripT + currentT;
  10187. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  10188. var applyRefinement = (refinement &&
  10189. decodeInteger(contextCache, 'IARI', decoder));
  10190. var symbolBitmap = inputSymbols[symbolId];
  10191. var symbolWidth = symbolBitmap[0].length;
  10192. var symbolHeight = symbolBitmap.length;
  10193. if (applyRefinement) {
  10194. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  10195. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  10196. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  10197. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  10198. symbolWidth += rdw;
  10199. symbolHeight += rdh;
  10200. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  10201. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  10202. (rdh >> 1) + rdy, false, refinementAt,
  10203. decodingContext);
  10204. }
  10205. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  10206. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  10207. var s2, t2, symbolRow;
  10208. if (transposed) {
  10209. // Place Symbol Bitmap from T1,S1
  10210. for (s2 = 0; s2 < symbolHeight; s2++) {
  10211. row = bitmap[offsetS + s2];
  10212. if (!row) {
  10213. continue;
  10214. }
  10215. symbolRow = symbolBitmap[s2];
  10216. // To ignore Parts of Symbol bitmap which goes
  10217. // outside bitmap region
  10218. var maxWidth = Math.min(width - offsetT, symbolWidth);
  10219. switch (combinationOperator) {
  10220. case 0: // OR
  10221. for (t2 = 0; t2 < maxWidth; t2++) {
  10222. row[offsetT + t2] |= symbolRow[t2];
  10223. }
  10224. break;
  10225. case 2: // XOR
  10226. for (t2 = 0; t2 < maxWidth; t2++) {
  10227. row[offsetT + t2] ^= symbolRow[t2];
  10228. }
  10229. break;
  10230. default:
  10231. error('JBIG2 error: operator ' + combinationOperator +
  10232. ' is not supported');
  10233. }
  10234. }
  10235. currentS += symbolHeight - 1;
  10236. } else {
  10237. for (t2 = 0; t2 < symbolHeight; t2++) {
  10238. row = bitmap[offsetT + t2];
  10239. if (!row) {
  10240. continue;
  10241. }
  10242. symbolRow = symbolBitmap[t2];
  10243. switch (combinationOperator) {
  10244. case 0: // OR
  10245. for (s2 = 0; s2 < symbolWidth; s2++) {
  10246. row[offsetS + s2] |= symbolRow[s2];
  10247. }
  10248. break;
  10249. case 2: // XOR
  10250. for (s2 = 0; s2 < symbolWidth; s2++) {
  10251. row[offsetS + s2] ^= symbolRow[s2];
  10252. }
  10253. break;
  10254. default:
  10255. error('JBIG2 error: operator ' + combinationOperator +
  10256. ' is not supported');
  10257. }
  10258. }
  10259. currentS += symbolWidth - 1;
  10260. }
  10261. i++;
  10262. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  10263. if (deltaS === null) {
  10264. break; // OOB
  10265. }
  10266. currentS += deltaS + dsOffset;
  10267. } while (true);
  10268. }
  10269. return bitmap;
  10270. }
  10271. function readSegmentHeader(data, start) {
  10272. var segmentHeader = {};
  10273. segmentHeader.number = readUint32(data, start);
  10274. var flags = data[start + 4];
  10275. var segmentType = flags & 0x3F;
  10276. if (!SegmentTypes[segmentType]) {
  10277. error('JBIG2 error: invalid segment type: ' + segmentType);
  10278. }
  10279. segmentHeader.type = segmentType;
  10280. segmentHeader.typeName = SegmentTypes[segmentType];
  10281. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  10282. var pageAssociationFieldSize = !!(flags & 0x40);
  10283. var referredFlags = data[start + 5];
  10284. var referredToCount = (referredFlags >> 5) & 7;
  10285. var retainBits = [referredFlags & 31];
  10286. var position = start + 6;
  10287. if (referredFlags === 7) {
  10288. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  10289. position += 3;
  10290. var bytes = (referredToCount + 7) >> 3;
  10291. retainBits[0] = data[position++];
  10292. while (--bytes > 0) {
  10293. retainBits.push(data[position++]);
  10294. }
  10295. } else if (referredFlags === 5 || referredFlags === 6) {
  10296. error('JBIG2 error: invalid referred-to flags');
  10297. }
  10298. segmentHeader.retainBits = retainBits;
  10299. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  10300. (segmentHeader.number <= 65536 ? 2 : 4));
  10301. var referredTo = [];
  10302. var i, ii;
  10303. for (i = 0; i < referredToCount; i++) {
  10304. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  10305. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  10306. readUint32(data, position)));
  10307. referredTo.push(number);
  10308. position += referredToSegmentNumberSize;
  10309. }
  10310. segmentHeader.referredTo = referredTo;
  10311. if (!pageAssociationFieldSize) {
  10312. segmentHeader.pageAssociation = data[position++];
  10313. } else {
  10314. segmentHeader.pageAssociation = readUint32(data, position);
  10315. position += 4;
  10316. }
  10317. segmentHeader.length = readUint32(data, position);
  10318. position += 4;
  10319. if (segmentHeader.length === 0xFFFFFFFF) {
  10320. // 7.2.7 Segment data length, unknown segment length
  10321. if (segmentType === 38) { // ImmediateGenericRegion
  10322. var genericRegionInfo = readRegionSegmentInformation(data, position);
  10323. var genericRegionSegmentFlags = data[position +
  10324. RegionSegmentInformationFieldLength];
  10325. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  10326. // searching for the segment end
  10327. var searchPatternLength = 6;
  10328. var searchPattern = new Uint8Array(searchPatternLength);
  10329. if (!genericRegionMmr) {
  10330. searchPattern[0] = 0xFF;
  10331. searchPattern[1] = 0xAC;
  10332. }
  10333. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  10334. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  10335. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  10336. searchPattern[5] = genericRegionInfo.height & 0xFF;
  10337. for (i = position, ii = data.length; i < ii; i++) {
  10338. var j = 0;
  10339. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  10340. j++;
  10341. }
  10342. if (j === searchPatternLength) {
  10343. segmentHeader.length = i + searchPatternLength;
  10344. break;
  10345. }
  10346. }
  10347. if (segmentHeader.length === 0xFFFFFFFF) {
  10348. error('JBIG2 error: segment end was not found');
  10349. }
  10350. } else {
  10351. error('JBIG2 error: invalid unknown segment length');
  10352. }
  10353. }
  10354. segmentHeader.headerEnd = position;
  10355. return segmentHeader;
  10356. }
  10357. function readSegments(header, data, start, end) {
  10358. var segments = [];
  10359. var position = start;
  10360. while (position < end) {
  10361. var segmentHeader = readSegmentHeader(data, position);
  10362. position = segmentHeader.headerEnd;
  10363. var segment = {
  10364. header: segmentHeader,
  10365. data: data
  10366. };
  10367. if (!header.randomAccess) {
  10368. segment.start = position;
  10369. position += segmentHeader.length;
  10370. segment.end = position;
  10371. }
  10372. segments.push(segment);
  10373. if (segmentHeader.type === 51) {
  10374. break; // end of file is found
  10375. }
  10376. }
  10377. if (header.randomAccess) {
  10378. for (var i = 0, ii = segments.length; i < ii; i++) {
  10379. segments[i].start = position;
  10380. position += segments[i].header.length;
  10381. segments[i].end = position;
  10382. }
  10383. }
  10384. return segments;
  10385. }
  10386. // 7.4.1 Region segment information field
  10387. function readRegionSegmentInformation(data, start) {
  10388. return {
  10389. width: readUint32(data, start),
  10390. height: readUint32(data, start + 4),
  10391. x: readUint32(data, start + 8),
  10392. y: readUint32(data, start + 12),
  10393. combinationOperator: data[start + 16] & 7
  10394. };
  10395. }
  10396. var RegionSegmentInformationFieldLength = 17;
  10397. function processSegment(segment, visitor) {
  10398. var header = segment.header;
  10399. var data = segment.data, position = segment.start, end = segment.end;
  10400. var args, at, i, atLength;
  10401. switch (header.type) {
  10402. case 0: // SymbolDictionary
  10403. // 7.4.2 Symbol dictionary segment syntax
  10404. var dictionary = {};
  10405. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  10406. dictionary.huffman = !!(dictionaryFlags & 1);
  10407. dictionary.refinement = !!(dictionaryFlags & 2);
  10408. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  10409. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  10410. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  10411. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  10412. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  10413. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  10414. dictionary.template = (dictionaryFlags >> 10) & 3;
  10415. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  10416. position += 2;
  10417. if (!dictionary.huffman) {
  10418. atLength = dictionary.template === 0 ? 4 : 1;
  10419. at = [];
  10420. for (i = 0; i < atLength; i++) {
  10421. at.push({
  10422. x: readInt8(data, position),
  10423. y: readInt8(data, position + 1)
  10424. });
  10425. position += 2;
  10426. }
  10427. dictionary.at = at;
  10428. }
  10429. if (dictionary.refinement && !dictionary.refinementTemplate) {
  10430. at = [];
  10431. for (i = 0; i < 2; i++) {
  10432. at.push({
  10433. x: readInt8(data, position),
  10434. y: readInt8(data, position + 1)
  10435. });
  10436. position += 2;
  10437. }
  10438. dictionary.refinementAt = at;
  10439. }
  10440. dictionary.numberOfExportedSymbols = readUint32(data, position);
  10441. position += 4;
  10442. dictionary.numberOfNewSymbols = readUint32(data, position);
  10443. position += 4;
  10444. args = [dictionary, header.number, header.referredTo,
  10445. data, position, end];
  10446. break;
  10447. case 6: // ImmediateTextRegion
  10448. case 7: // ImmediateLosslessTextRegion
  10449. var textRegion = {};
  10450. textRegion.info = readRegionSegmentInformation(data, position);
  10451. position += RegionSegmentInformationFieldLength;
  10452. var textRegionSegmentFlags = readUint16(data, position);
  10453. position += 2;
  10454. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  10455. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  10456. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  10457. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  10458. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  10459. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  10460. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  10461. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  10462. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  10463. if (textRegion.huffman) {
  10464. var textRegionHuffmanFlags = readUint16(data, position);
  10465. position += 2;
  10466. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  10467. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  10468. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  10469. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  10470. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  10471. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  10472. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  10473. textRegion.huffmanRefinementSizeSelector =
  10474. !!(textRegionHuffmanFlags & 14);
  10475. }
  10476. if (textRegion.refinement && !textRegion.refinementTemplate) {
  10477. at = [];
  10478. for (i = 0; i < 2; i++) {
  10479. at.push({
  10480. x: readInt8(data, position),
  10481. y: readInt8(data, position + 1)
  10482. });
  10483. position += 2;
  10484. }
  10485. textRegion.refinementAt = at;
  10486. }
  10487. textRegion.numberOfSymbolInstances = readUint32(data, position);
  10488. position += 4;
  10489. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  10490. if (textRegion.huffman) {
  10491. error('JBIG2 error: huffman is not supported');
  10492. }
  10493. args = [textRegion, header.referredTo, data, position, end];
  10494. break;
  10495. case 38: // ImmediateGenericRegion
  10496. case 39: // ImmediateLosslessGenericRegion
  10497. var genericRegion = {};
  10498. genericRegion.info = readRegionSegmentInformation(data, position);
  10499. position += RegionSegmentInformationFieldLength;
  10500. var genericRegionSegmentFlags = data[position++];
  10501. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  10502. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  10503. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  10504. if (!genericRegion.mmr) {
  10505. atLength = genericRegion.template === 0 ? 4 : 1;
  10506. at = [];
  10507. for (i = 0; i < atLength; i++) {
  10508. at.push({
  10509. x: readInt8(data, position),
  10510. y: readInt8(data, position + 1)
  10511. });
  10512. position += 2;
  10513. }
  10514. genericRegion.at = at;
  10515. }
  10516. args = [genericRegion, data, position, end];
  10517. break;
  10518. case 48: // PageInformation
  10519. var pageInfo = {
  10520. width: readUint32(data, position),
  10521. height: readUint32(data, position + 4),
  10522. resolutionX: readUint32(data, position + 8),
  10523. resolutionY: readUint32(data, position + 12)
  10524. };
  10525. if (pageInfo.height === 0xFFFFFFFF) {
  10526. delete pageInfo.height;
  10527. }
  10528. var pageSegmentFlags = data[position + 16];
  10529. var pageStripingInformation = readUint16(data, position + 17);
  10530. pageInfo.lossless = !!(pageSegmentFlags & 1);
  10531. pageInfo.refinement = !!(pageSegmentFlags & 2);
  10532. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  10533. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  10534. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  10535. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  10536. args = [pageInfo];
  10537. break;
  10538. case 49: // EndOfPage
  10539. break;
  10540. case 50: // EndOfStripe
  10541. break;
  10542. case 51: // EndOfFile
  10543. break;
  10544. case 62: // 7.4.15 defines 2 extension types which
  10545. // are comments and can be ignored.
  10546. break;
  10547. default:
  10548. error('JBIG2 error: segment type ' + header.typeName + '(' +
  10549. header.type + ') is not implemented');
  10550. }
  10551. var callbackName = 'on' + header.typeName;
  10552. if (callbackName in visitor) {
  10553. visitor[callbackName].apply(visitor, args);
  10554. }
  10555. }
  10556. function processSegments(segments, visitor) {
  10557. for (var i = 0, ii = segments.length; i < ii; i++) {
  10558. processSegment(segments[i], visitor);
  10559. }
  10560. }
  10561. function parseJbig2(data, start, end) {
  10562. var position = start;
  10563. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  10564. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  10565. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  10566. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  10567. error('JBIG2 error: invalid header');
  10568. }
  10569. var header = {};
  10570. position += 8;
  10571. var flags = data[position++];
  10572. header.randomAccess = !(flags & 1);
  10573. if (!(flags & 2)) {
  10574. header.numberOfPages = readUint32(data, position);
  10575. position += 4;
  10576. }
  10577. var segments = readSegments(header, data, position, end);
  10578. error('Not implemented');
  10579. // processSegments(segments, new SimpleSegmentVisitor());
  10580. }
  10581. function parseJbig2Chunks(chunks) {
  10582. var visitor = new SimpleSegmentVisitor();
  10583. for (var i = 0, ii = chunks.length; i < ii; i++) {
  10584. var chunk = chunks[i];
  10585. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  10586. processSegments(segments, visitor);
  10587. }
  10588. return visitor.buffer;
  10589. }
  10590. function SimpleSegmentVisitor() {}
  10591. SimpleSegmentVisitor.prototype = {
  10592. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  10593. this.currentPageInfo = info;
  10594. var rowSize = (info.width + 7) >> 3;
  10595. var buffer = new Uint8Array(rowSize * info.height);
  10596. // The contents of ArrayBuffers are initialized to 0.
  10597. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  10598. if (info.defaultPixelValue) {
  10599. for (var i = 0, ii = buffer.length; i < ii; i++) {
  10600. buffer[i] = 0xFF;
  10601. }
  10602. }
  10603. this.buffer = buffer;
  10604. },
  10605. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  10606. var pageInfo = this.currentPageInfo;
  10607. var width = regionInfo.width, height = regionInfo.height;
  10608. var rowSize = (pageInfo.width + 7) >> 3;
  10609. var combinationOperator = pageInfo.combinationOperatorOverride ?
  10610. regionInfo.combinationOperator : pageInfo.combinationOperator;
  10611. var buffer = this.buffer;
  10612. var mask0 = 128 >> (regionInfo.x & 7);
  10613. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  10614. var i, j, mask, offset;
  10615. switch (combinationOperator) {
  10616. case 0: // OR
  10617. for (i = 0; i < height; i++) {
  10618. mask = mask0;
  10619. offset = offset0;
  10620. for (j = 0; j < width; j++) {
  10621. if (bitmap[i][j]) {
  10622. buffer[offset] |= mask;
  10623. }
  10624. mask >>= 1;
  10625. if (!mask) {
  10626. mask = 128;
  10627. offset++;
  10628. }
  10629. }
  10630. offset0 += rowSize;
  10631. }
  10632. break;
  10633. case 2: // XOR
  10634. for (i = 0; i < height; i++) {
  10635. mask = mask0;
  10636. offset = offset0;
  10637. for (j = 0; j < width; j++) {
  10638. if (bitmap[i][j]) {
  10639. buffer[offset] ^= mask;
  10640. }
  10641. mask >>= 1;
  10642. if (!mask) {
  10643. mask = 128;
  10644. offset++;
  10645. }
  10646. }
  10647. offset0 += rowSize;
  10648. }
  10649. break;
  10650. default:
  10651. error('JBIG2 error: operator ' + combinationOperator +
  10652. ' is not supported');
  10653. }
  10654. },
  10655. onImmediateGenericRegion:
  10656. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  10657. start, end) {
  10658. var regionInfo = region.info;
  10659. var decodingContext = new DecodingContext(data, start, end);
  10660. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  10661. region.template, region.prediction, null,
  10662. region.at, decodingContext);
  10663. this.drawBitmap(regionInfo, bitmap);
  10664. },
  10665. onImmediateLosslessGenericRegion:
  10666. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  10667. this.onImmediateGenericRegion.apply(this, arguments);
  10668. },
  10669. onSymbolDictionary:
  10670. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  10671. currentSegment,
  10672. referredSegments,
  10673. data, start, end) {
  10674. var huffmanTables;
  10675. if (dictionary.huffman) {
  10676. error('JBIG2 error: huffman is not supported');
  10677. }
  10678. // Combines exported symbols from all referred segments
  10679. var symbols = this.symbols;
  10680. if (!symbols) {
  10681. this.symbols = symbols = {};
  10682. }
  10683. var inputSymbols = [];
  10684. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  10685. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  10686. }
  10687. var decodingContext = new DecodingContext(data, start, end);
  10688. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  10689. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  10690. dictionary.numberOfExportedSymbols, huffmanTables,
  10691. dictionary.template, dictionary.at,
  10692. dictionary.refinementTemplate, dictionary.refinementAt,
  10693. decodingContext);
  10694. },
  10695. onImmediateTextRegion:
  10696. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  10697. referredSegments,
  10698. data, start, end) {
  10699. var regionInfo = region.info;
  10700. var huffmanTables;
  10701. // Combines exported symbols from all referred segments
  10702. var symbols = this.symbols;
  10703. var inputSymbols = [];
  10704. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  10705. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  10706. }
  10707. var symbolCodeLength = log2(inputSymbols.length);
  10708. var decodingContext = new DecodingContext(data, start, end);
  10709. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  10710. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  10711. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  10712. symbolCodeLength, region.transposed, region.dsOffset,
  10713. region.referenceCorner, region.combinationOperator, huffmanTables,
  10714. region.refinementTemplate, region.refinementAt, decodingContext);
  10715. this.drawBitmap(regionInfo, bitmap);
  10716. },
  10717. onImmediateLosslessTextRegion:
  10718. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  10719. this.onImmediateTextRegion.apply(this, arguments);
  10720. }
  10721. };
  10722. function Jbig2Image() {}
  10723. Jbig2Image.prototype = {
  10724. parseChunks: function Jbig2Image_parseChunks(chunks) {
  10725. return parseJbig2Chunks(chunks);
  10726. }
  10727. };
  10728. return Jbig2Image;
  10729. })();
  10730. exports.Jbig2Image = Jbig2Image;
  10731. }));
  10732. (function (root, factory) {
  10733. {
  10734. factory((root.pdfjsCoreJpg = {}), root.pdfjsSharedUtil);
  10735. }
  10736. }(this, function (exports, sharedUtil) {
  10737. var error = sharedUtil.error;
  10738. /**
  10739. * This code was forked from https://github.com/notmasteryet/jpgjs.
  10740. * The original version was created by GitHub user notmasteryet.
  10741. *
  10742. * - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  10743. * (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  10744. * - The JFIF specification can be found in the JPEG File Interchange Format
  10745. * (www.w3.org/Graphics/JPEG/jfif3.pdf)
  10746. * - The Adobe Application-Specific JPEG markers in the
  10747. * Supporting the DCT Filters in PostScript Level 2, Technical Note #5116
  10748. * (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  10749. */
  10750. var JpegImage = (function JpegImageClosure() {
  10751. var dctZigZag = new Uint8Array([
  10752. 0,
  10753. 1, 8,
  10754. 16, 9, 2,
  10755. 3, 10, 17, 24,
  10756. 32, 25, 18, 11, 4,
  10757. 5, 12, 19, 26, 33, 40,
  10758. 48, 41, 34, 27, 20, 13, 6,
  10759. 7, 14, 21, 28, 35, 42, 49, 56,
  10760. 57, 50, 43, 36, 29, 22, 15,
  10761. 23, 30, 37, 44, 51, 58,
  10762. 59, 52, 45, 38, 31,
  10763. 39, 46, 53, 60,
  10764. 61, 54, 47,
  10765. 55, 62,
  10766. 63
  10767. ]);
  10768. var dctCos1 = 4017; // cos(pi/16)
  10769. var dctSin1 = 799; // sin(pi/16)
  10770. var dctCos3 = 3406; // cos(3*pi/16)
  10771. var dctSin3 = 2276; // sin(3*pi/16)
  10772. var dctCos6 = 1567; // cos(6*pi/16)
  10773. var dctSin6 = 3784; // sin(6*pi/16)
  10774. var dctSqrt2 = 5793; // sqrt(2)
  10775. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  10776. function JpegImage() {
  10777. this.decodeTransform = null;
  10778. this.colorTransform = -1;
  10779. }
  10780. function buildHuffmanTable(codeLengths, values) {
  10781. var k = 0, code = [], i, j, length = 16;
  10782. while (length > 0 && !codeLengths[length - 1]) {
  10783. length--;
  10784. }
  10785. code.push({children: [], index: 0});
  10786. var p = code[0], q;
  10787. for (i = 0; i < length; i++) {
  10788. for (j = 0; j < codeLengths[i]; j++) {
  10789. p = code.pop();
  10790. p.children[p.index] = values[k];
  10791. while (p.index > 0) {
  10792. p = code.pop();
  10793. }
  10794. p.index++;
  10795. code.push(p);
  10796. while (code.length <= i) {
  10797. code.push(q = {children: [], index: 0});
  10798. p.children[p.index] = q.children;
  10799. p = q;
  10800. }
  10801. k++;
  10802. }
  10803. if (i + 1 < length) {
  10804. // p here points to last code
  10805. code.push(q = {children: [], index: 0});
  10806. p.children[p.index] = q.children;
  10807. p = q;
  10808. }
  10809. }
  10810. return code[0].children;
  10811. }
  10812. function getBlockBufferOffset(component, row, col) {
  10813. return 64 * ((component.blocksPerLine + 1) * row + col);
  10814. }
  10815. function decodeScan(data, offset, frame, components, resetInterval,
  10816. spectralStart, spectralEnd, successivePrev, successive) {
  10817. var mcusPerLine = frame.mcusPerLine;
  10818. var progressive = frame.progressive;
  10819. var startOffset = offset, bitsData = 0, bitsCount = 0;
  10820. function readBit() {
  10821. if (bitsCount > 0) {
  10822. bitsCount--;
  10823. return (bitsData >> bitsCount) & 1;
  10824. }
  10825. bitsData = data[offset++];
  10826. if (bitsData === 0xFF) {
  10827. var nextByte = data[offset++];
  10828. if (nextByte) {
  10829. error('JPEG error: unexpected marker ' +
  10830. ((bitsData << 8) | nextByte).toString(16));
  10831. }
  10832. // unstuff 0
  10833. }
  10834. bitsCount = 7;
  10835. return bitsData >>> 7;
  10836. }
  10837. function decodeHuffman(tree) {
  10838. var node = tree;
  10839. while (true) {
  10840. node = node[readBit()];
  10841. if (typeof node === 'number') {
  10842. return node;
  10843. }
  10844. if (typeof node !== 'object') {
  10845. error('JPEG error: invalid huffman sequence');
  10846. }
  10847. }
  10848. }
  10849. function receive(length) {
  10850. var n = 0;
  10851. while (length > 0) {
  10852. n = (n << 1) | readBit();
  10853. length--;
  10854. }
  10855. return n;
  10856. }
  10857. function receiveAndExtend(length) {
  10858. if (length === 1) {
  10859. return readBit() === 1 ? 1 : -1;
  10860. }
  10861. var n = receive(length);
  10862. if (n >= 1 << (length - 1)) {
  10863. return n;
  10864. }
  10865. return n + (-1 << length) + 1;
  10866. }
  10867. function decodeBaseline(component, offset) {
  10868. var t = decodeHuffman(component.huffmanTableDC);
  10869. var diff = t === 0 ? 0 : receiveAndExtend(t);
  10870. component.blockData[offset] = (component.pred += diff);
  10871. var k = 1;
  10872. while (k < 64) {
  10873. var rs = decodeHuffman(component.huffmanTableAC);
  10874. var s = rs & 15, r = rs >> 4;
  10875. if (s === 0) {
  10876. if (r < 15) {
  10877. break;
  10878. }
  10879. k += 16;
  10880. continue;
  10881. }
  10882. k += r;
  10883. var z = dctZigZag[k];
  10884. component.blockData[offset + z] = receiveAndExtend(s);
  10885. k++;
  10886. }
  10887. }
  10888. function decodeDCFirst(component, offset) {
  10889. var t = decodeHuffman(component.huffmanTableDC);
  10890. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  10891. component.blockData[offset] = (component.pred += diff);
  10892. }
  10893. function decodeDCSuccessive(component, offset) {
  10894. component.blockData[offset] |= readBit() << successive;
  10895. }
  10896. var eobrun = 0;
  10897. function decodeACFirst(component, offset) {
  10898. if (eobrun > 0) {
  10899. eobrun--;
  10900. return;
  10901. }
  10902. var k = spectralStart, e = spectralEnd;
  10903. while (k <= e) {
  10904. var rs = decodeHuffman(component.huffmanTableAC);
  10905. var s = rs & 15, r = rs >> 4;
  10906. if (s === 0) {
  10907. if (r < 15) {
  10908. eobrun = receive(r) + (1 << r) - 1;
  10909. break;
  10910. }
  10911. k += 16;
  10912. continue;
  10913. }
  10914. k += r;
  10915. var z = dctZigZag[k];
  10916. component.blockData[offset + z] =
  10917. receiveAndExtend(s) * (1 << successive);
  10918. k++;
  10919. }
  10920. }
  10921. var successiveACState = 0, successiveACNextValue;
  10922. function decodeACSuccessive(component, offset) {
  10923. var k = spectralStart;
  10924. var e = spectralEnd;
  10925. var r = 0;
  10926. var s;
  10927. var rs;
  10928. while (k <= e) {
  10929. var z = dctZigZag[k];
  10930. switch (successiveACState) {
  10931. case 0: // initial state
  10932. rs = decodeHuffman(component.huffmanTableAC);
  10933. s = rs & 15;
  10934. r = rs >> 4;
  10935. if (s === 0) {
  10936. if (r < 15) {
  10937. eobrun = receive(r) + (1 << r);
  10938. successiveACState = 4;
  10939. } else {
  10940. r = 16;
  10941. successiveACState = 1;
  10942. }
  10943. } else {
  10944. if (s !== 1) {
  10945. error('JPEG error: invalid ACn encoding');
  10946. }
  10947. successiveACNextValue = receiveAndExtend(s);
  10948. successiveACState = r ? 2 : 3;
  10949. }
  10950. continue;
  10951. case 1: // skipping r zero items
  10952. case 2:
  10953. if (component.blockData[offset + z]) {
  10954. component.blockData[offset + z] += (readBit() << successive);
  10955. } else {
  10956. r--;
  10957. if (r === 0) {
  10958. successiveACState = successiveACState === 2 ? 3 : 0;
  10959. }
  10960. }
  10961. break;
  10962. case 3: // set value for a zero item
  10963. if (component.blockData[offset + z]) {
  10964. component.blockData[offset + z] += (readBit() << successive);
  10965. } else {
  10966. component.blockData[offset + z] =
  10967. successiveACNextValue << successive;
  10968. successiveACState = 0;
  10969. }
  10970. break;
  10971. case 4: // eob
  10972. if (component.blockData[offset + z]) {
  10973. component.blockData[offset + z] += (readBit() << successive);
  10974. }
  10975. break;
  10976. }
  10977. k++;
  10978. }
  10979. if (successiveACState === 4) {
  10980. eobrun--;
  10981. if (eobrun === 0) {
  10982. successiveACState = 0;
  10983. }
  10984. }
  10985. }
  10986. function decodeMcu(component, decode, mcu, row, col) {
  10987. var mcuRow = (mcu / mcusPerLine) | 0;
  10988. var mcuCol = mcu % mcusPerLine;
  10989. var blockRow = mcuRow * component.v + row;
  10990. var blockCol = mcuCol * component.h + col;
  10991. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  10992. decode(component, offset);
  10993. }
  10994. function decodeBlock(component, decode, mcu) {
  10995. var blockRow = (mcu / component.blocksPerLine) | 0;
  10996. var blockCol = mcu % component.blocksPerLine;
  10997. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  10998. decode(component, offset);
  10999. }
  11000. var componentsLength = components.length;
  11001. var component, i, j, k, n;
  11002. var decodeFn;
  11003. if (progressive) {
  11004. if (spectralStart === 0) {
  11005. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  11006. } else {
  11007. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  11008. }
  11009. } else {
  11010. decodeFn = decodeBaseline;
  11011. }
  11012. var mcu = 0, marker;
  11013. var mcuExpected;
  11014. if (componentsLength === 1) {
  11015. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  11016. } else {
  11017. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  11018. }
  11019. if (!resetInterval) {
  11020. resetInterval = mcuExpected;
  11021. }
  11022. var h, v;
  11023. while (mcu < mcuExpected) {
  11024. // reset interval stuff
  11025. for (i = 0; i < componentsLength; i++) {
  11026. components[i].pred = 0;
  11027. }
  11028. eobrun = 0;
  11029. if (componentsLength === 1) {
  11030. component = components[0];
  11031. for (n = 0; n < resetInterval; n++) {
  11032. decodeBlock(component, decodeFn, mcu);
  11033. mcu++;
  11034. }
  11035. } else {
  11036. for (n = 0; n < resetInterval; n++) {
  11037. for (i = 0; i < componentsLength; i++) {
  11038. component = components[i];
  11039. h = component.h;
  11040. v = component.v;
  11041. for (j = 0; j < v; j++) {
  11042. for (k = 0; k < h; k++) {
  11043. decodeMcu(component, decodeFn, mcu, j, k);
  11044. }
  11045. }
  11046. }
  11047. mcu++;
  11048. }
  11049. }
  11050. // find marker
  11051. bitsCount = 0;
  11052. marker = (data[offset] << 8) | data[offset + 1];
  11053. // Some bad images seem to pad Scan blocks with zero bytes, skip past
  11054. // those to attempt to find a valid marker (fixes issue4090.pdf).
  11055. while (data[offset] === 0x00 && offset < data.length - 1) {
  11056. offset++;
  11057. marker = (data[offset] << 8) | data[offset + 1];
  11058. }
  11059. if (marker <= 0xFF00) {
  11060. error('JPEG error: marker was not found');
  11061. }
  11062. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  11063. offset += 2;
  11064. } else {
  11065. break;
  11066. }
  11067. }
  11068. return offset - startOffset;
  11069. }
  11070. // A port of poppler's IDCT method which in turn is taken from:
  11071. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  11072. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  11073. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  11074. // 988-991.
  11075. function quantizeAndInverse(component, blockBufferOffset, p) {
  11076. var qt = component.quantizationTable, blockData = component.blockData;
  11077. var v0, v1, v2, v3, v4, v5, v6, v7;
  11078. var p0, p1, p2, p3, p4, p5, p6, p7;
  11079. var t;
  11080. if (!qt) {
  11081. error('JPEG error: missing required Quantization Table.');
  11082. }
  11083. // inverse DCT on rows
  11084. for (var row = 0; row < 64; row += 8) {
  11085. // gather block data
  11086. p0 = blockData[blockBufferOffset + row];
  11087. p1 = blockData[blockBufferOffset + row + 1];
  11088. p2 = blockData[blockBufferOffset + row + 2];
  11089. p3 = blockData[blockBufferOffset + row + 3];
  11090. p4 = blockData[blockBufferOffset + row + 4];
  11091. p5 = blockData[blockBufferOffset + row + 5];
  11092. p6 = blockData[blockBufferOffset + row + 6];
  11093. p7 = blockData[blockBufferOffset + row + 7];
  11094. // dequant p0
  11095. p0 *= qt[row];
  11096. // check for all-zero AC coefficients
  11097. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  11098. t = (dctSqrt2 * p0 + 512) >> 10;
  11099. p[row] = t;
  11100. p[row + 1] = t;
  11101. p[row + 2] = t;
  11102. p[row + 3] = t;
  11103. p[row + 4] = t;
  11104. p[row + 5] = t;
  11105. p[row + 6] = t;
  11106. p[row + 7] = t;
  11107. continue;
  11108. }
  11109. // dequant p1 ... p7
  11110. p1 *= qt[row + 1];
  11111. p2 *= qt[row + 2];
  11112. p3 *= qt[row + 3];
  11113. p4 *= qt[row + 4];
  11114. p5 *= qt[row + 5];
  11115. p6 *= qt[row + 6];
  11116. p7 *= qt[row + 7];
  11117. // stage 4
  11118. v0 = (dctSqrt2 * p0 + 128) >> 8;
  11119. v1 = (dctSqrt2 * p4 + 128) >> 8;
  11120. v2 = p2;
  11121. v3 = p6;
  11122. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  11123. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  11124. v5 = p3 << 4;
  11125. v6 = p5 << 4;
  11126. // stage 3
  11127. v0 = (v0 + v1 + 1) >> 1;
  11128. v1 = v0 - v1;
  11129. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  11130. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  11131. v3 = t;
  11132. v4 = (v4 + v6 + 1) >> 1;
  11133. v6 = v4 - v6;
  11134. v7 = (v7 + v5 + 1) >> 1;
  11135. v5 = v7 - v5;
  11136. // stage 2
  11137. v0 = (v0 + v3 + 1) >> 1;
  11138. v3 = v0 - v3;
  11139. v1 = (v1 + v2 + 1) >> 1;
  11140. v2 = v1 - v2;
  11141. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  11142. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  11143. v7 = t;
  11144. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  11145. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  11146. v6 = t;
  11147. // stage 1
  11148. p[row] = v0 + v7;
  11149. p[row + 7] = v0 - v7;
  11150. p[row + 1] = v1 + v6;
  11151. p[row + 6] = v1 - v6;
  11152. p[row + 2] = v2 + v5;
  11153. p[row + 5] = v2 - v5;
  11154. p[row + 3] = v3 + v4;
  11155. p[row + 4] = v3 - v4;
  11156. }
  11157. // inverse DCT on columns
  11158. for (var col = 0; col < 8; ++col) {
  11159. p0 = p[col];
  11160. p1 = p[col + 8];
  11161. p2 = p[col + 16];
  11162. p3 = p[col + 24];
  11163. p4 = p[col + 32];
  11164. p5 = p[col + 40];
  11165. p6 = p[col + 48];
  11166. p7 = p[col + 56];
  11167. // check for all-zero AC coefficients
  11168. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  11169. t = (dctSqrt2 * p0 + 8192) >> 14;
  11170. // convert to 8 bit
  11171. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  11172. blockData[blockBufferOffset + col] = t;
  11173. blockData[blockBufferOffset + col + 8] = t;
  11174. blockData[blockBufferOffset + col + 16] = t;
  11175. blockData[blockBufferOffset + col + 24] = t;
  11176. blockData[blockBufferOffset + col + 32] = t;
  11177. blockData[blockBufferOffset + col + 40] = t;
  11178. blockData[blockBufferOffset + col + 48] = t;
  11179. blockData[blockBufferOffset + col + 56] = t;
  11180. continue;
  11181. }
  11182. // stage 4
  11183. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  11184. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  11185. v2 = p2;
  11186. v3 = p6;
  11187. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  11188. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  11189. v5 = p3;
  11190. v6 = p5;
  11191. // stage 3
  11192. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  11193. // converting to UInt8 range later.
  11194. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  11195. v1 = v0 - v1;
  11196. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  11197. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  11198. v3 = t;
  11199. v4 = (v4 + v6 + 1) >> 1;
  11200. v6 = v4 - v6;
  11201. v7 = (v7 + v5 + 1) >> 1;
  11202. v5 = v7 - v5;
  11203. // stage 2
  11204. v0 = (v0 + v3 + 1) >> 1;
  11205. v3 = v0 - v3;
  11206. v1 = (v1 + v2 + 1) >> 1;
  11207. v2 = v1 - v2;
  11208. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  11209. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  11210. v7 = t;
  11211. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  11212. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  11213. v6 = t;
  11214. // stage 1
  11215. p0 = v0 + v7;
  11216. p7 = v0 - v7;
  11217. p1 = v1 + v6;
  11218. p6 = v1 - v6;
  11219. p2 = v2 + v5;
  11220. p5 = v2 - v5;
  11221. p3 = v3 + v4;
  11222. p4 = v3 - v4;
  11223. // convert to 8-bit integers
  11224. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  11225. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  11226. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  11227. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  11228. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  11229. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  11230. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  11231. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  11232. // store block data
  11233. blockData[blockBufferOffset + col] = p0;
  11234. blockData[blockBufferOffset + col + 8] = p1;
  11235. blockData[blockBufferOffset + col + 16] = p2;
  11236. blockData[blockBufferOffset + col + 24] = p3;
  11237. blockData[blockBufferOffset + col + 32] = p4;
  11238. blockData[blockBufferOffset + col + 40] = p5;
  11239. blockData[blockBufferOffset + col + 48] = p6;
  11240. blockData[blockBufferOffset + col + 56] = p7;
  11241. }
  11242. }
  11243. function buildComponentData(frame, component) {
  11244. var blocksPerLine = component.blocksPerLine;
  11245. var blocksPerColumn = component.blocksPerColumn;
  11246. var computationBuffer = new Int16Array(64);
  11247. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  11248. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  11249. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  11250. quantizeAndInverse(component, offset, computationBuffer);
  11251. }
  11252. }
  11253. return component.blockData;
  11254. }
  11255. function clamp0to255(a) {
  11256. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  11257. }
  11258. JpegImage.prototype = {
  11259. parse: function parse(data) {
  11260. function readUint16() {
  11261. var value = (data[offset] << 8) | data[offset + 1];
  11262. offset += 2;
  11263. return value;
  11264. }
  11265. function readDataBlock() {
  11266. var length = readUint16();
  11267. var array = data.subarray(offset, offset + length - 2);
  11268. offset += array.length;
  11269. return array;
  11270. }
  11271. function prepareComponents(frame) {
  11272. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  11273. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  11274. for (var i = 0; i < frame.components.length; i++) {
  11275. component = frame.components[i];
  11276. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  11277. component.h / frame.maxH);
  11278. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  11279. component.v / frame.maxV);
  11280. var blocksPerLineForMcu = mcusPerLine * component.h;
  11281. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  11282. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  11283. (blocksPerLineForMcu + 1);
  11284. component.blockData = new Int16Array(blocksBufferSize);
  11285. component.blocksPerLine = blocksPerLine;
  11286. component.blocksPerColumn = blocksPerColumn;
  11287. }
  11288. frame.mcusPerLine = mcusPerLine;
  11289. frame.mcusPerColumn = mcusPerColumn;
  11290. }
  11291. var offset = 0;
  11292. var jfif = null;
  11293. var adobe = null;
  11294. var frame, resetInterval;
  11295. var quantizationTables = [];
  11296. var huffmanTablesAC = [], huffmanTablesDC = [];
  11297. var fileMarker = readUint16();
  11298. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  11299. error('JPEG error: SOI not found');
  11300. }
  11301. fileMarker = readUint16();
  11302. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  11303. var i, j, l;
  11304. switch(fileMarker) {
  11305. case 0xFFE0: // APP0 (Application Specific)
  11306. case 0xFFE1: // APP1
  11307. case 0xFFE2: // APP2
  11308. case 0xFFE3: // APP3
  11309. case 0xFFE4: // APP4
  11310. case 0xFFE5: // APP5
  11311. case 0xFFE6: // APP6
  11312. case 0xFFE7: // APP7
  11313. case 0xFFE8: // APP8
  11314. case 0xFFE9: // APP9
  11315. case 0xFFEA: // APP10
  11316. case 0xFFEB: // APP11
  11317. case 0xFFEC: // APP12
  11318. case 0xFFED: // APP13
  11319. case 0xFFEE: // APP14
  11320. case 0xFFEF: // APP15
  11321. case 0xFFFE: // COM (Comment)
  11322. var appData = readDataBlock();
  11323. if (fileMarker === 0xFFE0) {
  11324. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  11325. appData[2] === 0x49 && appData[3] === 0x46 &&
  11326. appData[4] === 0) { // 'JFIF\x00'
  11327. jfif = {
  11328. version: { major: appData[5], minor: appData[6] },
  11329. densityUnits: appData[7],
  11330. xDensity: (appData[8] << 8) | appData[9],
  11331. yDensity: (appData[10] << 8) | appData[11],
  11332. thumbWidth: appData[12],
  11333. thumbHeight: appData[13],
  11334. thumbData: appData.subarray(14, 14 +
  11335. 3 * appData[12] * appData[13])
  11336. };
  11337. }
  11338. }
  11339. // TODO APP1 - Exif
  11340. if (fileMarker === 0xFFEE) {
  11341. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  11342. appData[2] === 0x6F && appData[3] === 0x62 &&
  11343. appData[4] === 0x65) { // 'Adobe'
  11344. adobe = {
  11345. version: (appData[5] << 8) | appData[6],
  11346. flags0: (appData[7] << 8) | appData[8],
  11347. flags1: (appData[9] << 8) | appData[10],
  11348. transformCode: appData[11]
  11349. };
  11350. }
  11351. }
  11352. break;
  11353. case 0xFFDB: // DQT (Define Quantization Tables)
  11354. var quantizationTablesLength = readUint16();
  11355. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  11356. var z;
  11357. while (offset < quantizationTablesEnd) {
  11358. var quantizationTableSpec = data[offset++];
  11359. var tableData = new Uint16Array(64);
  11360. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  11361. for (j = 0; j < 64; j++) {
  11362. z = dctZigZag[j];
  11363. tableData[z] = data[offset++];
  11364. }
  11365. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  11366. for (j = 0; j < 64; j++) {
  11367. z = dctZigZag[j];
  11368. tableData[z] = readUint16();
  11369. }
  11370. } else {
  11371. error('JPEG error: DQT - invalid table spec');
  11372. }
  11373. quantizationTables[quantizationTableSpec & 15] = tableData;
  11374. }
  11375. break;
  11376. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  11377. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  11378. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  11379. if (frame) {
  11380. error('JPEG error: Only single frame JPEGs supported');
  11381. }
  11382. readUint16(); // skip data length
  11383. frame = {};
  11384. frame.extended = (fileMarker === 0xFFC1);
  11385. frame.progressive = (fileMarker === 0xFFC2);
  11386. frame.precision = data[offset++];
  11387. frame.scanLines = readUint16();
  11388. frame.samplesPerLine = readUint16();
  11389. frame.components = [];
  11390. frame.componentIds = {};
  11391. var componentsCount = data[offset++], componentId;
  11392. var maxH = 0, maxV = 0;
  11393. for (i = 0; i < componentsCount; i++) {
  11394. componentId = data[offset];
  11395. var h = data[offset + 1] >> 4;
  11396. var v = data[offset + 1] & 15;
  11397. if (maxH < h) {
  11398. maxH = h;
  11399. }
  11400. if (maxV < v) {
  11401. maxV = v;
  11402. }
  11403. var qId = data[offset + 2];
  11404. l = frame.components.push({
  11405. h: h,
  11406. v: v,
  11407. quantizationId: qId,
  11408. quantizationTable: null, // See comment below.
  11409. });
  11410. frame.componentIds[componentId] = l - 1;
  11411. offset += 3;
  11412. }
  11413. frame.maxH = maxH;
  11414. frame.maxV = maxV;
  11415. prepareComponents(frame);
  11416. break;
  11417. case 0xFFC4: // DHT (Define Huffman Tables)
  11418. var huffmanLength = readUint16();
  11419. for (i = 2; i < huffmanLength;) {
  11420. var huffmanTableSpec = data[offset++];
  11421. var codeLengths = new Uint8Array(16);
  11422. var codeLengthSum = 0;
  11423. for (j = 0; j < 16; j++, offset++) {
  11424. codeLengthSum += (codeLengths[j] = data[offset]);
  11425. }
  11426. var huffmanValues = new Uint8Array(codeLengthSum);
  11427. for (j = 0; j < codeLengthSum; j++, offset++) {
  11428. huffmanValues[j] = data[offset];
  11429. }
  11430. i += 17 + codeLengthSum;
  11431. ((huffmanTableSpec >> 4) === 0 ?
  11432. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  11433. buildHuffmanTable(codeLengths, huffmanValues);
  11434. }
  11435. break;
  11436. case 0xFFDD: // DRI (Define Restart Interval)
  11437. readUint16(); // skip data length
  11438. resetInterval = readUint16();
  11439. break;
  11440. case 0xFFDA: // SOS (Start of Scan)
  11441. var scanLength = readUint16();
  11442. var selectorsCount = data[offset++];
  11443. var components = [], component;
  11444. for (i = 0; i < selectorsCount; i++) {
  11445. var componentIndex = frame.componentIds[data[offset++]];
  11446. component = frame.components[componentIndex];
  11447. var tableSpec = data[offset++];
  11448. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  11449. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  11450. components.push(component);
  11451. }
  11452. var spectralStart = data[offset++];
  11453. var spectralEnd = data[offset++];
  11454. var successiveApproximation = data[offset++];
  11455. var processed = decodeScan(data, offset,
  11456. frame, components, resetInterval,
  11457. spectralStart, spectralEnd,
  11458. successiveApproximation >> 4, successiveApproximation & 15);
  11459. offset += processed;
  11460. break;
  11461. case 0xFFFF: // Fill bytes
  11462. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  11463. offset--;
  11464. }
  11465. break;
  11466. default:
  11467. if (data[offset - 3] === 0xFF &&
  11468. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  11469. // could be incorrect encoding -- last 0xFF byte of the previous
  11470. // block was eaten by the encoder
  11471. offset -= 3;
  11472. break;
  11473. }
  11474. error('JPEG error: unknown marker ' + fileMarker.toString(16));
  11475. }
  11476. fileMarker = readUint16();
  11477. }
  11478. this.width = frame.samplesPerLine;
  11479. this.height = frame.scanLines;
  11480. this.jfif = jfif;
  11481. this.adobe = adobe;
  11482. this.components = [];
  11483. for (i = 0; i < frame.components.length; i++) {
  11484. component = frame.components[i];
  11485. // Prevent errors when DQT markers are placed after SOF{n} markers,
  11486. // by assigning the `quantizationTable` entry after the entire image
  11487. // has been parsed (fixes issue7406.pdf).
  11488. var quantizationTable = quantizationTables[component.quantizationId];
  11489. if (quantizationTable) {
  11490. component.quantizationTable = quantizationTable;
  11491. }
  11492. this.components.push({
  11493. output: buildComponentData(frame, component),
  11494. scaleX: component.h / frame.maxH,
  11495. scaleY: component.v / frame.maxV,
  11496. blocksPerLine: component.blocksPerLine,
  11497. blocksPerColumn: component.blocksPerColumn
  11498. });
  11499. }
  11500. this.numComponents = this.components.length;
  11501. },
  11502. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  11503. var scaleX = this.width / width, scaleY = this.height / height;
  11504. var component, componentScaleX, componentScaleY, blocksPerScanline;
  11505. var x, y, i, j, k;
  11506. var index;
  11507. var offset = 0;
  11508. var output;
  11509. var numComponents = this.components.length;
  11510. var dataLength = width * height * numComponents;
  11511. var data = new Uint8Array(dataLength);
  11512. var xScaleBlockOffset = new Uint32Array(width);
  11513. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  11514. for (i = 0; i < numComponents; i++) {
  11515. component = this.components[i];
  11516. componentScaleX = component.scaleX * scaleX;
  11517. componentScaleY = component.scaleY * scaleY;
  11518. offset = i;
  11519. output = component.output;
  11520. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  11521. // precalculate the xScaleBlockOffset
  11522. for (x = 0; x < width; x++) {
  11523. j = 0 | (x * componentScaleX);
  11524. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  11525. }
  11526. // linearize the blocks of the component
  11527. for (y = 0; y < height; y++) {
  11528. j = 0 | (y * componentScaleY);
  11529. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  11530. for (x = 0; x < width; x++) {
  11531. data[offset] = output[index + xScaleBlockOffset[x]];
  11532. offset += numComponents;
  11533. }
  11534. }
  11535. }
  11536. // decodeTransform contains pairs of multiplier (-256..256) and additive
  11537. var transform = this.decodeTransform;
  11538. if (transform) {
  11539. for (i = 0; i < dataLength;) {
  11540. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  11541. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  11542. }
  11543. }
  11544. }
  11545. return data;
  11546. },
  11547. _isColorConversionNeeded: function isColorConversionNeeded() {
  11548. if (this.adobe && this.adobe.transformCode) {
  11549. // The adobe transform marker overrides any previous setting
  11550. return true;
  11551. } else if (this.numComponents === 3) {
  11552. if (!this.adobe && this.colorTransform === 0) {
  11553. // If the Adobe transform marker is not present and the image
  11554. // dictionary has a 'ColorTransform' entry, explicitly set to `0`,
  11555. // then the colours should *not* be transformed.
  11556. return false;
  11557. }
  11558. return true;
  11559. } else { // `this.numComponents !== 3`
  11560. if (!this.adobe && this.colorTransform === 1) {
  11561. // If the Adobe transform marker is not present and the image
  11562. // dictionary has a 'ColorTransform' entry, explicitly set to `1`,
  11563. // then the colours should be transformed.
  11564. return true;
  11565. }
  11566. return false;
  11567. }
  11568. },
  11569. _convertYccToRgb: function convertYccToRgb(data) {
  11570. var Y, Cb, Cr;
  11571. for (var i = 0, length = data.length; i < length; i += 3) {
  11572. Y = data[i ];
  11573. Cb = data[i + 1];
  11574. Cr = data[i + 2];
  11575. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  11576. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  11577. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  11578. }
  11579. return data;
  11580. },
  11581. _convertYcckToRgb: function convertYcckToRgb(data) {
  11582. var Y, Cb, Cr, k;
  11583. var offset = 0;
  11584. for (var i = 0, length = data.length; i < length; i += 4) {
  11585. Y = data[i];
  11586. Cb = data[i + 1];
  11587. Cr = data[i + 2];
  11588. k = data[i + 3];
  11589. var r = -122.67195406894 +
  11590. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  11591. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  11592. 0.154362151871126) +
  11593. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  11594. 0.00477271405408747 * k + 1.53380253221734) +
  11595. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  11596. 0.48357088451265) +
  11597. k * (-0.000336197177618394 * k + 0.484791561490776);
  11598. var g = 107.268039397724 +
  11599. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  11600. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  11601. 0.176491792462875) +
  11602. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  11603. 0.000770482631801132 * k - 0.151051492775562) +
  11604. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  11605. 0.25802910206845) +
  11606. k * (-0.000318913117588328 * k - 0.213742400323665);
  11607. var b = -20.810012546947 +
  11608. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  11609. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  11610. 0.814272968359295) +
  11611. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  11612. 0.000560833691242812 * k - 0.195152027534049) +
  11613. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  11614. 0.116935020465145) +
  11615. k * (-0.000343531996510555 * k + 0.24165260232407);
  11616. data[offset++] = clamp0to255(r);
  11617. data[offset++] = clamp0to255(g);
  11618. data[offset++] = clamp0to255(b);
  11619. }
  11620. return data;
  11621. },
  11622. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  11623. var Y, Cb, Cr;
  11624. for (var i = 0, length = data.length; i < length; i += 4) {
  11625. Y = data[i];
  11626. Cb = data[i + 1];
  11627. Cr = data[i + 2];
  11628. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  11629. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  11630. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  11631. // K in data[i + 3] is unchanged
  11632. }
  11633. return data;
  11634. },
  11635. _convertCmykToRgb: function convertCmykToRgb(data) {
  11636. var c, m, y, k;
  11637. var offset = 0;
  11638. var min = -255 * 255 * 255;
  11639. var scale = 1 / 255 / 255;
  11640. for (var i = 0, length = data.length; i < length; i += 4) {
  11641. c = data[i];
  11642. m = data[i + 1];
  11643. y = data[i + 2];
  11644. k = data[i + 3];
  11645. var r =
  11646. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  11647. 18.82290502165302 * y + 212.25662451639585 * k -
  11648. 72734.4411664936) +
  11649. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  11650. 17.873870861415444 * k - 1401.7366389350734) +
  11651. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  11652. 4465.541406466231) -
  11653. k * (21.86122147463605 * k + 48317.86113160301);
  11654. var g =
  11655. c * (8.841041422036149 * c + 60.118027045597366 * m +
  11656. 6.871425592049007 * y + 31.159100130055922 * k -
  11657. 20220.756542821975) +
  11658. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  11659. 131.35250912493976 * k - 48691.05921601825) +
  11660. y * (4.444339102852739 * y + 9.8632861493405 * k -
  11661. 6341.191035517494) -
  11662. k * (20.737325471181034 * k + 47890.15695978492);
  11663. var b =
  11664. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  11665. 30.89978309703729 * y - 0.23883238689178934 * k -
  11666. 3616.812083916688) +
  11667. m * (10.49593273432072 * m + 63.02378494754052 * y +
  11668. 50.606957656360734 * k - 28620.90484698408) +
  11669. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  11670. 49363.43385999684) -
  11671. k * (22.33816807309886 * k + 45932.16563550634);
  11672. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  11673. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  11674. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  11675. }
  11676. return data;
  11677. },
  11678. getData: function getData(width, height, forceRGBoutput) {
  11679. if (this.numComponents > 4) {
  11680. error('JPEG error: Unsupported color mode');
  11681. }
  11682. // type of data: Uint8Array(width * height * numComponents)
  11683. var data = this._getLinearizedBlockData(width, height);
  11684. if (this.numComponents === 1 && forceRGBoutput) {
  11685. var dataLength = data.length;
  11686. var rgbData = new Uint8Array(dataLength * 3);
  11687. var offset = 0;
  11688. for (var i = 0; i < dataLength; i++) {
  11689. var grayColor = data[i];
  11690. rgbData[offset++] = grayColor;
  11691. rgbData[offset++] = grayColor;
  11692. rgbData[offset++] = grayColor;
  11693. }
  11694. return rgbData;
  11695. } else if (this.numComponents === 3 && this._isColorConversionNeeded()) {
  11696. return this._convertYccToRgb(data);
  11697. } else if (this.numComponents === 4) {
  11698. if (this._isColorConversionNeeded()) {
  11699. if (forceRGBoutput) {
  11700. return this._convertYcckToRgb(data);
  11701. } else {
  11702. return this._convertYcckToCmyk(data);
  11703. }
  11704. } else if (forceRGBoutput) {
  11705. return this._convertCmykToRgb(data);
  11706. }
  11707. }
  11708. return data;
  11709. }
  11710. };
  11711. return JpegImage;
  11712. })();
  11713. exports.JpegImage = JpegImage;
  11714. }));
  11715. (function (root, factory) {
  11716. {
  11717. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  11718. root.pdfjsCoreArithmeticDecoder);
  11719. }
  11720. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  11721. var info = sharedUtil.info;
  11722. var warn = sharedUtil.warn;
  11723. var error = sharedUtil.error;
  11724. var log2 = sharedUtil.log2;
  11725. var readUint16 = sharedUtil.readUint16;
  11726. var readUint32 = sharedUtil.readUint32;
  11727. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  11728. var JpxImage = (function JpxImageClosure() {
  11729. // Table E.1
  11730. var SubbandsGainLog2 = {
  11731. 'LL': 0,
  11732. 'LH': 1,
  11733. 'HL': 1,
  11734. 'HH': 2
  11735. };
  11736. function JpxImage() {
  11737. this.failOnCorruptedImage = false;
  11738. }
  11739. JpxImage.prototype = {
  11740. parse: function JpxImage_parse(data) {
  11741. var head = readUint16(data, 0);
  11742. // No box header, immediate start of codestream (SOC)
  11743. if (head === 0xFF4F) {
  11744. this.parseCodestream(data, 0, data.length);
  11745. return;
  11746. }
  11747. var position = 0, length = data.length;
  11748. while (position < length) {
  11749. var headerSize = 8;
  11750. var lbox = readUint32(data, position);
  11751. var tbox = readUint32(data, position + 4);
  11752. position += headerSize;
  11753. if (lbox === 1) {
  11754. // XLBox: read UInt64 according to spec.
  11755. // JavaScript's int precision of 53 bit should be sufficient here.
  11756. lbox = readUint32(data, position) * 4294967296 +
  11757. readUint32(data, position + 4);
  11758. position += 8;
  11759. headerSize += 8;
  11760. }
  11761. if (lbox === 0) {
  11762. lbox = length - position + headerSize;
  11763. }
  11764. if (lbox < headerSize) {
  11765. error('JPX Error: Invalid box field size');
  11766. }
  11767. var dataLength = lbox - headerSize;
  11768. var jumpDataLength = true;
  11769. switch (tbox) {
  11770. case 0x6A703268: // 'jp2h'
  11771. jumpDataLength = false; // parsing child boxes
  11772. break;
  11773. case 0x636F6C72: // 'colr'
  11774. // Colorspaces are not used, the CS from the PDF is used.
  11775. var method = data[position];
  11776. if (method === 1) {
  11777. // enumerated colorspace
  11778. var colorspace = readUint32(data, position + 3);
  11779. switch (colorspace) {
  11780. case 16: // this indicates a sRGB colorspace
  11781. case 17: // this indicates a grayscale colorspace
  11782. case 18: // this indicates a YUV colorspace
  11783. break;
  11784. default:
  11785. warn('Unknown colorspace ' + colorspace);
  11786. break;
  11787. }
  11788. } else if (method === 2) {
  11789. info('ICC profile not supported');
  11790. }
  11791. break;
  11792. case 0x6A703263: // 'jp2c'
  11793. this.parseCodestream(data, position, position + dataLength);
  11794. break;
  11795. case 0x6A502020: // 'jP\024\024'
  11796. if (0x0d0a870a !== readUint32(data, position)) {
  11797. warn('Invalid JP2 signature');
  11798. }
  11799. break;
  11800. // The following header types are valid but currently not used:
  11801. case 0x6A501A1A: // 'jP\032\032'
  11802. case 0x66747970: // 'ftyp'
  11803. case 0x72726571: // 'rreq'
  11804. case 0x72657320: // 'res '
  11805. case 0x69686472: // 'ihdr'
  11806. break;
  11807. default:
  11808. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  11809. (tbox >> 16) & 0xFF,
  11810. (tbox >> 8) & 0xFF,
  11811. tbox & 0xFF);
  11812. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  11813. break;
  11814. }
  11815. if (jumpDataLength) {
  11816. position += dataLength;
  11817. }
  11818. }
  11819. },
  11820. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  11821. var newByte = stream.getByte();
  11822. while (newByte >= 0) {
  11823. var oldByte = newByte;
  11824. newByte = stream.getByte();
  11825. var code = (oldByte << 8) | newByte;
  11826. // Image and tile size (SIZ)
  11827. if (code === 0xFF51) {
  11828. stream.skip(4);
  11829. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  11830. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  11831. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  11832. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  11833. stream.skip(16);
  11834. var Csiz = stream.getUint16(); // Byte 36
  11835. this.width = Xsiz - XOsiz;
  11836. this.height = Ysiz - YOsiz;
  11837. this.componentsCount = Csiz;
  11838. // Results are always returned as Uint8Arrays
  11839. this.bitsPerComponent = 8;
  11840. return;
  11841. }
  11842. }
  11843. error('JPX Error: No size marker found in JPX stream');
  11844. },
  11845. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  11846. var context = {};
  11847. var doNotRecover = false;
  11848. try {
  11849. var position = start;
  11850. while (position + 1 < end) {
  11851. var code = readUint16(data, position);
  11852. position += 2;
  11853. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  11854. switch (code) {
  11855. case 0xFF4F: // Start of codestream (SOC)
  11856. context.mainHeader = true;
  11857. break;
  11858. case 0xFFD9: // End of codestream (EOC)
  11859. break;
  11860. case 0xFF51: // Image and tile size (SIZ)
  11861. length = readUint16(data, position);
  11862. var siz = {};
  11863. siz.Xsiz = readUint32(data, position + 4);
  11864. siz.Ysiz = readUint32(data, position + 8);
  11865. siz.XOsiz = readUint32(data, position + 12);
  11866. siz.YOsiz = readUint32(data, position + 16);
  11867. siz.XTsiz = readUint32(data, position + 20);
  11868. siz.YTsiz = readUint32(data, position + 24);
  11869. siz.XTOsiz = readUint32(data, position + 28);
  11870. siz.YTOsiz = readUint32(data, position + 32);
  11871. var componentsCount = readUint16(data, position + 36);
  11872. siz.Csiz = componentsCount;
  11873. var components = [];
  11874. j = position + 38;
  11875. for (var i = 0; i < componentsCount; i++) {
  11876. var component = {
  11877. precision: (data[j] & 0x7F) + 1,
  11878. isSigned: !!(data[j] & 0x80),
  11879. XRsiz: data[j + 1],
  11880. YRsiz: data[j + 1]
  11881. };
  11882. calculateComponentDimensions(component, siz);
  11883. components.push(component);
  11884. }
  11885. context.SIZ = siz;
  11886. context.components = components;
  11887. calculateTileGrids(context, components);
  11888. context.QCC = [];
  11889. context.COC = [];
  11890. break;
  11891. case 0xFF5C: // Quantization default (QCD)
  11892. length = readUint16(data, position);
  11893. var qcd = {};
  11894. j = position + 2;
  11895. sqcd = data[j++];
  11896. switch (sqcd & 0x1F) {
  11897. case 0:
  11898. spqcdSize = 8;
  11899. scalarExpounded = true;
  11900. break;
  11901. case 1:
  11902. spqcdSize = 16;
  11903. scalarExpounded = false;
  11904. break;
  11905. case 2:
  11906. spqcdSize = 16;
  11907. scalarExpounded = true;
  11908. break;
  11909. default:
  11910. throw new Error('Invalid SQcd value ' + sqcd);
  11911. }
  11912. qcd.noQuantization = (spqcdSize === 8);
  11913. qcd.scalarExpounded = scalarExpounded;
  11914. qcd.guardBits = sqcd >> 5;
  11915. spqcds = [];
  11916. while (j < length + position) {
  11917. var spqcd = {};
  11918. if (spqcdSize === 8) {
  11919. spqcd.epsilon = data[j++] >> 3;
  11920. spqcd.mu = 0;
  11921. } else {
  11922. spqcd.epsilon = data[j] >> 3;
  11923. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  11924. j += 2;
  11925. }
  11926. spqcds.push(spqcd);
  11927. }
  11928. qcd.SPqcds = spqcds;
  11929. if (context.mainHeader) {
  11930. context.QCD = qcd;
  11931. } else {
  11932. context.currentTile.QCD = qcd;
  11933. context.currentTile.QCC = [];
  11934. }
  11935. break;
  11936. case 0xFF5D: // Quantization component (QCC)
  11937. length = readUint16(data, position);
  11938. var qcc = {};
  11939. j = position + 2;
  11940. var cqcc;
  11941. if (context.SIZ.Csiz < 257) {
  11942. cqcc = data[j++];
  11943. } else {
  11944. cqcc = readUint16(data, j);
  11945. j += 2;
  11946. }
  11947. sqcd = data[j++];
  11948. switch (sqcd & 0x1F) {
  11949. case 0:
  11950. spqcdSize = 8;
  11951. scalarExpounded = true;
  11952. break;
  11953. case 1:
  11954. spqcdSize = 16;
  11955. scalarExpounded = false;
  11956. break;
  11957. case 2:
  11958. spqcdSize = 16;
  11959. scalarExpounded = true;
  11960. break;
  11961. default:
  11962. throw new Error('Invalid SQcd value ' + sqcd);
  11963. }
  11964. qcc.noQuantization = (spqcdSize === 8);
  11965. qcc.scalarExpounded = scalarExpounded;
  11966. qcc.guardBits = sqcd >> 5;
  11967. spqcds = [];
  11968. while (j < (length + position)) {
  11969. spqcd = {};
  11970. if (spqcdSize === 8) {
  11971. spqcd.epsilon = data[j++] >> 3;
  11972. spqcd.mu = 0;
  11973. } else {
  11974. spqcd.epsilon = data[j] >> 3;
  11975. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  11976. j += 2;
  11977. }
  11978. spqcds.push(spqcd);
  11979. }
  11980. qcc.SPqcds = spqcds;
  11981. if (context.mainHeader) {
  11982. context.QCC[cqcc] = qcc;
  11983. } else {
  11984. context.currentTile.QCC[cqcc] = qcc;
  11985. }
  11986. break;
  11987. case 0xFF52: // Coding style default (COD)
  11988. length = readUint16(data, position);
  11989. var cod = {};
  11990. j = position + 2;
  11991. var scod = data[j++];
  11992. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  11993. cod.sopMarkerUsed = !!(scod & 2);
  11994. cod.ephMarkerUsed = !!(scod & 4);
  11995. cod.progressionOrder = data[j++];
  11996. cod.layersCount = readUint16(data, j);
  11997. j += 2;
  11998. cod.multipleComponentTransform = data[j++];
  11999. cod.decompositionLevelsCount = data[j++];
  12000. cod.xcb = (data[j++] & 0xF) + 2;
  12001. cod.ycb = (data[j++] & 0xF) + 2;
  12002. var blockStyle = data[j++];
  12003. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  12004. cod.resetContextProbabilities = !!(blockStyle & 2);
  12005. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  12006. cod.verticalyStripe = !!(blockStyle & 8);
  12007. cod.predictableTermination = !!(blockStyle & 16);
  12008. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  12009. cod.reversibleTransformation = data[j++];
  12010. if (cod.entropyCoderWithCustomPrecincts) {
  12011. var precinctsSizes = [];
  12012. while (j < length + position) {
  12013. var precinctsSize = data[j++];
  12014. precinctsSizes.push({
  12015. PPx: precinctsSize & 0xF,
  12016. PPy: precinctsSize >> 4
  12017. });
  12018. }
  12019. cod.precinctsSizes = precinctsSizes;
  12020. }
  12021. var unsupported = [];
  12022. if (cod.selectiveArithmeticCodingBypass) {
  12023. unsupported.push('selectiveArithmeticCodingBypass');
  12024. }
  12025. if (cod.resetContextProbabilities) {
  12026. unsupported.push('resetContextProbabilities');
  12027. }
  12028. if (cod.terminationOnEachCodingPass) {
  12029. unsupported.push('terminationOnEachCodingPass');
  12030. }
  12031. if (cod.verticalyStripe) {
  12032. unsupported.push('verticalyStripe');
  12033. }
  12034. if (cod.predictableTermination) {
  12035. unsupported.push('predictableTermination');
  12036. }
  12037. if (unsupported.length > 0) {
  12038. doNotRecover = true;
  12039. throw new Error('Unsupported COD options (' +
  12040. unsupported.join(', ') + ')');
  12041. }
  12042. if (context.mainHeader) {
  12043. context.COD = cod;
  12044. } else {
  12045. context.currentTile.COD = cod;
  12046. context.currentTile.COC = [];
  12047. }
  12048. break;
  12049. case 0xFF90: // Start of tile-part (SOT)
  12050. length = readUint16(data, position);
  12051. tile = {};
  12052. tile.index = readUint16(data, position + 2);
  12053. tile.length = readUint32(data, position + 4);
  12054. tile.dataEnd = tile.length + position - 2;
  12055. tile.partIndex = data[position + 8];
  12056. tile.partsCount = data[position + 9];
  12057. context.mainHeader = false;
  12058. if (tile.partIndex === 0) {
  12059. // reset component specific settings
  12060. tile.COD = context.COD;
  12061. tile.COC = context.COC.slice(0); // clone of the global COC
  12062. tile.QCD = context.QCD;
  12063. tile.QCC = context.QCC.slice(0); // clone of the global COC
  12064. }
  12065. context.currentTile = tile;
  12066. break;
  12067. case 0xFF93: // Start of data (SOD)
  12068. tile = context.currentTile;
  12069. if (tile.partIndex === 0) {
  12070. initializeTile(context, tile.index);
  12071. buildPackets(context);
  12072. }
  12073. // moving to the end of the data
  12074. length = tile.dataEnd - position;
  12075. parseTilePackets(context, data, position, length);
  12076. break;
  12077. case 0xFF55: // Tile-part lengths, main header (TLM)
  12078. case 0xFF57: // Packet length, main header (PLM)
  12079. case 0xFF58: // Packet length, tile-part header (PLT)
  12080. case 0xFF64: // Comment (COM)
  12081. length = readUint16(data, position);
  12082. // skipping content
  12083. break;
  12084. case 0xFF53: // Coding style component (COC)
  12085. throw new Error('Codestream code 0xFF53 (COC) is ' +
  12086. 'not implemented');
  12087. default:
  12088. throw new Error('Unknown codestream code: ' + code.toString(16));
  12089. }
  12090. position += length;
  12091. }
  12092. } catch (e) {
  12093. if (doNotRecover || this.failOnCorruptedImage) {
  12094. error('JPX Error: ' + e.message);
  12095. } else {
  12096. warn('JPX: Trying to recover from: ' + e.message);
  12097. }
  12098. }
  12099. this.tiles = transformComponents(context);
  12100. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  12101. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  12102. this.componentsCount = context.SIZ.Csiz;
  12103. }
  12104. };
  12105. function calculateComponentDimensions(component, siz) {
  12106. // Section B.2 Component mapping
  12107. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  12108. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  12109. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  12110. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  12111. component.width = component.x1 - component.x0;
  12112. component.height = component.y1 - component.y0;
  12113. }
  12114. function calculateTileGrids(context, components) {
  12115. var siz = context.SIZ;
  12116. // Section B.3 Division into tile and tile-components
  12117. var tile, tiles = [];
  12118. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  12119. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  12120. for (var q = 0; q < numYtiles; q++) {
  12121. for (var p = 0; p < numXtiles; p++) {
  12122. tile = {};
  12123. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  12124. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  12125. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  12126. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  12127. tile.width = tile.tx1 - tile.tx0;
  12128. tile.height = tile.ty1 - tile.ty0;
  12129. tile.components = [];
  12130. tiles.push(tile);
  12131. }
  12132. }
  12133. context.tiles = tiles;
  12134. var componentsCount = siz.Csiz;
  12135. for (var i = 0, ii = componentsCount; i < ii; i++) {
  12136. var component = components[i];
  12137. for (var j = 0, jj = tiles.length; j < jj; j++) {
  12138. var tileComponent = {};
  12139. tile = tiles[j];
  12140. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  12141. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  12142. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  12143. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  12144. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  12145. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  12146. tile.components[i] = tileComponent;
  12147. }
  12148. }
  12149. }
  12150. function getBlocksDimensions(context, component, r) {
  12151. var codOrCoc = component.codingStyleParameters;
  12152. var result = {};
  12153. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  12154. result.PPx = 15;
  12155. result.PPy = 15;
  12156. } else {
  12157. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  12158. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  12159. }
  12160. // calculate codeblock size as described in section B.7
  12161. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  12162. Math.min(codOrCoc.xcb, result.PPx));
  12163. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  12164. Math.min(codOrCoc.ycb, result.PPy));
  12165. return result;
  12166. }
  12167. function buildPrecincts(context, resolution, dimensions) {
  12168. // Section B.6 Division resolution to precincts
  12169. var precinctWidth = 1 << dimensions.PPx;
  12170. var precinctHeight = 1 << dimensions.PPy;
  12171. // Jasper introduces codeblock groups for mapping each subband codeblocks
  12172. // to precincts. Precinct partition divides a resolution according to width
  12173. // and height parameters. The subband that belongs to the resolution level
  12174. // has a different size than the level, unless it is the zero resolution.
  12175. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  12176. // The precinct partitioning for a particular subband is derived from a
  12177. // partitioning of its parent LL band (i.e., the LL band at the next higher
  12178. // resolution level)... The LL band associated with each resolution level is
  12179. // divided into precincts... Each of the resulting precinct regions is then
  12180. // mapped into its child subbands (if any) at the next lower resolution
  12181. // level. This is accomplished by using the coordinate transformation
  12182. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  12183. // coordinates of a point in the LL band and child subband, respectively.
  12184. var isZeroRes = resolution.resLevel === 0;
  12185. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  12186. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  12187. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  12188. Math.ceil(resolution.trx1 / precinctWidth) -
  12189. Math.floor(resolution.trx0 / precinctWidth) : 0);
  12190. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  12191. Math.ceil(resolution.try1 / precinctHeight) -
  12192. Math.floor(resolution.try0 / precinctHeight) : 0);
  12193. var numprecincts = numprecinctswide * numprecinctshigh;
  12194. resolution.precinctParameters = {
  12195. precinctWidth: precinctWidth,
  12196. precinctHeight: precinctHeight,
  12197. numprecinctswide: numprecinctswide,
  12198. numprecinctshigh: numprecinctshigh,
  12199. numprecincts: numprecincts,
  12200. precinctWidthInSubband: precinctWidthInSubband,
  12201. precinctHeightInSubband: precinctHeightInSubband
  12202. };
  12203. }
  12204. function buildCodeblocks(context, subband, dimensions) {
  12205. // Section B.7 Division sub-band into code-blocks
  12206. var xcb_ = dimensions.xcb_;
  12207. var ycb_ = dimensions.ycb_;
  12208. var codeblockWidth = 1 << xcb_;
  12209. var codeblockHeight = 1 << ycb_;
  12210. var cbx0 = subband.tbx0 >> xcb_;
  12211. var cby0 = subband.tby0 >> ycb_;
  12212. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  12213. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  12214. var precinctParameters = subband.resolution.precinctParameters;
  12215. var codeblocks = [];
  12216. var precincts = [];
  12217. var i, j, codeblock, precinctNumber;
  12218. for (j = cby0; j < cby1; j++) {
  12219. for (i = cbx0; i < cbx1; i++) {
  12220. codeblock = {
  12221. cbx: i,
  12222. cby: j,
  12223. tbx0: codeblockWidth * i,
  12224. tby0: codeblockHeight * j,
  12225. tbx1: codeblockWidth * (i + 1),
  12226. tby1: codeblockHeight * (j + 1)
  12227. };
  12228. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  12229. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  12230. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  12231. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  12232. // Calculate precinct number for this codeblock, codeblock position
  12233. // should be relative to its subband, use actual dimension and position
  12234. // See comment about codeblock group width and height
  12235. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  12236. precinctParameters.precinctWidthInSubband);
  12237. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  12238. precinctParameters.precinctHeightInSubband);
  12239. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  12240. codeblock.precinctNumber = precinctNumber;
  12241. codeblock.subbandType = subband.type;
  12242. codeblock.Lblock = 3;
  12243. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  12244. codeblock.tby1_ <= codeblock.tby0_) {
  12245. continue;
  12246. }
  12247. codeblocks.push(codeblock);
  12248. // building precinct for the sub-band
  12249. var precinct = precincts[precinctNumber];
  12250. if (precinct !== undefined) {
  12251. if (i < precinct.cbxMin) {
  12252. precinct.cbxMin = i;
  12253. } else if (i > precinct.cbxMax) {
  12254. precinct.cbxMax = i;
  12255. }
  12256. if (j < precinct.cbyMin) {
  12257. precinct.cbxMin = j;
  12258. } else if (j > precinct.cbyMax) {
  12259. precinct.cbyMax = j;
  12260. }
  12261. } else {
  12262. precincts[precinctNumber] = precinct = {
  12263. cbxMin: i,
  12264. cbyMin: j,
  12265. cbxMax: i,
  12266. cbyMax: j
  12267. };
  12268. }
  12269. codeblock.precinct = precinct;
  12270. }
  12271. }
  12272. subband.codeblockParameters = {
  12273. codeblockWidth: xcb_,
  12274. codeblockHeight: ycb_,
  12275. numcodeblockwide: cbx1 - cbx0 + 1,
  12276. numcodeblockhigh: cby1 - cby0 + 1
  12277. };
  12278. subband.codeblocks = codeblocks;
  12279. subband.precincts = precincts;
  12280. }
  12281. function createPacket(resolution, precinctNumber, layerNumber) {
  12282. var precinctCodeblocks = [];
  12283. // Section B.10.8 Order of info in packet
  12284. var subbands = resolution.subbands;
  12285. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  12286. for (var i = 0, ii = subbands.length; i < ii; i++) {
  12287. var subband = subbands[i];
  12288. var codeblocks = subband.codeblocks;
  12289. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  12290. var codeblock = codeblocks[j];
  12291. if (codeblock.precinctNumber !== precinctNumber) {
  12292. continue;
  12293. }
  12294. precinctCodeblocks.push(codeblock);
  12295. }
  12296. }
  12297. return {
  12298. layerNumber: layerNumber,
  12299. codeblocks: precinctCodeblocks
  12300. };
  12301. }
  12302. function LayerResolutionComponentPositionIterator(context) {
  12303. var siz = context.SIZ;
  12304. var tileIndex = context.currentTile.index;
  12305. var tile = context.tiles[tileIndex];
  12306. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12307. var componentsCount = siz.Csiz;
  12308. var maxDecompositionLevelsCount = 0;
  12309. for (var q = 0; q < componentsCount; q++) {
  12310. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12311. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12312. }
  12313. var l = 0, r = 0, i = 0, k = 0;
  12314. this.nextPacket = function JpxImage_nextPacket() {
  12315. // Section B.12.1.1 Layer-resolution-component-position
  12316. for (; l < layersCount; l++) {
  12317. for (; r <= maxDecompositionLevelsCount; r++) {
  12318. for (; i < componentsCount; i++) {
  12319. var component = tile.components[i];
  12320. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12321. continue;
  12322. }
  12323. var resolution = component.resolutions[r];
  12324. var numprecincts = resolution.precinctParameters.numprecincts;
  12325. for (; k < numprecincts;) {
  12326. var packet = createPacket(resolution, k, l);
  12327. k++;
  12328. return packet;
  12329. }
  12330. k = 0;
  12331. }
  12332. i = 0;
  12333. }
  12334. r = 0;
  12335. }
  12336. error('JPX Error: Out of packets');
  12337. };
  12338. }
  12339. function ResolutionLayerComponentPositionIterator(context) {
  12340. var siz = context.SIZ;
  12341. var tileIndex = context.currentTile.index;
  12342. var tile = context.tiles[tileIndex];
  12343. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12344. var componentsCount = siz.Csiz;
  12345. var maxDecompositionLevelsCount = 0;
  12346. for (var q = 0; q < componentsCount; q++) {
  12347. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12348. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12349. }
  12350. var r = 0, l = 0, i = 0, k = 0;
  12351. this.nextPacket = function JpxImage_nextPacket() {
  12352. // Section B.12.1.2 Resolution-layer-component-position
  12353. for (; r <= maxDecompositionLevelsCount; r++) {
  12354. for (; l < layersCount; l++) {
  12355. for (; i < componentsCount; i++) {
  12356. var component = tile.components[i];
  12357. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12358. continue;
  12359. }
  12360. var resolution = component.resolutions[r];
  12361. var numprecincts = resolution.precinctParameters.numprecincts;
  12362. for (; k < numprecincts;) {
  12363. var packet = createPacket(resolution, k, l);
  12364. k++;
  12365. return packet;
  12366. }
  12367. k = 0;
  12368. }
  12369. i = 0;
  12370. }
  12371. l = 0;
  12372. }
  12373. error('JPX Error: Out of packets');
  12374. };
  12375. }
  12376. function ResolutionPositionComponentLayerIterator(context) {
  12377. var siz = context.SIZ;
  12378. var tileIndex = context.currentTile.index;
  12379. var tile = context.tiles[tileIndex];
  12380. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12381. var componentsCount = siz.Csiz;
  12382. var l, r, c, p;
  12383. var maxDecompositionLevelsCount = 0;
  12384. for (c = 0; c < componentsCount; c++) {
  12385. var component = tile.components[c];
  12386. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12387. component.codingStyleParameters.decompositionLevelsCount);
  12388. }
  12389. var maxNumPrecinctsInLevel = new Int32Array(
  12390. maxDecompositionLevelsCount + 1);
  12391. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  12392. var maxNumPrecincts = 0;
  12393. for (c = 0; c < componentsCount; ++c) {
  12394. var resolutions = tile.components[c].resolutions;
  12395. if (r < resolutions.length) {
  12396. maxNumPrecincts = Math.max(maxNumPrecincts,
  12397. resolutions[r].precinctParameters.numprecincts);
  12398. }
  12399. }
  12400. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  12401. }
  12402. l = 0;
  12403. r = 0;
  12404. c = 0;
  12405. p = 0;
  12406. this.nextPacket = function JpxImage_nextPacket() {
  12407. // Section B.12.1.3 Resolution-position-component-layer
  12408. for (; r <= maxDecompositionLevelsCount; r++) {
  12409. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  12410. for (; c < componentsCount; c++) {
  12411. var component = tile.components[c];
  12412. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12413. continue;
  12414. }
  12415. var resolution = component.resolutions[r];
  12416. var numprecincts = resolution.precinctParameters.numprecincts;
  12417. if (p >= numprecincts) {
  12418. continue;
  12419. }
  12420. for (; l < layersCount;) {
  12421. var packet = createPacket(resolution, p, l);
  12422. l++;
  12423. return packet;
  12424. }
  12425. l = 0;
  12426. }
  12427. c = 0;
  12428. }
  12429. p = 0;
  12430. }
  12431. error('JPX Error: Out of packets');
  12432. };
  12433. }
  12434. function PositionComponentResolutionLayerIterator(context) {
  12435. var siz = context.SIZ;
  12436. var tileIndex = context.currentTile.index;
  12437. var tile = context.tiles[tileIndex];
  12438. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12439. var componentsCount = siz.Csiz;
  12440. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12441. var precinctsIterationSizes = precinctsSizes;
  12442. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12443. this.nextPacket = function JpxImage_nextPacket() {
  12444. // Section B.12.1.4 Position-component-resolution-layer
  12445. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12446. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12447. for (; c < componentsCount; c++) {
  12448. var component = tile.components[c];
  12449. var decompositionLevelsCount =
  12450. component.codingStyleParameters.decompositionLevelsCount;
  12451. for (; r <= decompositionLevelsCount; r++) {
  12452. var resolution = component.resolutions[r];
  12453. var sizeInImageScale =
  12454. precinctsSizes.components[c].resolutions[r];
  12455. var k = getPrecinctIndexIfExist(
  12456. px,
  12457. py,
  12458. sizeInImageScale,
  12459. precinctsIterationSizes,
  12460. resolution);
  12461. if (k === null) {
  12462. continue;
  12463. }
  12464. for (; l < layersCount;) {
  12465. var packet = createPacket(resolution, k, l);
  12466. l++;
  12467. return packet;
  12468. }
  12469. l = 0;
  12470. }
  12471. r = 0;
  12472. }
  12473. c = 0;
  12474. }
  12475. px = 0;
  12476. }
  12477. error('JPX Error: Out of packets');
  12478. };
  12479. }
  12480. function ComponentPositionResolutionLayerIterator(context) {
  12481. var siz = context.SIZ;
  12482. var tileIndex = context.currentTile.index;
  12483. var tile = context.tiles[tileIndex];
  12484. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12485. var componentsCount = siz.Csiz;
  12486. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12487. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12488. this.nextPacket = function JpxImage_nextPacket() {
  12489. // Section B.12.1.5 Component-position-resolution-layer
  12490. for (; c < componentsCount; ++c) {
  12491. var component = tile.components[c];
  12492. var precinctsIterationSizes = precinctsSizes.components[c];
  12493. var decompositionLevelsCount =
  12494. component.codingStyleParameters.decompositionLevelsCount;
  12495. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12496. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12497. for (; r <= decompositionLevelsCount; r++) {
  12498. var resolution = component.resolutions[r];
  12499. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  12500. var k = getPrecinctIndexIfExist(
  12501. px,
  12502. py,
  12503. sizeInImageScale,
  12504. precinctsIterationSizes,
  12505. resolution);
  12506. if (k === null) {
  12507. continue;
  12508. }
  12509. for (; l < layersCount;) {
  12510. var packet = createPacket(resolution, k, l);
  12511. l++;
  12512. return packet;
  12513. }
  12514. l = 0;
  12515. }
  12516. r = 0;
  12517. }
  12518. px = 0;
  12519. }
  12520. py = 0;
  12521. }
  12522. error('JPX Error: Out of packets');
  12523. };
  12524. }
  12525. function getPrecinctIndexIfExist(
  12526. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  12527. var posX = pxIndex * precinctIterationSizes.minWidth;
  12528. var posY = pyIndex * precinctIterationSizes.minHeight;
  12529. if (posX % sizeInImageScale.width !== 0 ||
  12530. posY % sizeInImageScale.height !== 0) {
  12531. return null;
  12532. }
  12533. var startPrecinctRowIndex =
  12534. (posY / sizeInImageScale.width) *
  12535. resolution.precinctParameters.numprecinctswide;
  12536. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  12537. }
  12538. function getPrecinctSizesInImageScale(tile) {
  12539. var componentsCount = tile.components.length;
  12540. var minWidth = Number.MAX_VALUE;
  12541. var minHeight = Number.MAX_VALUE;
  12542. var maxNumWide = 0;
  12543. var maxNumHigh = 0;
  12544. var sizePerComponent = new Array(componentsCount);
  12545. for (var c = 0; c < componentsCount; c++) {
  12546. var component = tile.components[c];
  12547. var decompositionLevelsCount =
  12548. component.codingStyleParameters.decompositionLevelsCount;
  12549. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  12550. var minWidthCurrentComponent = Number.MAX_VALUE;
  12551. var minHeightCurrentComponent = Number.MAX_VALUE;
  12552. var maxNumWideCurrentComponent = 0;
  12553. var maxNumHighCurrentComponent = 0;
  12554. var scale = 1;
  12555. for (var r = decompositionLevelsCount; r >= 0; --r) {
  12556. var resolution = component.resolutions[r];
  12557. var widthCurrentResolution =
  12558. scale * resolution.precinctParameters.precinctWidth;
  12559. var heightCurrentResolution =
  12560. scale * resolution.precinctParameters.precinctHeight;
  12561. minWidthCurrentComponent = Math.min(
  12562. minWidthCurrentComponent,
  12563. widthCurrentResolution);
  12564. minHeightCurrentComponent = Math.min(
  12565. minHeightCurrentComponent,
  12566. heightCurrentResolution);
  12567. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  12568. resolution.precinctParameters.numprecinctswide);
  12569. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  12570. resolution.precinctParameters.numprecinctshigh);
  12571. sizePerResolution[r] = {
  12572. width: widthCurrentResolution,
  12573. height: heightCurrentResolution
  12574. };
  12575. scale <<= 1;
  12576. }
  12577. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  12578. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  12579. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  12580. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  12581. sizePerComponent[c] = {
  12582. resolutions: sizePerResolution,
  12583. minWidth: minWidthCurrentComponent,
  12584. minHeight: minHeightCurrentComponent,
  12585. maxNumWide: maxNumWideCurrentComponent,
  12586. maxNumHigh: maxNumHighCurrentComponent
  12587. };
  12588. }
  12589. return {
  12590. components: sizePerComponent,
  12591. minWidth: minWidth,
  12592. minHeight: minHeight,
  12593. maxNumWide: maxNumWide,
  12594. maxNumHigh: maxNumHigh
  12595. };
  12596. }
  12597. function buildPackets(context) {
  12598. var siz = context.SIZ;
  12599. var tileIndex = context.currentTile.index;
  12600. var tile = context.tiles[tileIndex];
  12601. var componentsCount = siz.Csiz;
  12602. // Creating resolutions and sub-bands for each component
  12603. for (var c = 0; c < componentsCount; c++) {
  12604. var component = tile.components[c];
  12605. var decompositionLevelsCount =
  12606. component.codingStyleParameters.decompositionLevelsCount;
  12607. // Section B.5 Resolution levels and sub-bands
  12608. var resolutions = [];
  12609. var subbands = [];
  12610. for (var r = 0; r <= decompositionLevelsCount; r++) {
  12611. var blocksDimensions = getBlocksDimensions(context, component, r);
  12612. var resolution = {};
  12613. var scale = 1 << (decompositionLevelsCount - r);
  12614. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  12615. resolution.try0 = Math.ceil(component.tcy0 / scale);
  12616. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  12617. resolution.try1 = Math.ceil(component.tcy1 / scale);
  12618. resolution.resLevel = r;
  12619. buildPrecincts(context, resolution, blocksDimensions);
  12620. resolutions.push(resolution);
  12621. var subband;
  12622. if (r === 0) {
  12623. // one sub-band (LL) with last decomposition
  12624. subband = {};
  12625. subband.type = 'LL';
  12626. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  12627. subband.tby0 = Math.ceil(component.tcy0 / scale);
  12628. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  12629. subband.tby1 = Math.ceil(component.tcy1 / scale);
  12630. subband.resolution = resolution;
  12631. buildCodeblocks(context, subband, blocksDimensions);
  12632. subbands.push(subband);
  12633. resolution.subbands = [subband];
  12634. } else {
  12635. var bscale = 1 << (decompositionLevelsCount - r + 1);
  12636. var resolutionSubbands = [];
  12637. // three sub-bands (HL, LH and HH) with rest of decompositions
  12638. subband = {};
  12639. subband.type = 'HL';
  12640. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  12641. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  12642. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  12643. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  12644. subband.resolution = resolution;
  12645. buildCodeblocks(context, subband, blocksDimensions);
  12646. subbands.push(subband);
  12647. resolutionSubbands.push(subband);
  12648. subband = {};
  12649. subband.type = 'LH';
  12650. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  12651. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  12652. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  12653. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  12654. subband.resolution = resolution;
  12655. buildCodeblocks(context, subband, blocksDimensions);
  12656. subbands.push(subband);
  12657. resolutionSubbands.push(subband);
  12658. subband = {};
  12659. subband.type = 'HH';
  12660. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  12661. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  12662. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  12663. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  12664. subband.resolution = resolution;
  12665. buildCodeblocks(context, subband, blocksDimensions);
  12666. subbands.push(subband);
  12667. resolutionSubbands.push(subband);
  12668. resolution.subbands = resolutionSubbands;
  12669. }
  12670. }
  12671. component.resolutions = resolutions;
  12672. component.subbands = subbands;
  12673. }
  12674. // Generate the packets sequence
  12675. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  12676. switch (progressionOrder) {
  12677. case 0:
  12678. tile.packetsIterator =
  12679. new LayerResolutionComponentPositionIterator(context);
  12680. break;
  12681. case 1:
  12682. tile.packetsIterator =
  12683. new ResolutionLayerComponentPositionIterator(context);
  12684. break;
  12685. case 2:
  12686. tile.packetsIterator =
  12687. new ResolutionPositionComponentLayerIterator(context);
  12688. break;
  12689. case 3:
  12690. tile.packetsIterator =
  12691. new PositionComponentResolutionLayerIterator(context);
  12692. break;
  12693. case 4:
  12694. tile.packetsIterator =
  12695. new ComponentPositionResolutionLayerIterator(context);
  12696. break;
  12697. default:
  12698. error('JPX Error: Unsupported progression order ' + progressionOrder);
  12699. }
  12700. }
  12701. function parseTilePackets(context, data, offset, dataLength) {
  12702. var position = 0;
  12703. var buffer, bufferSize = 0, skipNextBit = false;
  12704. function readBits(count) {
  12705. while (bufferSize < count) {
  12706. var b = data[offset + position];
  12707. position++;
  12708. if (skipNextBit) {
  12709. buffer = (buffer << 7) | b;
  12710. bufferSize += 7;
  12711. skipNextBit = false;
  12712. } else {
  12713. buffer = (buffer << 8) | b;
  12714. bufferSize += 8;
  12715. }
  12716. if (b === 0xFF) {
  12717. skipNextBit = true;
  12718. }
  12719. }
  12720. bufferSize -= count;
  12721. return (buffer >>> bufferSize) & ((1 << count) - 1);
  12722. }
  12723. function skipMarkerIfEqual(value) {
  12724. if (data[offset + position - 1] === 0xFF &&
  12725. data[offset + position] === value) {
  12726. skipBytes(1);
  12727. return true;
  12728. } else if (data[offset + position] === 0xFF &&
  12729. data[offset + position + 1] === value) {
  12730. skipBytes(2);
  12731. return true;
  12732. }
  12733. return false;
  12734. }
  12735. function skipBytes(count) {
  12736. position += count;
  12737. }
  12738. function alignToByte() {
  12739. bufferSize = 0;
  12740. if (skipNextBit) {
  12741. position++;
  12742. skipNextBit = false;
  12743. }
  12744. }
  12745. function readCodingpasses() {
  12746. if (readBits(1) === 0) {
  12747. return 1;
  12748. }
  12749. if (readBits(1) === 0) {
  12750. return 2;
  12751. }
  12752. var value = readBits(2);
  12753. if (value < 3) {
  12754. return value + 3;
  12755. }
  12756. value = readBits(5);
  12757. if (value < 31) {
  12758. return value + 6;
  12759. }
  12760. value = readBits(7);
  12761. return value + 37;
  12762. }
  12763. var tileIndex = context.currentTile.index;
  12764. var tile = context.tiles[tileIndex];
  12765. var sopMarkerUsed = context.COD.sopMarkerUsed;
  12766. var ephMarkerUsed = context.COD.ephMarkerUsed;
  12767. var packetsIterator = tile.packetsIterator;
  12768. while (position < dataLength) {
  12769. alignToByte();
  12770. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  12771. // Skip also marker segment length and packet sequence ID
  12772. skipBytes(4);
  12773. }
  12774. var packet = packetsIterator.nextPacket();
  12775. if (!readBits(1)) {
  12776. continue;
  12777. }
  12778. var layerNumber = packet.layerNumber;
  12779. var queue = [], codeblock;
  12780. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  12781. codeblock = packet.codeblocks[i];
  12782. var precinct = codeblock.precinct;
  12783. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  12784. var codeblockRow = codeblock.cby - precinct.cbyMin;
  12785. var codeblockIncluded = false;
  12786. var firstTimeInclusion = false;
  12787. var valueReady;
  12788. if (codeblock['included'] !== undefined) {
  12789. codeblockIncluded = !!readBits(1);
  12790. } else {
  12791. // reading inclusion tree
  12792. precinct = codeblock.precinct;
  12793. var inclusionTree, zeroBitPlanesTree;
  12794. if (precinct['inclusionTree'] !== undefined) {
  12795. inclusionTree = precinct.inclusionTree;
  12796. } else {
  12797. // building inclusion and zero bit-planes trees
  12798. var width = precinct.cbxMax - precinct.cbxMin + 1;
  12799. var height = precinct.cbyMax - precinct.cbyMin + 1;
  12800. inclusionTree = new InclusionTree(width, height, layerNumber);
  12801. zeroBitPlanesTree = new TagTree(width, height);
  12802. precinct.inclusionTree = inclusionTree;
  12803. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  12804. }
  12805. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  12806. while (true) {
  12807. if (readBits(1)) {
  12808. valueReady = !inclusionTree.nextLevel();
  12809. if (valueReady) {
  12810. codeblock.included = true;
  12811. codeblockIncluded = firstTimeInclusion = true;
  12812. break;
  12813. }
  12814. } else {
  12815. inclusionTree.incrementValue(layerNumber);
  12816. break;
  12817. }
  12818. }
  12819. }
  12820. }
  12821. if (!codeblockIncluded) {
  12822. continue;
  12823. }
  12824. if (firstTimeInclusion) {
  12825. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  12826. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  12827. while (true) {
  12828. if (readBits(1)) {
  12829. valueReady = !zeroBitPlanesTree.nextLevel();
  12830. if (valueReady) {
  12831. break;
  12832. }
  12833. } else {
  12834. zeroBitPlanesTree.incrementValue();
  12835. }
  12836. }
  12837. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  12838. }
  12839. var codingpasses = readCodingpasses();
  12840. while (readBits(1)) {
  12841. codeblock.Lblock++;
  12842. }
  12843. var codingpassesLog2 = log2(codingpasses);
  12844. // rounding down log2
  12845. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  12846. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  12847. var codedDataLength = readBits(bits);
  12848. queue.push({
  12849. codeblock: codeblock,
  12850. codingpasses: codingpasses,
  12851. dataLength: codedDataLength
  12852. });
  12853. }
  12854. alignToByte();
  12855. if (ephMarkerUsed) {
  12856. skipMarkerIfEqual(0x92);
  12857. }
  12858. while (queue.length > 0) {
  12859. var packetItem = queue.shift();
  12860. codeblock = packetItem.codeblock;
  12861. if (codeblock['data'] === undefined) {
  12862. codeblock.data = [];
  12863. }
  12864. codeblock.data.push({
  12865. data: data,
  12866. start: offset + position,
  12867. end: offset + position + packetItem.dataLength,
  12868. codingpasses: packetItem.codingpasses
  12869. });
  12870. position += packetItem.dataLength;
  12871. }
  12872. }
  12873. return position;
  12874. }
  12875. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  12876. delta, mb, reversible, segmentationSymbolUsed) {
  12877. var x0 = subband.tbx0;
  12878. var y0 = subband.tby0;
  12879. var width = subband.tbx1 - subband.tbx0;
  12880. var codeblocks = subband.codeblocks;
  12881. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  12882. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  12883. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  12884. var codeblock = codeblocks[i];
  12885. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  12886. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  12887. if (blockWidth === 0 || blockHeight === 0) {
  12888. continue;
  12889. }
  12890. if (codeblock['data'] === undefined) {
  12891. continue;
  12892. }
  12893. var bitModel, currentCodingpassType;
  12894. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  12895. codeblock.zeroBitPlanes, mb);
  12896. currentCodingpassType = 2; // first bit plane starts from cleanup
  12897. // collect data
  12898. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  12899. var j, jj, dataItem;
  12900. for (j = 0, jj = data.length; j < jj; j++) {
  12901. dataItem = data[j];
  12902. totalLength += dataItem.end - dataItem.start;
  12903. codingpasses += dataItem.codingpasses;
  12904. }
  12905. var encodedData = new Uint8Array(totalLength);
  12906. var position = 0;
  12907. for (j = 0, jj = data.length; j < jj; j++) {
  12908. dataItem = data[j];
  12909. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  12910. encodedData.set(chunk, position);
  12911. position += chunk.length;
  12912. }
  12913. // decoding the item
  12914. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  12915. bitModel.setDecoder(decoder);
  12916. for (j = 0; j < codingpasses; j++) {
  12917. switch (currentCodingpassType) {
  12918. case 0:
  12919. bitModel.runSignificancePropagationPass();
  12920. break;
  12921. case 1:
  12922. bitModel.runMagnitudeRefinementPass();
  12923. break;
  12924. case 2:
  12925. bitModel.runCleanupPass();
  12926. if (segmentationSymbolUsed) {
  12927. bitModel.checkSegmentationSymbol();
  12928. }
  12929. break;
  12930. }
  12931. currentCodingpassType = (currentCodingpassType + 1) % 3;
  12932. }
  12933. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  12934. var sign = bitModel.coefficentsSign;
  12935. var magnitude = bitModel.coefficentsMagnitude;
  12936. var bitsDecoded = bitModel.bitsDecoded;
  12937. var magnitudeCorrection = reversible ? 0 : 0.5;
  12938. var k, n, nb;
  12939. position = 0;
  12940. // Do the interleaving of Section F.3.3 here, so we do not need
  12941. // to copy later. LL level is not interleaved, just copied.
  12942. var interleave = (subband.type !== 'LL');
  12943. for (j = 0; j < blockHeight; j++) {
  12944. var row = (offset / width) | 0; // row in the non-interleaved subband
  12945. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  12946. for (k = 0; k < blockWidth; k++) {
  12947. n = magnitude[position];
  12948. if (n !== 0) {
  12949. n = (n + magnitudeCorrection) * delta;
  12950. if (sign[position] !== 0) {
  12951. n = -n;
  12952. }
  12953. nb = bitsDecoded[position];
  12954. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  12955. if (reversible && (nb >= mb)) {
  12956. coefficients[pos] = n;
  12957. } else {
  12958. coefficients[pos] = n * (1 << (mb - nb));
  12959. }
  12960. }
  12961. offset++;
  12962. position++;
  12963. }
  12964. offset += width - blockWidth;
  12965. }
  12966. }
  12967. }
  12968. function transformTile(context, tile, c) {
  12969. var component = tile.components[c];
  12970. var codingStyleParameters = component.codingStyleParameters;
  12971. var quantizationParameters = component.quantizationParameters;
  12972. var decompositionLevelsCount =
  12973. codingStyleParameters.decompositionLevelsCount;
  12974. var spqcds = quantizationParameters.SPqcds;
  12975. var scalarExpounded = quantizationParameters.scalarExpounded;
  12976. var guardBits = quantizationParameters.guardBits;
  12977. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  12978. var precision = context.components[c].precision;
  12979. var reversible = codingStyleParameters.reversibleTransformation;
  12980. var transform = (reversible ? new ReversibleTransform() :
  12981. new IrreversibleTransform());
  12982. var subbandCoefficients = [];
  12983. var b = 0;
  12984. for (var i = 0; i <= decompositionLevelsCount; i++) {
  12985. var resolution = component.resolutions[i];
  12986. var width = resolution.trx1 - resolution.trx0;
  12987. var height = resolution.try1 - resolution.try0;
  12988. // Allocate space for the whole sublevel.
  12989. var coefficients = new Float32Array(width * height);
  12990. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  12991. var mu, epsilon;
  12992. if (!scalarExpounded) {
  12993. // formula E-5
  12994. mu = spqcds[0].mu;
  12995. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  12996. } else {
  12997. mu = spqcds[b].mu;
  12998. epsilon = spqcds[b].epsilon;
  12999. b++;
  13000. }
  13001. var subband = resolution.subbands[j];
  13002. var gainLog2 = SubbandsGainLog2[subband.type];
  13003. // calculate quantization coefficient (Section E.1.1.1)
  13004. var delta = (reversible ? 1 :
  13005. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  13006. var mb = (guardBits + epsilon - 1);
  13007. // In the first resolution level, copyCoefficients will fill the
  13008. // whole array with coefficients. In the succeeding passes,
  13009. // copyCoefficients will consecutively fill in the values that belong
  13010. // to the interleaved positions of the HL, LH, and HH coefficients.
  13011. // The LL coefficients will then be interleaved in Transform.iterate().
  13012. copyCoefficients(coefficients, width, height, subband, delta, mb,
  13013. reversible, segmentationSymbolUsed);
  13014. }
  13015. subbandCoefficients.push({
  13016. width: width,
  13017. height: height,
  13018. items: coefficients
  13019. });
  13020. }
  13021. var result = transform.calculate(subbandCoefficients,
  13022. component.tcx0, component.tcy0);
  13023. return {
  13024. left: component.tcx0,
  13025. top: component.tcy0,
  13026. width: result.width,
  13027. height: result.height,
  13028. items: result.items
  13029. };
  13030. }
  13031. function transformComponents(context) {
  13032. var siz = context.SIZ;
  13033. var components = context.components;
  13034. var componentsCount = siz.Csiz;
  13035. var resultImages = [];
  13036. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  13037. var tile = context.tiles[i];
  13038. var transformedTiles = [];
  13039. var c;
  13040. for (c = 0; c < componentsCount; c++) {
  13041. transformedTiles[c] = transformTile(context, tile, c);
  13042. }
  13043. var tile0 = transformedTiles[0];
  13044. var out = new Uint8Array(tile0.items.length * componentsCount);
  13045. var result = {
  13046. left: tile0.left,
  13047. top: tile0.top,
  13048. width: tile0.width,
  13049. height: tile0.height,
  13050. items: out
  13051. };
  13052. // Section G.2.2 Inverse multi component transform
  13053. var shift, offset, max, min, maxK;
  13054. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  13055. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  13056. var fourComponents = componentsCount === 4;
  13057. var y0items = transformedTiles[0].items;
  13058. var y1items = transformedTiles[1].items;
  13059. var y2items = transformedTiles[2].items;
  13060. var y3items = fourComponents ? transformedTiles[3].items : null;
  13061. // HACK: The multiple component transform formulas below assume that
  13062. // all components have the same precision. With this in mind, we
  13063. // compute shift and offset only once.
  13064. shift = components[0].precision - 8;
  13065. offset = (128 << shift) + 0.5;
  13066. max = 255 * (1 << shift);
  13067. maxK = max * 0.5;
  13068. min = -maxK;
  13069. var component0 = tile.components[0];
  13070. var alpha01 = componentsCount - 3;
  13071. jj = y0items.length;
  13072. if (!component0.codingStyleParameters.reversibleTransformation) {
  13073. // inverse irreversible multiple component transform
  13074. for (j = 0; j < jj; j++, pos += alpha01) {
  13075. y0 = y0items[j] + offset;
  13076. y1 = y1items[j];
  13077. y2 = y2items[j];
  13078. r = y0 + 1.402 * y2;
  13079. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  13080. b = y0 + 1.772 * y1;
  13081. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  13082. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  13083. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  13084. }
  13085. } else {
  13086. // inverse reversible multiple component transform
  13087. for (j = 0; j < jj; j++, pos += alpha01) {
  13088. y0 = y0items[j] + offset;
  13089. y1 = y1items[j];
  13090. y2 = y2items[j];
  13091. g = y0 - ((y2 + y1) >> 2);
  13092. r = g + y2;
  13093. b = g + y1;
  13094. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  13095. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  13096. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  13097. }
  13098. }
  13099. if (fourComponents) {
  13100. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  13101. k = y3items[j];
  13102. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  13103. }
  13104. }
  13105. } else { // no multi-component transform
  13106. for (c = 0; c < componentsCount; c++) {
  13107. var items = transformedTiles[c].items;
  13108. shift = components[c].precision - 8;
  13109. offset = (128 << shift) + 0.5;
  13110. max = (127.5 * (1 << shift));
  13111. min = -max;
  13112. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  13113. val = items[j];
  13114. out[pos] = val <= min ? 0 :
  13115. val >= max ? 255 : (val + offset) >> shift;
  13116. pos += componentsCount;
  13117. }
  13118. }
  13119. }
  13120. resultImages.push(result);
  13121. }
  13122. return resultImages;
  13123. }
  13124. function initializeTile(context, tileIndex) {
  13125. var siz = context.SIZ;
  13126. var componentsCount = siz.Csiz;
  13127. var tile = context.tiles[tileIndex];
  13128. for (var c = 0; c < componentsCount; c++) {
  13129. var component = tile.components[c];
  13130. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  13131. context.currentTile.QCC[c] : context.currentTile.QCD);
  13132. component.quantizationParameters = qcdOrQcc;
  13133. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  13134. context.currentTile.COC[c] : context.currentTile.COD);
  13135. component.codingStyleParameters = codOrCoc;
  13136. }
  13137. tile.codingStyleDefaultParameters = context.currentTile.COD;
  13138. }
  13139. // Section B.10.2 Tag trees
  13140. var TagTree = (function TagTreeClosure() {
  13141. function TagTree(width, height) {
  13142. var levelsLength = log2(Math.max(width, height)) + 1;
  13143. this.levels = [];
  13144. for (var i = 0; i < levelsLength; i++) {
  13145. var level = {
  13146. width: width,
  13147. height: height,
  13148. items: []
  13149. };
  13150. this.levels.push(level);
  13151. width = Math.ceil(width / 2);
  13152. height = Math.ceil(height / 2);
  13153. }
  13154. }
  13155. TagTree.prototype = {
  13156. reset: function TagTree_reset(i, j) {
  13157. var currentLevel = 0, value = 0, level;
  13158. while (currentLevel < this.levels.length) {
  13159. level = this.levels[currentLevel];
  13160. var index = i + j * level.width;
  13161. if (level.items[index] !== undefined) {
  13162. value = level.items[index];
  13163. break;
  13164. }
  13165. level.index = index;
  13166. i >>= 1;
  13167. j >>= 1;
  13168. currentLevel++;
  13169. }
  13170. currentLevel--;
  13171. level = this.levels[currentLevel];
  13172. level.items[level.index] = value;
  13173. this.currentLevel = currentLevel;
  13174. delete this.value;
  13175. },
  13176. incrementValue: function TagTree_incrementValue() {
  13177. var level = this.levels[this.currentLevel];
  13178. level.items[level.index]++;
  13179. },
  13180. nextLevel: function TagTree_nextLevel() {
  13181. var currentLevel = this.currentLevel;
  13182. var level = this.levels[currentLevel];
  13183. var value = level.items[level.index];
  13184. currentLevel--;
  13185. if (currentLevel < 0) {
  13186. this.value = value;
  13187. return false;
  13188. }
  13189. this.currentLevel = currentLevel;
  13190. level = this.levels[currentLevel];
  13191. level.items[level.index] = value;
  13192. return true;
  13193. }
  13194. };
  13195. return TagTree;
  13196. })();
  13197. var InclusionTree = (function InclusionTreeClosure() {
  13198. function InclusionTree(width, height, defaultValue) {
  13199. var levelsLength = log2(Math.max(width, height)) + 1;
  13200. this.levels = [];
  13201. for (var i = 0; i < levelsLength; i++) {
  13202. var items = new Uint8Array(width * height);
  13203. for (var j = 0, jj = items.length; j < jj; j++) {
  13204. items[j] = defaultValue;
  13205. }
  13206. var level = {
  13207. width: width,
  13208. height: height,
  13209. items: items
  13210. };
  13211. this.levels.push(level);
  13212. width = Math.ceil(width / 2);
  13213. height = Math.ceil(height / 2);
  13214. }
  13215. }
  13216. InclusionTree.prototype = {
  13217. reset: function InclusionTree_reset(i, j, stopValue) {
  13218. var currentLevel = 0;
  13219. while (currentLevel < this.levels.length) {
  13220. var level = this.levels[currentLevel];
  13221. var index = i + j * level.width;
  13222. level.index = index;
  13223. var value = level.items[index];
  13224. if (value === 0xFF) {
  13225. break;
  13226. }
  13227. if (value > stopValue) {
  13228. this.currentLevel = currentLevel;
  13229. // already know about this one, propagating the value to top levels
  13230. this.propagateValues();
  13231. return false;
  13232. }
  13233. i >>= 1;
  13234. j >>= 1;
  13235. currentLevel++;
  13236. }
  13237. this.currentLevel = currentLevel - 1;
  13238. return true;
  13239. },
  13240. incrementValue: function InclusionTree_incrementValue(stopValue) {
  13241. var level = this.levels[this.currentLevel];
  13242. level.items[level.index] = stopValue + 1;
  13243. this.propagateValues();
  13244. },
  13245. propagateValues: function InclusionTree_propagateValues() {
  13246. var levelIndex = this.currentLevel;
  13247. var level = this.levels[levelIndex];
  13248. var currentValue = level.items[level.index];
  13249. while (--levelIndex >= 0) {
  13250. level = this.levels[levelIndex];
  13251. level.items[level.index] = currentValue;
  13252. }
  13253. },
  13254. nextLevel: function InclusionTree_nextLevel() {
  13255. var currentLevel = this.currentLevel;
  13256. var level = this.levels[currentLevel];
  13257. var value = level.items[level.index];
  13258. level.items[level.index] = 0xFF;
  13259. currentLevel--;
  13260. if (currentLevel < 0) {
  13261. return false;
  13262. }
  13263. this.currentLevel = currentLevel;
  13264. level = this.levels[currentLevel];
  13265. level.items[level.index] = value;
  13266. return true;
  13267. }
  13268. };
  13269. return InclusionTree;
  13270. })();
  13271. // Section D. Coefficient bit modeling
  13272. var BitModel = (function BitModelClosure() {
  13273. var UNIFORM_CONTEXT = 17;
  13274. var RUNLENGTH_CONTEXT = 18;
  13275. // Table D-1
  13276. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  13277. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  13278. var LLAndLHContextsLabel = new Uint8Array([
  13279. 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,
  13280. 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,
  13281. 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
  13282. ]);
  13283. var HLContextLabel = new Uint8Array([
  13284. 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,
  13285. 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,
  13286. 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
  13287. ]);
  13288. var HHContextLabel = new Uint8Array([
  13289. 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,
  13290. 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,
  13291. 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
  13292. ]);
  13293. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  13294. this.width = width;
  13295. this.height = height;
  13296. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  13297. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  13298. var coefficientCount = width * height;
  13299. // coefficients outside the encoding region treated as insignificant
  13300. // add border state cells for significanceState
  13301. this.neighborsSignificance = new Uint8Array(coefficientCount);
  13302. this.coefficentsSign = new Uint8Array(coefficientCount);
  13303. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  13304. mb > 6 ? new Uint16Array(coefficientCount) :
  13305. new Uint8Array(coefficientCount);
  13306. this.processingFlags = new Uint8Array(coefficientCount);
  13307. var bitsDecoded = new Uint8Array(coefficientCount);
  13308. if (zeroBitPlanes !== 0) {
  13309. for (var i = 0; i < coefficientCount; i++) {
  13310. bitsDecoded[i] = zeroBitPlanes;
  13311. }
  13312. }
  13313. this.bitsDecoded = bitsDecoded;
  13314. this.reset();
  13315. }
  13316. BitModel.prototype = {
  13317. setDecoder: function BitModel_setDecoder(decoder) {
  13318. this.decoder = decoder;
  13319. },
  13320. reset: function BitModel_reset() {
  13321. // We have 17 contexts that are accessed via context labels,
  13322. // plus the uniform and runlength context.
  13323. this.contexts = new Int8Array(19);
  13324. // Contexts are packed into 1 byte:
  13325. // highest 7 bits carry the index, lowest bit carries mps
  13326. this.contexts[0] = (4 << 1) | 0;
  13327. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  13328. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  13329. },
  13330. setNeighborsSignificance:
  13331. function BitModel_setNeighborsSignificance(row, column, index) {
  13332. var neighborsSignificance = this.neighborsSignificance;
  13333. var width = this.width, height = this.height;
  13334. var left = (column > 0);
  13335. var right = (column + 1 < width);
  13336. var i;
  13337. if (row > 0) {
  13338. i = index - width;
  13339. if (left) {
  13340. neighborsSignificance[i - 1] += 0x10;
  13341. }
  13342. if (right) {
  13343. neighborsSignificance[i + 1] += 0x10;
  13344. }
  13345. neighborsSignificance[i] += 0x04;
  13346. }
  13347. if (row + 1 < height) {
  13348. i = index + width;
  13349. if (left) {
  13350. neighborsSignificance[i - 1] += 0x10;
  13351. }
  13352. if (right) {
  13353. neighborsSignificance[i + 1] += 0x10;
  13354. }
  13355. neighborsSignificance[i] += 0x04;
  13356. }
  13357. if (left) {
  13358. neighborsSignificance[index - 1] += 0x01;
  13359. }
  13360. if (right) {
  13361. neighborsSignificance[index + 1] += 0x01;
  13362. }
  13363. neighborsSignificance[index] |= 0x80;
  13364. },
  13365. runSignificancePropagationPass:
  13366. function BitModel_runSignificancePropagationPass() {
  13367. var decoder = this.decoder;
  13368. var width = this.width, height = this.height;
  13369. var coefficentsMagnitude = this.coefficentsMagnitude;
  13370. var coefficentsSign = this.coefficentsSign;
  13371. var neighborsSignificance = this.neighborsSignificance;
  13372. var processingFlags = this.processingFlags;
  13373. var contexts = this.contexts;
  13374. var labels = this.contextLabelTable;
  13375. var bitsDecoded = this.bitsDecoded;
  13376. var processedInverseMask = ~1;
  13377. var processedMask = 1;
  13378. var firstMagnitudeBitMask = 2;
  13379. for (var i0 = 0; i0 < height; i0 += 4) {
  13380. for (var j = 0; j < width; j++) {
  13381. var index = i0 * width + j;
  13382. for (var i1 = 0; i1 < 4; i1++, index += width) {
  13383. var i = i0 + i1;
  13384. if (i >= height) {
  13385. break;
  13386. }
  13387. // clear processed flag first
  13388. processingFlags[index] &= processedInverseMask;
  13389. if (coefficentsMagnitude[index] ||
  13390. !neighborsSignificance[index]) {
  13391. continue;
  13392. }
  13393. var contextLabel = labels[neighborsSignificance[index]];
  13394. var decision = decoder.readBit(contexts, contextLabel);
  13395. if (decision) {
  13396. var sign = this.decodeSignBit(i, j, index);
  13397. coefficentsSign[index] = sign;
  13398. coefficentsMagnitude[index] = 1;
  13399. this.setNeighborsSignificance(i, j, index);
  13400. processingFlags[index] |= firstMagnitudeBitMask;
  13401. }
  13402. bitsDecoded[index]++;
  13403. processingFlags[index] |= processedMask;
  13404. }
  13405. }
  13406. }
  13407. },
  13408. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  13409. var width = this.width, height = this.height;
  13410. var coefficentsMagnitude = this.coefficentsMagnitude;
  13411. var coefficentsSign = this.coefficentsSign;
  13412. var contribution, sign0, sign1, significance1;
  13413. var contextLabel, decoded;
  13414. // calculate horizontal contribution
  13415. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  13416. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  13417. sign1 = coefficentsSign[index + 1];
  13418. if (significance1) {
  13419. sign0 = coefficentsSign[index - 1];
  13420. contribution = 1 - sign1 - sign0;
  13421. } else {
  13422. contribution = 1 - sign1 - sign1;
  13423. }
  13424. } else if (significance1) {
  13425. sign0 = coefficentsSign[index - 1];
  13426. contribution = 1 - sign0 - sign0;
  13427. } else {
  13428. contribution = 0;
  13429. }
  13430. var horizontalContribution = 3 * contribution;
  13431. // calculate vertical contribution and combine with the horizontal
  13432. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  13433. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  13434. sign1 = coefficentsSign[index + width];
  13435. if (significance1) {
  13436. sign0 = coefficentsSign[index - width];
  13437. contribution = 1 - sign1 - sign0 + horizontalContribution;
  13438. } else {
  13439. contribution = 1 - sign1 - sign1 + horizontalContribution;
  13440. }
  13441. } else if (significance1) {
  13442. sign0 = coefficentsSign[index - width];
  13443. contribution = 1 - sign0 - sign0 + horizontalContribution;
  13444. } else {
  13445. contribution = horizontalContribution;
  13446. }
  13447. if (contribution >= 0) {
  13448. contextLabel = 9 + contribution;
  13449. decoded = this.decoder.readBit(this.contexts, contextLabel);
  13450. } else {
  13451. contextLabel = 9 - contribution;
  13452. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  13453. }
  13454. return decoded;
  13455. },
  13456. runMagnitudeRefinementPass:
  13457. function BitModel_runMagnitudeRefinementPass() {
  13458. var decoder = this.decoder;
  13459. var width = this.width, height = this.height;
  13460. var coefficentsMagnitude = this.coefficentsMagnitude;
  13461. var neighborsSignificance = this.neighborsSignificance;
  13462. var contexts = this.contexts;
  13463. var bitsDecoded = this.bitsDecoded;
  13464. var processingFlags = this.processingFlags;
  13465. var processedMask = 1;
  13466. var firstMagnitudeBitMask = 2;
  13467. var length = width * height;
  13468. var width4 = width * 4;
  13469. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  13470. indexNext = Math.min(length, index0 + width4);
  13471. for (var j = 0; j < width; j++) {
  13472. for (var index = index0 + j; index < indexNext; index += width) {
  13473. // significant but not those that have just become
  13474. if (!coefficentsMagnitude[index] ||
  13475. (processingFlags[index] & processedMask) !== 0) {
  13476. continue;
  13477. }
  13478. var contextLabel = 16;
  13479. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  13480. processingFlags[index] ^= firstMagnitudeBitMask;
  13481. // first refinement
  13482. var significance = neighborsSignificance[index] & 127;
  13483. contextLabel = significance === 0 ? 15 : 14;
  13484. }
  13485. var bit = decoder.readBit(contexts, contextLabel);
  13486. coefficentsMagnitude[index] =
  13487. (coefficentsMagnitude[index] << 1) | bit;
  13488. bitsDecoded[index]++;
  13489. processingFlags[index] |= processedMask;
  13490. }
  13491. }
  13492. }
  13493. },
  13494. runCleanupPass: function BitModel_runCleanupPass() {
  13495. var decoder = this.decoder;
  13496. var width = this.width, height = this.height;
  13497. var neighborsSignificance = this.neighborsSignificance;
  13498. var coefficentsMagnitude = this.coefficentsMagnitude;
  13499. var coefficentsSign = this.coefficentsSign;
  13500. var contexts = this.contexts;
  13501. var labels = this.contextLabelTable;
  13502. var bitsDecoded = this.bitsDecoded;
  13503. var processingFlags = this.processingFlags;
  13504. var processedMask = 1;
  13505. var firstMagnitudeBitMask = 2;
  13506. var oneRowDown = width;
  13507. var twoRowsDown = width * 2;
  13508. var threeRowsDown = width * 3;
  13509. var iNext;
  13510. for (var i0 = 0; i0 < height; i0 = iNext) {
  13511. iNext = Math.min(i0 + 4, height);
  13512. var indexBase = i0 * width;
  13513. var checkAllEmpty = i0 + 3 < height;
  13514. for (var j = 0; j < width; j++) {
  13515. var index0 = indexBase + j;
  13516. // using the property: labels[neighborsSignificance[index]] === 0
  13517. // when neighborsSignificance[index] === 0
  13518. var allEmpty = (checkAllEmpty &&
  13519. processingFlags[index0] === 0 &&
  13520. processingFlags[index0 + oneRowDown] === 0 &&
  13521. processingFlags[index0 + twoRowsDown] === 0 &&
  13522. processingFlags[index0 + threeRowsDown] === 0 &&
  13523. neighborsSignificance[index0] === 0 &&
  13524. neighborsSignificance[index0 + oneRowDown] === 0 &&
  13525. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  13526. neighborsSignificance[index0 + threeRowsDown] === 0);
  13527. var i1 = 0, index = index0;
  13528. var i = i0, sign;
  13529. if (allEmpty) {
  13530. var hasSignificantCoefficent =
  13531. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  13532. if (!hasSignificantCoefficent) {
  13533. bitsDecoded[index0]++;
  13534. bitsDecoded[index0 + oneRowDown]++;
  13535. bitsDecoded[index0 + twoRowsDown]++;
  13536. bitsDecoded[index0 + threeRowsDown]++;
  13537. continue; // next column
  13538. }
  13539. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  13540. decoder.readBit(contexts, UNIFORM_CONTEXT);
  13541. if (i1 !== 0) {
  13542. i = i0 + i1;
  13543. index += i1 * width;
  13544. }
  13545. sign = this.decodeSignBit(i, j, index);
  13546. coefficentsSign[index] = sign;
  13547. coefficentsMagnitude[index] = 1;
  13548. this.setNeighborsSignificance(i, j, index);
  13549. processingFlags[index] |= firstMagnitudeBitMask;
  13550. index = index0;
  13551. for (var i2 = i0; i2 <= i; i2++, index += width) {
  13552. bitsDecoded[index]++;
  13553. }
  13554. i1++;
  13555. }
  13556. for (i = i0 + i1; i < iNext; i++, index += width) {
  13557. if (coefficentsMagnitude[index] ||
  13558. (processingFlags[index] & processedMask) !== 0) {
  13559. continue;
  13560. }
  13561. var contextLabel = labels[neighborsSignificance[index]];
  13562. var decision = decoder.readBit(contexts, contextLabel);
  13563. if (decision === 1) {
  13564. sign = this.decodeSignBit(i, j, index);
  13565. coefficentsSign[index] = sign;
  13566. coefficentsMagnitude[index] = 1;
  13567. this.setNeighborsSignificance(i, j, index);
  13568. processingFlags[index] |= firstMagnitudeBitMask;
  13569. }
  13570. bitsDecoded[index]++;
  13571. }
  13572. }
  13573. }
  13574. },
  13575. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  13576. var decoder = this.decoder;
  13577. var contexts = this.contexts;
  13578. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  13579. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  13580. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  13581. decoder.readBit(contexts, UNIFORM_CONTEXT);
  13582. if (symbol !== 0xA) {
  13583. error('JPX Error: Invalid segmentation symbol');
  13584. }
  13585. }
  13586. };
  13587. return BitModel;
  13588. })();
  13589. // Section F, Discrete wavelet transformation
  13590. var Transform = (function TransformClosure() {
  13591. function Transform() {}
  13592. Transform.prototype.calculate =
  13593. function transformCalculate(subbands, u0, v0) {
  13594. var ll = subbands[0];
  13595. for (var i = 1, ii = subbands.length; i < ii; i++) {
  13596. ll = this.iterate(ll, subbands[i], u0, v0);
  13597. }
  13598. return ll;
  13599. };
  13600. Transform.prototype.extend = function extend(buffer, offset, size) {
  13601. // Section F.3.7 extending... using max extension of 4
  13602. var i1 = offset - 1, j1 = offset + 1;
  13603. var i2 = offset + size - 2, j2 = offset + size;
  13604. buffer[i1--] = buffer[j1++];
  13605. buffer[j2++] = buffer[i2--];
  13606. buffer[i1--] = buffer[j1++];
  13607. buffer[j2++] = buffer[i2--];
  13608. buffer[i1--] = buffer[j1++];
  13609. buffer[j2++] = buffer[i2--];
  13610. buffer[i1] = buffer[j1];
  13611. buffer[j2] = buffer[i2];
  13612. };
  13613. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  13614. u0, v0) {
  13615. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  13616. var width = hl_lh_hh.width;
  13617. var height = hl_lh_hh.height;
  13618. var items = hl_lh_hh.items;
  13619. var i, j, k, l, u, v;
  13620. // Interleave LL according to Section F.3.3
  13621. for (k = 0, i = 0; i < llHeight; i++) {
  13622. l = i * 2 * width;
  13623. for (j = 0; j < llWidth; j++, k++, l += 2) {
  13624. items[l] = llItems[k];
  13625. }
  13626. }
  13627. // The LL band is not needed anymore.
  13628. llItems = ll.items = null;
  13629. var bufferPadding = 4;
  13630. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  13631. // Section F.3.4 HOR_SR
  13632. if (width === 1) {
  13633. // if width = 1, when u0 even keep items as is, when odd divide by 2
  13634. if ((u0 & 1) !== 0) {
  13635. for (v = 0, k = 0; v < height; v++, k += width) {
  13636. items[k] *= 0.5;
  13637. }
  13638. }
  13639. } else {
  13640. for (v = 0, k = 0; v < height; v++, k += width) {
  13641. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  13642. this.extend(rowBuffer, bufferPadding, width);
  13643. this.filter(rowBuffer, bufferPadding, width);
  13644. items.set(
  13645. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  13646. k);
  13647. }
  13648. }
  13649. // Accesses to the items array can take long, because it may not fit into
  13650. // CPU cache and has to be fetched from main memory. Since subsequent
  13651. // accesses to the items array are not local when reading columns, we
  13652. // have a cache miss every time. To reduce cache misses, get up to
  13653. // 'numBuffers' items at a time and store them into the individual
  13654. // buffers. The colBuffers should be small enough to fit into CPU cache.
  13655. var numBuffers = 16;
  13656. var colBuffers = [];
  13657. for (i = 0; i < numBuffers; i++) {
  13658. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  13659. }
  13660. var b, currentBuffer = 0;
  13661. ll = bufferPadding + height;
  13662. // Section F.3.5 VER_SR
  13663. if (height === 1) {
  13664. // if height = 1, when v0 even keep items as is, when odd divide by 2
  13665. if ((v0 & 1) !== 0) {
  13666. for (u = 0; u < width; u++) {
  13667. items[u] *= 0.5;
  13668. }
  13669. }
  13670. } else {
  13671. for (u = 0; u < width; u++) {
  13672. // if we ran out of buffers, copy several image columns at once
  13673. if (currentBuffer === 0) {
  13674. numBuffers = Math.min(width - u, numBuffers);
  13675. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  13676. for (b = 0; b < numBuffers; b++) {
  13677. colBuffers[b][l] = items[k + b];
  13678. }
  13679. }
  13680. currentBuffer = numBuffers;
  13681. }
  13682. currentBuffer--;
  13683. var buffer = colBuffers[currentBuffer];
  13684. this.extend(buffer, bufferPadding, height);
  13685. this.filter(buffer, bufferPadding, height);
  13686. // If this is last buffer in this group of buffers, flush all buffers.
  13687. if (currentBuffer === 0) {
  13688. k = u - numBuffers + 1;
  13689. for (l = bufferPadding; l < ll; k += width, l++) {
  13690. for (b = 0; b < numBuffers; b++) {
  13691. items[k + b] = colBuffers[b][l];
  13692. }
  13693. }
  13694. }
  13695. }
  13696. }
  13697. return {
  13698. width: width,
  13699. height: height,
  13700. items: items
  13701. };
  13702. };
  13703. return Transform;
  13704. })();
  13705. // Section 3.8.2 Irreversible 9-7 filter
  13706. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  13707. function IrreversibleTransform() {
  13708. Transform.call(this);
  13709. }
  13710. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  13711. IrreversibleTransform.prototype.filter =
  13712. function irreversibleTransformFilter(x, offset, length) {
  13713. var len = length >> 1;
  13714. offset = offset | 0;
  13715. var j, n, current, next;
  13716. var alpha = -1.586134342059924;
  13717. var beta = -0.052980118572961;
  13718. var gamma = 0.882911075530934;
  13719. var delta = 0.443506852043971;
  13720. var K = 1.230174104914001;
  13721. var K_ = 1 / K;
  13722. // step 1 is combined with step 3
  13723. // step 2
  13724. j = offset - 3;
  13725. for (n = len + 4; n--; j += 2) {
  13726. x[j] *= K_;
  13727. }
  13728. // step 1 & 3
  13729. j = offset - 2;
  13730. current = delta * x[j -1];
  13731. for (n = len + 3; n--; j += 2) {
  13732. next = delta * x[j + 1];
  13733. x[j] = K * x[j] - current - next;
  13734. if (n--) {
  13735. j += 2;
  13736. current = delta * x[j + 1];
  13737. x[j] = K * x[j] - current - next;
  13738. } else {
  13739. break;
  13740. }
  13741. }
  13742. // step 4
  13743. j = offset - 1;
  13744. current = gamma * x[j - 1];
  13745. for (n = len + 2; n--; j += 2) {
  13746. next = gamma * x[j + 1];
  13747. x[j] -= current + next;
  13748. if (n--) {
  13749. j += 2;
  13750. current = gamma * x[j + 1];
  13751. x[j] -= current + next;
  13752. } else {
  13753. break;
  13754. }
  13755. }
  13756. // step 5
  13757. j = offset;
  13758. current = beta * x[j - 1];
  13759. for (n = len + 1; n--; j += 2) {
  13760. next = beta * x[j + 1];
  13761. x[j] -= current + next;
  13762. if (n--) {
  13763. j += 2;
  13764. current = beta * x[j + 1];
  13765. x[j] -= current + next;
  13766. } else {
  13767. break;
  13768. }
  13769. }
  13770. // step 6
  13771. if (len !== 0) {
  13772. j = offset + 1;
  13773. current = alpha * x[j - 1];
  13774. for (n = len; n--; j += 2) {
  13775. next = alpha * x[j + 1];
  13776. x[j] -= current + next;
  13777. if (n--) {
  13778. j += 2;
  13779. current = alpha * x[j + 1];
  13780. x[j] -= current + next;
  13781. } else {
  13782. break;
  13783. }
  13784. }
  13785. }
  13786. };
  13787. return IrreversibleTransform;
  13788. })();
  13789. // Section 3.8.1 Reversible 5-3 filter
  13790. var ReversibleTransform = (function ReversibleTransformClosure() {
  13791. function ReversibleTransform() {
  13792. Transform.call(this);
  13793. }
  13794. ReversibleTransform.prototype = Object.create(Transform.prototype);
  13795. ReversibleTransform.prototype.filter =
  13796. function reversibleTransformFilter(x, offset, length) {
  13797. var len = length >> 1;
  13798. offset = offset | 0;
  13799. var j, n;
  13800. for (j = offset, n = len + 1; n--; j += 2) {
  13801. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  13802. }
  13803. for (j = offset + 1, n = len; n--; j += 2) {
  13804. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  13805. }
  13806. };
  13807. return ReversibleTransform;
  13808. })();
  13809. return JpxImage;
  13810. })();
  13811. exports.JpxImage = JpxImage;
  13812. }));
  13813. (function (root, factory) {
  13814. {
  13815. factory((root.pdfjsCoreMetrics = {}), root.pdfjsSharedUtil);
  13816. }
  13817. }(this, function (exports, sharedUtil) {
  13818. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  13819. // The Metrics object contains glyph widths (in glyph space units).
  13820. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  13821. // space unit corresponds to 1/1000th of text space unit.
  13822. var getMetrics = getLookupTableFactory(function (t) {
  13823. t['Courier'] = 600;
  13824. t['Courier-Bold'] = 600;
  13825. t['Courier-BoldOblique'] = 600;
  13826. t['Courier-Oblique'] = 600;
  13827. t['Helvetica'] = getLookupTableFactory(function (t) {
  13828. t['space'] = 278;
  13829. t['exclam'] = 278;
  13830. t['quotedbl'] = 355;
  13831. t['numbersign'] = 556;
  13832. t['dollar'] = 556;
  13833. t['percent'] = 889;
  13834. t['ampersand'] = 667;
  13835. t['quoteright'] = 222;
  13836. t['parenleft'] = 333;
  13837. t['parenright'] = 333;
  13838. t['asterisk'] = 389;
  13839. t['plus'] = 584;
  13840. t['comma'] = 278;
  13841. t['hyphen'] = 333;
  13842. t['period'] = 278;
  13843. t['slash'] = 278;
  13844. t['zero'] = 556;
  13845. t['one'] = 556;
  13846. t['two'] = 556;
  13847. t['three'] = 556;
  13848. t['four'] = 556;
  13849. t['five'] = 556;
  13850. t['six'] = 556;
  13851. t['seven'] = 556;
  13852. t['eight'] = 556;
  13853. t['nine'] = 556;
  13854. t['colon'] = 278;
  13855. t['semicolon'] = 278;
  13856. t['less'] = 584;
  13857. t['equal'] = 584;
  13858. t['greater'] = 584;
  13859. t['question'] = 556;
  13860. t['at'] = 1015;
  13861. t['A'] = 667;
  13862. t['B'] = 667;
  13863. t['C'] = 722;
  13864. t['D'] = 722;
  13865. t['E'] = 667;
  13866. t['F'] = 611;
  13867. t['G'] = 778;
  13868. t['H'] = 722;
  13869. t['I'] = 278;
  13870. t['J'] = 500;
  13871. t['K'] = 667;
  13872. t['L'] = 556;
  13873. t['M'] = 833;
  13874. t['N'] = 722;
  13875. t['O'] = 778;
  13876. t['P'] = 667;
  13877. t['Q'] = 778;
  13878. t['R'] = 722;
  13879. t['S'] = 667;
  13880. t['T'] = 611;
  13881. t['U'] = 722;
  13882. t['V'] = 667;
  13883. t['W'] = 944;
  13884. t['X'] = 667;
  13885. t['Y'] = 667;
  13886. t['Z'] = 611;
  13887. t['bracketleft'] = 278;
  13888. t['backslash'] = 278;
  13889. t['bracketright'] = 278;
  13890. t['asciicircum'] = 469;
  13891. t['underscore'] = 556;
  13892. t['quoteleft'] = 222;
  13893. t['a'] = 556;
  13894. t['b'] = 556;
  13895. t['c'] = 500;
  13896. t['d'] = 556;
  13897. t['e'] = 556;
  13898. t['f'] = 278;
  13899. t['g'] = 556;
  13900. t['h'] = 556;
  13901. t['i'] = 222;
  13902. t['j'] = 222;
  13903. t['k'] = 500;
  13904. t['l'] = 222;
  13905. t['m'] = 833;
  13906. t['n'] = 556;
  13907. t['o'] = 556;
  13908. t['p'] = 556;
  13909. t['q'] = 556;
  13910. t['r'] = 333;
  13911. t['s'] = 500;
  13912. t['t'] = 278;
  13913. t['u'] = 556;
  13914. t['v'] = 500;
  13915. t['w'] = 722;
  13916. t['x'] = 500;
  13917. t['y'] = 500;
  13918. t['z'] = 500;
  13919. t['braceleft'] = 334;
  13920. t['bar'] = 260;
  13921. t['braceright'] = 334;
  13922. t['asciitilde'] = 584;
  13923. t['exclamdown'] = 333;
  13924. t['cent'] = 556;
  13925. t['sterling'] = 556;
  13926. t['fraction'] = 167;
  13927. t['yen'] = 556;
  13928. t['florin'] = 556;
  13929. t['section'] = 556;
  13930. t['currency'] = 556;
  13931. t['quotesingle'] = 191;
  13932. t['quotedblleft'] = 333;
  13933. t['guillemotleft'] = 556;
  13934. t['guilsinglleft'] = 333;
  13935. t['guilsinglright'] = 333;
  13936. t['fi'] = 500;
  13937. t['fl'] = 500;
  13938. t['endash'] = 556;
  13939. t['dagger'] = 556;
  13940. t['daggerdbl'] = 556;
  13941. t['periodcentered'] = 278;
  13942. t['paragraph'] = 537;
  13943. t['bullet'] = 350;
  13944. t['quotesinglbase'] = 222;
  13945. t['quotedblbase'] = 333;
  13946. t['quotedblright'] = 333;
  13947. t['guillemotright'] = 556;
  13948. t['ellipsis'] = 1000;
  13949. t['perthousand'] = 1000;
  13950. t['questiondown'] = 611;
  13951. t['grave'] = 333;
  13952. t['acute'] = 333;
  13953. t['circumflex'] = 333;
  13954. t['tilde'] = 333;
  13955. t['macron'] = 333;
  13956. t['breve'] = 333;
  13957. t['dotaccent'] = 333;
  13958. t['dieresis'] = 333;
  13959. t['ring'] = 333;
  13960. t['cedilla'] = 333;
  13961. t['hungarumlaut'] = 333;
  13962. t['ogonek'] = 333;
  13963. t['caron'] = 333;
  13964. t['emdash'] = 1000;
  13965. t['AE'] = 1000;
  13966. t['ordfeminine'] = 370;
  13967. t['Lslash'] = 556;
  13968. t['Oslash'] = 778;
  13969. t['OE'] = 1000;
  13970. t['ordmasculine'] = 365;
  13971. t['ae'] = 889;
  13972. t['dotlessi'] = 278;
  13973. t['lslash'] = 222;
  13974. t['oslash'] = 611;
  13975. t['oe'] = 944;
  13976. t['germandbls'] = 611;
  13977. t['Idieresis'] = 278;
  13978. t['eacute'] = 556;
  13979. t['abreve'] = 556;
  13980. t['uhungarumlaut'] = 556;
  13981. t['ecaron'] = 556;
  13982. t['Ydieresis'] = 667;
  13983. t['divide'] = 584;
  13984. t['Yacute'] = 667;
  13985. t['Acircumflex'] = 667;
  13986. t['aacute'] = 556;
  13987. t['Ucircumflex'] = 722;
  13988. t['yacute'] = 500;
  13989. t['scommaaccent'] = 500;
  13990. t['ecircumflex'] = 556;
  13991. t['Uring'] = 722;
  13992. t['Udieresis'] = 722;
  13993. t['aogonek'] = 556;
  13994. t['Uacute'] = 722;
  13995. t['uogonek'] = 556;
  13996. t['Edieresis'] = 667;
  13997. t['Dcroat'] = 722;
  13998. t['commaaccent'] = 250;
  13999. t['copyright'] = 737;
  14000. t['Emacron'] = 667;
  14001. t['ccaron'] = 500;
  14002. t['aring'] = 556;
  14003. t['Ncommaaccent'] = 722;
  14004. t['lacute'] = 222;
  14005. t['agrave'] = 556;
  14006. t['Tcommaaccent'] = 611;
  14007. t['Cacute'] = 722;
  14008. t['atilde'] = 556;
  14009. t['Edotaccent'] = 667;
  14010. t['scaron'] = 500;
  14011. t['scedilla'] = 500;
  14012. t['iacute'] = 278;
  14013. t['lozenge'] = 471;
  14014. t['Rcaron'] = 722;
  14015. t['Gcommaaccent'] = 778;
  14016. t['ucircumflex'] = 556;
  14017. t['acircumflex'] = 556;
  14018. t['Amacron'] = 667;
  14019. t['rcaron'] = 333;
  14020. t['ccedilla'] = 500;
  14021. t['Zdotaccent'] = 611;
  14022. t['Thorn'] = 667;
  14023. t['Omacron'] = 778;
  14024. t['Racute'] = 722;
  14025. t['Sacute'] = 667;
  14026. t['dcaron'] = 643;
  14027. t['Umacron'] = 722;
  14028. t['uring'] = 556;
  14029. t['threesuperior'] = 333;
  14030. t['Ograve'] = 778;
  14031. t['Agrave'] = 667;
  14032. t['Abreve'] = 667;
  14033. t['multiply'] = 584;
  14034. t['uacute'] = 556;
  14035. t['Tcaron'] = 611;
  14036. t['partialdiff'] = 476;
  14037. t['ydieresis'] = 500;
  14038. t['Nacute'] = 722;
  14039. t['icircumflex'] = 278;
  14040. t['Ecircumflex'] = 667;
  14041. t['adieresis'] = 556;
  14042. t['edieresis'] = 556;
  14043. t['cacute'] = 500;
  14044. t['nacute'] = 556;
  14045. t['umacron'] = 556;
  14046. t['Ncaron'] = 722;
  14047. t['Iacute'] = 278;
  14048. t['plusminus'] = 584;
  14049. t['brokenbar'] = 260;
  14050. t['registered'] = 737;
  14051. t['Gbreve'] = 778;
  14052. t['Idotaccent'] = 278;
  14053. t['summation'] = 600;
  14054. t['Egrave'] = 667;
  14055. t['racute'] = 333;
  14056. t['omacron'] = 556;
  14057. t['Zacute'] = 611;
  14058. t['Zcaron'] = 611;
  14059. t['greaterequal'] = 549;
  14060. t['Eth'] = 722;
  14061. t['Ccedilla'] = 722;
  14062. t['lcommaaccent'] = 222;
  14063. t['tcaron'] = 317;
  14064. t['eogonek'] = 556;
  14065. t['Uogonek'] = 722;
  14066. t['Aacute'] = 667;
  14067. t['Adieresis'] = 667;
  14068. t['egrave'] = 556;
  14069. t['zacute'] = 500;
  14070. t['iogonek'] = 222;
  14071. t['Oacute'] = 778;
  14072. t['oacute'] = 556;
  14073. t['amacron'] = 556;
  14074. t['sacute'] = 500;
  14075. t['idieresis'] = 278;
  14076. t['Ocircumflex'] = 778;
  14077. t['Ugrave'] = 722;
  14078. t['Delta'] = 612;
  14079. t['thorn'] = 556;
  14080. t['twosuperior'] = 333;
  14081. t['Odieresis'] = 778;
  14082. t['mu'] = 556;
  14083. t['igrave'] = 278;
  14084. t['ohungarumlaut'] = 556;
  14085. t['Eogonek'] = 667;
  14086. t['dcroat'] = 556;
  14087. t['threequarters'] = 834;
  14088. t['Scedilla'] = 667;
  14089. t['lcaron'] = 299;
  14090. t['Kcommaaccent'] = 667;
  14091. t['Lacute'] = 556;
  14092. t['trademark'] = 1000;
  14093. t['edotaccent'] = 556;
  14094. t['Igrave'] = 278;
  14095. t['Imacron'] = 278;
  14096. t['Lcaron'] = 556;
  14097. t['onehalf'] = 834;
  14098. t['lessequal'] = 549;
  14099. t['ocircumflex'] = 556;
  14100. t['ntilde'] = 556;
  14101. t['Uhungarumlaut'] = 722;
  14102. t['Eacute'] = 667;
  14103. t['emacron'] = 556;
  14104. t['gbreve'] = 556;
  14105. t['onequarter'] = 834;
  14106. t['Scaron'] = 667;
  14107. t['Scommaaccent'] = 667;
  14108. t['Ohungarumlaut'] = 778;
  14109. t['degree'] = 400;
  14110. t['ograve'] = 556;
  14111. t['Ccaron'] = 722;
  14112. t['ugrave'] = 556;
  14113. t['radical'] = 453;
  14114. t['Dcaron'] = 722;
  14115. t['rcommaaccent'] = 333;
  14116. t['Ntilde'] = 722;
  14117. t['otilde'] = 556;
  14118. t['Rcommaaccent'] = 722;
  14119. t['Lcommaaccent'] = 556;
  14120. t['Atilde'] = 667;
  14121. t['Aogonek'] = 667;
  14122. t['Aring'] = 667;
  14123. t['Otilde'] = 778;
  14124. t['zdotaccent'] = 500;
  14125. t['Ecaron'] = 667;
  14126. t['Iogonek'] = 278;
  14127. t['kcommaaccent'] = 500;
  14128. t['minus'] = 584;
  14129. t['Icircumflex'] = 278;
  14130. t['ncaron'] = 556;
  14131. t['tcommaaccent'] = 278;
  14132. t['logicalnot'] = 584;
  14133. t['odieresis'] = 556;
  14134. t['udieresis'] = 556;
  14135. t['notequal'] = 549;
  14136. t['gcommaaccent'] = 556;
  14137. t['eth'] = 556;
  14138. t['zcaron'] = 500;
  14139. t['ncommaaccent'] = 556;
  14140. t['onesuperior'] = 333;
  14141. t['imacron'] = 278;
  14142. t['Euro'] = 556;
  14143. });
  14144. t['Helvetica-Bold'] = getLookupTableFactory(function (t) {
  14145. t['space'] = 278;
  14146. t['exclam'] = 333;
  14147. t['quotedbl'] = 474;
  14148. t['numbersign'] = 556;
  14149. t['dollar'] = 556;
  14150. t['percent'] = 889;
  14151. t['ampersand'] = 722;
  14152. t['quoteright'] = 278;
  14153. t['parenleft'] = 333;
  14154. t['parenright'] = 333;
  14155. t['asterisk'] = 389;
  14156. t['plus'] = 584;
  14157. t['comma'] = 278;
  14158. t['hyphen'] = 333;
  14159. t['period'] = 278;
  14160. t['slash'] = 278;
  14161. t['zero'] = 556;
  14162. t['one'] = 556;
  14163. t['two'] = 556;
  14164. t['three'] = 556;
  14165. t['four'] = 556;
  14166. t['five'] = 556;
  14167. t['six'] = 556;
  14168. t['seven'] = 556;
  14169. t['eight'] = 556;
  14170. t['nine'] = 556;
  14171. t['colon'] = 333;
  14172. t['semicolon'] = 333;
  14173. t['less'] = 584;
  14174. t['equal'] = 584;
  14175. t['greater'] = 584;
  14176. t['question'] = 611;
  14177. t['at'] = 975;
  14178. t['A'] = 722;
  14179. t['B'] = 722;
  14180. t['C'] = 722;
  14181. t['D'] = 722;
  14182. t['E'] = 667;
  14183. t['F'] = 611;
  14184. t['G'] = 778;
  14185. t['H'] = 722;
  14186. t['I'] = 278;
  14187. t['J'] = 556;
  14188. t['K'] = 722;
  14189. t['L'] = 611;
  14190. t['M'] = 833;
  14191. t['N'] = 722;
  14192. t['O'] = 778;
  14193. t['P'] = 667;
  14194. t['Q'] = 778;
  14195. t['R'] = 722;
  14196. t['S'] = 667;
  14197. t['T'] = 611;
  14198. t['U'] = 722;
  14199. t['V'] = 667;
  14200. t['W'] = 944;
  14201. t['X'] = 667;
  14202. t['Y'] = 667;
  14203. t['Z'] = 611;
  14204. t['bracketleft'] = 333;
  14205. t['backslash'] = 278;
  14206. t['bracketright'] = 333;
  14207. t['asciicircum'] = 584;
  14208. t['underscore'] = 556;
  14209. t['quoteleft'] = 278;
  14210. t['a'] = 556;
  14211. t['b'] = 611;
  14212. t['c'] = 556;
  14213. t['d'] = 611;
  14214. t['e'] = 556;
  14215. t['f'] = 333;
  14216. t['g'] = 611;
  14217. t['h'] = 611;
  14218. t['i'] = 278;
  14219. t['j'] = 278;
  14220. t['k'] = 556;
  14221. t['l'] = 278;
  14222. t['m'] = 889;
  14223. t['n'] = 611;
  14224. t['o'] = 611;
  14225. t['p'] = 611;
  14226. t['q'] = 611;
  14227. t['r'] = 389;
  14228. t['s'] = 556;
  14229. t['t'] = 333;
  14230. t['u'] = 611;
  14231. t['v'] = 556;
  14232. t['w'] = 778;
  14233. t['x'] = 556;
  14234. t['y'] = 556;
  14235. t['z'] = 500;
  14236. t['braceleft'] = 389;
  14237. t['bar'] = 280;
  14238. t['braceright'] = 389;
  14239. t['asciitilde'] = 584;
  14240. t['exclamdown'] = 333;
  14241. t['cent'] = 556;
  14242. t['sterling'] = 556;
  14243. t['fraction'] = 167;
  14244. t['yen'] = 556;
  14245. t['florin'] = 556;
  14246. t['section'] = 556;
  14247. t['currency'] = 556;
  14248. t['quotesingle'] = 238;
  14249. t['quotedblleft'] = 500;
  14250. t['guillemotleft'] = 556;
  14251. t['guilsinglleft'] = 333;
  14252. t['guilsinglright'] = 333;
  14253. t['fi'] = 611;
  14254. t['fl'] = 611;
  14255. t['endash'] = 556;
  14256. t['dagger'] = 556;
  14257. t['daggerdbl'] = 556;
  14258. t['periodcentered'] = 278;
  14259. t['paragraph'] = 556;
  14260. t['bullet'] = 350;
  14261. t['quotesinglbase'] = 278;
  14262. t['quotedblbase'] = 500;
  14263. t['quotedblright'] = 500;
  14264. t['guillemotright'] = 556;
  14265. t['ellipsis'] = 1000;
  14266. t['perthousand'] = 1000;
  14267. t['questiondown'] = 611;
  14268. t['grave'] = 333;
  14269. t['acute'] = 333;
  14270. t['circumflex'] = 333;
  14271. t['tilde'] = 333;
  14272. t['macron'] = 333;
  14273. t['breve'] = 333;
  14274. t['dotaccent'] = 333;
  14275. t['dieresis'] = 333;
  14276. t['ring'] = 333;
  14277. t['cedilla'] = 333;
  14278. t['hungarumlaut'] = 333;
  14279. t['ogonek'] = 333;
  14280. t['caron'] = 333;
  14281. t['emdash'] = 1000;
  14282. t['AE'] = 1000;
  14283. t['ordfeminine'] = 370;
  14284. t['Lslash'] = 611;
  14285. t['Oslash'] = 778;
  14286. t['OE'] = 1000;
  14287. t['ordmasculine'] = 365;
  14288. t['ae'] = 889;
  14289. t['dotlessi'] = 278;
  14290. t['lslash'] = 278;
  14291. t['oslash'] = 611;
  14292. t['oe'] = 944;
  14293. t['germandbls'] = 611;
  14294. t['Idieresis'] = 278;
  14295. t['eacute'] = 556;
  14296. t['abreve'] = 556;
  14297. t['uhungarumlaut'] = 611;
  14298. t['ecaron'] = 556;
  14299. t['Ydieresis'] = 667;
  14300. t['divide'] = 584;
  14301. t['Yacute'] = 667;
  14302. t['Acircumflex'] = 722;
  14303. t['aacute'] = 556;
  14304. t['Ucircumflex'] = 722;
  14305. t['yacute'] = 556;
  14306. t['scommaaccent'] = 556;
  14307. t['ecircumflex'] = 556;
  14308. t['Uring'] = 722;
  14309. t['Udieresis'] = 722;
  14310. t['aogonek'] = 556;
  14311. t['Uacute'] = 722;
  14312. t['uogonek'] = 611;
  14313. t['Edieresis'] = 667;
  14314. t['Dcroat'] = 722;
  14315. t['commaaccent'] = 250;
  14316. t['copyright'] = 737;
  14317. t['Emacron'] = 667;
  14318. t['ccaron'] = 556;
  14319. t['aring'] = 556;
  14320. t['Ncommaaccent'] = 722;
  14321. t['lacute'] = 278;
  14322. t['agrave'] = 556;
  14323. t['Tcommaaccent'] = 611;
  14324. t['Cacute'] = 722;
  14325. t['atilde'] = 556;
  14326. t['Edotaccent'] = 667;
  14327. t['scaron'] = 556;
  14328. t['scedilla'] = 556;
  14329. t['iacute'] = 278;
  14330. t['lozenge'] = 494;
  14331. t['Rcaron'] = 722;
  14332. t['Gcommaaccent'] = 778;
  14333. t['ucircumflex'] = 611;
  14334. t['acircumflex'] = 556;
  14335. t['Amacron'] = 722;
  14336. t['rcaron'] = 389;
  14337. t['ccedilla'] = 556;
  14338. t['Zdotaccent'] = 611;
  14339. t['Thorn'] = 667;
  14340. t['Omacron'] = 778;
  14341. t['Racute'] = 722;
  14342. t['Sacute'] = 667;
  14343. t['dcaron'] = 743;
  14344. t['Umacron'] = 722;
  14345. t['uring'] = 611;
  14346. t['threesuperior'] = 333;
  14347. t['Ograve'] = 778;
  14348. t['Agrave'] = 722;
  14349. t['Abreve'] = 722;
  14350. t['multiply'] = 584;
  14351. t['uacute'] = 611;
  14352. t['Tcaron'] = 611;
  14353. t['partialdiff'] = 494;
  14354. t['ydieresis'] = 556;
  14355. t['Nacute'] = 722;
  14356. t['icircumflex'] = 278;
  14357. t['Ecircumflex'] = 667;
  14358. t['adieresis'] = 556;
  14359. t['edieresis'] = 556;
  14360. t['cacute'] = 556;
  14361. t['nacute'] = 611;
  14362. t['umacron'] = 611;
  14363. t['Ncaron'] = 722;
  14364. t['Iacute'] = 278;
  14365. t['plusminus'] = 584;
  14366. t['brokenbar'] = 280;
  14367. t['registered'] = 737;
  14368. t['Gbreve'] = 778;
  14369. t['Idotaccent'] = 278;
  14370. t['summation'] = 600;
  14371. t['Egrave'] = 667;
  14372. t['racute'] = 389;
  14373. t['omacron'] = 611;
  14374. t['Zacute'] = 611;
  14375. t['Zcaron'] = 611;
  14376. t['greaterequal'] = 549;
  14377. t['Eth'] = 722;
  14378. t['Ccedilla'] = 722;
  14379. t['lcommaaccent'] = 278;
  14380. t['tcaron'] = 389;
  14381. t['eogonek'] = 556;
  14382. t['Uogonek'] = 722;
  14383. t['Aacute'] = 722;
  14384. t['Adieresis'] = 722;
  14385. t['egrave'] = 556;
  14386. t['zacute'] = 500;
  14387. t['iogonek'] = 278;
  14388. t['Oacute'] = 778;
  14389. t['oacute'] = 611;
  14390. t['amacron'] = 556;
  14391. t['sacute'] = 556;
  14392. t['idieresis'] = 278;
  14393. t['Ocircumflex'] = 778;
  14394. t['Ugrave'] = 722;
  14395. t['Delta'] = 612;
  14396. t['thorn'] = 611;
  14397. t['twosuperior'] = 333;
  14398. t['Odieresis'] = 778;
  14399. t['mu'] = 611;
  14400. t['igrave'] = 278;
  14401. t['ohungarumlaut'] = 611;
  14402. t['Eogonek'] = 667;
  14403. t['dcroat'] = 611;
  14404. t['threequarters'] = 834;
  14405. t['Scedilla'] = 667;
  14406. t['lcaron'] = 400;
  14407. t['Kcommaaccent'] = 722;
  14408. t['Lacute'] = 611;
  14409. t['trademark'] = 1000;
  14410. t['edotaccent'] = 556;
  14411. t['Igrave'] = 278;
  14412. t['Imacron'] = 278;
  14413. t['Lcaron'] = 611;
  14414. t['onehalf'] = 834;
  14415. t['lessequal'] = 549;
  14416. t['ocircumflex'] = 611;
  14417. t['ntilde'] = 611;
  14418. t['Uhungarumlaut'] = 722;
  14419. t['Eacute'] = 667;
  14420. t['emacron'] = 556;
  14421. t['gbreve'] = 611;
  14422. t['onequarter'] = 834;
  14423. t['Scaron'] = 667;
  14424. t['Scommaaccent'] = 667;
  14425. t['Ohungarumlaut'] = 778;
  14426. t['degree'] = 400;
  14427. t['ograve'] = 611;
  14428. t['Ccaron'] = 722;
  14429. t['ugrave'] = 611;
  14430. t['radical'] = 549;
  14431. t['Dcaron'] = 722;
  14432. t['rcommaaccent'] = 389;
  14433. t['Ntilde'] = 722;
  14434. t['otilde'] = 611;
  14435. t['Rcommaaccent'] = 722;
  14436. t['Lcommaaccent'] = 611;
  14437. t['Atilde'] = 722;
  14438. t['Aogonek'] = 722;
  14439. t['Aring'] = 722;
  14440. t['Otilde'] = 778;
  14441. t['zdotaccent'] = 500;
  14442. t['Ecaron'] = 667;
  14443. t['Iogonek'] = 278;
  14444. t['kcommaaccent'] = 556;
  14445. t['minus'] = 584;
  14446. t['Icircumflex'] = 278;
  14447. t['ncaron'] = 611;
  14448. t['tcommaaccent'] = 333;
  14449. t['logicalnot'] = 584;
  14450. t['odieresis'] = 611;
  14451. t['udieresis'] = 611;
  14452. t['notequal'] = 549;
  14453. t['gcommaaccent'] = 611;
  14454. t['eth'] = 611;
  14455. t['zcaron'] = 500;
  14456. t['ncommaaccent'] = 611;
  14457. t['onesuperior'] = 333;
  14458. t['imacron'] = 278;
  14459. t['Euro'] = 556;
  14460. });
  14461. t['Helvetica-BoldOblique'] = getLookupTableFactory(function (t) {
  14462. t['space'] = 278;
  14463. t['exclam'] = 333;
  14464. t['quotedbl'] = 474;
  14465. t['numbersign'] = 556;
  14466. t['dollar'] = 556;
  14467. t['percent'] = 889;
  14468. t['ampersand'] = 722;
  14469. t['quoteright'] = 278;
  14470. t['parenleft'] = 333;
  14471. t['parenright'] = 333;
  14472. t['asterisk'] = 389;
  14473. t['plus'] = 584;
  14474. t['comma'] = 278;
  14475. t['hyphen'] = 333;
  14476. t['period'] = 278;
  14477. t['slash'] = 278;
  14478. t['zero'] = 556;
  14479. t['one'] = 556;
  14480. t['two'] = 556;
  14481. t['three'] = 556;
  14482. t['four'] = 556;
  14483. t['five'] = 556;
  14484. t['six'] = 556;
  14485. t['seven'] = 556;
  14486. t['eight'] = 556;
  14487. t['nine'] = 556;
  14488. t['colon'] = 333;
  14489. t['semicolon'] = 333;
  14490. t['less'] = 584;
  14491. t['equal'] = 584;
  14492. t['greater'] = 584;
  14493. t['question'] = 611;
  14494. t['at'] = 975;
  14495. t['A'] = 722;
  14496. t['B'] = 722;
  14497. t['C'] = 722;
  14498. t['D'] = 722;
  14499. t['E'] = 667;
  14500. t['F'] = 611;
  14501. t['G'] = 778;
  14502. t['H'] = 722;
  14503. t['I'] = 278;
  14504. t['J'] = 556;
  14505. t['K'] = 722;
  14506. t['L'] = 611;
  14507. t['M'] = 833;
  14508. t['N'] = 722;
  14509. t['O'] = 778;
  14510. t['P'] = 667;
  14511. t['Q'] = 778;
  14512. t['R'] = 722;
  14513. t['S'] = 667;
  14514. t['T'] = 611;
  14515. t['U'] = 722;
  14516. t['V'] = 667;
  14517. t['W'] = 944;
  14518. t['X'] = 667;
  14519. t['Y'] = 667;
  14520. t['Z'] = 611;
  14521. t['bracketleft'] = 333;
  14522. t['backslash'] = 278;
  14523. t['bracketright'] = 333;
  14524. t['asciicircum'] = 584;
  14525. t['underscore'] = 556;
  14526. t['quoteleft'] = 278;
  14527. t['a'] = 556;
  14528. t['b'] = 611;
  14529. t['c'] = 556;
  14530. t['d'] = 611;
  14531. t['e'] = 556;
  14532. t['f'] = 333;
  14533. t['g'] = 611;
  14534. t['h'] = 611;
  14535. t['i'] = 278;
  14536. t['j'] = 278;
  14537. t['k'] = 556;
  14538. t['l'] = 278;
  14539. t['m'] = 889;
  14540. t['n'] = 611;
  14541. t['o'] = 611;
  14542. t['p'] = 611;
  14543. t['q'] = 611;
  14544. t['r'] = 389;
  14545. t['s'] = 556;
  14546. t['t'] = 333;
  14547. t['u'] = 611;
  14548. t['v'] = 556;
  14549. t['w'] = 778;
  14550. t['x'] = 556;
  14551. t['y'] = 556;
  14552. t['z'] = 500;
  14553. t['braceleft'] = 389;
  14554. t['bar'] = 280;
  14555. t['braceright'] = 389;
  14556. t['asciitilde'] = 584;
  14557. t['exclamdown'] = 333;
  14558. t['cent'] = 556;
  14559. t['sterling'] = 556;
  14560. t['fraction'] = 167;
  14561. t['yen'] = 556;
  14562. t['florin'] = 556;
  14563. t['section'] = 556;
  14564. t['currency'] = 556;
  14565. t['quotesingle'] = 238;
  14566. t['quotedblleft'] = 500;
  14567. t['guillemotleft'] = 556;
  14568. t['guilsinglleft'] = 333;
  14569. t['guilsinglright'] = 333;
  14570. t['fi'] = 611;
  14571. t['fl'] = 611;
  14572. t['endash'] = 556;
  14573. t['dagger'] = 556;
  14574. t['daggerdbl'] = 556;
  14575. t['periodcentered'] = 278;
  14576. t['paragraph'] = 556;
  14577. t['bullet'] = 350;
  14578. t['quotesinglbase'] = 278;
  14579. t['quotedblbase'] = 500;
  14580. t['quotedblright'] = 500;
  14581. t['guillemotright'] = 556;
  14582. t['ellipsis'] = 1000;
  14583. t['perthousand'] = 1000;
  14584. t['questiondown'] = 611;
  14585. t['grave'] = 333;
  14586. t['acute'] = 333;
  14587. t['circumflex'] = 333;
  14588. t['tilde'] = 333;
  14589. t['macron'] = 333;
  14590. t['breve'] = 333;
  14591. t['dotaccent'] = 333;
  14592. t['dieresis'] = 333;
  14593. t['ring'] = 333;
  14594. t['cedilla'] = 333;
  14595. t['hungarumlaut'] = 333;
  14596. t['ogonek'] = 333;
  14597. t['caron'] = 333;
  14598. t['emdash'] = 1000;
  14599. t['AE'] = 1000;
  14600. t['ordfeminine'] = 370;
  14601. t['Lslash'] = 611;
  14602. t['Oslash'] = 778;
  14603. t['OE'] = 1000;
  14604. t['ordmasculine'] = 365;
  14605. t['ae'] = 889;
  14606. t['dotlessi'] = 278;
  14607. t['lslash'] = 278;
  14608. t['oslash'] = 611;
  14609. t['oe'] = 944;
  14610. t['germandbls'] = 611;
  14611. t['Idieresis'] = 278;
  14612. t['eacute'] = 556;
  14613. t['abreve'] = 556;
  14614. t['uhungarumlaut'] = 611;
  14615. t['ecaron'] = 556;
  14616. t['Ydieresis'] = 667;
  14617. t['divide'] = 584;
  14618. t['Yacute'] = 667;
  14619. t['Acircumflex'] = 722;
  14620. t['aacute'] = 556;
  14621. t['Ucircumflex'] = 722;
  14622. t['yacute'] = 556;
  14623. t['scommaaccent'] = 556;
  14624. t['ecircumflex'] = 556;
  14625. t['Uring'] = 722;
  14626. t['Udieresis'] = 722;
  14627. t['aogonek'] = 556;
  14628. t['Uacute'] = 722;
  14629. t['uogonek'] = 611;
  14630. t['Edieresis'] = 667;
  14631. t['Dcroat'] = 722;
  14632. t['commaaccent'] = 250;
  14633. t['copyright'] = 737;
  14634. t['Emacron'] = 667;
  14635. t['ccaron'] = 556;
  14636. t['aring'] = 556;
  14637. t['Ncommaaccent'] = 722;
  14638. t['lacute'] = 278;
  14639. t['agrave'] = 556;
  14640. t['Tcommaaccent'] = 611;
  14641. t['Cacute'] = 722;
  14642. t['atilde'] = 556;
  14643. t['Edotaccent'] = 667;
  14644. t['scaron'] = 556;
  14645. t['scedilla'] = 556;
  14646. t['iacute'] = 278;
  14647. t['lozenge'] = 494;
  14648. t['Rcaron'] = 722;
  14649. t['Gcommaaccent'] = 778;
  14650. t['ucircumflex'] = 611;
  14651. t['acircumflex'] = 556;
  14652. t['Amacron'] = 722;
  14653. t['rcaron'] = 389;
  14654. t['ccedilla'] = 556;
  14655. t['Zdotaccent'] = 611;
  14656. t['Thorn'] = 667;
  14657. t['Omacron'] = 778;
  14658. t['Racute'] = 722;
  14659. t['Sacute'] = 667;
  14660. t['dcaron'] = 743;
  14661. t['Umacron'] = 722;
  14662. t['uring'] = 611;
  14663. t['threesuperior'] = 333;
  14664. t['Ograve'] = 778;
  14665. t['Agrave'] = 722;
  14666. t['Abreve'] = 722;
  14667. t['multiply'] = 584;
  14668. t['uacute'] = 611;
  14669. t['Tcaron'] = 611;
  14670. t['partialdiff'] = 494;
  14671. t['ydieresis'] = 556;
  14672. t['Nacute'] = 722;
  14673. t['icircumflex'] = 278;
  14674. t['Ecircumflex'] = 667;
  14675. t['adieresis'] = 556;
  14676. t['edieresis'] = 556;
  14677. t['cacute'] = 556;
  14678. t['nacute'] = 611;
  14679. t['umacron'] = 611;
  14680. t['Ncaron'] = 722;
  14681. t['Iacute'] = 278;
  14682. t['plusminus'] = 584;
  14683. t['brokenbar'] = 280;
  14684. t['registered'] = 737;
  14685. t['Gbreve'] = 778;
  14686. t['Idotaccent'] = 278;
  14687. t['summation'] = 600;
  14688. t['Egrave'] = 667;
  14689. t['racute'] = 389;
  14690. t['omacron'] = 611;
  14691. t['Zacute'] = 611;
  14692. t['Zcaron'] = 611;
  14693. t['greaterequal'] = 549;
  14694. t['Eth'] = 722;
  14695. t['Ccedilla'] = 722;
  14696. t['lcommaaccent'] = 278;
  14697. t['tcaron'] = 389;
  14698. t['eogonek'] = 556;
  14699. t['Uogonek'] = 722;
  14700. t['Aacute'] = 722;
  14701. t['Adieresis'] = 722;
  14702. t['egrave'] = 556;
  14703. t['zacute'] = 500;
  14704. t['iogonek'] = 278;
  14705. t['Oacute'] = 778;
  14706. t['oacute'] = 611;
  14707. t['amacron'] = 556;
  14708. t['sacute'] = 556;
  14709. t['idieresis'] = 278;
  14710. t['Ocircumflex'] = 778;
  14711. t['Ugrave'] = 722;
  14712. t['Delta'] = 612;
  14713. t['thorn'] = 611;
  14714. t['twosuperior'] = 333;
  14715. t['Odieresis'] = 778;
  14716. t['mu'] = 611;
  14717. t['igrave'] = 278;
  14718. t['ohungarumlaut'] = 611;
  14719. t['Eogonek'] = 667;
  14720. t['dcroat'] = 611;
  14721. t['threequarters'] = 834;
  14722. t['Scedilla'] = 667;
  14723. t['lcaron'] = 400;
  14724. t['Kcommaaccent'] = 722;
  14725. t['Lacute'] = 611;
  14726. t['trademark'] = 1000;
  14727. t['edotaccent'] = 556;
  14728. t['Igrave'] = 278;
  14729. t['Imacron'] = 278;
  14730. t['Lcaron'] = 611;
  14731. t['onehalf'] = 834;
  14732. t['lessequal'] = 549;
  14733. t['ocircumflex'] = 611;
  14734. t['ntilde'] = 611;
  14735. t['Uhungarumlaut'] = 722;
  14736. t['Eacute'] = 667;
  14737. t['emacron'] = 556;
  14738. t['gbreve'] = 611;
  14739. t['onequarter'] = 834;
  14740. t['Scaron'] = 667;
  14741. t['Scommaaccent'] = 667;
  14742. t['Ohungarumlaut'] = 778;
  14743. t['degree'] = 400;
  14744. t['ograve'] = 611;
  14745. t['Ccaron'] = 722;
  14746. t['ugrave'] = 611;
  14747. t['radical'] = 549;
  14748. t['Dcaron'] = 722;
  14749. t['rcommaaccent'] = 389;
  14750. t['Ntilde'] = 722;
  14751. t['otilde'] = 611;
  14752. t['Rcommaaccent'] = 722;
  14753. t['Lcommaaccent'] = 611;
  14754. t['Atilde'] = 722;
  14755. t['Aogonek'] = 722;
  14756. t['Aring'] = 722;
  14757. t['Otilde'] = 778;
  14758. t['zdotaccent'] = 500;
  14759. t['Ecaron'] = 667;
  14760. t['Iogonek'] = 278;
  14761. t['kcommaaccent'] = 556;
  14762. t['minus'] = 584;
  14763. t['Icircumflex'] = 278;
  14764. t['ncaron'] = 611;
  14765. t['tcommaaccent'] = 333;
  14766. t['logicalnot'] = 584;
  14767. t['odieresis'] = 611;
  14768. t['udieresis'] = 611;
  14769. t['notequal'] = 549;
  14770. t['gcommaaccent'] = 611;
  14771. t['eth'] = 611;
  14772. t['zcaron'] = 500;
  14773. t['ncommaaccent'] = 611;
  14774. t['onesuperior'] = 333;
  14775. t['imacron'] = 278;
  14776. t['Euro'] = 556;
  14777. });
  14778. t['Helvetica-Oblique'] = getLookupTableFactory(function (t) {
  14779. t['space'] = 278;
  14780. t['exclam'] = 278;
  14781. t['quotedbl'] = 355;
  14782. t['numbersign'] = 556;
  14783. t['dollar'] = 556;
  14784. t['percent'] = 889;
  14785. t['ampersand'] = 667;
  14786. t['quoteright'] = 222;
  14787. t['parenleft'] = 333;
  14788. t['parenright'] = 333;
  14789. t['asterisk'] = 389;
  14790. t['plus'] = 584;
  14791. t['comma'] = 278;
  14792. t['hyphen'] = 333;
  14793. t['period'] = 278;
  14794. t['slash'] = 278;
  14795. t['zero'] = 556;
  14796. t['one'] = 556;
  14797. t['two'] = 556;
  14798. t['three'] = 556;
  14799. t['four'] = 556;
  14800. t['five'] = 556;
  14801. t['six'] = 556;
  14802. t['seven'] = 556;
  14803. t['eight'] = 556;
  14804. t['nine'] = 556;
  14805. t['colon'] = 278;
  14806. t['semicolon'] = 278;
  14807. t['less'] = 584;
  14808. t['equal'] = 584;
  14809. t['greater'] = 584;
  14810. t['question'] = 556;
  14811. t['at'] = 1015;
  14812. t['A'] = 667;
  14813. t['B'] = 667;
  14814. t['C'] = 722;
  14815. t['D'] = 722;
  14816. t['E'] = 667;
  14817. t['F'] = 611;
  14818. t['G'] = 778;
  14819. t['H'] = 722;
  14820. t['I'] = 278;
  14821. t['J'] = 500;
  14822. t['K'] = 667;
  14823. t['L'] = 556;
  14824. t['M'] = 833;
  14825. t['N'] = 722;
  14826. t['O'] = 778;
  14827. t['P'] = 667;
  14828. t['Q'] = 778;
  14829. t['R'] = 722;
  14830. t['S'] = 667;
  14831. t['T'] = 611;
  14832. t['U'] = 722;
  14833. t['V'] = 667;
  14834. t['W'] = 944;
  14835. t['X'] = 667;
  14836. t['Y'] = 667;
  14837. t['Z'] = 611;
  14838. t['bracketleft'] = 278;
  14839. t['backslash'] = 278;
  14840. t['bracketright'] = 278;
  14841. t['asciicircum'] = 469;
  14842. t['underscore'] = 556;
  14843. t['quoteleft'] = 222;
  14844. t['a'] = 556;
  14845. t['b'] = 556;
  14846. t['c'] = 500;
  14847. t['d'] = 556;
  14848. t['e'] = 556;
  14849. t['f'] = 278;
  14850. t['g'] = 556;
  14851. t['h'] = 556;
  14852. t['i'] = 222;
  14853. t['j'] = 222;
  14854. t['k'] = 500;
  14855. t['l'] = 222;
  14856. t['m'] = 833;
  14857. t['n'] = 556;
  14858. t['o'] = 556;
  14859. t['p'] = 556;
  14860. t['q'] = 556;
  14861. t['r'] = 333;
  14862. t['s'] = 500;
  14863. t['t'] = 278;
  14864. t['u'] = 556;
  14865. t['v'] = 500;
  14866. t['w'] = 722;
  14867. t['x'] = 500;
  14868. t['y'] = 500;
  14869. t['z'] = 500;
  14870. t['braceleft'] = 334;
  14871. t['bar'] = 260;
  14872. t['braceright'] = 334;
  14873. t['asciitilde'] = 584;
  14874. t['exclamdown'] = 333;
  14875. t['cent'] = 556;
  14876. t['sterling'] = 556;
  14877. t['fraction'] = 167;
  14878. t['yen'] = 556;
  14879. t['florin'] = 556;
  14880. t['section'] = 556;
  14881. t['currency'] = 556;
  14882. t['quotesingle'] = 191;
  14883. t['quotedblleft'] = 333;
  14884. t['guillemotleft'] = 556;
  14885. t['guilsinglleft'] = 333;
  14886. t['guilsinglright'] = 333;
  14887. t['fi'] = 500;
  14888. t['fl'] = 500;
  14889. t['endash'] = 556;
  14890. t['dagger'] = 556;
  14891. t['daggerdbl'] = 556;
  14892. t['periodcentered'] = 278;
  14893. t['paragraph'] = 537;
  14894. t['bullet'] = 350;
  14895. t['quotesinglbase'] = 222;
  14896. t['quotedblbase'] = 333;
  14897. t['quotedblright'] = 333;
  14898. t['guillemotright'] = 556;
  14899. t['ellipsis'] = 1000;
  14900. t['perthousand'] = 1000;
  14901. t['questiondown'] = 611;
  14902. t['grave'] = 333;
  14903. t['acute'] = 333;
  14904. t['circumflex'] = 333;
  14905. t['tilde'] = 333;
  14906. t['macron'] = 333;
  14907. t['breve'] = 333;
  14908. t['dotaccent'] = 333;
  14909. t['dieresis'] = 333;
  14910. t['ring'] = 333;
  14911. t['cedilla'] = 333;
  14912. t['hungarumlaut'] = 333;
  14913. t['ogonek'] = 333;
  14914. t['caron'] = 333;
  14915. t['emdash'] = 1000;
  14916. t['AE'] = 1000;
  14917. t['ordfeminine'] = 370;
  14918. t['Lslash'] = 556;
  14919. t['Oslash'] = 778;
  14920. t['OE'] = 1000;
  14921. t['ordmasculine'] = 365;
  14922. t['ae'] = 889;
  14923. t['dotlessi'] = 278;
  14924. t['lslash'] = 222;
  14925. t['oslash'] = 611;
  14926. t['oe'] = 944;
  14927. t['germandbls'] = 611;
  14928. t['Idieresis'] = 278;
  14929. t['eacute'] = 556;
  14930. t['abreve'] = 556;
  14931. t['uhungarumlaut'] = 556;
  14932. t['ecaron'] = 556;
  14933. t['Ydieresis'] = 667;
  14934. t['divide'] = 584;
  14935. t['Yacute'] = 667;
  14936. t['Acircumflex'] = 667;
  14937. t['aacute'] = 556;
  14938. t['Ucircumflex'] = 722;
  14939. t['yacute'] = 500;
  14940. t['scommaaccent'] = 500;
  14941. t['ecircumflex'] = 556;
  14942. t['Uring'] = 722;
  14943. t['Udieresis'] = 722;
  14944. t['aogonek'] = 556;
  14945. t['Uacute'] = 722;
  14946. t['uogonek'] = 556;
  14947. t['Edieresis'] = 667;
  14948. t['Dcroat'] = 722;
  14949. t['commaaccent'] = 250;
  14950. t['copyright'] = 737;
  14951. t['Emacron'] = 667;
  14952. t['ccaron'] = 500;
  14953. t['aring'] = 556;
  14954. t['Ncommaaccent'] = 722;
  14955. t['lacute'] = 222;
  14956. t['agrave'] = 556;
  14957. t['Tcommaaccent'] = 611;
  14958. t['Cacute'] = 722;
  14959. t['atilde'] = 556;
  14960. t['Edotaccent'] = 667;
  14961. t['scaron'] = 500;
  14962. t['scedilla'] = 500;
  14963. t['iacute'] = 278;
  14964. t['lozenge'] = 471;
  14965. t['Rcaron'] = 722;
  14966. t['Gcommaaccent'] = 778;
  14967. t['ucircumflex'] = 556;
  14968. t['acircumflex'] = 556;
  14969. t['Amacron'] = 667;
  14970. t['rcaron'] = 333;
  14971. t['ccedilla'] = 500;
  14972. t['Zdotaccent'] = 611;
  14973. t['Thorn'] = 667;
  14974. t['Omacron'] = 778;
  14975. t['Racute'] = 722;
  14976. t['Sacute'] = 667;
  14977. t['dcaron'] = 643;
  14978. t['Umacron'] = 722;
  14979. t['uring'] = 556;
  14980. t['threesuperior'] = 333;
  14981. t['Ograve'] = 778;
  14982. t['Agrave'] = 667;
  14983. t['Abreve'] = 667;
  14984. t['multiply'] = 584;
  14985. t['uacute'] = 556;
  14986. t['Tcaron'] = 611;
  14987. t['partialdiff'] = 476;
  14988. t['ydieresis'] = 500;
  14989. t['Nacute'] = 722;
  14990. t['icircumflex'] = 278;
  14991. t['Ecircumflex'] = 667;
  14992. t['adieresis'] = 556;
  14993. t['edieresis'] = 556;
  14994. t['cacute'] = 500;
  14995. t['nacute'] = 556;
  14996. t['umacron'] = 556;
  14997. t['Ncaron'] = 722;
  14998. t['Iacute'] = 278;
  14999. t['plusminus'] = 584;
  15000. t['brokenbar'] = 260;
  15001. t['registered'] = 737;
  15002. t['Gbreve'] = 778;
  15003. t['Idotaccent'] = 278;
  15004. t['summation'] = 600;
  15005. t['Egrave'] = 667;
  15006. t['racute'] = 333;
  15007. t['omacron'] = 556;
  15008. t['Zacute'] = 611;
  15009. t['Zcaron'] = 611;
  15010. t['greaterequal'] = 549;
  15011. t['Eth'] = 722;
  15012. t['Ccedilla'] = 722;
  15013. t['lcommaaccent'] = 222;
  15014. t['tcaron'] = 317;
  15015. t['eogonek'] = 556;
  15016. t['Uogonek'] = 722;
  15017. t['Aacute'] = 667;
  15018. t['Adieresis'] = 667;
  15019. t['egrave'] = 556;
  15020. t['zacute'] = 500;
  15021. t['iogonek'] = 222;
  15022. t['Oacute'] = 778;
  15023. t['oacute'] = 556;
  15024. t['amacron'] = 556;
  15025. t['sacute'] = 500;
  15026. t['idieresis'] = 278;
  15027. t['Ocircumflex'] = 778;
  15028. t['Ugrave'] = 722;
  15029. t['Delta'] = 612;
  15030. t['thorn'] = 556;
  15031. t['twosuperior'] = 333;
  15032. t['Odieresis'] = 778;
  15033. t['mu'] = 556;
  15034. t['igrave'] = 278;
  15035. t['ohungarumlaut'] = 556;
  15036. t['Eogonek'] = 667;
  15037. t['dcroat'] = 556;
  15038. t['threequarters'] = 834;
  15039. t['Scedilla'] = 667;
  15040. t['lcaron'] = 299;
  15041. t['Kcommaaccent'] = 667;
  15042. t['Lacute'] = 556;
  15043. t['trademark'] = 1000;
  15044. t['edotaccent'] = 556;
  15045. t['Igrave'] = 278;
  15046. t['Imacron'] = 278;
  15047. t['Lcaron'] = 556;
  15048. t['onehalf'] = 834;
  15049. t['lessequal'] = 549;
  15050. t['ocircumflex'] = 556;
  15051. t['ntilde'] = 556;
  15052. t['Uhungarumlaut'] = 722;
  15053. t['Eacute'] = 667;
  15054. t['emacron'] = 556;
  15055. t['gbreve'] = 556;
  15056. t['onequarter'] = 834;
  15057. t['Scaron'] = 667;
  15058. t['Scommaaccent'] = 667;
  15059. t['Ohungarumlaut'] = 778;
  15060. t['degree'] = 400;
  15061. t['ograve'] = 556;
  15062. t['Ccaron'] = 722;
  15063. t['ugrave'] = 556;
  15064. t['radical'] = 453;
  15065. t['Dcaron'] = 722;
  15066. t['rcommaaccent'] = 333;
  15067. t['Ntilde'] = 722;
  15068. t['otilde'] = 556;
  15069. t['Rcommaaccent'] = 722;
  15070. t['Lcommaaccent'] = 556;
  15071. t['Atilde'] = 667;
  15072. t['Aogonek'] = 667;
  15073. t['Aring'] = 667;
  15074. t['Otilde'] = 778;
  15075. t['zdotaccent'] = 500;
  15076. t['Ecaron'] = 667;
  15077. t['Iogonek'] = 278;
  15078. t['kcommaaccent'] = 500;
  15079. t['minus'] = 584;
  15080. t['Icircumflex'] = 278;
  15081. t['ncaron'] = 556;
  15082. t['tcommaaccent'] = 278;
  15083. t['logicalnot'] = 584;
  15084. t['odieresis'] = 556;
  15085. t['udieresis'] = 556;
  15086. t['notequal'] = 549;
  15087. t['gcommaaccent'] = 556;
  15088. t['eth'] = 556;
  15089. t['zcaron'] = 500;
  15090. t['ncommaaccent'] = 556;
  15091. t['onesuperior'] = 333;
  15092. t['imacron'] = 278;
  15093. t['Euro'] = 556;
  15094. });
  15095. t['Symbol'] = getLookupTableFactory(function (t) {
  15096. t['space'] = 250;
  15097. t['exclam'] = 333;
  15098. t['universal'] = 713;
  15099. t['numbersign'] = 500;
  15100. t['existential'] = 549;
  15101. t['percent'] = 833;
  15102. t['ampersand'] = 778;
  15103. t['suchthat'] = 439;
  15104. t['parenleft'] = 333;
  15105. t['parenright'] = 333;
  15106. t['asteriskmath'] = 500;
  15107. t['plus'] = 549;
  15108. t['comma'] = 250;
  15109. t['minus'] = 549;
  15110. t['period'] = 250;
  15111. t['slash'] = 278;
  15112. t['zero'] = 500;
  15113. t['one'] = 500;
  15114. t['two'] = 500;
  15115. t['three'] = 500;
  15116. t['four'] = 500;
  15117. t['five'] = 500;
  15118. t['six'] = 500;
  15119. t['seven'] = 500;
  15120. t['eight'] = 500;
  15121. t['nine'] = 500;
  15122. t['colon'] = 278;
  15123. t['semicolon'] = 278;
  15124. t['less'] = 549;
  15125. t['equal'] = 549;
  15126. t['greater'] = 549;
  15127. t['question'] = 444;
  15128. t['congruent'] = 549;
  15129. t['Alpha'] = 722;
  15130. t['Beta'] = 667;
  15131. t['Chi'] = 722;
  15132. t['Delta'] = 612;
  15133. t['Epsilon'] = 611;
  15134. t['Phi'] = 763;
  15135. t['Gamma'] = 603;
  15136. t['Eta'] = 722;
  15137. t['Iota'] = 333;
  15138. t['theta1'] = 631;
  15139. t['Kappa'] = 722;
  15140. t['Lambda'] = 686;
  15141. t['Mu'] = 889;
  15142. t['Nu'] = 722;
  15143. t['Omicron'] = 722;
  15144. t['Pi'] = 768;
  15145. t['Theta'] = 741;
  15146. t['Rho'] = 556;
  15147. t['Sigma'] = 592;
  15148. t['Tau'] = 611;
  15149. t['Upsilon'] = 690;
  15150. t['sigma1'] = 439;
  15151. t['Omega'] = 768;
  15152. t['Xi'] = 645;
  15153. t['Psi'] = 795;
  15154. t['Zeta'] = 611;
  15155. t['bracketleft'] = 333;
  15156. t['therefore'] = 863;
  15157. t['bracketright'] = 333;
  15158. t['perpendicular'] = 658;
  15159. t['underscore'] = 500;
  15160. t['radicalex'] = 500;
  15161. t['alpha'] = 631;
  15162. t['beta'] = 549;
  15163. t['chi'] = 549;
  15164. t['delta'] = 494;
  15165. t['epsilon'] = 439;
  15166. t['phi'] = 521;
  15167. t['gamma'] = 411;
  15168. t['eta'] = 603;
  15169. t['iota'] = 329;
  15170. t['phi1'] = 603;
  15171. t['kappa'] = 549;
  15172. t['lambda'] = 549;
  15173. t['mu'] = 576;
  15174. t['nu'] = 521;
  15175. t['omicron'] = 549;
  15176. t['pi'] = 549;
  15177. t['theta'] = 521;
  15178. t['rho'] = 549;
  15179. t['sigma'] = 603;
  15180. t['tau'] = 439;
  15181. t['upsilon'] = 576;
  15182. t['omega1'] = 713;
  15183. t['omega'] = 686;
  15184. t['xi'] = 493;
  15185. t['psi'] = 686;
  15186. t['zeta'] = 494;
  15187. t['braceleft'] = 480;
  15188. t['bar'] = 200;
  15189. t['braceright'] = 480;
  15190. t['similar'] = 549;
  15191. t['Euro'] = 750;
  15192. t['Upsilon1'] = 620;
  15193. t['minute'] = 247;
  15194. t['lessequal'] = 549;
  15195. t['fraction'] = 167;
  15196. t['infinity'] = 713;
  15197. t['florin'] = 500;
  15198. t['club'] = 753;
  15199. t['diamond'] = 753;
  15200. t['heart'] = 753;
  15201. t['spade'] = 753;
  15202. t['arrowboth'] = 1042;
  15203. t['arrowleft'] = 987;
  15204. t['arrowup'] = 603;
  15205. t['arrowright'] = 987;
  15206. t['arrowdown'] = 603;
  15207. t['degree'] = 400;
  15208. t['plusminus'] = 549;
  15209. t['second'] = 411;
  15210. t['greaterequal'] = 549;
  15211. t['multiply'] = 549;
  15212. t['proportional'] = 713;
  15213. t['partialdiff'] = 494;
  15214. t['bullet'] = 460;
  15215. t['divide'] = 549;
  15216. t['notequal'] = 549;
  15217. t['equivalence'] = 549;
  15218. t['approxequal'] = 549;
  15219. t['ellipsis'] = 1000;
  15220. t['arrowvertex'] = 603;
  15221. t['arrowhorizex'] = 1000;
  15222. t['carriagereturn'] = 658;
  15223. t['aleph'] = 823;
  15224. t['Ifraktur'] = 686;
  15225. t['Rfraktur'] = 795;
  15226. t['weierstrass'] = 987;
  15227. t['circlemultiply'] = 768;
  15228. t['circleplus'] = 768;
  15229. t['emptyset'] = 823;
  15230. t['intersection'] = 768;
  15231. t['union'] = 768;
  15232. t['propersuperset'] = 713;
  15233. t['reflexsuperset'] = 713;
  15234. t['notsubset'] = 713;
  15235. t['propersubset'] = 713;
  15236. t['reflexsubset'] = 713;
  15237. t['element'] = 713;
  15238. t['notelement'] = 713;
  15239. t['angle'] = 768;
  15240. t['gradient'] = 713;
  15241. t['registerserif'] = 790;
  15242. t['copyrightserif'] = 790;
  15243. t['trademarkserif'] = 890;
  15244. t['product'] = 823;
  15245. t['radical'] = 549;
  15246. t['dotmath'] = 250;
  15247. t['logicalnot'] = 713;
  15248. t['logicaland'] = 603;
  15249. t['logicalor'] = 603;
  15250. t['arrowdblboth'] = 1042;
  15251. t['arrowdblleft'] = 987;
  15252. t['arrowdblup'] = 603;
  15253. t['arrowdblright'] = 987;
  15254. t['arrowdbldown'] = 603;
  15255. t['lozenge'] = 494;
  15256. t['angleleft'] = 329;
  15257. t['registersans'] = 790;
  15258. t['copyrightsans'] = 790;
  15259. t['trademarksans'] = 786;
  15260. t['summation'] = 713;
  15261. t['parenlefttp'] = 384;
  15262. t['parenleftex'] = 384;
  15263. t['parenleftbt'] = 384;
  15264. t['bracketlefttp'] = 384;
  15265. t['bracketleftex'] = 384;
  15266. t['bracketleftbt'] = 384;
  15267. t['bracelefttp'] = 494;
  15268. t['braceleftmid'] = 494;
  15269. t['braceleftbt'] = 494;
  15270. t['braceex'] = 494;
  15271. t['angleright'] = 329;
  15272. t['integral'] = 274;
  15273. t['integraltp'] = 686;
  15274. t['integralex'] = 686;
  15275. t['integralbt'] = 686;
  15276. t['parenrighttp'] = 384;
  15277. t['parenrightex'] = 384;
  15278. t['parenrightbt'] = 384;
  15279. t['bracketrighttp'] = 384;
  15280. t['bracketrightex'] = 384;
  15281. t['bracketrightbt'] = 384;
  15282. t['bracerighttp'] = 494;
  15283. t['bracerightmid'] = 494;
  15284. t['bracerightbt'] = 494;
  15285. t['apple'] = 790;
  15286. });
  15287. t['Times-Roman'] = getLookupTableFactory(function (t) {
  15288. t['space'] = 250;
  15289. t['exclam'] = 333;
  15290. t['quotedbl'] = 408;
  15291. t['numbersign'] = 500;
  15292. t['dollar'] = 500;
  15293. t['percent'] = 833;
  15294. t['ampersand'] = 778;
  15295. t['quoteright'] = 333;
  15296. t['parenleft'] = 333;
  15297. t['parenright'] = 333;
  15298. t['asterisk'] = 500;
  15299. t['plus'] = 564;
  15300. t['comma'] = 250;
  15301. t['hyphen'] = 333;
  15302. t['period'] = 250;
  15303. t['slash'] = 278;
  15304. t['zero'] = 500;
  15305. t['one'] = 500;
  15306. t['two'] = 500;
  15307. t['three'] = 500;
  15308. t['four'] = 500;
  15309. t['five'] = 500;
  15310. t['six'] = 500;
  15311. t['seven'] = 500;
  15312. t['eight'] = 500;
  15313. t['nine'] = 500;
  15314. t['colon'] = 278;
  15315. t['semicolon'] = 278;
  15316. t['less'] = 564;
  15317. t['equal'] = 564;
  15318. t['greater'] = 564;
  15319. t['question'] = 444;
  15320. t['at'] = 921;
  15321. t['A'] = 722;
  15322. t['B'] = 667;
  15323. t['C'] = 667;
  15324. t['D'] = 722;
  15325. t['E'] = 611;
  15326. t['F'] = 556;
  15327. t['G'] = 722;
  15328. t['H'] = 722;
  15329. t['I'] = 333;
  15330. t['J'] = 389;
  15331. t['K'] = 722;
  15332. t['L'] = 611;
  15333. t['M'] = 889;
  15334. t['N'] = 722;
  15335. t['O'] = 722;
  15336. t['P'] = 556;
  15337. t['Q'] = 722;
  15338. t['R'] = 667;
  15339. t['S'] = 556;
  15340. t['T'] = 611;
  15341. t['U'] = 722;
  15342. t['V'] = 722;
  15343. t['W'] = 944;
  15344. t['X'] = 722;
  15345. t['Y'] = 722;
  15346. t['Z'] = 611;
  15347. t['bracketleft'] = 333;
  15348. t['backslash'] = 278;
  15349. t['bracketright'] = 333;
  15350. t['asciicircum'] = 469;
  15351. t['underscore'] = 500;
  15352. t['quoteleft'] = 333;
  15353. t['a'] = 444;
  15354. t['b'] = 500;
  15355. t['c'] = 444;
  15356. t['d'] = 500;
  15357. t['e'] = 444;
  15358. t['f'] = 333;
  15359. t['g'] = 500;
  15360. t['h'] = 500;
  15361. t['i'] = 278;
  15362. t['j'] = 278;
  15363. t['k'] = 500;
  15364. t['l'] = 278;
  15365. t['m'] = 778;
  15366. t['n'] = 500;
  15367. t['o'] = 500;
  15368. t['p'] = 500;
  15369. t['q'] = 500;
  15370. t['r'] = 333;
  15371. t['s'] = 389;
  15372. t['t'] = 278;
  15373. t['u'] = 500;
  15374. t['v'] = 500;
  15375. t['w'] = 722;
  15376. t['x'] = 500;
  15377. t['y'] = 500;
  15378. t['z'] = 444;
  15379. t['braceleft'] = 480;
  15380. t['bar'] = 200;
  15381. t['braceright'] = 480;
  15382. t['asciitilde'] = 541;
  15383. t['exclamdown'] = 333;
  15384. t['cent'] = 500;
  15385. t['sterling'] = 500;
  15386. t['fraction'] = 167;
  15387. t['yen'] = 500;
  15388. t['florin'] = 500;
  15389. t['section'] = 500;
  15390. t['currency'] = 500;
  15391. t['quotesingle'] = 180;
  15392. t['quotedblleft'] = 444;
  15393. t['guillemotleft'] = 500;
  15394. t['guilsinglleft'] = 333;
  15395. t['guilsinglright'] = 333;
  15396. t['fi'] = 556;
  15397. t['fl'] = 556;
  15398. t['endash'] = 500;
  15399. t['dagger'] = 500;
  15400. t['daggerdbl'] = 500;
  15401. t['periodcentered'] = 250;
  15402. t['paragraph'] = 453;
  15403. t['bullet'] = 350;
  15404. t['quotesinglbase'] = 333;
  15405. t['quotedblbase'] = 444;
  15406. t['quotedblright'] = 444;
  15407. t['guillemotright'] = 500;
  15408. t['ellipsis'] = 1000;
  15409. t['perthousand'] = 1000;
  15410. t['questiondown'] = 444;
  15411. t['grave'] = 333;
  15412. t['acute'] = 333;
  15413. t['circumflex'] = 333;
  15414. t['tilde'] = 333;
  15415. t['macron'] = 333;
  15416. t['breve'] = 333;
  15417. t['dotaccent'] = 333;
  15418. t['dieresis'] = 333;
  15419. t['ring'] = 333;
  15420. t['cedilla'] = 333;
  15421. t['hungarumlaut'] = 333;
  15422. t['ogonek'] = 333;
  15423. t['caron'] = 333;
  15424. t['emdash'] = 1000;
  15425. t['AE'] = 889;
  15426. t['ordfeminine'] = 276;
  15427. t['Lslash'] = 611;
  15428. t['Oslash'] = 722;
  15429. t['OE'] = 889;
  15430. t['ordmasculine'] = 310;
  15431. t['ae'] = 667;
  15432. t['dotlessi'] = 278;
  15433. t['lslash'] = 278;
  15434. t['oslash'] = 500;
  15435. t['oe'] = 722;
  15436. t['germandbls'] = 500;
  15437. t['Idieresis'] = 333;
  15438. t['eacute'] = 444;
  15439. t['abreve'] = 444;
  15440. t['uhungarumlaut'] = 500;
  15441. t['ecaron'] = 444;
  15442. t['Ydieresis'] = 722;
  15443. t['divide'] = 564;
  15444. t['Yacute'] = 722;
  15445. t['Acircumflex'] = 722;
  15446. t['aacute'] = 444;
  15447. t['Ucircumflex'] = 722;
  15448. t['yacute'] = 500;
  15449. t['scommaaccent'] = 389;
  15450. t['ecircumflex'] = 444;
  15451. t['Uring'] = 722;
  15452. t['Udieresis'] = 722;
  15453. t['aogonek'] = 444;
  15454. t['Uacute'] = 722;
  15455. t['uogonek'] = 500;
  15456. t['Edieresis'] = 611;
  15457. t['Dcroat'] = 722;
  15458. t['commaaccent'] = 250;
  15459. t['copyright'] = 760;
  15460. t['Emacron'] = 611;
  15461. t['ccaron'] = 444;
  15462. t['aring'] = 444;
  15463. t['Ncommaaccent'] = 722;
  15464. t['lacute'] = 278;
  15465. t['agrave'] = 444;
  15466. t['Tcommaaccent'] = 611;
  15467. t['Cacute'] = 667;
  15468. t['atilde'] = 444;
  15469. t['Edotaccent'] = 611;
  15470. t['scaron'] = 389;
  15471. t['scedilla'] = 389;
  15472. t['iacute'] = 278;
  15473. t['lozenge'] = 471;
  15474. t['Rcaron'] = 667;
  15475. t['Gcommaaccent'] = 722;
  15476. t['ucircumflex'] = 500;
  15477. t['acircumflex'] = 444;
  15478. t['Amacron'] = 722;
  15479. t['rcaron'] = 333;
  15480. t['ccedilla'] = 444;
  15481. t['Zdotaccent'] = 611;
  15482. t['Thorn'] = 556;
  15483. t['Omacron'] = 722;
  15484. t['Racute'] = 667;
  15485. t['Sacute'] = 556;
  15486. t['dcaron'] = 588;
  15487. t['Umacron'] = 722;
  15488. t['uring'] = 500;
  15489. t['threesuperior'] = 300;
  15490. t['Ograve'] = 722;
  15491. t['Agrave'] = 722;
  15492. t['Abreve'] = 722;
  15493. t['multiply'] = 564;
  15494. t['uacute'] = 500;
  15495. t['Tcaron'] = 611;
  15496. t['partialdiff'] = 476;
  15497. t['ydieresis'] = 500;
  15498. t['Nacute'] = 722;
  15499. t['icircumflex'] = 278;
  15500. t['Ecircumflex'] = 611;
  15501. t['adieresis'] = 444;
  15502. t['edieresis'] = 444;
  15503. t['cacute'] = 444;
  15504. t['nacute'] = 500;
  15505. t['umacron'] = 500;
  15506. t['Ncaron'] = 722;
  15507. t['Iacute'] = 333;
  15508. t['plusminus'] = 564;
  15509. t['brokenbar'] = 200;
  15510. t['registered'] = 760;
  15511. t['Gbreve'] = 722;
  15512. t['Idotaccent'] = 333;
  15513. t['summation'] = 600;
  15514. t['Egrave'] = 611;
  15515. t['racute'] = 333;
  15516. t['omacron'] = 500;
  15517. t['Zacute'] = 611;
  15518. t['Zcaron'] = 611;
  15519. t['greaterequal'] = 549;
  15520. t['Eth'] = 722;
  15521. t['Ccedilla'] = 667;
  15522. t['lcommaaccent'] = 278;
  15523. t['tcaron'] = 326;
  15524. t['eogonek'] = 444;
  15525. t['Uogonek'] = 722;
  15526. t['Aacute'] = 722;
  15527. t['Adieresis'] = 722;
  15528. t['egrave'] = 444;
  15529. t['zacute'] = 444;
  15530. t['iogonek'] = 278;
  15531. t['Oacute'] = 722;
  15532. t['oacute'] = 500;
  15533. t['amacron'] = 444;
  15534. t['sacute'] = 389;
  15535. t['idieresis'] = 278;
  15536. t['Ocircumflex'] = 722;
  15537. t['Ugrave'] = 722;
  15538. t['Delta'] = 612;
  15539. t['thorn'] = 500;
  15540. t['twosuperior'] = 300;
  15541. t['Odieresis'] = 722;
  15542. t['mu'] = 500;
  15543. t['igrave'] = 278;
  15544. t['ohungarumlaut'] = 500;
  15545. t['Eogonek'] = 611;
  15546. t['dcroat'] = 500;
  15547. t['threequarters'] = 750;
  15548. t['Scedilla'] = 556;
  15549. t['lcaron'] = 344;
  15550. t['Kcommaaccent'] = 722;
  15551. t['Lacute'] = 611;
  15552. t['trademark'] = 980;
  15553. t['edotaccent'] = 444;
  15554. t['Igrave'] = 333;
  15555. t['Imacron'] = 333;
  15556. t['Lcaron'] = 611;
  15557. t['onehalf'] = 750;
  15558. t['lessequal'] = 549;
  15559. t['ocircumflex'] = 500;
  15560. t['ntilde'] = 500;
  15561. t['Uhungarumlaut'] = 722;
  15562. t['Eacute'] = 611;
  15563. t['emacron'] = 444;
  15564. t['gbreve'] = 500;
  15565. t['onequarter'] = 750;
  15566. t['Scaron'] = 556;
  15567. t['Scommaaccent'] = 556;
  15568. t['Ohungarumlaut'] = 722;
  15569. t['degree'] = 400;
  15570. t['ograve'] = 500;
  15571. t['Ccaron'] = 667;
  15572. t['ugrave'] = 500;
  15573. t['radical'] = 453;
  15574. t['Dcaron'] = 722;
  15575. t['rcommaaccent'] = 333;
  15576. t['Ntilde'] = 722;
  15577. t['otilde'] = 500;
  15578. t['Rcommaaccent'] = 667;
  15579. t['Lcommaaccent'] = 611;
  15580. t['Atilde'] = 722;
  15581. t['Aogonek'] = 722;
  15582. t['Aring'] = 722;
  15583. t['Otilde'] = 722;
  15584. t['zdotaccent'] = 444;
  15585. t['Ecaron'] = 611;
  15586. t['Iogonek'] = 333;
  15587. t['kcommaaccent'] = 500;
  15588. t['minus'] = 564;
  15589. t['Icircumflex'] = 333;
  15590. t['ncaron'] = 500;
  15591. t['tcommaaccent'] = 278;
  15592. t['logicalnot'] = 564;
  15593. t['odieresis'] = 500;
  15594. t['udieresis'] = 500;
  15595. t['notequal'] = 549;
  15596. t['gcommaaccent'] = 500;
  15597. t['eth'] = 500;
  15598. t['zcaron'] = 444;
  15599. t['ncommaaccent'] = 500;
  15600. t['onesuperior'] = 300;
  15601. t['imacron'] = 278;
  15602. t['Euro'] = 500;
  15603. });
  15604. t['Times-Bold'] = getLookupTableFactory(function (t) {
  15605. t['space'] = 250;
  15606. t['exclam'] = 333;
  15607. t['quotedbl'] = 555;
  15608. t['numbersign'] = 500;
  15609. t['dollar'] = 500;
  15610. t['percent'] = 1000;
  15611. t['ampersand'] = 833;
  15612. t['quoteright'] = 333;
  15613. t['parenleft'] = 333;
  15614. t['parenright'] = 333;
  15615. t['asterisk'] = 500;
  15616. t['plus'] = 570;
  15617. t['comma'] = 250;
  15618. t['hyphen'] = 333;
  15619. t['period'] = 250;
  15620. t['slash'] = 278;
  15621. t['zero'] = 500;
  15622. t['one'] = 500;
  15623. t['two'] = 500;
  15624. t['three'] = 500;
  15625. t['four'] = 500;
  15626. t['five'] = 500;
  15627. t['six'] = 500;
  15628. t['seven'] = 500;
  15629. t['eight'] = 500;
  15630. t['nine'] = 500;
  15631. t['colon'] = 333;
  15632. t['semicolon'] = 333;
  15633. t['less'] = 570;
  15634. t['equal'] = 570;
  15635. t['greater'] = 570;
  15636. t['question'] = 500;
  15637. t['at'] = 930;
  15638. t['A'] = 722;
  15639. t['B'] = 667;
  15640. t['C'] = 722;
  15641. t['D'] = 722;
  15642. t['E'] = 667;
  15643. t['F'] = 611;
  15644. t['G'] = 778;
  15645. t['H'] = 778;
  15646. t['I'] = 389;
  15647. t['J'] = 500;
  15648. t['K'] = 778;
  15649. t['L'] = 667;
  15650. t['M'] = 944;
  15651. t['N'] = 722;
  15652. t['O'] = 778;
  15653. t['P'] = 611;
  15654. t['Q'] = 778;
  15655. t['R'] = 722;
  15656. t['S'] = 556;
  15657. t['T'] = 667;
  15658. t['U'] = 722;
  15659. t['V'] = 722;
  15660. t['W'] = 1000;
  15661. t['X'] = 722;
  15662. t['Y'] = 722;
  15663. t['Z'] = 667;
  15664. t['bracketleft'] = 333;
  15665. t['backslash'] = 278;
  15666. t['bracketright'] = 333;
  15667. t['asciicircum'] = 581;
  15668. t['underscore'] = 500;
  15669. t['quoteleft'] = 333;
  15670. t['a'] = 500;
  15671. t['b'] = 556;
  15672. t['c'] = 444;
  15673. t['d'] = 556;
  15674. t['e'] = 444;
  15675. t['f'] = 333;
  15676. t['g'] = 500;
  15677. t['h'] = 556;
  15678. t['i'] = 278;
  15679. t['j'] = 333;
  15680. t['k'] = 556;
  15681. t['l'] = 278;
  15682. t['m'] = 833;
  15683. t['n'] = 556;
  15684. t['o'] = 500;
  15685. t['p'] = 556;
  15686. t['q'] = 556;
  15687. t['r'] = 444;
  15688. t['s'] = 389;
  15689. t['t'] = 333;
  15690. t['u'] = 556;
  15691. t['v'] = 500;
  15692. t['w'] = 722;
  15693. t['x'] = 500;
  15694. t['y'] = 500;
  15695. t['z'] = 444;
  15696. t['braceleft'] = 394;
  15697. t['bar'] = 220;
  15698. t['braceright'] = 394;
  15699. t['asciitilde'] = 520;
  15700. t['exclamdown'] = 333;
  15701. t['cent'] = 500;
  15702. t['sterling'] = 500;
  15703. t['fraction'] = 167;
  15704. t['yen'] = 500;
  15705. t['florin'] = 500;
  15706. t['section'] = 500;
  15707. t['currency'] = 500;
  15708. t['quotesingle'] = 278;
  15709. t['quotedblleft'] = 500;
  15710. t['guillemotleft'] = 500;
  15711. t['guilsinglleft'] = 333;
  15712. t['guilsinglright'] = 333;
  15713. t['fi'] = 556;
  15714. t['fl'] = 556;
  15715. t['endash'] = 500;
  15716. t['dagger'] = 500;
  15717. t['daggerdbl'] = 500;
  15718. t['periodcentered'] = 250;
  15719. t['paragraph'] = 540;
  15720. t['bullet'] = 350;
  15721. t['quotesinglbase'] = 333;
  15722. t['quotedblbase'] = 500;
  15723. t['quotedblright'] = 500;
  15724. t['guillemotright'] = 500;
  15725. t['ellipsis'] = 1000;
  15726. t['perthousand'] = 1000;
  15727. t['questiondown'] = 500;
  15728. t['grave'] = 333;
  15729. t['acute'] = 333;
  15730. t['circumflex'] = 333;
  15731. t['tilde'] = 333;
  15732. t['macron'] = 333;
  15733. t['breve'] = 333;
  15734. t['dotaccent'] = 333;
  15735. t['dieresis'] = 333;
  15736. t['ring'] = 333;
  15737. t['cedilla'] = 333;
  15738. t['hungarumlaut'] = 333;
  15739. t['ogonek'] = 333;
  15740. t['caron'] = 333;
  15741. t['emdash'] = 1000;
  15742. t['AE'] = 1000;
  15743. t['ordfeminine'] = 300;
  15744. t['Lslash'] = 667;
  15745. t['Oslash'] = 778;
  15746. t['OE'] = 1000;
  15747. t['ordmasculine'] = 330;
  15748. t['ae'] = 722;
  15749. t['dotlessi'] = 278;
  15750. t['lslash'] = 278;
  15751. t['oslash'] = 500;
  15752. t['oe'] = 722;
  15753. t['germandbls'] = 556;
  15754. t['Idieresis'] = 389;
  15755. t['eacute'] = 444;
  15756. t['abreve'] = 500;
  15757. t['uhungarumlaut'] = 556;
  15758. t['ecaron'] = 444;
  15759. t['Ydieresis'] = 722;
  15760. t['divide'] = 570;
  15761. t['Yacute'] = 722;
  15762. t['Acircumflex'] = 722;
  15763. t['aacute'] = 500;
  15764. t['Ucircumflex'] = 722;
  15765. t['yacute'] = 500;
  15766. t['scommaaccent'] = 389;
  15767. t['ecircumflex'] = 444;
  15768. t['Uring'] = 722;
  15769. t['Udieresis'] = 722;
  15770. t['aogonek'] = 500;
  15771. t['Uacute'] = 722;
  15772. t['uogonek'] = 556;
  15773. t['Edieresis'] = 667;
  15774. t['Dcroat'] = 722;
  15775. t['commaaccent'] = 250;
  15776. t['copyright'] = 747;
  15777. t['Emacron'] = 667;
  15778. t['ccaron'] = 444;
  15779. t['aring'] = 500;
  15780. t['Ncommaaccent'] = 722;
  15781. t['lacute'] = 278;
  15782. t['agrave'] = 500;
  15783. t['Tcommaaccent'] = 667;
  15784. t['Cacute'] = 722;
  15785. t['atilde'] = 500;
  15786. t['Edotaccent'] = 667;
  15787. t['scaron'] = 389;
  15788. t['scedilla'] = 389;
  15789. t['iacute'] = 278;
  15790. t['lozenge'] = 494;
  15791. t['Rcaron'] = 722;
  15792. t['Gcommaaccent'] = 778;
  15793. t['ucircumflex'] = 556;
  15794. t['acircumflex'] = 500;
  15795. t['Amacron'] = 722;
  15796. t['rcaron'] = 444;
  15797. t['ccedilla'] = 444;
  15798. t['Zdotaccent'] = 667;
  15799. t['Thorn'] = 611;
  15800. t['Omacron'] = 778;
  15801. t['Racute'] = 722;
  15802. t['Sacute'] = 556;
  15803. t['dcaron'] = 672;
  15804. t['Umacron'] = 722;
  15805. t['uring'] = 556;
  15806. t['threesuperior'] = 300;
  15807. t['Ograve'] = 778;
  15808. t['Agrave'] = 722;
  15809. t['Abreve'] = 722;
  15810. t['multiply'] = 570;
  15811. t['uacute'] = 556;
  15812. t['Tcaron'] = 667;
  15813. t['partialdiff'] = 494;
  15814. t['ydieresis'] = 500;
  15815. t['Nacute'] = 722;
  15816. t['icircumflex'] = 278;
  15817. t['Ecircumflex'] = 667;
  15818. t['adieresis'] = 500;
  15819. t['edieresis'] = 444;
  15820. t['cacute'] = 444;
  15821. t['nacute'] = 556;
  15822. t['umacron'] = 556;
  15823. t['Ncaron'] = 722;
  15824. t['Iacute'] = 389;
  15825. t['plusminus'] = 570;
  15826. t['brokenbar'] = 220;
  15827. t['registered'] = 747;
  15828. t['Gbreve'] = 778;
  15829. t['Idotaccent'] = 389;
  15830. t['summation'] = 600;
  15831. t['Egrave'] = 667;
  15832. t['racute'] = 444;
  15833. t['omacron'] = 500;
  15834. t['Zacute'] = 667;
  15835. t['Zcaron'] = 667;
  15836. t['greaterequal'] = 549;
  15837. t['Eth'] = 722;
  15838. t['Ccedilla'] = 722;
  15839. t['lcommaaccent'] = 278;
  15840. t['tcaron'] = 416;
  15841. t['eogonek'] = 444;
  15842. t['Uogonek'] = 722;
  15843. t['Aacute'] = 722;
  15844. t['Adieresis'] = 722;
  15845. t['egrave'] = 444;
  15846. t['zacute'] = 444;
  15847. t['iogonek'] = 278;
  15848. t['Oacute'] = 778;
  15849. t['oacute'] = 500;
  15850. t['amacron'] = 500;
  15851. t['sacute'] = 389;
  15852. t['idieresis'] = 278;
  15853. t['Ocircumflex'] = 778;
  15854. t['Ugrave'] = 722;
  15855. t['Delta'] = 612;
  15856. t['thorn'] = 556;
  15857. t['twosuperior'] = 300;
  15858. t['Odieresis'] = 778;
  15859. t['mu'] = 556;
  15860. t['igrave'] = 278;
  15861. t['ohungarumlaut'] = 500;
  15862. t['Eogonek'] = 667;
  15863. t['dcroat'] = 556;
  15864. t['threequarters'] = 750;
  15865. t['Scedilla'] = 556;
  15866. t['lcaron'] = 394;
  15867. t['Kcommaaccent'] = 778;
  15868. t['Lacute'] = 667;
  15869. t['trademark'] = 1000;
  15870. t['edotaccent'] = 444;
  15871. t['Igrave'] = 389;
  15872. t['Imacron'] = 389;
  15873. t['Lcaron'] = 667;
  15874. t['onehalf'] = 750;
  15875. t['lessequal'] = 549;
  15876. t['ocircumflex'] = 500;
  15877. t['ntilde'] = 556;
  15878. t['Uhungarumlaut'] = 722;
  15879. t['Eacute'] = 667;
  15880. t['emacron'] = 444;
  15881. t['gbreve'] = 500;
  15882. t['onequarter'] = 750;
  15883. t['Scaron'] = 556;
  15884. t['Scommaaccent'] = 556;
  15885. t['Ohungarumlaut'] = 778;
  15886. t['degree'] = 400;
  15887. t['ograve'] = 500;
  15888. t['Ccaron'] = 722;
  15889. t['ugrave'] = 556;
  15890. t['radical'] = 549;
  15891. t['Dcaron'] = 722;
  15892. t['rcommaaccent'] = 444;
  15893. t['Ntilde'] = 722;
  15894. t['otilde'] = 500;
  15895. t['Rcommaaccent'] = 722;
  15896. t['Lcommaaccent'] = 667;
  15897. t['Atilde'] = 722;
  15898. t['Aogonek'] = 722;
  15899. t['Aring'] = 722;
  15900. t['Otilde'] = 778;
  15901. t['zdotaccent'] = 444;
  15902. t['Ecaron'] = 667;
  15903. t['Iogonek'] = 389;
  15904. t['kcommaaccent'] = 556;
  15905. t['minus'] = 570;
  15906. t['Icircumflex'] = 389;
  15907. t['ncaron'] = 556;
  15908. t['tcommaaccent'] = 333;
  15909. t['logicalnot'] = 570;
  15910. t['odieresis'] = 500;
  15911. t['udieresis'] = 556;
  15912. t['notequal'] = 549;
  15913. t['gcommaaccent'] = 500;
  15914. t['eth'] = 500;
  15915. t['zcaron'] = 444;
  15916. t['ncommaaccent'] = 556;
  15917. t['onesuperior'] = 300;
  15918. t['imacron'] = 278;
  15919. t['Euro'] = 500;
  15920. });
  15921. t['Times-BoldItalic'] = getLookupTableFactory(function (t) {
  15922. t['space'] = 250;
  15923. t['exclam'] = 389;
  15924. t['quotedbl'] = 555;
  15925. t['numbersign'] = 500;
  15926. t['dollar'] = 500;
  15927. t['percent'] = 833;
  15928. t['ampersand'] = 778;
  15929. t['quoteright'] = 333;
  15930. t['parenleft'] = 333;
  15931. t['parenright'] = 333;
  15932. t['asterisk'] = 500;
  15933. t['plus'] = 570;
  15934. t['comma'] = 250;
  15935. t['hyphen'] = 333;
  15936. t['period'] = 250;
  15937. t['slash'] = 278;
  15938. t['zero'] = 500;
  15939. t['one'] = 500;
  15940. t['two'] = 500;
  15941. t['three'] = 500;
  15942. t['four'] = 500;
  15943. t['five'] = 500;
  15944. t['six'] = 500;
  15945. t['seven'] = 500;
  15946. t['eight'] = 500;
  15947. t['nine'] = 500;
  15948. t['colon'] = 333;
  15949. t['semicolon'] = 333;
  15950. t['less'] = 570;
  15951. t['equal'] = 570;
  15952. t['greater'] = 570;
  15953. t['question'] = 500;
  15954. t['at'] = 832;
  15955. t['A'] = 667;
  15956. t['B'] = 667;
  15957. t['C'] = 667;
  15958. t['D'] = 722;
  15959. t['E'] = 667;
  15960. t['F'] = 667;
  15961. t['G'] = 722;
  15962. t['H'] = 778;
  15963. t['I'] = 389;
  15964. t['J'] = 500;
  15965. t['K'] = 667;
  15966. t['L'] = 611;
  15967. t['M'] = 889;
  15968. t['N'] = 722;
  15969. t['O'] = 722;
  15970. t['P'] = 611;
  15971. t['Q'] = 722;
  15972. t['R'] = 667;
  15973. t['S'] = 556;
  15974. t['T'] = 611;
  15975. t['U'] = 722;
  15976. t['V'] = 667;
  15977. t['W'] = 889;
  15978. t['X'] = 667;
  15979. t['Y'] = 611;
  15980. t['Z'] = 611;
  15981. t['bracketleft'] = 333;
  15982. t['backslash'] = 278;
  15983. t['bracketright'] = 333;
  15984. t['asciicircum'] = 570;
  15985. t['underscore'] = 500;
  15986. t['quoteleft'] = 333;
  15987. t['a'] = 500;
  15988. t['b'] = 500;
  15989. t['c'] = 444;
  15990. t['d'] = 500;
  15991. t['e'] = 444;
  15992. t['f'] = 333;
  15993. t['g'] = 500;
  15994. t['h'] = 556;
  15995. t['i'] = 278;
  15996. t['j'] = 278;
  15997. t['k'] = 500;
  15998. t['l'] = 278;
  15999. t['m'] = 778;
  16000. t['n'] = 556;
  16001. t['o'] = 500;
  16002. t['p'] = 500;
  16003. t['q'] = 500;
  16004. t['r'] = 389;
  16005. t['s'] = 389;
  16006. t['t'] = 278;
  16007. t['u'] = 556;
  16008. t['v'] = 444;
  16009. t['w'] = 667;
  16010. t['x'] = 500;
  16011. t['y'] = 444;
  16012. t['z'] = 389;
  16013. t['braceleft'] = 348;
  16014. t['bar'] = 220;
  16015. t['braceright'] = 348;
  16016. t['asciitilde'] = 570;
  16017. t['exclamdown'] = 389;
  16018. t['cent'] = 500;
  16019. t['sterling'] = 500;
  16020. t['fraction'] = 167;
  16021. t['yen'] = 500;
  16022. t['florin'] = 500;
  16023. t['section'] = 500;
  16024. t['currency'] = 500;
  16025. t['quotesingle'] = 278;
  16026. t['quotedblleft'] = 500;
  16027. t['guillemotleft'] = 500;
  16028. t['guilsinglleft'] = 333;
  16029. t['guilsinglright'] = 333;
  16030. t['fi'] = 556;
  16031. t['fl'] = 556;
  16032. t['endash'] = 500;
  16033. t['dagger'] = 500;
  16034. t['daggerdbl'] = 500;
  16035. t['periodcentered'] = 250;
  16036. t['paragraph'] = 500;
  16037. t['bullet'] = 350;
  16038. t['quotesinglbase'] = 333;
  16039. t['quotedblbase'] = 500;
  16040. t['quotedblright'] = 500;
  16041. t['guillemotright'] = 500;
  16042. t['ellipsis'] = 1000;
  16043. t['perthousand'] = 1000;
  16044. t['questiondown'] = 500;
  16045. t['grave'] = 333;
  16046. t['acute'] = 333;
  16047. t['circumflex'] = 333;
  16048. t['tilde'] = 333;
  16049. t['macron'] = 333;
  16050. t['breve'] = 333;
  16051. t['dotaccent'] = 333;
  16052. t['dieresis'] = 333;
  16053. t['ring'] = 333;
  16054. t['cedilla'] = 333;
  16055. t['hungarumlaut'] = 333;
  16056. t['ogonek'] = 333;
  16057. t['caron'] = 333;
  16058. t['emdash'] = 1000;
  16059. t['AE'] = 944;
  16060. t['ordfeminine'] = 266;
  16061. t['Lslash'] = 611;
  16062. t['Oslash'] = 722;
  16063. t['OE'] = 944;
  16064. t['ordmasculine'] = 300;
  16065. t['ae'] = 722;
  16066. t['dotlessi'] = 278;
  16067. t['lslash'] = 278;
  16068. t['oslash'] = 500;
  16069. t['oe'] = 722;
  16070. t['germandbls'] = 500;
  16071. t['Idieresis'] = 389;
  16072. t['eacute'] = 444;
  16073. t['abreve'] = 500;
  16074. t['uhungarumlaut'] = 556;
  16075. t['ecaron'] = 444;
  16076. t['Ydieresis'] = 611;
  16077. t['divide'] = 570;
  16078. t['Yacute'] = 611;
  16079. t['Acircumflex'] = 667;
  16080. t['aacute'] = 500;
  16081. t['Ucircumflex'] = 722;
  16082. t['yacute'] = 444;
  16083. t['scommaaccent'] = 389;
  16084. t['ecircumflex'] = 444;
  16085. t['Uring'] = 722;
  16086. t['Udieresis'] = 722;
  16087. t['aogonek'] = 500;
  16088. t['Uacute'] = 722;
  16089. t['uogonek'] = 556;
  16090. t['Edieresis'] = 667;
  16091. t['Dcroat'] = 722;
  16092. t['commaaccent'] = 250;
  16093. t['copyright'] = 747;
  16094. t['Emacron'] = 667;
  16095. t['ccaron'] = 444;
  16096. t['aring'] = 500;
  16097. t['Ncommaaccent'] = 722;
  16098. t['lacute'] = 278;
  16099. t['agrave'] = 500;
  16100. t['Tcommaaccent'] = 611;
  16101. t['Cacute'] = 667;
  16102. t['atilde'] = 500;
  16103. t['Edotaccent'] = 667;
  16104. t['scaron'] = 389;
  16105. t['scedilla'] = 389;
  16106. t['iacute'] = 278;
  16107. t['lozenge'] = 494;
  16108. t['Rcaron'] = 667;
  16109. t['Gcommaaccent'] = 722;
  16110. t['ucircumflex'] = 556;
  16111. t['acircumflex'] = 500;
  16112. t['Amacron'] = 667;
  16113. t['rcaron'] = 389;
  16114. t['ccedilla'] = 444;
  16115. t['Zdotaccent'] = 611;
  16116. t['Thorn'] = 611;
  16117. t['Omacron'] = 722;
  16118. t['Racute'] = 667;
  16119. t['Sacute'] = 556;
  16120. t['dcaron'] = 608;
  16121. t['Umacron'] = 722;
  16122. t['uring'] = 556;
  16123. t['threesuperior'] = 300;
  16124. t['Ograve'] = 722;
  16125. t['Agrave'] = 667;
  16126. t['Abreve'] = 667;
  16127. t['multiply'] = 570;
  16128. t['uacute'] = 556;
  16129. t['Tcaron'] = 611;
  16130. t['partialdiff'] = 494;
  16131. t['ydieresis'] = 444;
  16132. t['Nacute'] = 722;
  16133. t['icircumflex'] = 278;
  16134. t['Ecircumflex'] = 667;
  16135. t['adieresis'] = 500;
  16136. t['edieresis'] = 444;
  16137. t['cacute'] = 444;
  16138. t['nacute'] = 556;
  16139. t['umacron'] = 556;
  16140. t['Ncaron'] = 722;
  16141. t['Iacute'] = 389;
  16142. t['plusminus'] = 570;
  16143. t['brokenbar'] = 220;
  16144. t['registered'] = 747;
  16145. t['Gbreve'] = 722;
  16146. t['Idotaccent'] = 389;
  16147. t['summation'] = 600;
  16148. t['Egrave'] = 667;
  16149. t['racute'] = 389;
  16150. t['omacron'] = 500;
  16151. t['Zacute'] = 611;
  16152. t['Zcaron'] = 611;
  16153. t['greaterequal'] = 549;
  16154. t['Eth'] = 722;
  16155. t['Ccedilla'] = 667;
  16156. t['lcommaaccent'] = 278;
  16157. t['tcaron'] = 366;
  16158. t['eogonek'] = 444;
  16159. t['Uogonek'] = 722;
  16160. t['Aacute'] = 667;
  16161. t['Adieresis'] = 667;
  16162. t['egrave'] = 444;
  16163. t['zacute'] = 389;
  16164. t['iogonek'] = 278;
  16165. t['Oacute'] = 722;
  16166. t['oacute'] = 500;
  16167. t['amacron'] = 500;
  16168. t['sacute'] = 389;
  16169. t['idieresis'] = 278;
  16170. t['Ocircumflex'] = 722;
  16171. t['Ugrave'] = 722;
  16172. t['Delta'] = 612;
  16173. t['thorn'] = 500;
  16174. t['twosuperior'] = 300;
  16175. t['Odieresis'] = 722;
  16176. t['mu'] = 576;
  16177. t['igrave'] = 278;
  16178. t['ohungarumlaut'] = 500;
  16179. t['Eogonek'] = 667;
  16180. t['dcroat'] = 500;
  16181. t['threequarters'] = 750;
  16182. t['Scedilla'] = 556;
  16183. t['lcaron'] = 382;
  16184. t['Kcommaaccent'] = 667;
  16185. t['Lacute'] = 611;
  16186. t['trademark'] = 1000;
  16187. t['edotaccent'] = 444;
  16188. t['Igrave'] = 389;
  16189. t['Imacron'] = 389;
  16190. t['Lcaron'] = 611;
  16191. t['onehalf'] = 750;
  16192. t['lessequal'] = 549;
  16193. t['ocircumflex'] = 500;
  16194. t['ntilde'] = 556;
  16195. t['Uhungarumlaut'] = 722;
  16196. t['Eacute'] = 667;
  16197. t['emacron'] = 444;
  16198. t['gbreve'] = 500;
  16199. t['onequarter'] = 750;
  16200. t['Scaron'] = 556;
  16201. t['Scommaaccent'] = 556;
  16202. t['Ohungarumlaut'] = 722;
  16203. t['degree'] = 400;
  16204. t['ograve'] = 500;
  16205. t['Ccaron'] = 667;
  16206. t['ugrave'] = 556;
  16207. t['radical'] = 549;
  16208. t['Dcaron'] = 722;
  16209. t['rcommaaccent'] = 389;
  16210. t['Ntilde'] = 722;
  16211. t['otilde'] = 500;
  16212. t['Rcommaaccent'] = 667;
  16213. t['Lcommaaccent'] = 611;
  16214. t['Atilde'] = 667;
  16215. t['Aogonek'] = 667;
  16216. t['Aring'] = 667;
  16217. t['Otilde'] = 722;
  16218. t['zdotaccent'] = 389;
  16219. t['Ecaron'] = 667;
  16220. t['Iogonek'] = 389;
  16221. t['kcommaaccent'] = 500;
  16222. t['minus'] = 606;
  16223. t['Icircumflex'] = 389;
  16224. t['ncaron'] = 556;
  16225. t['tcommaaccent'] = 278;
  16226. t['logicalnot'] = 606;
  16227. t['odieresis'] = 500;
  16228. t['udieresis'] = 556;
  16229. t['notequal'] = 549;
  16230. t['gcommaaccent'] = 500;
  16231. t['eth'] = 500;
  16232. t['zcaron'] = 389;
  16233. t['ncommaaccent'] = 556;
  16234. t['onesuperior'] = 300;
  16235. t['imacron'] = 278;
  16236. t['Euro'] = 500;
  16237. });
  16238. t['Times-Italic'] = getLookupTableFactory(function (t) {
  16239. t['space'] = 250;
  16240. t['exclam'] = 333;
  16241. t['quotedbl'] = 420;
  16242. t['numbersign'] = 500;
  16243. t['dollar'] = 500;
  16244. t['percent'] = 833;
  16245. t['ampersand'] = 778;
  16246. t['quoteright'] = 333;
  16247. t['parenleft'] = 333;
  16248. t['parenright'] = 333;
  16249. t['asterisk'] = 500;
  16250. t['plus'] = 675;
  16251. t['comma'] = 250;
  16252. t['hyphen'] = 333;
  16253. t['period'] = 250;
  16254. t['slash'] = 278;
  16255. t['zero'] = 500;
  16256. t['one'] = 500;
  16257. t['two'] = 500;
  16258. t['three'] = 500;
  16259. t['four'] = 500;
  16260. t['five'] = 500;
  16261. t['six'] = 500;
  16262. t['seven'] = 500;
  16263. t['eight'] = 500;
  16264. t['nine'] = 500;
  16265. t['colon'] = 333;
  16266. t['semicolon'] = 333;
  16267. t['less'] = 675;
  16268. t['equal'] = 675;
  16269. t['greater'] = 675;
  16270. t['question'] = 500;
  16271. t['at'] = 920;
  16272. t['A'] = 611;
  16273. t['B'] = 611;
  16274. t['C'] = 667;
  16275. t['D'] = 722;
  16276. t['E'] = 611;
  16277. t['F'] = 611;
  16278. t['G'] = 722;
  16279. t['H'] = 722;
  16280. t['I'] = 333;
  16281. t['J'] = 444;
  16282. t['K'] = 667;
  16283. t['L'] = 556;
  16284. t['M'] = 833;
  16285. t['N'] = 667;
  16286. t['O'] = 722;
  16287. t['P'] = 611;
  16288. t['Q'] = 722;
  16289. t['R'] = 611;
  16290. t['S'] = 500;
  16291. t['T'] = 556;
  16292. t['U'] = 722;
  16293. t['V'] = 611;
  16294. t['W'] = 833;
  16295. t['X'] = 611;
  16296. t['Y'] = 556;
  16297. t['Z'] = 556;
  16298. t['bracketleft'] = 389;
  16299. t['backslash'] = 278;
  16300. t['bracketright'] = 389;
  16301. t['asciicircum'] = 422;
  16302. t['underscore'] = 500;
  16303. t['quoteleft'] = 333;
  16304. t['a'] = 500;
  16305. t['b'] = 500;
  16306. t['c'] = 444;
  16307. t['d'] = 500;
  16308. t['e'] = 444;
  16309. t['f'] = 278;
  16310. t['g'] = 500;
  16311. t['h'] = 500;
  16312. t['i'] = 278;
  16313. t['j'] = 278;
  16314. t['k'] = 444;
  16315. t['l'] = 278;
  16316. t['m'] = 722;
  16317. t['n'] = 500;
  16318. t['o'] = 500;
  16319. t['p'] = 500;
  16320. t['q'] = 500;
  16321. t['r'] = 389;
  16322. t['s'] = 389;
  16323. t['t'] = 278;
  16324. t['u'] = 500;
  16325. t['v'] = 444;
  16326. t['w'] = 667;
  16327. t['x'] = 444;
  16328. t['y'] = 444;
  16329. t['z'] = 389;
  16330. t['braceleft'] = 400;
  16331. t['bar'] = 275;
  16332. t['braceright'] = 400;
  16333. t['asciitilde'] = 541;
  16334. t['exclamdown'] = 389;
  16335. t['cent'] = 500;
  16336. t['sterling'] = 500;
  16337. t['fraction'] = 167;
  16338. t['yen'] = 500;
  16339. t['florin'] = 500;
  16340. t['section'] = 500;
  16341. t['currency'] = 500;
  16342. t['quotesingle'] = 214;
  16343. t['quotedblleft'] = 556;
  16344. t['guillemotleft'] = 500;
  16345. t['guilsinglleft'] = 333;
  16346. t['guilsinglright'] = 333;
  16347. t['fi'] = 500;
  16348. t['fl'] = 500;
  16349. t['endash'] = 500;
  16350. t['dagger'] = 500;
  16351. t['daggerdbl'] = 500;
  16352. t['periodcentered'] = 250;
  16353. t['paragraph'] = 523;
  16354. t['bullet'] = 350;
  16355. t['quotesinglbase'] = 333;
  16356. t['quotedblbase'] = 556;
  16357. t['quotedblright'] = 556;
  16358. t['guillemotright'] = 500;
  16359. t['ellipsis'] = 889;
  16360. t['perthousand'] = 1000;
  16361. t['questiondown'] = 500;
  16362. t['grave'] = 333;
  16363. t['acute'] = 333;
  16364. t['circumflex'] = 333;
  16365. t['tilde'] = 333;
  16366. t['macron'] = 333;
  16367. t['breve'] = 333;
  16368. t['dotaccent'] = 333;
  16369. t['dieresis'] = 333;
  16370. t['ring'] = 333;
  16371. t['cedilla'] = 333;
  16372. t['hungarumlaut'] = 333;
  16373. t['ogonek'] = 333;
  16374. t['caron'] = 333;
  16375. t['emdash'] = 889;
  16376. t['AE'] = 889;
  16377. t['ordfeminine'] = 276;
  16378. t['Lslash'] = 556;
  16379. t['Oslash'] = 722;
  16380. t['OE'] = 944;
  16381. t['ordmasculine'] = 310;
  16382. t['ae'] = 667;
  16383. t['dotlessi'] = 278;
  16384. t['lslash'] = 278;
  16385. t['oslash'] = 500;
  16386. t['oe'] = 667;
  16387. t['germandbls'] = 500;
  16388. t['Idieresis'] = 333;
  16389. t['eacute'] = 444;
  16390. t['abreve'] = 500;
  16391. t['uhungarumlaut'] = 500;
  16392. t['ecaron'] = 444;
  16393. t['Ydieresis'] = 556;
  16394. t['divide'] = 675;
  16395. t['Yacute'] = 556;
  16396. t['Acircumflex'] = 611;
  16397. t['aacute'] = 500;
  16398. t['Ucircumflex'] = 722;
  16399. t['yacute'] = 444;
  16400. t['scommaaccent'] = 389;
  16401. t['ecircumflex'] = 444;
  16402. t['Uring'] = 722;
  16403. t['Udieresis'] = 722;
  16404. t['aogonek'] = 500;
  16405. t['Uacute'] = 722;
  16406. t['uogonek'] = 500;
  16407. t['Edieresis'] = 611;
  16408. t['Dcroat'] = 722;
  16409. t['commaaccent'] = 250;
  16410. t['copyright'] = 760;
  16411. t['Emacron'] = 611;
  16412. t['ccaron'] = 444;
  16413. t['aring'] = 500;
  16414. t['Ncommaaccent'] = 667;
  16415. t['lacute'] = 278;
  16416. t['agrave'] = 500;
  16417. t['Tcommaaccent'] = 556;
  16418. t['Cacute'] = 667;
  16419. t['atilde'] = 500;
  16420. t['Edotaccent'] = 611;
  16421. t['scaron'] = 389;
  16422. t['scedilla'] = 389;
  16423. t['iacute'] = 278;
  16424. t['lozenge'] = 471;
  16425. t['Rcaron'] = 611;
  16426. t['Gcommaaccent'] = 722;
  16427. t['ucircumflex'] = 500;
  16428. t['acircumflex'] = 500;
  16429. t['Amacron'] = 611;
  16430. t['rcaron'] = 389;
  16431. t['ccedilla'] = 444;
  16432. t['Zdotaccent'] = 556;
  16433. t['Thorn'] = 611;
  16434. t['Omacron'] = 722;
  16435. t['Racute'] = 611;
  16436. t['Sacute'] = 500;
  16437. t['dcaron'] = 544;
  16438. t['Umacron'] = 722;
  16439. t['uring'] = 500;
  16440. t['threesuperior'] = 300;
  16441. t['Ograve'] = 722;
  16442. t['Agrave'] = 611;
  16443. t['Abreve'] = 611;
  16444. t['multiply'] = 675;
  16445. t['uacute'] = 500;
  16446. t['Tcaron'] = 556;
  16447. t['partialdiff'] = 476;
  16448. t['ydieresis'] = 444;
  16449. t['Nacute'] = 667;
  16450. t['icircumflex'] = 278;
  16451. t['Ecircumflex'] = 611;
  16452. t['adieresis'] = 500;
  16453. t['edieresis'] = 444;
  16454. t['cacute'] = 444;
  16455. t['nacute'] = 500;
  16456. t['umacron'] = 500;
  16457. t['Ncaron'] = 667;
  16458. t['Iacute'] = 333;
  16459. t['plusminus'] = 675;
  16460. t['brokenbar'] = 275;
  16461. t['registered'] = 760;
  16462. t['Gbreve'] = 722;
  16463. t['Idotaccent'] = 333;
  16464. t['summation'] = 600;
  16465. t['Egrave'] = 611;
  16466. t['racute'] = 389;
  16467. t['omacron'] = 500;
  16468. t['Zacute'] = 556;
  16469. t['Zcaron'] = 556;
  16470. t['greaterequal'] = 549;
  16471. t['Eth'] = 722;
  16472. t['Ccedilla'] = 667;
  16473. t['lcommaaccent'] = 278;
  16474. t['tcaron'] = 300;
  16475. t['eogonek'] = 444;
  16476. t['Uogonek'] = 722;
  16477. t['Aacute'] = 611;
  16478. t['Adieresis'] = 611;
  16479. t['egrave'] = 444;
  16480. t['zacute'] = 389;
  16481. t['iogonek'] = 278;
  16482. t['Oacute'] = 722;
  16483. t['oacute'] = 500;
  16484. t['amacron'] = 500;
  16485. t['sacute'] = 389;
  16486. t['idieresis'] = 278;
  16487. t['Ocircumflex'] = 722;
  16488. t['Ugrave'] = 722;
  16489. t['Delta'] = 612;
  16490. t['thorn'] = 500;
  16491. t['twosuperior'] = 300;
  16492. t['Odieresis'] = 722;
  16493. t['mu'] = 500;
  16494. t['igrave'] = 278;
  16495. t['ohungarumlaut'] = 500;
  16496. t['Eogonek'] = 611;
  16497. t['dcroat'] = 500;
  16498. t['threequarters'] = 750;
  16499. t['Scedilla'] = 500;
  16500. t['lcaron'] = 300;
  16501. t['Kcommaaccent'] = 667;
  16502. t['Lacute'] = 556;
  16503. t['trademark'] = 980;
  16504. t['edotaccent'] = 444;
  16505. t['Igrave'] = 333;
  16506. t['Imacron'] = 333;
  16507. t['Lcaron'] = 611;
  16508. t['onehalf'] = 750;
  16509. t['lessequal'] = 549;
  16510. t['ocircumflex'] = 500;
  16511. t['ntilde'] = 500;
  16512. t['Uhungarumlaut'] = 722;
  16513. t['Eacute'] = 611;
  16514. t['emacron'] = 444;
  16515. t['gbreve'] = 500;
  16516. t['onequarter'] = 750;
  16517. t['Scaron'] = 500;
  16518. t['Scommaaccent'] = 500;
  16519. t['Ohungarumlaut'] = 722;
  16520. t['degree'] = 400;
  16521. t['ograve'] = 500;
  16522. t['Ccaron'] = 667;
  16523. t['ugrave'] = 500;
  16524. t['radical'] = 453;
  16525. t['Dcaron'] = 722;
  16526. t['rcommaaccent'] = 389;
  16527. t['Ntilde'] = 667;
  16528. t['otilde'] = 500;
  16529. t['Rcommaaccent'] = 611;
  16530. t['Lcommaaccent'] = 556;
  16531. t['Atilde'] = 611;
  16532. t['Aogonek'] = 611;
  16533. t['Aring'] = 611;
  16534. t['Otilde'] = 722;
  16535. t['zdotaccent'] = 389;
  16536. t['Ecaron'] = 611;
  16537. t['Iogonek'] = 333;
  16538. t['kcommaaccent'] = 444;
  16539. t['minus'] = 675;
  16540. t['Icircumflex'] = 333;
  16541. t['ncaron'] = 500;
  16542. t['tcommaaccent'] = 278;
  16543. t['logicalnot'] = 675;
  16544. t['odieresis'] = 500;
  16545. t['udieresis'] = 500;
  16546. t['notequal'] = 549;
  16547. t['gcommaaccent'] = 500;
  16548. t['eth'] = 500;
  16549. t['zcaron'] = 389;
  16550. t['ncommaaccent'] = 500;
  16551. t['onesuperior'] = 300;
  16552. t['imacron'] = 278;
  16553. t['Euro'] = 500;
  16554. });
  16555. t['ZapfDingbats'] = getLookupTableFactory(function (t) {
  16556. t['space'] = 278;
  16557. t['a1'] = 974;
  16558. t['a2'] = 961;
  16559. t['a202'] = 974;
  16560. t['a3'] = 980;
  16561. t['a4'] = 719;
  16562. t['a5'] = 789;
  16563. t['a119'] = 790;
  16564. t['a118'] = 791;
  16565. t['a117'] = 690;
  16566. t['a11'] = 960;
  16567. t['a12'] = 939;
  16568. t['a13'] = 549;
  16569. t['a14'] = 855;
  16570. t['a15'] = 911;
  16571. t['a16'] = 933;
  16572. t['a105'] = 911;
  16573. t['a17'] = 945;
  16574. t['a18'] = 974;
  16575. t['a19'] = 755;
  16576. t['a20'] = 846;
  16577. t['a21'] = 762;
  16578. t['a22'] = 761;
  16579. t['a23'] = 571;
  16580. t['a24'] = 677;
  16581. t['a25'] = 763;
  16582. t['a26'] = 760;
  16583. t['a27'] = 759;
  16584. t['a28'] = 754;
  16585. t['a6'] = 494;
  16586. t['a7'] = 552;
  16587. t['a8'] = 537;
  16588. t['a9'] = 577;
  16589. t['a10'] = 692;
  16590. t['a29'] = 786;
  16591. t['a30'] = 788;
  16592. t['a31'] = 788;
  16593. t['a32'] = 790;
  16594. t['a33'] = 793;
  16595. t['a34'] = 794;
  16596. t['a35'] = 816;
  16597. t['a36'] = 823;
  16598. t['a37'] = 789;
  16599. t['a38'] = 841;
  16600. t['a39'] = 823;
  16601. t['a40'] = 833;
  16602. t['a41'] = 816;
  16603. t['a42'] = 831;
  16604. t['a43'] = 923;
  16605. t['a44'] = 744;
  16606. t['a45'] = 723;
  16607. t['a46'] = 749;
  16608. t['a47'] = 790;
  16609. t['a48'] = 792;
  16610. t['a49'] = 695;
  16611. t['a50'] = 776;
  16612. t['a51'] = 768;
  16613. t['a52'] = 792;
  16614. t['a53'] = 759;
  16615. t['a54'] = 707;
  16616. t['a55'] = 708;
  16617. t['a56'] = 682;
  16618. t['a57'] = 701;
  16619. t['a58'] = 826;
  16620. t['a59'] = 815;
  16621. t['a60'] = 789;
  16622. t['a61'] = 789;
  16623. t['a62'] = 707;
  16624. t['a63'] = 687;
  16625. t['a64'] = 696;
  16626. t['a65'] = 689;
  16627. t['a66'] = 786;
  16628. t['a67'] = 787;
  16629. t['a68'] = 713;
  16630. t['a69'] = 791;
  16631. t['a70'] = 785;
  16632. t['a71'] = 791;
  16633. t['a72'] = 873;
  16634. t['a73'] = 761;
  16635. t['a74'] = 762;
  16636. t['a203'] = 762;
  16637. t['a75'] = 759;
  16638. t['a204'] = 759;
  16639. t['a76'] = 892;
  16640. t['a77'] = 892;
  16641. t['a78'] = 788;
  16642. t['a79'] = 784;
  16643. t['a81'] = 438;
  16644. t['a82'] = 138;
  16645. t['a83'] = 277;
  16646. t['a84'] = 415;
  16647. t['a97'] = 392;
  16648. t['a98'] = 392;
  16649. t['a99'] = 668;
  16650. t['a100'] = 668;
  16651. t['a89'] = 390;
  16652. t['a90'] = 390;
  16653. t['a93'] = 317;
  16654. t['a94'] = 317;
  16655. t['a91'] = 276;
  16656. t['a92'] = 276;
  16657. t['a205'] = 509;
  16658. t['a85'] = 509;
  16659. t['a206'] = 410;
  16660. t['a86'] = 410;
  16661. t['a87'] = 234;
  16662. t['a88'] = 234;
  16663. t['a95'] = 334;
  16664. t['a96'] = 334;
  16665. t['a101'] = 732;
  16666. t['a102'] = 544;
  16667. t['a103'] = 544;
  16668. t['a104'] = 910;
  16669. t['a106'] = 667;
  16670. t['a107'] = 760;
  16671. t['a108'] = 760;
  16672. t['a112'] = 776;
  16673. t['a111'] = 595;
  16674. t['a110'] = 694;
  16675. t['a109'] = 626;
  16676. t['a120'] = 788;
  16677. t['a121'] = 788;
  16678. t['a122'] = 788;
  16679. t['a123'] = 788;
  16680. t['a124'] = 788;
  16681. t['a125'] = 788;
  16682. t['a126'] = 788;
  16683. t['a127'] = 788;
  16684. t['a128'] = 788;
  16685. t['a129'] = 788;
  16686. t['a130'] = 788;
  16687. t['a131'] = 788;
  16688. t['a132'] = 788;
  16689. t['a133'] = 788;
  16690. t['a134'] = 788;
  16691. t['a135'] = 788;
  16692. t['a136'] = 788;
  16693. t['a137'] = 788;
  16694. t['a138'] = 788;
  16695. t['a139'] = 788;
  16696. t['a140'] = 788;
  16697. t['a141'] = 788;
  16698. t['a142'] = 788;
  16699. t['a143'] = 788;
  16700. t['a144'] = 788;
  16701. t['a145'] = 788;
  16702. t['a146'] = 788;
  16703. t['a147'] = 788;
  16704. t['a148'] = 788;
  16705. t['a149'] = 788;
  16706. t['a150'] = 788;
  16707. t['a151'] = 788;
  16708. t['a152'] = 788;
  16709. t['a153'] = 788;
  16710. t['a154'] = 788;
  16711. t['a155'] = 788;
  16712. t['a156'] = 788;
  16713. t['a157'] = 788;
  16714. t['a158'] = 788;
  16715. t['a159'] = 788;
  16716. t['a160'] = 894;
  16717. t['a161'] = 838;
  16718. t['a163'] = 1016;
  16719. t['a164'] = 458;
  16720. t['a196'] = 748;
  16721. t['a165'] = 924;
  16722. t['a192'] = 748;
  16723. t['a166'] = 918;
  16724. t['a167'] = 927;
  16725. t['a168'] = 928;
  16726. t['a169'] = 928;
  16727. t['a170'] = 834;
  16728. t['a171'] = 873;
  16729. t['a172'] = 828;
  16730. t['a173'] = 924;
  16731. t['a162'] = 924;
  16732. t['a174'] = 917;
  16733. t['a175'] = 930;
  16734. t['a176'] = 931;
  16735. t['a177'] = 463;
  16736. t['a178'] = 883;
  16737. t['a179'] = 836;
  16738. t['a193'] = 836;
  16739. t['a180'] = 867;
  16740. t['a199'] = 867;
  16741. t['a181'] = 696;
  16742. t['a200'] = 696;
  16743. t['a182'] = 874;
  16744. t['a201'] = 874;
  16745. t['a183'] = 760;
  16746. t['a184'] = 946;
  16747. t['a197'] = 771;
  16748. t['a185'] = 865;
  16749. t['a194'] = 771;
  16750. t['a198'] = 888;
  16751. t['a186'] = 967;
  16752. t['a195'] = 888;
  16753. t['a187'] = 831;
  16754. t['a188'] = 873;
  16755. t['a189'] = 927;
  16756. t['a190'] = 970;
  16757. t['a191'] = 918;
  16758. });
  16759. });
  16760. exports.getMetrics = getMetrics;
  16761. }));
  16762. (function (root, factory) {
  16763. {
  16764. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  16765. }
  16766. }(this, function (exports, sharedUtil) {
  16767. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  16768. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  16769. // Workaround for missing math precision in JS.
  16770. var MASK_HIGH = 0xffff0000;
  16771. var MASK_LOW = 0xffff;
  16772. function MurmurHash3_64 (seed) {
  16773. var SEED = 0xc3d2e1f0;
  16774. this.h1 = seed ? seed & 0xffffffff : SEED;
  16775. this.h2 = seed ? seed & 0xffffffff : SEED;
  16776. }
  16777. var alwaysUseUint32ArrayView = false;
  16778. // old webkits have issues with non-aligned arrays
  16779. try {
  16780. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  16781. } catch (e) {
  16782. alwaysUseUint32ArrayView = true;
  16783. }
  16784. MurmurHash3_64.prototype = {
  16785. update: function MurmurHash3_64_update(input) {
  16786. var useUint32ArrayView = alwaysUseUint32ArrayView;
  16787. var i;
  16788. if (typeof input === 'string') {
  16789. var data = new Uint8Array(input.length * 2);
  16790. var length = 0;
  16791. for (i = 0; i < input.length; i++) {
  16792. var code = input.charCodeAt(i);
  16793. if (code <= 0xff) {
  16794. data[length++] = code;
  16795. }
  16796. else {
  16797. data[length++] = code >>> 8;
  16798. data[length++] = code & 0xff;
  16799. }
  16800. }
  16801. } else if (input instanceof Uint8Array) {
  16802. data = input;
  16803. length = data.length;
  16804. } else if (typeof input === 'object' && ('length' in input)) {
  16805. // processing regular arrays as well, e.g. for IE9
  16806. data = input;
  16807. length = data.length;
  16808. useUint32ArrayView = true;
  16809. } else {
  16810. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  16811. 'Input must be a string or array.');
  16812. }
  16813. var blockCounts = length >> 2;
  16814. var tailLength = length - blockCounts * 4;
  16815. // we don't care about endianness here
  16816. var dataUint32 = useUint32ArrayView ?
  16817. new Uint32ArrayView(data, blockCounts) :
  16818. new Uint32Array(data.buffer, 0, blockCounts);
  16819. var k1 = 0;
  16820. var k2 = 0;
  16821. var h1 = this.h1;
  16822. var h2 = this.h2;
  16823. var C1 = 0xcc9e2d51;
  16824. var C2 = 0x1b873593;
  16825. var C1_LOW = C1 & MASK_LOW;
  16826. var C2_LOW = C2 & MASK_LOW;
  16827. for (i = 0; i < blockCounts; i++) {
  16828. if (i & 1) {
  16829. k1 = dataUint32[i];
  16830. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  16831. k1 = k1 << 15 | k1 >>> 17;
  16832. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  16833. h1 ^= k1;
  16834. h1 = h1 << 13 | h1 >>> 19;
  16835. h1 = h1 * 5 + 0xe6546b64;
  16836. } else {
  16837. k2 = dataUint32[i];
  16838. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  16839. k2 = k2 << 15 | k2 >>> 17;
  16840. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  16841. h2 ^= k2;
  16842. h2 = h2 << 13 | h2 >>> 19;
  16843. h2 = h2 * 5 + 0xe6546b64;
  16844. }
  16845. }
  16846. k1 = 0;
  16847. switch (tailLength) {
  16848. case 3:
  16849. k1 ^= data[blockCounts * 4 + 2] << 16;
  16850. /* falls through */
  16851. case 2:
  16852. k1 ^= data[blockCounts * 4 + 1] << 8;
  16853. /* falls through */
  16854. case 1:
  16855. k1 ^= data[blockCounts * 4];
  16856. /* falls through */
  16857. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  16858. k1 = k1 << 15 | k1 >>> 17;
  16859. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  16860. if (blockCounts & 1) {
  16861. h1 ^= k1;
  16862. } else {
  16863. h2 ^= k1;
  16864. }
  16865. }
  16866. this.h1 = h1;
  16867. this.h2 = h2;
  16868. return this;
  16869. },
  16870. hexdigest: function MurmurHash3_64_hexdigest () {
  16871. var h1 = this.h1;
  16872. var h2 = this.h2;
  16873. h1 ^= h2 >>> 1;
  16874. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  16875. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  16876. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  16877. h1 ^= h2 >>> 1;
  16878. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  16879. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  16880. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  16881. h1 ^= h2 >>> 1;
  16882. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  16883. var hex = (arr[i] >>> 0).toString(16);
  16884. while (hex.length < 8) {
  16885. hex = '0' + hex;
  16886. }
  16887. str += hex;
  16888. }
  16889. return str;
  16890. }
  16891. };
  16892. return MurmurHash3_64;
  16893. })();
  16894. exports.MurmurHash3_64 = MurmurHash3_64;
  16895. }));
  16896. (function (root, factory) {
  16897. {
  16898. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  16899. }
  16900. }(this, function (exports, sharedUtil) {
  16901. var isArray = sharedUtil.isArray;
  16902. var Name = (function NameClosure() {
  16903. function Name(name) {
  16904. this.name = name;
  16905. }
  16906. Name.prototype = {};
  16907. var nameCache = Object.create(null);
  16908. Name.get = function Name_get(name) {
  16909. var nameValue = nameCache[name];
  16910. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  16911. };
  16912. return Name;
  16913. })();
  16914. var Cmd = (function CmdClosure() {
  16915. function Cmd(cmd) {
  16916. this.cmd = cmd;
  16917. }
  16918. Cmd.prototype = {};
  16919. var cmdCache = Object.create(null);
  16920. Cmd.get = function Cmd_get(cmd) {
  16921. var cmdValue = cmdCache[cmd];
  16922. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  16923. };
  16924. return Cmd;
  16925. })();
  16926. var Dict = (function DictClosure() {
  16927. var nonSerializable = function nonSerializableClosure() {
  16928. return nonSerializable; // creating closure on some variable
  16929. };
  16930. // xref is optional
  16931. function Dict(xref) {
  16932. // Map should only be used internally, use functions below to access.
  16933. this.map = Object.create(null);
  16934. this.xref = xref;
  16935. this.objId = null;
  16936. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  16937. }
  16938. Dict.prototype = {
  16939. assignXref: function Dict_assignXref(newXref) {
  16940. this.xref = newXref;
  16941. },
  16942. // automatically dereferences Ref objects
  16943. get: function Dict_get(key1, key2, key3) {
  16944. var value;
  16945. var xref = this.xref;
  16946. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  16947. typeof key2 === 'undefined') {
  16948. return xref ? xref.fetchIfRef(value) : value;
  16949. }
  16950. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  16951. typeof key3 === 'undefined') {
  16952. return xref ? xref.fetchIfRef(value) : value;
  16953. }
  16954. value = this.map[key3] || null;
  16955. return xref ? xref.fetchIfRef(value) : value;
  16956. },
  16957. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  16958. getAsync: function Dict_getAsync(key1, key2, key3) {
  16959. var value;
  16960. var xref = this.xref;
  16961. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  16962. typeof key2 === 'undefined') {
  16963. if (xref) {
  16964. return xref.fetchIfRefAsync(value);
  16965. }
  16966. return Promise.resolve(value);
  16967. }
  16968. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  16969. typeof key3 === 'undefined') {
  16970. if (xref) {
  16971. return xref.fetchIfRefAsync(value);
  16972. }
  16973. return Promise.resolve(value);
  16974. }
  16975. value = this.map[key3] || null;
  16976. if (xref) {
  16977. return xref.fetchIfRefAsync(value);
  16978. }
  16979. return Promise.resolve(value);
  16980. },
  16981. // Same as get(), but dereferences all elements if the result is an Array.
  16982. getArray: function Dict_getArray(key1, key2, key3) {
  16983. var value = this.get(key1, key2, key3);
  16984. var xref = this.xref;
  16985. if (!isArray(value) || !xref) {
  16986. return value;
  16987. }
  16988. value = value.slice(); // Ensure that we don't modify the Dict data.
  16989. for (var i = 0, ii = value.length; i < ii; i++) {
  16990. if (!isRef(value[i])) {
  16991. continue;
  16992. }
  16993. value[i] = xref.fetch(value[i]);
  16994. }
  16995. return value;
  16996. },
  16997. // no dereferencing
  16998. getRaw: function Dict_getRaw(key) {
  16999. return this.map[key];
  17000. },
  17001. getKeys: function Dict_getKeys() {
  17002. return Object.keys(this.map);
  17003. },
  17004. set: function Dict_set(key, value) {
  17005. this.map[key] = value;
  17006. },
  17007. has: function Dict_has(key) {
  17008. return key in this.map;
  17009. },
  17010. forEach: function Dict_forEach(callback) {
  17011. for (var key in this.map) {
  17012. callback(key, this.get(key));
  17013. }
  17014. }
  17015. };
  17016. Dict.empty = new Dict(null);
  17017. Dict.merge = function Dict_merge(xref, dictArray) {
  17018. var mergedDict = new Dict(xref);
  17019. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  17020. var dict = dictArray[i];
  17021. if (!isDict(dict)) {
  17022. continue;
  17023. }
  17024. for (var keyName in dict.map) {
  17025. if (mergedDict.map[keyName]) {
  17026. continue;
  17027. }
  17028. mergedDict.map[keyName] = dict.map[keyName];
  17029. }
  17030. }
  17031. return mergedDict;
  17032. };
  17033. return Dict;
  17034. })();
  17035. var Ref = (function RefClosure() {
  17036. function Ref(num, gen) {
  17037. this.num = num;
  17038. this.gen = gen;
  17039. }
  17040. Ref.prototype = {
  17041. toString: function Ref_toString() {
  17042. // This function is hot, so we make the string as compact as possible.
  17043. // |this.gen| is almost always zero, so we treat that case specially.
  17044. var str = this.num + 'R';
  17045. if (this.gen !== 0) {
  17046. str += this.gen;
  17047. }
  17048. return str;
  17049. }
  17050. };
  17051. return Ref;
  17052. })();
  17053. // The reference is identified by number and generation.
  17054. // This structure stores only one instance of the reference.
  17055. var RefSet = (function RefSetClosure() {
  17056. function RefSet() {
  17057. this.dict = Object.create(null);
  17058. }
  17059. RefSet.prototype = {
  17060. has: function RefSet_has(ref) {
  17061. return ref.toString() in this.dict;
  17062. },
  17063. put: function RefSet_put(ref) {
  17064. this.dict[ref.toString()] = true;
  17065. },
  17066. remove: function RefSet_remove(ref) {
  17067. delete this.dict[ref.toString()];
  17068. }
  17069. };
  17070. return RefSet;
  17071. })();
  17072. var RefSetCache = (function RefSetCacheClosure() {
  17073. function RefSetCache() {
  17074. this.dict = Object.create(null);
  17075. }
  17076. RefSetCache.prototype = {
  17077. get: function RefSetCache_get(ref) {
  17078. return this.dict[ref.toString()];
  17079. },
  17080. has: function RefSetCache_has(ref) {
  17081. return ref.toString() in this.dict;
  17082. },
  17083. put: function RefSetCache_put(ref, obj) {
  17084. this.dict[ref.toString()] = obj;
  17085. },
  17086. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  17087. this.dict[ref.toString()] = this.get(aliasRef);
  17088. },
  17089. forEach: function RefSetCache_forEach(fn, thisArg) {
  17090. for (var i in this.dict) {
  17091. fn.call(thisArg, this.dict[i]);
  17092. }
  17093. },
  17094. clear: function RefSetCache_clear() {
  17095. this.dict = Object.create(null);
  17096. }
  17097. };
  17098. return RefSetCache;
  17099. })();
  17100. function isName(v, name) {
  17101. return v instanceof Name && (name === undefined || v.name === name);
  17102. }
  17103. function isCmd(v, cmd) {
  17104. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  17105. }
  17106. function isDict(v, type) {
  17107. return v instanceof Dict &&
  17108. (type === undefined || isName(v.get('Type'), type));
  17109. }
  17110. function isRef(v) {
  17111. return v instanceof Ref;
  17112. }
  17113. function isRefsEqual(v1, v2) {
  17114. return v1.num === v2.num && v1.gen === v2.gen;
  17115. }
  17116. function isStream(v) {
  17117. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  17118. }
  17119. exports.Cmd = Cmd;
  17120. exports.Dict = Dict;
  17121. exports.Name = Name;
  17122. exports.Ref = Ref;
  17123. exports.RefSet = RefSet;
  17124. exports.RefSetCache = RefSetCache;
  17125. exports.isCmd = isCmd;
  17126. exports.isDict = isDict;
  17127. exports.isName = isName;
  17128. exports.isRef = isRef;
  17129. exports.isRefsEqual = isRefsEqual;
  17130. exports.isStream = isStream;
  17131. }));
  17132. (function (root, factory) {
  17133. {
  17134. factory((root.pdfjsCoreStandardFonts = {}), root.pdfjsSharedUtil);
  17135. }
  17136. }(this, function (exports, sharedUtil) {
  17137. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  17138. /**
  17139. * Hold a map of decoded fonts and of the standard fourteen Type1
  17140. * fonts and their acronyms.
  17141. */
  17142. var getStdFontMap = getLookupTableFactory(function (t) {
  17143. t['ArialNarrow'] = 'Helvetica';
  17144. t['ArialNarrow-Bold'] = 'Helvetica-Bold';
  17145. t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique';
  17146. t['ArialNarrow-Italic'] = 'Helvetica-Oblique';
  17147. t['ArialBlack'] = 'Helvetica';
  17148. t['ArialBlack-Bold'] = 'Helvetica-Bold';
  17149. t['ArialBlack-BoldItalic'] = 'Helvetica-BoldOblique';
  17150. t['ArialBlack-Italic'] = 'Helvetica-Oblique';
  17151. t['Arial'] = 'Helvetica';
  17152. t['Arial-Bold'] = 'Helvetica-Bold';
  17153. t['Arial-BoldItalic'] = 'Helvetica-BoldOblique';
  17154. t['Arial-Italic'] = 'Helvetica-Oblique';
  17155. t['Arial-BoldItalicMT'] = 'Helvetica-BoldOblique';
  17156. t['Arial-BoldMT'] = 'Helvetica-Bold';
  17157. t['Arial-ItalicMT'] = 'Helvetica-Oblique';
  17158. t['ArialMT'] = 'Helvetica';
  17159. t['Courier-Bold'] = 'Courier-Bold';
  17160. t['Courier-BoldItalic'] = 'Courier-BoldOblique';
  17161. t['Courier-Italic'] = 'Courier-Oblique';
  17162. t['CourierNew'] = 'Courier';
  17163. t['CourierNew-Bold'] = 'Courier-Bold';
  17164. t['CourierNew-BoldItalic'] = 'Courier-BoldOblique';
  17165. t['CourierNew-Italic'] = 'Courier-Oblique';
  17166. t['CourierNewPS-BoldItalicMT'] = 'Courier-BoldOblique';
  17167. t['CourierNewPS-BoldMT'] = 'Courier-Bold';
  17168. t['CourierNewPS-ItalicMT'] = 'Courier-Oblique';
  17169. t['CourierNewPSMT'] = 'Courier';
  17170. t['Helvetica'] = 'Helvetica';
  17171. t['Helvetica-Bold'] = 'Helvetica-Bold';
  17172. t['Helvetica-BoldItalic'] = 'Helvetica-BoldOblique';
  17173. t['Helvetica-BoldOblique'] = 'Helvetica-BoldOblique';
  17174. t['Helvetica-Italic'] = 'Helvetica-Oblique';
  17175. t['Helvetica-Oblique'] = 'Helvetica-Oblique';
  17176. t['Symbol-Bold'] = 'Symbol';
  17177. t['Symbol-BoldItalic'] = 'Symbol';
  17178. t['Symbol-Italic'] = 'Symbol';
  17179. t['TimesNewRoman'] = 'Times-Roman';
  17180. t['TimesNewRoman-Bold'] = 'Times-Bold';
  17181. t['TimesNewRoman-BoldItalic'] = 'Times-BoldItalic';
  17182. t['TimesNewRoman-Italic'] = 'Times-Italic';
  17183. t['TimesNewRomanPS'] = 'Times-Roman';
  17184. t['TimesNewRomanPS-Bold'] = 'Times-Bold';
  17185. t['TimesNewRomanPS-BoldItalic'] = 'Times-BoldItalic';
  17186. t['TimesNewRomanPS-BoldItalicMT'] = 'Times-BoldItalic';
  17187. t['TimesNewRomanPS-BoldMT'] = 'Times-Bold';
  17188. t['TimesNewRomanPS-Italic'] = 'Times-Italic';
  17189. t['TimesNewRomanPS-ItalicMT'] = 'Times-Italic';
  17190. t['TimesNewRomanPSMT'] = 'Times-Roman';
  17191. t['TimesNewRomanPSMT-Bold'] = 'Times-Bold';
  17192. t['TimesNewRomanPSMT-BoldItalic'] = 'Times-BoldItalic';
  17193. t['TimesNewRomanPSMT-Italic'] = 'Times-Italic';
  17194. });
  17195. /**
  17196. * Holds the map of the non-standard fonts that might be included as
  17197. * a standard fonts without glyph data.
  17198. */
  17199. var getNonStdFontMap = getLookupTableFactory(function (t) {
  17200. t['CenturyGothic'] = 'Helvetica';
  17201. t['CenturyGothic-Bold'] = 'Helvetica-Bold';
  17202. t['CenturyGothic-BoldItalic'] = 'Helvetica-BoldOblique';
  17203. t['CenturyGothic-Italic'] = 'Helvetica-Oblique';
  17204. t['ComicSansMS'] = 'Comic Sans MS';
  17205. t['ComicSansMS-Bold'] = 'Comic Sans MS-Bold';
  17206. t['ComicSansMS-BoldItalic'] = 'Comic Sans MS-BoldItalic';
  17207. t['ComicSansMS-Italic'] = 'Comic Sans MS-Italic';
  17208. t['LucidaConsole'] = 'Courier';
  17209. t['LucidaConsole-Bold'] = 'Courier-Bold';
  17210. t['LucidaConsole-BoldItalic'] = 'Courier-BoldOblique';
  17211. t['LucidaConsole-Italic'] = 'Courier-Oblique';
  17212. t['MS-Gothic'] = 'MS Gothic';
  17213. t['MS-Gothic-Bold'] = 'MS Gothic-Bold';
  17214. t['MS-Gothic-BoldItalic'] = 'MS Gothic-BoldItalic';
  17215. t['MS-Gothic-Italic'] = 'MS Gothic-Italic';
  17216. t['MS-Mincho'] = 'MS Mincho';
  17217. t['MS-Mincho-Bold'] = 'MS Mincho-Bold';
  17218. t['MS-Mincho-BoldItalic'] = 'MS Mincho-BoldItalic';
  17219. t['MS-Mincho-Italic'] = 'MS Mincho-Italic';
  17220. t['MS-PGothic'] = 'MS PGothic';
  17221. t['MS-PGothic-Bold'] = 'MS PGothic-Bold';
  17222. t['MS-PGothic-BoldItalic'] = 'MS PGothic-BoldItalic';
  17223. t['MS-PGothic-Italic'] = 'MS PGothic-Italic';
  17224. t['MS-PMincho'] = 'MS PMincho';
  17225. t['MS-PMincho-Bold'] = 'MS PMincho-Bold';
  17226. t['MS-PMincho-BoldItalic'] = 'MS PMincho-BoldItalic';
  17227. t['MS-PMincho-Italic'] = 'MS PMincho-Italic';
  17228. t['Wingdings'] = 'ZapfDingbats';
  17229. });
  17230. var getSerifFonts = getLookupTableFactory(function (t) {
  17231. t['Adobe Jenson'] = true;
  17232. t['Adobe Text'] = true;
  17233. t['Albertus'] = true;
  17234. t['Aldus'] = true;
  17235. t['Alexandria'] = true;
  17236. t['Algerian'] = true;
  17237. t['American Typewriter'] = true;
  17238. t['Antiqua'] = true;
  17239. t['Apex'] = true;
  17240. t['Arno'] = true;
  17241. t['Aster'] = true;
  17242. t['Aurora'] = true;
  17243. t['Baskerville'] = true;
  17244. t['Bell'] = true;
  17245. t['Bembo'] = true;
  17246. t['Bembo Schoolbook'] = true;
  17247. t['Benguiat'] = true;
  17248. t['Berkeley Old Style'] = true;
  17249. t['Bernhard Modern'] = true;
  17250. t['Berthold City'] = true;
  17251. t['Bodoni'] = true;
  17252. t['Bauer Bodoni'] = true;
  17253. t['Book Antiqua'] = true;
  17254. t['Bookman'] = true;
  17255. t['Bordeaux Roman'] = true;
  17256. t['Californian FB'] = true;
  17257. t['Calisto'] = true;
  17258. t['Calvert'] = true;
  17259. t['Capitals'] = true;
  17260. t['Cambria'] = true;
  17261. t['Cartier'] = true;
  17262. t['Caslon'] = true;
  17263. t['Catull'] = true;
  17264. t['Centaur'] = true;
  17265. t['Century Old Style'] = true;
  17266. t['Century Schoolbook'] = true;
  17267. t['Chaparral'] = true;
  17268. t['Charis SIL'] = true;
  17269. t['Cheltenham'] = true;
  17270. t['Cholla Slab'] = true;
  17271. t['Clarendon'] = true;
  17272. t['Clearface'] = true;
  17273. t['Cochin'] = true;
  17274. t['Colonna'] = true;
  17275. t['Computer Modern'] = true;
  17276. t['Concrete Roman'] = true;
  17277. t['Constantia'] = true;
  17278. t['Cooper Black'] = true;
  17279. t['Corona'] = true;
  17280. t['Ecotype'] = true;
  17281. t['Egyptienne'] = true;
  17282. t['Elephant'] = true;
  17283. t['Excelsior'] = true;
  17284. t['Fairfield'] = true;
  17285. t['FF Scala'] = true;
  17286. t['Folkard'] = true;
  17287. t['Footlight'] = true;
  17288. t['FreeSerif'] = true;
  17289. t['Friz Quadrata'] = true;
  17290. t['Garamond'] = true;
  17291. t['Gentium'] = true;
  17292. t['Georgia'] = true;
  17293. t['Gloucester'] = true;
  17294. t['Goudy Old Style'] = true;
  17295. t['Goudy Schoolbook'] = true;
  17296. t['Goudy Pro Font'] = true;
  17297. t['Granjon'] = true;
  17298. t['Guardian Egyptian'] = true;
  17299. t['Heather'] = true;
  17300. t['Hercules'] = true;
  17301. t['High Tower Text'] = true;
  17302. t['Hiroshige'] = true;
  17303. t['Hoefler Text'] = true;
  17304. t['Humana Serif'] = true;
  17305. t['Imprint'] = true;
  17306. t['Ionic No. 5'] = true;
  17307. t['Janson'] = true;
  17308. t['Joanna'] = true;
  17309. t['Korinna'] = true;
  17310. t['Lexicon'] = true;
  17311. t['Liberation Serif'] = true;
  17312. t['Linux Libertine'] = true;
  17313. t['Literaturnaya'] = true;
  17314. t['Lucida'] = true;
  17315. t['Lucida Bright'] = true;
  17316. t['Melior'] = true;
  17317. t['Memphis'] = true;
  17318. t['Miller'] = true;
  17319. t['Minion'] = true;
  17320. t['Modern'] = true;
  17321. t['Mona Lisa'] = true;
  17322. t['Mrs Eaves'] = true;
  17323. t['MS Serif'] = true;
  17324. t['Museo Slab'] = true;
  17325. t['New York'] = true;
  17326. t['Nimbus Roman'] = true;
  17327. t['NPS Rawlinson Roadway'] = true;
  17328. t['Palatino'] = true;
  17329. t['Perpetua'] = true;
  17330. t['Plantin'] = true;
  17331. t['Plantin Schoolbook'] = true;
  17332. t['Playbill'] = true;
  17333. t['Poor Richard'] = true;
  17334. t['Rawlinson Roadway'] = true;
  17335. t['Renault'] = true;
  17336. t['Requiem'] = true;
  17337. t['Rockwell'] = true;
  17338. t['Roman'] = true;
  17339. t['Rotis Serif'] = true;
  17340. t['Sabon'] = true;
  17341. t['Scala'] = true;
  17342. t['Seagull'] = true;
  17343. t['Sistina'] = true;
  17344. t['Souvenir'] = true;
  17345. t['STIX'] = true;
  17346. t['Stone Informal'] = true;
  17347. t['Stone Serif'] = true;
  17348. t['Sylfaen'] = true;
  17349. t['Times'] = true;
  17350. t['Trajan'] = true;
  17351. t['Trinité'] = true;
  17352. t['Trump Mediaeval'] = true;
  17353. t['Utopia'] = true;
  17354. t['Vale Type'] = true;
  17355. t['Bitstream Vera'] = true;
  17356. t['Vera Serif'] = true;
  17357. t['Versailles'] = true;
  17358. t['Wanted'] = true;
  17359. t['Weiss'] = true;
  17360. t['Wide Latin'] = true;
  17361. t['Windsor'] = true;
  17362. t['XITS'] = true;
  17363. });
  17364. var getSymbolsFonts = getLookupTableFactory(function (t) {
  17365. t['Dingbats'] = true;
  17366. t['Symbol'] = true;
  17367. t['ZapfDingbats'] = true;
  17368. });
  17369. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
  17370. // fonts, but does not embed the CID to GID mapping. The mapping is incomplete
  17371. // for all glyphs, but common for some set of the standard fonts.
  17372. var getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  17373. t[2] = 10; t[3] = 32; t[4] = 33; t[5] = 34; t[6] = 35; t[7] = 36; t[8] = 37;
  17374. t[9] = 38; t[10] = 39; t[11] = 40; t[12] = 41; t[13] = 42; t[14] = 43;
  17375. t[15] = 44; t[16] = 45; t[17] = 46; t[18] = 47; t[19] = 48; t[20] = 49;
  17376. t[21] = 50; t[22] = 51; t[23] = 52; t[24] = 53; t[25] = 54; t[26] = 55;
  17377. t[27] = 56; t[28] = 57; t[29] = 58; t[30] = 894; t[31] = 60; t[32] = 61;
  17378. t[33] = 62; t[34] = 63; t[35] = 64; t[36] = 65; t[37] = 66; t[38] = 67;
  17379. t[39] = 68; t[40] = 69; t[41] = 70; t[42] = 71; t[43] = 72; t[44] = 73;
  17380. t[45] = 74; t[46] = 75; t[47] = 76; t[48] = 77; t[49] = 78; t[50] = 79;
  17381. t[51] = 80; t[52] = 81; t[53] = 82; t[54] = 83; t[55] = 84; t[56] = 85;
  17382. t[57] = 86; t[58] = 87; t[59] = 88; t[60] = 89; t[61] = 90; t[62] = 91;
  17383. t[63] = 92; t[64] = 93; t[65] = 94; t[66] = 95; t[67] = 96; t[68] = 97;
  17384. t[69] = 98; t[70] = 99; t[71] = 100; t[72] = 101; t[73] = 102; t[74] = 103;
  17385. t[75] = 104; t[76] = 105; t[77] = 106; t[78] = 107; t[79] = 108;
  17386. t[80] = 109; t[81] = 110; t[82] = 111; t[83] = 112; t[84] = 113;
  17387. t[85] = 114; t[86] = 115; t[87] = 116; t[88] = 117; t[89] = 118;
  17388. t[90] = 119; t[91] = 120; t[92] = 121; t[93] = 122; t[94] = 123;
  17389. t[95] = 124; t[96] = 125; t[97] = 126; t[98] = 196; t[99] = 197;
  17390. t[100] = 199; t[101] = 201; t[102] = 209; t[103] = 214; t[104] = 220;
  17391. t[105] = 225; t[106] = 224; t[107] = 226; t[108] = 228; t[109] = 227;
  17392. t[110] = 229; t[111] = 231; t[112] = 233; t[113] = 232; t[114] = 234;
  17393. t[115] = 235; t[116] = 237; t[117] = 236; t[118] = 238; t[119] = 239;
  17394. t[120] = 241; t[121] = 243; t[122] = 242; t[123] = 244; t[124] = 246;
  17395. t[125] = 245; t[126] = 250; t[127] = 249; t[128] = 251; t[129] = 252;
  17396. t[130] = 8224; t[131] = 176; t[132] = 162; t[133] = 163; t[134] = 167;
  17397. t[135] = 8226; t[136] = 182; t[137] = 223; t[138] = 174; t[139] = 169;
  17398. t[140] = 8482; t[141] = 180; t[142] = 168; t[143] = 8800; t[144] = 198;
  17399. t[145] = 216; t[146] = 8734; t[147] = 177; t[148] = 8804; t[149] = 8805;
  17400. t[150] = 165; t[151] = 181; t[152] = 8706; t[153] = 8721; t[154] = 8719;
  17401. t[156] = 8747; t[157] = 170; t[158] = 186; t[159] = 8486; t[160] = 230;
  17402. t[161] = 248; t[162] = 191; t[163] = 161; t[164] = 172; t[165] = 8730;
  17403. t[166] = 402; t[167] = 8776; t[168] = 8710; t[169] = 171; t[170] = 187;
  17404. t[171] = 8230; t[210] = 218; t[223] = 711; t[224] = 321; t[225] = 322;
  17405. t[227] = 353; t[229] = 382; t[234] = 253; t[252] = 263; t[253] = 268;
  17406. t[254] = 269; t[258] = 258; t[260] = 260; t[261] = 261; t[265] = 280;
  17407. t[266] = 281; t[268] = 283; t[269] = 313; t[275] = 323; t[276] = 324;
  17408. t[278] = 328; t[284] = 345; t[285] = 346; t[286] = 347; t[292] = 367;
  17409. t[295] = 377; t[296] = 378; t[298] = 380; t[305] = 963; t[306] = 964;
  17410. t[307] = 966; t[308] = 8215; t[309] = 8252; t[310] = 8319; t[311] = 8359;
  17411. t[312] = 8592; t[313] = 8593; t[337] = 9552; t[493] = 1039;
  17412. t[494] = 1040; t[705] = 1524; t[706] = 8362; t[710] = 64288; t[711] = 64298;
  17413. t[759] = 1617; t[761] = 1776; t[763] = 1778; t[775] = 1652; t[777] = 1764;
  17414. t[778] = 1780; t[779] = 1781; t[780] = 1782; t[782] = 771; t[783] = 64726;
  17415. t[786] = 8363; t[788] = 8532; t[790] = 768; t[791] = 769; t[792] = 768;
  17416. t[795] = 803; t[797] = 64336; t[798] = 64337; t[799] = 64342;
  17417. t[800] = 64343; t[801] = 64344; t[802] = 64345; t[803] = 64362;
  17418. t[804] = 64363; t[805] = 64364; t[2424] = 7821; t[2425] = 7822;
  17419. t[2426] = 7823; t[2427] = 7824; t[2428] = 7825; t[2429] = 7826;
  17420. t[2430] = 7827; t[2433] = 7682; t[2678] = 8045; t[2679] = 8046;
  17421. t[2830] = 1552; t[2838] = 686; t[2840] = 751; t[2842] = 753; t[2843] = 754;
  17422. t[2844] = 755; t[2846] = 757; t[2856] = 767; t[2857] = 848; t[2858] = 849;
  17423. t[2862] = 853; t[2863] = 854; t[2864] = 855; t[2865] = 861; t[2866] = 862;
  17424. t[2906] = 7460; t[2908] = 7462; t[2909] = 7463; t[2910] = 7464;
  17425. t[2912] = 7466; t[2913] = 7467; t[2914] = 7468; t[2916] = 7470;
  17426. t[2917] = 7471; t[2918] = 7472; t[2920] = 7474; t[2921] = 7475;
  17427. t[2922] = 7476; t[2924] = 7478; t[2925] = 7479; t[2926] = 7480;
  17428. t[2928] = 7482; t[2929] = 7483; t[2930] = 7484; t[2932] = 7486;
  17429. t[2933] = 7487; t[2934] = 7488; t[2936] = 7490; t[2937] = 7491;
  17430. t[2938] = 7492; t[2940] = 7494; t[2941] = 7495; t[2942] = 7496;
  17431. t[2944] = 7498; t[2946] = 7500; t[2948] = 7502; t[2950] = 7504;
  17432. t[2951] = 7505; t[2952] = 7506; t[2954] = 7508; t[2955] = 7509;
  17433. t[2956] = 7510; t[2958] = 7512; t[2959] = 7513; t[2960] = 7514;
  17434. t[2962] = 7516; t[2963] = 7517; t[2964] = 7518; t[2966] = 7520;
  17435. t[2967] = 7521; t[2968] = 7522; t[2970] = 7524; t[2971] = 7525;
  17436. t[2972] = 7526; t[2974] = 7528; t[2975] = 7529; t[2976] = 7530;
  17437. t[2978] = 1537; t[2979] = 1538; t[2980] = 1539; t[2982] = 1549;
  17438. t[2983] = 1551; t[2984] = 1552; t[2986] = 1554; t[2987] = 1555;
  17439. t[2988] = 1556; t[2990] = 1623; t[2991] = 1624; t[2995] = 1775;
  17440. t[2999] = 1791; t[3002] = 64290; t[3003] = 64291; t[3004] = 64292;
  17441. t[3006] = 64294; t[3007] = 64295; t[3008] = 64296; t[3011] = 1900;
  17442. t[3014] = 8223; t[3015] = 8244; t[3017] = 7532; t[3018] = 7533;
  17443. t[3019] = 7534; t[3075] = 7590; t[3076] = 7591; t[3079] = 7594;
  17444. t[3080] = 7595; t[3083] = 7598; t[3084] = 7599; t[3087] = 7602;
  17445. t[3088] = 7603; t[3091] = 7606; t[3092] = 7607; t[3095] = 7610;
  17446. t[3096] = 7611; t[3099] = 7614; t[3100] = 7615; t[3103] = 7618;
  17447. t[3104] = 7619; t[3107] = 8337; t[3108] = 8338; t[3116] = 1884;
  17448. t[3119] = 1885; t[3120] = 1885; t[3123] = 1886; t[3124] = 1886;
  17449. t[3127] = 1887; t[3128] = 1887; t[3131] = 1888; t[3132] = 1888;
  17450. t[3135] = 1889; t[3136] = 1889; t[3139] = 1890; t[3140] = 1890;
  17451. t[3143] = 1891; t[3144] = 1891; t[3147] = 1892; t[3148] = 1892;
  17452. t[3153] = 580; t[3154] = 581; t[3157] = 584; t[3158] = 585; t[3161] = 588;
  17453. t[3162] = 589; t[3165] = 891; t[3166] = 892; t[3169] = 1274; t[3170] = 1275;
  17454. t[3173] = 1278; t[3174] = 1279; t[3181] = 7622; t[3182] = 7623;
  17455. t[3282] = 11799; t[3316] = 578; t[3379] = 42785; t[3393] = 1159;
  17456. t[3416] = 8377;
  17457. });
  17458. // The glyph map for ArialBlack differs slightly from the glyph map used for
  17459. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  17460. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  17461. var getSupplementalGlyphMapForArialBlack =
  17462. getLookupTableFactory(function (t) {
  17463. t[227] = 322; t[264] = 261; t[291] = 346;
  17464. });
  17465. exports.getStdFontMap = getStdFontMap;
  17466. exports.getNonStdFontMap = getNonStdFontMap;
  17467. exports.getSerifFonts = getSerifFonts;
  17468. exports.getSymbolsFonts = getSymbolsFonts;
  17469. exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts;
  17470. exports.getSupplementalGlyphMapForArialBlack =
  17471. getSupplementalGlyphMapForArialBlack;
  17472. }));
  17473. (function (root, factory) {
  17474. {
  17475. factory((root.pdfjsCoreUnicode = {}), root.pdfjsSharedUtil);
  17476. }
  17477. }(this, function (exports, sharedUtil) {
  17478. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  17479. // Some characters, e.g. copyrightserif, are mapped to the private use area
  17480. // and might not be displayed using standard fonts. Mapping/hacking well-known
  17481. // chars to the similar equivalents in the normal characters range.
  17482. var getSpecialPUASymbols = getLookupTableFactory(function (t) {
  17483. t[63721] = 0x00A9; // copyrightsans (0xF8E9) => copyright
  17484. t[63193] = 0x00A9; // copyrightserif (0xF6D9) => copyright
  17485. t[63720] = 0x00AE; // registersans (0xF8E8) => registered
  17486. t[63194] = 0x00AE; // registerserif (0xF6DA) => registered
  17487. t[63722] = 0x2122; // trademarksans (0xF8EA) => trademark
  17488. t[63195] = 0x2122; // trademarkserif (0xF6DB) => trademark
  17489. t[63729] = 0x23A7; // bracelefttp (0xF8F1)
  17490. t[63730] = 0x23A8; // braceleftmid (0xF8F2)
  17491. t[63731] = 0x23A9; // braceleftbt (0xF8F3)
  17492. t[63740] = 0x23AB; // bracerighttp (0xF8FC)
  17493. t[63741] = 0x23AC; // bracerightmid (0xF8FD)
  17494. t[63742] = 0x23AD; // bracerightbt (0xF8FE)
  17495. t[63726] = 0x23A1; // bracketlefttp (0xF8EE)
  17496. t[63727] = 0x23A2; // bracketleftex (0xF8EF)
  17497. t[63728] = 0x23A3; // bracketleftbt (0xF8F0)
  17498. t[63737] = 0x23A4; // bracketrighttp (0xF8F9)
  17499. t[63738] = 0x23A5; // bracketrightex (0xF8FA)
  17500. t[63739] = 0x23A6; // bracketrightbt (0xF8FB)
  17501. t[63723] = 0x239B; // parenlefttp (0xF8EB)
  17502. t[63724] = 0x239C; // parenleftex (0xF8EC)
  17503. t[63725] = 0x239D; // parenleftbt (0xF8ED)
  17504. t[63734] = 0x239E; // parenrighttp (0xF8F6)
  17505. t[63735] = 0x239F; // parenrightex (0xF8F7)
  17506. t[63736] = 0x23A0; // parenrightbt (0xF8F8)
  17507. });
  17508. function mapSpecialUnicodeValues(code) {
  17509. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  17510. return 0;
  17511. } else if (code >= 0xF600 && code <= 0xF8FF) {
  17512. return (getSpecialPUASymbols()[code] || code);
  17513. }
  17514. return code;
  17515. }
  17516. function getUnicodeForGlyph(name, glyphsUnicodeMap) {
  17517. var unicode = glyphsUnicodeMap[name];
  17518. if (unicode !== undefined) {
  17519. return unicode;
  17520. }
  17521. if (!name) {
  17522. return -1;
  17523. }
  17524. // Try to recover valid Unicode values from 'uniXXXX'/'uXXXX{XX}' glyphs.
  17525. if (name[0] === 'u') {
  17526. var nameLen = name.length, hexStr;
  17527. if (nameLen === 7 && name[1] === 'n' && name[2] === 'i') { // 'uniXXXX'
  17528. hexStr = name.substr(3);
  17529. } else if (nameLen >= 5 && nameLen <= 7) { // 'uXXXX{XX}'
  17530. hexStr = name.substr(1);
  17531. } else {
  17532. return -1;
  17533. }
  17534. // Check for upper-case hexadecimal characters, to avoid false positives.
  17535. if (hexStr === hexStr.toUpperCase()) {
  17536. unicode = parseInt(hexStr, 16);
  17537. if (unicode >= 0) {
  17538. return unicode;
  17539. }
  17540. }
  17541. }
  17542. return -1;
  17543. }
  17544. var UnicodeRanges = [
  17545. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  17546. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  17547. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  17548. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  17549. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  17550. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  17551. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  17552. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  17553. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  17554. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  17555. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  17556. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  17557. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  17558. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  17559. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  17560. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  17561. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  17562. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  17563. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  17564. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  17565. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  17566. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  17567. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  17568. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  17569. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  17570. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  17571. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  17572. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  17573. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  17574. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  17575. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  17576. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  17577. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  17578. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  17579. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks
  17580. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  17581. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  17582. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  17583. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  17584. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  17585. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  17586. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  17587. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  17588. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  17589. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  17590. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  17591. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  17592. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  17593. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  17594. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  17595. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  17596. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  17597. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  17598. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  17599. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  17600. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  17601. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  17602. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  17603. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  17604. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  17605. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  17606. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  17607. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  17608. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  17609. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  17610. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  17611. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  17612. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  17613. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  17614. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  17615. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  17616. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  17617. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  17618. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  17619. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  17620. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  17621. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  17622. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  17623. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  17624. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  17625. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  17626. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  17627. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  17628. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  17629. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  17630. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  17631. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  17632. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  17633. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  17634. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  17635. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  17636. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  17637. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  17638. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  17639. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  17640. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  17641. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  17642. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  17643. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  17644. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  17645. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  17646. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  17647. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  17648. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  17649. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  17650. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  17651. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  17652. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  17653. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  17654. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  17655. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  17656. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  17657. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  17658. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  17659. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  17660. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  17661. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  17662. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  17663. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  17664. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  17665. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  17666. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  17667. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  17668. ];
  17669. function getUnicodeRangeFor(value) {
  17670. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  17671. var range = UnicodeRanges[i];
  17672. if (value >= range.begin && value < range.end) {
  17673. return i;
  17674. }
  17675. }
  17676. return -1;
  17677. }
  17678. function isRTLRangeFor(value) {
  17679. var range = UnicodeRanges[13];
  17680. if (value >= range.begin && value < range.end) {
  17681. return true;
  17682. }
  17683. range = UnicodeRanges[11];
  17684. if (value >= range.begin && value < range.end) {
  17685. return true;
  17686. }
  17687. return false;
  17688. }
  17689. // The normalization table is obtained by filtering the Unicode characters
  17690. // database with <compat> entries.
  17691. var getNormalizedUnicodes = getLookupTableFactory(function (t) {
  17692. t['\u00A8'] = '\u0020\u0308';
  17693. t['\u00AF'] = '\u0020\u0304';
  17694. t['\u00B4'] = '\u0020\u0301';
  17695. t['\u00B5'] = '\u03BC';
  17696. t['\u00B8'] = '\u0020\u0327';
  17697. t['\u0132'] = '\u0049\u004A';
  17698. t['\u0133'] = '\u0069\u006A';
  17699. t['\u013F'] = '\u004C\u00B7';
  17700. t['\u0140'] = '\u006C\u00B7';
  17701. t['\u0149'] = '\u02BC\u006E';
  17702. t['\u017F'] = '\u0073';
  17703. t['\u01C4'] = '\u0044\u017D';
  17704. t['\u01C5'] = '\u0044\u017E';
  17705. t['\u01C6'] = '\u0064\u017E';
  17706. t['\u01C7'] = '\u004C\u004A';
  17707. t['\u01C8'] = '\u004C\u006A';
  17708. t['\u01C9'] = '\u006C\u006A';
  17709. t['\u01CA'] = '\u004E\u004A';
  17710. t['\u01CB'] = '\u004E\u006A';
  17711. t['\u01CC'] = '\u006E\u006A';
  17712. t['\u01F1'] = '\u0044\u005A';
  17713. t['\u01F2'] = '\u0044\u007A';
  17714. t['\u01F3'] = '\u0064\u007A';
  17715. t['\u02D8'] = '\u0020\u0306';
  17716. t['\u02D9'] = '\u0020\u0307';
  17717. t['\u02DA'] = '\u0020\u030A';
  17718. t['\u02DB'] = '\u0020\u0328';
  17719. t['\u02DC'] = '\u0020\u0303';
  17720. t['\u02DD'] = '\u0020\u030B';
  17721. t['\u037A'] = '\u0020\u0345';
  17722. t['\u0384'] = '\u0020\u0301';
  17723. t['\u03D0'] = '\u03B2';
  17724. t['\u03D1'] = '\u03B8';
  17725. t['\u03D2'] = '\u03A5';
  17726. t['\u03D5'] = '\u03C6';
  17727. t['\u03D6'] = '\u03C0';
  17728. t['\u03F0'] = '\u03BA';
  17729. t['\u03F1'] = '\u03C1';
  17730. t['\u03F2'] = '\u03C2';
  17731. t['\u03F4'] = '\u0398';
  17732. t['\u03F5'] = '\u03B5';
  17733. t['\u03F9'] = '\u03A3';
  17734. t['\u0587'] = '\u0565\u0582';
  17735. t['\u0675'] = '\u0627\u0674';
  17736. t['\u0676'] = '\u0648\u0674';
  17737. t['\u0677'] = '\u06C7\u0674';
  17738. t['\u0678'] = '\u064A\u0674';
  17739. t['\u0E33'] = '\u0E4D\u0E32';
  17740. t['\u0EB3'] = '\u0ECD\u0EB2';
  17741. t['\u0EDC'] = '\u0EAB\u0E99';
  17742. t['\u0EDD'] = '\u0EAB\u0EA1';
  17743. t['\u0F77'] = '\u0FB2\u0F81';
  17744. t['\u0F79'] = '\u0FB3\u0F81';
  17745. t['\u1E9A'] = '\u0061\u02BE';
  17746. t['\u1FBD'] = '\u0020\u0313';
  17747. t['\u1FBF'] = '\u0020\u0313';
  17748. t['\u1FC0'] = '\u0020\u0342';
  17749. t['\u1FFE'] = '\u0020\u0314';
  17750. t['\u2002'] = '\u0020';
  17751. t['\u2003'] = '\u0020';
  17752. t['\u2004'] = '\u0020';
  17753. t['\u2005'] = '\u0020';
  17754. t['\u2006'] = '\u0020';
  17755. t['\u2008'] = '\u0020';
  17756. t['\u2009'] = '\u0020';
  17757. t['\u200A'] = '\u0020';
  17758. t['\u2017'] = '\u0020\u0333';
  17759. t['\u2024'] = '\u002E';
  17760. t['\u2025'] = '\u002E\u002E';
  17761. t['\u2026'] = '\u002E\u002E\u002E';
  17762. t['\u2033'] = '\u2032\u2032';
  17763. t['\u2034'] = '\u2032\u2032\u2032';
  17764. t['\u2036'] = '\u2035\u2035';
  17765. t['\u2037'] = '\u2035\u2035\u2035';
  17766. t['\u203C'] = '\u0021\u0021';
  17767. t['\u203E'] = '\u0020\u0305';
  17768. t['\u2047'] = '\u003F\u003F';
  17769. t['\u2048'] = '\u003F\u0021';
  17770. t['\u2049'] = '\u0021\u003F';
  17771. t['\u2057'] = '\u2032\u2032\u2032\u2032';
  17772. t['\u205F'] = '\u0020';
  17773. t['\u20A8'] = '\u0052\u0073';
  17774. t['\u2100'] = '\u0061\u002F\u0063';
  17775. t['\u2101'] = '\u0061\u002F\u0073';
  17776. t['\u2103'] = '\u00B0\u0043';
  17777. t['\u2105'] = '\u0063\u002F\u006F';
  17778. t['\u2106'] = '\u0063\u002F\u0075';
  17779. t['\u2107'] = '\u0190';
  17780. t['\u2109'] = '\u00B0\u0046';
  17781. t['\u2116'] = '\u004E\u006F';
  17782. t['\u2121'] = '\u0054\u0045\u004C';
  17783. t['\u2135'] = '\u05D0';
  17784. t['\u2136'] = '\u05D1';
  17785. t['\u2137'] = '\u05D2';
  17786. t['\u2138'] = '\u05D3';
  17787. t['\u213B'] = '\u0046\u0041\u0058';
  17788. t['\u2160'] = '\u0049';
  17789. t['\u2161'] = '\u0049\u0049';
  17790. t['\u2162'] = '\u0049\u0049\u0049';
  17791. t['\u2163'] = '\u0049\u0056';
  17792. t['\u2164'] = '\u0056';
  17793. t['\u2165'] = '\u0056\u0049';
  17794. t['\u2166'] = '\u0056\u0049\u0049';
  17795. t['\u2167'] = '\u0056\u0049\u0049\u0049';
  17796. t['\u2168'] = '\u0049\u0058';
  17797. t['\u2169'] = '\u0058';
  17798. t['\u216A'] = '\u0058\u0049';
  17799. t['\u216B'] = '\u0058\u0049\u0049';
  17800. t['\u216C'] = '\u004C';
  17801. t['\u216D'] = '\u0043';
  17802. t['\u216E'] = '\u0044';
  17803. t['\u216F'] = '\u004D';
  17804. t['\u2170'] = '\u0069';
  17805. t['\u2171'] = '\u0069\u0069';
  17806. t['\u2172'] = '\u0069\u0069\u0069';
  17807. t['\u2173'] = '\u0069\u0076';
  17808. t['\u2174'] = '\u0076';
  17809. t['\u2175'] = '\u0076\u0069';
  17810. t['\u2176'] = '\u0076\u0069\u0069';
  17811. t['\u2177'] = '\u0076\u0069\u0069\u0069';
  17812. t['\u2178'] = '\u0069\u0078';
  17813. t['\u2179'] = '\u0078';
  17814. t['\u217A'] = '\u0078\u0069';
  17815. t['\u217B'] = '\u0078\u0069\u0069';
  17816. t['\u217C'] = '\u006C';
  17817. t['\u217D'] = '\u0063';
  17818. t['\u217E'] = '\u0064';
  17819. t['\u217F'] = '\u006D';
  17820. t['\u222C'] = '\u222B\u222B';
  17821. t['\u222D'] = '\u222B\u222B\u222B';
  17822. t['\u222F'] = '\u222E\u222E';
  17823. t['\u2230'] = '\u222E\u222E\u222E';
  17824. t['\u2474'] = '\u0028\u0031\u0029';
  17825. t['\u2475'] = '\u0028\u0032\u0029';
  17826. t['\u2476'] = '\u0028\u0033\u0029';
  17827. t['\u2477'] = '\u0028\u0034\u0029';
  17828. t['\u2478'] = '\u0028\u0035\u0029';
  17829. t['\u2479'] = '\u0028\u0036\u0029';
  17830. t['\u247A'] = '\u0028\u0037\u0029';
  17831. t['\u247B'] = '\u0028\u0038\u0029';
  17832. t['\u247C'] = '\u0028\u0039\u0029';
  17833. t['\u247D'] = '\u0028\u0031\u0030\u0029';
  17834. t['\u247E'] = '\u0028\u0031\u0031\u0029';
  17835. t['\u247F'] = '\u0028\u0031\u0032\u0029';
  17836. t['\u2480'] = '\u0028\u0031\u0033\u0029';
  17837. t['\u2481'] = '\u0028\u0031\u0034\u0029';
  17838. t['\u2482'] = '\u0028\u0031\u0035\u0029';
  17839. t['\u2483'] = '\u0028\u0031\u0036\u0029';
  17840. t['\u2484'] = '\u0028\u0031\u0037\u0029';
  17841. t['\u2485'] = '\u0028\u0031\u0038\u0029';
  17842. t['\u2486'] = '\u0028\u0031\u0039\u0029';
  17843. t['\u2487'] = '\u0028\u0032\u0030\u0029';
  17844. t['\u2488'] = '\u0031\u002E';
  17845. t['\u2489'] = '\u0032\u002E';
  17846. t['\u248A'] = '\u0033\u002E';
  17847. t['\u248B'] = '\u0034\u002E';
  17848. t['\u248C'] = '\u0035\u002E';
  17849. t['\u248D'] = '\u0036\u002E';
  17850. t['\u248E'] = '\u0037\u002E';
  17851. t['\u248F'] = '\u0038\u002E';
  17852. t['\u2490'] = '\u0039\u002E';
  17853. t['\u2491'] = '\u0031\u0030\u002E';
  17854. t['\u2492'] = '\u0031\u0031\u002E';
  17855. t['\u2493'] = '\u0031\u0032\u002E';
  17856. t['\u2494'] = '\u0031\u0033\u002E';
  17857. t['\u2495'] = '\u0031\u0034\u002E';
  17858. t['\u2496'] = '\u0031\u0035\u002E';
  17859. t['\u2497'] = '\u0031\u0036\u002E';
  17860. t['\u2498'] = '\u0031\u0037\u002E';
  17861. t['\u2499'] = '\u0031\u0038\u002E';
  17862. t['\u249A'] = '\u0031\u0039\u002E';
  17863. t['\u249B'] = '\u0032\u0030\u002E';
  17864. t['\u249C'] = '\u0028\u0061\u0029';
  17865. t['\u249D'] = '\u0028\u0062\u0029';
  17866. t['\u249E'] = '\u0028\u0063\u0029';
  17867. t['\u249F'] = '\u0028\u0064\u0029';
  17868. t['\u24A0'] = '\u0028\u0065\u0029';
  17869. t['\u24A1'] = '\u0028\u0066\u0029';
  17870. t['\u24A2'] = '\u0028\u0067\u0029';
  17871. t['\u24A3'] = '\u0028\u0068\u0029';
  17872. t['\u24A4'] = '\u0028\u0069\u0029';
  17873. t['\u24A5'] = '\u0028\u006A\u0029';
  17874. t['\u24A6'] = '\u0028\u006B\u0029';
  17875. t['\u24A7'] = '\u0028\u006C\u0029';
  17876. t['\u24A8'] = '\u0028\u006D\u0029';
  17877. t['\u24A9'] = '\u0028\u006E\u0029';
  17878. t['\u24AA'] = '\u0028\u006F\u0029';
  17879. t['\u24AB'] = '\u0028\u0070\u0029';
  17880. t['\u24AC'] = '\u0028\u0071\u0029';
  17881. t['\u24AD'] = '\u0028\u0072\u0029';
  17882. t['\u24AE'] = '\u0028\u0073\u0029';
  17883. t['\u24AF'] = '\u0028\u0074\u0029';
  17884. t['\u24B0'] = '\u0028\u0075\u0029';
  17885. t['\u24B1'] = '\u0028\u0076\u0029';
  17886. t['\u24B2'] = '\u0028\u0077\u0029';
  17887. t['\u24B3'] = '\u0028\u0078\u0029';
  17888. t['\u24B4'] = '\u0028\u0079\u0029';
  17889. t['\u24B5'] = '\u0028\u007A\u0029';
  17890. t['\u2A0C'] = '\u222B\u222B\u222B\u222B';
  17891. t['\u2A74'] = '\u003A\u003A\u003D';
  17892. t['\u2A75'] = '\u003D\u003D';
  17893. t['\u2A76'] = '\u003D\u003D\u003D';
  17894. t['\u2E9F'] = '\u6BCD';
  17895. t['\u2EF3'] = '\u9F9F';
  17896. t['\u2F00'] = '\u4E00';
  17897. t['\u2F01'] = '\u4E28';
  17898. t['\u2F02'] = '\u4E36';
  17899. t['\u2F03'] = '\u4E3F';
  17900. t['\u2F04'] = '\u4E59';
  17901. t['\u2F05'] = '\u4E85';
  17902. t['\u2F06'] = '\u4E8C';
  17903. t['\u2F07'] = '\u4EA0';
  17904. t['\u2F08'] = '\u4EBA';
  17905. t['\u2F09'] = '\u513F';
  17906. t['\u2F0A'] = '\u5165';
  17907. t['\u2F0B'] = '\u516B';
  17908. t['\u2F0C'] = '\u5182';
  17909. t['\u2F0D'] = '\u5196';
  17910. t['\u2F0E'] = '\u51AB';
  17911. t['\u2F0F'] = '\u51E0';
  17912. t['\u2F10'] = '\u51F5';
  17913. t['\u2F11'] = '\u5200';
  17914. t['\u2F12'] = '\u529B';
  17915. t['\u2F13'] = '\u52F9';
  17916. t['\u2F14'] = '\u5315';
  17917. t['\u2F15'] = '\u531A';
  17918. t['\u2F16'] = '\u5338';
  17919. t['\u2F17'] = '\u5341';
  17920. t['\u2F18'] = '\u535C';
  17921. t['\u2F19'] = '\u5369';
  17922. t['\u2F1A'] = '\u5382';
  17923. t['\u2F1B'] = '\u53B6';
  17924. t['\u2F1C'] = '\u53C8';
  17925. t['\u2F1D'] = '\u53E3';
  17926. t['\u2F1E'] = '\u56D7';
  17927. t['\u2F1F'] = '\u571F';
  17928. t['\u2F20'] = '\u58EB';
  17929. t['\u2F21'] = '\u5902';
  17930. t['\u2F22'] = '\u590A';
  17931. t['\u2F23'] = '\u5915';
  17932. t['\u2F24'] = '\u5927';
  17933. t['\u2F25'] = '\u5973';
  17934. t['\u2F26'] = '\u5B50';
  17935. t['\u2F27'] = '\u5B80';
  17936. t['\u2F28'] = '\u5BF8';
  17937. t['\u2F29'] = '\u5C0F';
  17938. t['\u2F2A'] = '\u5C22';
  17939. t['\u2F2B'] = '\u5C38';
  17940. t['\u2F2C'] = '\u5C6E';
  17941. t['\u2F2D'] = '\u5C71';
  17942. t['\u2F2E'] = '\u5DDB';
  17943. t['\u2F2F'] = '\u5DE5';
  17944. t['\u2F30'] = '\u5DF1';
  17945. t['\u2F31'] = '\u5DFE';
  17946. t['\u2F32'] = '\u5E72';
  17947. t['\u2F33'] = '\u5E7A';
  17948. t['\u2F34'] = '\u5E7F';
  17949. t['\u2F35'] = '\u5EF4';
  17950. t['\u2F36'] = '\u5EFE';
  17951. t['\u2F37'] = '\u5F0B';
  17952. t['\u2F38'] = '\u5F13';
  17953. t['\u2F39'] = '\u5F50';
  17954. t['\u2F3A'] = '\u5F61';
  17955. t['\u2F3B'] = '\u5F73';
  17956. t['\u2F3C'] = '\u5FC3';
  17957. t['\u2F3D'] = '\u6208';
  17958. t['\u2F3E'] = '\u6236';
  17959. t['\u2F3F'] = '\u624B';
  17960. t['\u2F40'] = '\u652F';
  17961. t['\u2F41'] = '\u6534';
  17962. t['\u2F42'] = '\u6587';
  17963. t['\u2F43'] = '\u6597';
  17964. t['\u2F44'] = '\u65A4';
  17965. t['\u2F45'] = '\u65B9';
  17966. t['\u2F46'] = '\u65E0';
  17967. t['\u2F47'] = '\u65E5';
  17968. t['\u2F48'] = '\u66F0';
  17969. t['\u2F49'] = '\u6708';
  17970. t['\u2F4A'] = '\u6728';
  17971. t['\u2F4B'] = '\u6B20';
  17972. t['\u2F4C'] = '\u6B62';
  17973. t['\u2F4D'] = '\u6B79';
  17974. t['\u2F4E'] = '\u6BB3';
  17975. t['\u2F4F'] = '\u6BCB';
  17976. t['\u2F50'] = '\u6BD4';
  17977. t['\u2F51'] = '\u6BDB';
  17978. t['\u2F52'] = '\u6C0F';
  17979. t['\u2F53'] = '\u6C14';
  17980. t['\u2F54'] = '\u6C34';
  17981. t['\u2F55'] = '\u706B';
  17982. t['\u2F56'] = '\u722A';
  17983. t['\u2F57'] = '\u7236';
  17984. t['\u2F58'] = '\u723B';
  17985. t['\u2F59'] = '\u723F';
  17986. t['\u2F5A'] = '\u7247';
  17987. t['\u2F5B'] = '\u7259';
  17988. t['\u2F5C'] = '\u725B';
  17989. t['\u2F5D'] = '\u72AC';
  17990. t['\u2F5E'] = '\u7384';
  17991. t['\u2F5F'] = '\u7389';
  17992. t['\u2F60'] = '\u74DC';
  17993. t['\u2F61'] = '\u74E6';
  17994. t['\u2F62'] = '\u7518';
  17995. t['\u2F63'] = '\u751F';
  17996. t['\u2F64'] = '\u7528';
  17997. t['\u2F65'] = '\u7530';
  17998. t['\u2F66'] = '\u758B';
  17999. t['\u2F67'] = '\u7592';
  18000. t['\u2F68'] = '\u7676';
  18001. t['\u2F69'] = '\u767D';
  18002. t['\u2F6A'] = '\u76AE';
  18003. t['\u2F6B'] = '\u76BF';
  18004. t['\u2F6C'] = '\u76EE';
  18005. t['\u2F6D'] = '\u77DB';
  18006. t['\u2F6E'] = '\u77E2';
  18007. t['\u2F6F'] = '\u77F3';
  18008. t['\u2F70'] = '\u793A';
  18009. t['\u2F71'] = '\u79B8';
  18010. t['\u2F72'] = '\u79BE';
  18011. t['\u2F73'] = '\u7A74';
  18012. t['\u2F74'] = '\u7ACB';
  18013. t['\u2F75'] = '\u7AF9';
  18014. t['\u2F76'] = '\u7C73';
  18015. t['\u2F77'] = '\u7CF8';
  18016. t['\u2F78'] = '\u7F36';
  18017. t['\u2F79'] = '\u7F51';
  18018. t['\u2F7A'] = '\u7F8A';
  18019. t['\u2F7B'] = '\u7FBD';
  18020. t['\u2F7C'] = '\u8001';
  18021. t['\u2F7D'] = '\u800C';
  18022. t['\u2F7E'] = '\u8012';
  18023. t['\u2F7F'] = '\u8033';
  18024. t['\u2F80'] = '\u807F';
  18025. t['\u2F81'] = '\u8089';
  18026. t['\u2F82'] = '\u81E3';
  18027. t['\u2F83'] = '\u81EA';
  18028. t['\u2F84'] = '\u81F3';
  18029. t['\u2F85'] = '\u81FC';
  18030. t['\u2F86'] = '\u820C';
  18031. t['\u2F87'] = '\u821B';
  18032. t['\u2F88'] = '\u821F';
  18033. t['\u2F89'] = '\u826E';
  18034. t['\u2F8A'] = '\u8272';
  18035. t['\u2F8B'] = '\u8278';
  18036. t['\u2F8C'] = '\u864D';
  18037. t['\u2F8D'] = '\u866B';
  18038. t['\u2F8E'] = '\u8840';
  18039. t['\u2F8F'] = '\u884C';
  18040. t['\u2F90'] = '\u8863';
  18041. t['\u2F91'] = '\u897E';
  18042. t['\u2F92'] = '\u898B';
  18043. t['\u2F93'] = '\u89D2';
  18044. t['\u2F94'] = '\u8A00';
  18045. t['\u2F95'] = '\u8C37';
  18046. t['\u2F96'] = '\u8C46';
  18047. t['\u2F97'] = '\u8C55';
  18048. t['\u2F98'] = '\u8C78';
  18049. t['\u2F99'] = '\u8C9D';
  18050. t['\u2F9A'] = '\u8D64';
  18051. t['\u2F9B'] = '\u8D70';
  18052. t['\u2F9C'] = '\u8DB3';
  18053. t['\u2F9D'] = '\u8EAB';
  18054. t['\u2F9E'] = '\u8ECA';
  18055. t['\u2F9F'] = '\u8F9B';
  18056. t['\u2FA0'] = '\u8FB0';
  18057. t['\u2FA1'] = '\u8FB5';
  18058. t['\u2FA2'] = '\u9091';
  18059. t['\u2FA3'] = '\u9149';
  18060. t['\u2FA4'] = '\u91C6';
  18061. t['\u2FA5'] = '\u91CC';
  18062. t['\u2FA6'] = '\u91D1';
  18063. t['\u2FA7'] = '\u9577';
  18064. t['\u2FA8'] = '\u9580';
  18065. t['\u2FA9'] = '\u961C';
  18066. t['\u2FAA'] = '\u96B6';
  18067. t['\u2FAB'] = '\u96B9';
  18068. t['\u2FAC'] = '\u96E8';
  18069. t['\u2FAD'] = '\u9751';
  18070. t['\u2FAE'] = '\u975E';
  18071. t['\u2FAF'] = '\u9762';
  18072. t['\u2FB0'] = '\u9769';
  18073. t['\u2FB1'] = '\u97CB';
  18074. t['\u2FB2'] = '\u97ED';
  18075. t['\u2FB3'] = '\u97F3';
  18076. t['\u2FB4'] = '\u9801';
  18077. t['\u2FB5'] = '\u98A8';
  18078. t['\u2FB6'] = '\u98DB';
  18079. t['\u2FB7'] = '\u98DF';
  18080. t['\u2FB8'] = '\u9996';
  18081. t['\u2FB9'] = '\u9999';
  18082. t['\u2FBA'] = '\u99AC';
  18083. t['\u2FBB'] = '\u9AA8';
  18084. t['\u2FBC'] = '\u9AD8';
  18085. t['\u2FBD'] = '\u9ADF';
  18086. t['\u2FBE'] = '\u9B25';
  18087. t['\u2FBF'] = '\u9B2F';
  18088. t['\u2FC0'] = '\u9B32';
  18089. t['\u2FC1'] = '\u9B3C';
  18090. t['\u2FC2'] = '\u9B5A';
  18091. t['\u2FC3'] = '\u9CE5';
  18092. t['\u2FC4'] = '\u9E75';
  18093. t['\u2FC5'] = '\u9E7F';
  18094. t['\u2FC6'] = '\u9EA5';
  18095. t['\u2FC7'] = '\u9EBB';
  18096. t['\u2FC8'] = '\u9EC3';
  18097. t['\u2FC9'] = '\u9ECD';
  18098. t['\u2FCA'] = '\u9ED1';
  18099. t['\u2FCB'] = '\u9EF9';
  18100. t['\u2FCC'] = '\u9EFD';
  18101. t['\u2FCD'] = '\u9F0E';
  18102. t['\u2FCE'] = '\u9F13';
  18103. t['\u2FCF'] = '\u9F20';
  18104. t['\u2FD0'] = '\u9F3B';
  18105. t['\u2FD1'] = '\u9F4A';
  18106. t['\u2FD2'] = '\u9F52';
  18107. t['\u2FD3'] = '\u9F8D';
  18108. t['\u2FD4'] = '\u9F9C';
  18109. t['\u2FD5'] = '\u9FA0';
  18110. t['\u3036'] = '\u3012';
  18111. t['\u3038'] = '\u5341';
  18112. t['\u3039'] = '\u5344';
  18113. t['\u303A'] = '\u5345';
  18114. t['\u309B'] = '\u0020\u3099';
  18115. t['\u309C'] = '\u0020\u309A';
  18116. t['\u3131'] = '\u1100';
  18117. t['\u3132'] = '\u1101';
  18118. t['\u3133'] = '\u11AA';
  18119. t['\u3134'] = '\u1102';
  18120. t['\u3135'] = '\u11AC';
  18121. t['\u3136'] = '\u11AD';
  18122. t['\u3137'] = '\u1103';
  18123. t['\u3138'] = '\u1104';
  18124. t['\u3139'] = '\u1105';
  18125. t['\u313A'] = '\u11B0';
  18126. t['\u313B'] = '\u11B1';
  18127. t['\u313C'] = '\u11B2';
  18128. t['\u313D'] = '\u11B3';
  18129. t['\u313E'] = '\u11B4';
  18130. t['\u313F'] = '\u11B5';
  18131. t['\u3140'] = '\u111A';
  18132. t['\u3141'] = '\u1106';
  18133. t['\u3142'] = '\u1107';
  18134. t['\u3143'] = '\u1108';
  18135. t['\u3144'] = '\u1121';
  18136. t['\u3145'] = '\u1109';
  18137. t['\u3146'] = '\u110A';
  18138. t['\u3147'] = '\u110B';
  18139. t['\u3148'] = '\u110C';
  18140. t['\u3149'] = '\u110D';
  18141. t['\u314A'] = '\u110E';
  18142. t['\u314B'] = '\u110F';
  18143. t['\u314C'] = '\u1110';
  18144. t['\u314D'] = '\u1111';
  18145. t['\u314E'] = '\u1112';
  18146. t['\u314F'] = '\u1161';
  18147. t['\u3150'] = '\u1162';
  18148. t['\u3151'] = '\u1163';
  18149. t['\u3152'] = '\u1164';
  18150. t['\u3153'] = '\u1165';
  18151. t['\u3154'] = '\u1166';
  18152. t['\u3155'] = '\u1167';
  18153. t['\u3156'] = '\u1168';
  18154. t['\u3157'] = '\u1169';
  18155. t['\u3158'] = '\u116A';
  18156. t['\u3159'] = '\u116B';
  18157. t['\u315A'] = '\u116C';
  18158. t['\u315B'] = '\u116D';
  18159. t['\u315C'] = '\u116E';
  18160. t['\u315D'] = '\u116F';
  18161. t['\u315E'] = '\u1170';
  18162. t['\u315F'] = '\u1171';
  18163. t['\u3160'] = '\u1172';
  18164. t['\u3161'] = '\u1173';
  18165. t['\u3162'] = '\u1174';
  18166. t['\u3163'] = '\u1175';
  18167. t['\u3164'] = '\u1160';
  18168. t['\u3165'] = '\u1114';
  18169. t['\u3166'] = '\u1115';
  18170. t['\u3167'] = '\u11C7';
  18171. t['\u3168'] = '\u11C8';
  18172. t['\u3169'] = '\u11CC';
  18173. t['\u316A'] = '\u11CE';
  18174. t['\u316B'] = '\u11D3';
  18175. t['\u316C'] = '\u11D7';
  18176. t['\u316D'] = '\u11D9';
  18177. t['\u316E'] = '\u111C';
  18178. t['\u316F'] = '\u11DD';
  18179. t['\u3170'] = '\u11DF';
  18180. t['\u3171'] = '\u111D';
  18181. t['\u3172'] = '\u111E';
  18182. t['\u3173'] = '\u1120';
  18183. t['\u3174'] = '\u1122';
  18184. t['\u3175'] = '\u1123';
  18185. t['\u3176'] = '\u1127';
  18186. t['\u3177'] = '\u1129';
  18187. t['\u3178'] = '\u112B';
  18188. t['\u3179'] = '\u112C';
  18189. t['\u317A'] = '\u112D';
  18190. t['\u317B'] = '\u112E';
  18191. t['\u317C'] = '\u112F';
  18192. t['\u317D'] = '\u1132';
  18193. t['\u317E'] = '\u1136';
  18194. t['\u317F'] = '\u1140';
  18195. t['\u3180'] = '\u1147';
  18196. t['\u3181'] = '\u114C';
  18197. t['\u3182'] = '\u11F1';
  18198. t['\u3183'] = '\u11F2';
  18199. t['\u3184'] = '\u1157';
  18200. t['\u3185'] = '\u1158';
  18201. t['\u3186'] = '\u1159';
  18202. t['\u3187'] = '\u1184';
  18203. t['\u3188'] = '\u1185';
  18204. t['\u3189'] = '\u1188';
  18205. t['\u318A'] = '\u1191';
  18206. t['\u318B'] = '\u1192';
  18207. t['\u318C'] = '\u1194';
  18208. t['\u318D'] = '\u119E';
  18209. t['\u318E'] = '\u11A1';
  18210. t['\u3200'] = '\u0028\u1100\u0029';
  18211. t['\u3201'] = '\u0028\u1102\u0029';
  18212. t['\u3202'] = '\u0028\u1103\u0029';
  18213. t['\u3203'] = '\u0028\u1105\u0029';
  18214. t['\u3204'] = '\u0028\u1106\u0029';
  18215. t['\u3205'] = '\u0028\u1107\u0029';
  18216. t['\u3206'] = '\u0028\u1109\u0029';
  18217. t['\u3207'] = '\u0028\u110B\u0029';
  18218. t['\u3208'] = '\u0028\u110C\u0029';
  18219. t['\u3209'] = '\u0028\u110E\u0029';
  18220. t['\u320A'] = '\u0028\u110F\u0029';
  18221. t['\u320B'] = '\u0028\u1110\u0029';
  18222. t['\u320C'] = '\u0028\u1111\u0029';
  18223. t['\u320D'] = '\u0028\u1112\u0029';
  18224. t['\u320E'] = '\u0028\u1100\u1161\u0029';
  18225. t['\u320F'] = '\u0028\u1102\u1161\u0029';
  18226. t['\u3210'] = '\u0028\u1103\u1161\u0029';
  18227. t['\u3211'] = '\u0028\u1105\u1161\u0029';
  18228. t['\u3212'] = '\u0028\u1106\u1161\u0029';
  18229. t['\u3213'] = '\u0028\u1107\u1161\u0029';
  18230. t['\u3214'] = '\u0028\u1109\u1161\u0029';
  18231. t['\u3215'] = '\u0028\u110B\u1161\u0029';
  18232. t['\u3216'] = '\u0028\u110C\u1161\u0029';
  18233. t['\u3217'] = '\u0028\u110E\u1161\u0029';
  18234. t['\u3218'] = '\u0028\u110F\u1161\u0029';
  18235. t['\u3219'] = '\u0028\u1110\u1161\u0029';
  18236. t['\u321A'] = '\u0028\u1111\u1161\u0029';
  18237. t['\u321B'] = '\u0028\u1112\u1161\u0029';
  18238. t['\u321C'] = '\u0028\u110C\u116E\u0029';
  18239. t['\u321D'] = '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029';
  18240. t['\u321E'] = '\u0028\u110B\u1169\u1112\u116E\u0029';
  18241. t['\u3220'] = '\u0028\u4E00\u0029';
  18242. t['\u3221'] = '\u0028\u4E8C\u0029';
  18243. t['\u3222'] = '\u0028\u4E09\u0029';
  18244. t['\u3223'] = '\u0028\u56DB\u0029';
  18245. t['\u3224'] = '\u0028\u4E94\u0029';
  18246. t['\u3225'] = '\u0028\u516D\u0029';
  18247. t['\u3226'] = '\u0028\u4E03\u0029';
  18248. t['\u3227'] = '\u0028\u516B\u0029';
  18249. t['\u3228'] = '\u0028\u4E5D\u0029';
  18250. t['\u3229'] = '\u0028\u5341\u0029';
  18251. t['\u322A'] = '\u0028\u6708\u0029';
  18252. t['\u322B'] = '\u0028\u706B\u0029';
  18253. t['\u322C'] = '\u0028\u6C34\u0029';
  18254. t['\u322D'] = '\u0028\u6728\u0029';
  18255. t['\u322E'] = '\u0028\u91D1\u0029';
  18256. t['\u322F'] = '\u0028\u571F\u0029';
  18257. t['\u3230'] = '\u0028\u65E5\u0029';
  18258. t['\u3231'] = '\u0028\u682A\u0029';
  18259. t['\u3232'] = '\u0028\u6709\u0029';
  18260. t['\u3233'] = '\u0028\u793E\u0029';
  18261. t['\u3234'] = '\u0028\u540D\u0029';
  18262. t['\u3235'] = '\u0028\u7279\u0029';
  18263. t['\u3236'] = '\u0028\u8CA1\u0029';
  18264. t['\u3237'] = '\u0028\u795D\u0029';
  18265. t['\u3238'] = '\u0028\u52B4\u0029';
  18266. t['\u3239'] = '\u0028\u4EE3\u0029';
  18267. t['\u323A'] = '\u0028\u547C\u0029';
  18268. t['\u323B'] = '\u0028\u5B66\u0029';
  18269. t['\u323C'] = '\u0028\u76E3\u0029';
  18270. t['\u323D'] = '\u0028\u4F01\u0029';
  18271. t['\u323E'] = '\u0028\u8CC7\u0029';
  18272. t['\u323F'] = '\u0028\u5354\u0029';
  18273. t['\u3240'] = '\u0028\u796D\u0029';
  18274. t['\u3241'] = '\u0028\u4F11\u0029';
  18275. t['\u3242'] = '\u0028\u81EA\u0029';
  18276. t['\u3243'] = '\u0028\u81F3\u0029';
  18277. t['\u32C0'] = '\u0031\u6708';
  18278. t['\u32C1'] = '\u0032\u6708';
  18279. t['\u32C2'] = '\u0033\u6708';
  18280. t['\u32C3'] = '\u0034\u6708';
  18281. t['\u32C4'] = '\u0035\u6708';
  18282. t['\u32C5'] = '\u0036\u6708';
  18283. t['\u32C6'] = '\u0037\u6708';
  18284. t['\u32C7'] = '\u0038\u6708';
  18285. t['\u32C8'] = '\u0039\u6708';
  18286. t['\u32C9'] = '\u0031\u0030\u6708';
  18287. t['\u32CA'] = '\u0031\u0031\u6708';
  18288. t['\u32CB'] = '\u0031\u0032\u6708';
  18289. t['\u3358'] = '\u0030\u70B9';
  18290. t['\u3359'] = '\u0031\u70B9';
  18291. t['\u335A'] = '\u0032\u70B9';
  18292. t['\u335B'] = '\u0033\u70B9';
  18293. t['\u335C'] = '\u0034\u70B9';
  18294. t['\u335D'] = '\u0035\u70B9';
  18295. t['\u335E'] = '\u0036\u70B9';
  18296. t['\u335F'] = '\u0037\u70B9';
  18297. t['\u3360'] = '\u0038\u70B9';
  18298. t['\u3361'] = '\u0039\u70B9';
  18299. t['\u3362'] = '\u0031\u0030\u70B9';
  18300. t['\u3363'] = '\u0031\u0031\u70B9';
  18301. t['\u3364'] = '\u0031\u0032\u70B9';
  18302. t['\u3365'] = '\u0031\u0033\u70B9';
  18303. t['\u3366'] = '\u0031\u0034\u70B9';
  18304. t['\u3367'] = '\u0031\u0035\u70B9';
  18305. t['\u3368'] = '\u0031\u0036\u70B9';
  18306. t['\u3369'] = '\u0031\u0037\u70B9';
  18307. t['\u336A'] = '\u0031\u0038\u70B9';
  18308. t['\u336B'] = '\u0031\u0039\u70B9';
  18309. t['\u336C'] = '\u0032\u0030\u70B9';
  18310. t['\u336D'] = '\u0032\u0031\u70B9';
  18311. t['\u336E'] = '\u0032\u0032\u70B9';
  18312. t['\u336F'] = '\u0032\u0033\u70B9';
  18313. t['\u3370'] = '\u0032\u0034\u70B9';
  18314. t['\u33E0'] = '\u0031\u65E5';
  18315. t['\u33E1'] = '\u0032\u65E5';
  18316. t['\u33E2'] = '\u0033\u65E5';
  18317. t['\u33E3'] = '\u0034\u65E5';
  18318. t['\u33E4'] = '\u0035\u65E5';
  18319. t['\u33E5'] = '\u0036\u65E5';
  18320. t['\u33E6'] = '\u0037\u65E5';
  18321. t['\u33E7'] = '\u0038\u65E5';
  18322. t['\u33E8'] = '\u0039\u65E5';
  18323. t['\u33E9'] = '\u0031\u0030\u65E5';
  18324. t['\u33EA'] = '\u0031\u0031\u65E5';
  18325. t['\u33EB'] = '\u0031\u0032\u65E5';
  18326. t['\u33EC'] = '\u0031\u0033\u65E5';
  18327. t['\u33ED'] = '\u0031\u0034\u65E5';
  18328. t['\u33EE'] = '\u0031\u0035\u65E5';
  18329. t['\u33EF'] = '\u0031\u0036\u65E5';
  18330. t['\u33F0'] = '\u0031\u0037\u65E5';
  18331. t['\u33F1'] = '\u0031\u0038\u65E5';
  18332. t['\u33F2'] = '\u0031\u0039\u65E5';
  18333. t['\u33F3'] = '\u0032\u0030\u65E5';
  18334. t['\u33F4'] = '\u0032\u0031\u65E5';
  18335. t['\u33F5'] = '\u0032\u0032\u65E5';
  18336. t['\u33F6'] = '\u0032\u0033\u65E5';
  18337. t['\u33F7'] = '\u0032\u0034\u65E5';
  18338. t['\u33F8'] = '\u0032\u0035\u65E5';
  18339. t['\u33F9'] = '\u0032\u0036\u65E5';
  18340. t['\u33FA'] = '\u0032\u0037\u65E5';
  18341. t['\u33FB'] = '\u0032\u0038\u65E5';
  18342. t['\u33FC'] = '\u0032\u0039\u65E5';
  18343. t['\u33FD'] = '\u0033\u0030\u65E5';
  18344. t['\u33FE'] = '\u0033\u0031\u65E5';
  18345. t['\uFB00'] = '\u0066\u0066';
  18346. t['\uFB01'] = '\u0066\u0069';
  18347. t['\uFB02'] = '\u0066\u006C';
  18348. t['\uFB03'] = '\u0066\u0066\u0069';
  18349. t['\uFB04'] = '\u0066\u0066\u006C';
  18350. t['\uFB05'] = '\u017F\u0074';
  18351. t['\uFB06'] = '\u0073\u0074';
  18352. t['\uFB13'] = '\u0574\u0576';
  18353. t['\uFB14'] = '\u0574\u0565';
  18354. t['\uFB15'] = '\u0574\u056B';
  18355. t['\uFB16'] = '\u057E\u0576';
  18356. t['\uFB17'] = '\u0574\u056D';
  18357. t['\uFB4F'] = '\u05D0\u05DC';
  18358. t['\uFB50'] = '\u0671';
  18359. t['\uFB51'] = '\u0671';
  18360. t['\uFB52'] = '\u067B';
  18361. t['\uFB53'] = '\u067B';
  18362. t['\uFB54'] = '\u067B';
  18363. t['\uFB55'] = '\u067B';
  18364. t['\uFB56'] = '\u067E';
  18365. t['\uFB57'] = '\u067E';
  18366. t['\uFB58'] = '\u067E';
  18367. t['\uFB59'] = '\u067E';
  18368. t['\uFB5A'] = '\u0680';
  18369. t['\uFB5B'] = '\u0680';
  18370. t['\uFB5C'] = '\u0680';
  18371. t['\uFB5D'] = '\u0680';
  18372. t['\uFB5E'] = '\u067A';
  18373. t['\uFB5F'] = '\u067A';
  18374. t['\uFB60'] = '\u067A';
  18375. t['\uFB61'] = '\u067A';
  18376. t['\uFB62'] = '\u067F';
  18377. t['\uFB63'] = '\u067F';
  18378. t['\uFB64'] = '\u067F';
  18379. t['\uFB65'] = '\u067F';
  18380. t['\uFB66'] = '\u0679';
  18381. t['\uFB67'] = '\u0679';
  18382. t['\uFB68'] = '\u0679';
  18383. t['\uFB69'] = '\u0679';
  18384. t['\uFB6A'] = '\u06A4';
  18385. t['\uFB6B'] = '\u06A4';
  18386. t['\uFB6C'] = '\u06A4';
  18387. t['\uFB6D'] = '\u06A4';
  18388. t['\uFB6E'] = '\u06A6';
  18389. t['\uFB6F'] = '\u06A6';
  18390. t['\uFB70'] = '\u06A6';
  18391. t['\uFB71'] = '\u06A6';
  18392. t['\uFB72'] = '\u0684';
  18393. t['\uFB73'] = '\u0684';
  18394. t['\uFB74'] = '\u0684';
  18395. t['\uFB75'] = '\u0684';
  18396. t['\uFB76'] = '\u0683';
  18397. t['\uFB77'] = '\u0683';
  18398. t['\uFB78'] = '\u0683';
  18399. t['\uFB79'] = '\u0683';
  18400. t['\uFB7A'] = '\u0686';
  18401. t['\uFB7B'] = '\u0686';
  18402. t['\uFB7C'] = '\u0686';
  18403. t['\uFB7D'] = '\u0686';
  18404. t['\uFB7E'] = '\u0687';
  18405. t['\uFB7F'] = '\u0687';
  18406. t['\uFB80'] = '\u0687';
  18407. t['\uFB81'] = '\u0687';
  18408. t['\uFB82'] = '\u068D';
  18409. t['\uFB83'] = '\u068D';
  18410. t['\uFB84'] = '\u068C';
  18411. t['\uFB85'] = '\u068C';
  18412. t['\uFB86'] = '\u068E';
  18413. t['\uFB87'] = '\u068E';
  18414. t['\uFB88'] = '\u0688';
  18415. t['\uFB89'] = '\u0688';
  18416. t['\uFB8A'] = '\u0698';
  18417. t['\uFB8B'] = '\u0698';
  18418. t['\uFB8C'] = '\u0691';
  18419. t['\uFB8D'] = '\u0691';
  18420. t['\uFB8E'] = '\u06A9';
  18421. t['\uFB8F'] = '\u06A9';
  18422. t['\uFB90'] = '\u06A9';
  18423. t['\uFB91'] = '\u06A9';
  18424. t['\uFB92'] = '\u06AF';
  18425. t['\uFB93'] = '\u06AF';
  18426. t['\uFB94'] = '\u06AF';
  18427. t['\uFB95'] = '\u06AF';
  18428. t['\uFB96'] = '\u06B3';
  18429. t['\uFB97'] = '\u06B3';
  18430. t['\uFB98'] = '\u06B3';
  18431. t['\uFB99'] = '\u06B3';
  18432. t['\uFB9A'] = '\u06B1';
  18433. t['\uFB9B'] = '\u06B1';
  18434. t['\uFB9C'] = '\u06B1';
  18435. t['\uFB9D'] = '\u06B1';
  18436. t['\uFB9E'] = '\u06BA';
  18437. t['\uFB9F'] = '\u06BA';
  18438. t['\uFBA0'] = '\u06BB';
  18439. t['\uFBA1'] = '\u06BB';
  18440. t['\uFBA2'] = '\u06BB';
  18441. t['\uFBA3'] = '\u06BB';
  18442. t['\uFBA4'] = '\u06C0';
  18443. t['\uFBA5'] = '\u06C0';
  18444. t['\uFBA6'] = '\u06C1';
  18445. t['\uFBA7'] = '\u06C1';
  18446. t['\uFBA8'] = '\u06C1';
  18447. t['\uFBA9'] = '\u06C1';
  18448. t['\uFBAA'] = '\u06BE';
  18449. t['\uFBAB'] = '\u06BE';
  18450. t['\uFBAC'] = '\u06BE';
  18451. t['\uFBAD'] = '\u06BE';
  18452. t['\uFBAE'] = '\u06D2';
  18453. t['\uFBAF'] = '\u06D2';
  18454. t['\uFBB0'] = '\u06D3';
  18455. t['\uFBB1'] = '\u06D3';
  18456. t['\uFBD3'] = '\u06AD';
  18457. t['\uFBD4'] = '\u06AD';
  18458. t['\uFBD5'] = '\u06AD';
  18459. t['\uFBD6'] = '\u06AD';
  18460. t['\uFBD7'] = '\u06C7';
  18461. t['\uFBD8'] = '\u06C7';
  18462. t['\uFBD9'] = '\u06C6';
  18463. t['\uFBDA'] = '\u06C6';
  18464. t['\uFBDB'] = '\u06C8';
  18465. t['\uFBDC'] = '\u06C8';
  18466. t['\uFBDD'] = '\u0677';
  18467. t['\uFBDE'] = '\u06CB';
  18468. t['\uFBDF'] = '\u06CB';
  18469. t['\uFBE0'] = '\u06C5';
  18470. t['\uFBE1'] = '\u06C5';
  18471. t['\uFBE2'] = '\u06C9';
  18472. t['\uFBE3'] = '\u06C9';
  18473. t['\uFBE4'] = '\u06D0';
  18474. t['\uFBE5'] = '\u06D0';
  18475. t['\uFBE6'] = '\u06D0';
  18476. t['\uFBE7'] = '\u06D0';
  18477. t['\uFBE8'] = '\u0649';
  18478. t['\uFBE9'] = '\u0649';
  18479. t['\uFBEA'] = '\u0626\u0627';
  18480. t['\uFBEB'] = '\u0626\u0627';
  18481. t['\uFBEC'] = '\u0626\u06D5';
  18482. t['\uFBED'] = '\u0626\u06D5';
  18483. t['\uFBEE'] = '\u0626\u0648';
  18484. t['\uFBEF'] = '\u0626\u0648';
  18485. t['\uFBF0'] = '\u0626\u06C7';
  18486. t['\uFBF1'] = '\u0626\u06C7';
  18487. t['\uFBF2'] = '\u0626\u06C6';
  18488. t['\uFBF3'] = '\u0626\u06C6';
  18489. t['\uFBF4'] = '\u0626\u06C8';
  18490. t['\uFBF5'] = '\u0626\u06C8';
  18491. t['\uFBF6'] = '\u0626\u06D0';
  18492. t['\uFBF7'] = '\u0626\u06D0';
  18493. t['\uFBF8'] = '\u0626\u06D0';
  18494. t['\uFBF9'] = '\u0626\u0649';
  18495. t['\uFBFA'] = '\u0626\u0649';
  18496. t['\uFBFB'] = '\u0626\u0649';
  18497. t['\uFBFC'] = '\u06CC';
  18498. t['\uFBFD'] = '\u06CC';
  18499. t['\uFBFE'] = '\u06CC';
  18500. t['\uFBFF'] = '\u06CC';
  18501. t['\uFC00'] = '\u0626\u062C';
  18502. t['\uFC01'] = '\u0626\u062D';
  18503. t['\uFC02'] = '\u0626\u0645';
  18504. t['\uFC03'] = '\u0626\u0649';
  18505. t['\uFC04'] = '\u0626\u064A';
  18506. t['\uFC05'] = '\u0628\u062C';
  18507. t['\uFC06'] = '\u0628\u062D';
  18508. t['\uFC07'] = '\u0628\u062E';
  18509. t['\uFC08'] = '\u0628\u0645';
  18510. t['\uFC09'] = '\u0628\u0649';
  18511. t['\uFC0A'] = '\u0628\u064A';
  18512. t['\uFC0B'] = '\u062A\u062C';
  18513. t['\uFC0C'] = '\u062A\u062D';
  18514. t['\uFC0D'] = '\u062A\u062E';
  18515. t['\uFC0E'] = '\u062A\u0645';
  18516. t['\uFC0F'] = '\u062A\u0649';
  18517. t['\uFC10'] = '\u062A\u064A';
  18518. t['\uFC11'] = '\u062B\u062C';
  18519. t['\uFC12'] = '\u062B\u0645';
  18520. t['\uFC13'] = '\u062B\u0649';
  18521. t['\uFC14'] = '\u062B\u064A';
  18522. t['\uFC15'] = '\u062C\u062D';
  18523. t['\uFC16'] = '\u062C\u0645';
  18524. t['\uFC17'] = '\u062D\u062C';
  18525. t['\uFC18'] = '\u062D\u0645';
  18526. t['\uFC19'] = '\u062E\u062C';
  18527. t['\uFC1A'] = '\u062E\u062D';
  18528. t['\uFC1B'] = '\u062E\u0645';
  18529. t['\uFC1C'] = '\u0633\u062C';
  18530. t['\uFC1D'] = '\u0633\u062D';
  18531. t['\uFC1E'] = '\u0633\u062E';
  18532. t['\uFC1F'] = '\u0633\u0645';
  18533. t['\uFC20'] = '\u0635\u062D';
  18534. t['\uFC21'] = '\u0635\u0645';
  18535. t['\uFC22'] = '\u0636\u062C';
  18536. t['\uFC23'] = '\u0636\u062D';
  18537. t['\uFC24'] = '\u0636\u062E';
  18538. t['\uFC25'] = '\u0636\u0645';
  18539. t['\uFC26'] = '\u0637\u062D';
  18540. t['\uFC27'] = '\u0637\u0645';
  18541. t['\uFC28'] = '\u0638\u0645';
  18542. t['\uFC29'] = '\u0639\u062C';
  18543. t['\uFC2A'] = '\u0639\u0645';
  18544. t['\uFC2B'] = '\u063A\u062C';
  18545. t['\uFC2C'] = '\u063A\u0645';
  18546. t['\uFC2D'] = '\u0641\u062C';
  18547. t['\uFC2E'] = '\u0641\u062D';
  18548. t['\uFC2F'] = '\u0641\u062E';
  18549. t['\uFC30'] = '\u0641\u0645';
  18550. t['\uFC31'] = '\u0641\u0649';
  18551. t['\uFC32'] = '\u0641\u064A';
  18552. t['\uFC33'] = '\u0642\u062D';
  18553. t['\uFC34'] = '\u0642\u0645';
  18554. t['\uFC35'] = '\u0642\u0649';
  18555. t['\uFC36'] = '\u0642\u064A';
  18556. t['\uFC37'] = '\u0643\u0627';
  18557. t['\uFC38'] = '\u0643\u062C';
  18558. t['\uFC39'] = '\u0643\u062D';
  18559. t['\uFC3A'] = '\u0643\u062E';
  18560. t['\uFC3B'] = '\u0643\u0644';
  18561. t['\uFC3C'] = '\u0643\u0645';
  18562. t['\uFC3D'] = '\u0643\u0649';
  18563. t['\uFC3E'] = '\u0643\u064A';
  18564. t['\uFC3F'] = '\u0644\u062C';
  18565. t['\uFC40'] = '\u0644\u062D';
  18566. t['\uFC41'] = '\u0644\u062E';
  18567. t['\uFC42'] = '\u0644\u0645';
  18568. t['\uFC43'] = '\u0644\u0649';
  18569. t['\uFC44'] = '\u0644\u064A';
  18570. t['\uFC45'] = '\u0645\u062C';
  18571. t['\uFC46'] = '\u0645\u062D';
  18572. t['\uFC47'] = '\u0645\u062E';
  18573. t['\uFC48'] = '\u0645\u0645';
  18574. t['\uFC49'] = '\u0645\u0649';
  18575. t['\uFC4A'] = '\u0645\u064A';
  18576. t['\uFC4B'] = '\u0646\u062C';
  18577. t['\uFC4C'] = '\u0646\u062D';
  18578. t['\uFC4D'] = '\u0646\u062E';
  18579. t['\uFC4E'] = '\u0646\u0645';
  18580. t['\uFC4F'] = '\u0646\u0649';
  18581. t['\uFC50'] = '\u0646\u064A';
  18582. t['\uFC51'] = '\u0647\u062C';
  18583. t['\uFC52'] = '\u0647\u0645';
  18584. t['\uFC53'] = '\u0647\u0649';
  18585. t['\uFC54'] = '\u0647\u064A';
  18586. t['\uFC55'] = '\u064A\u062C';
  18587. t['\uFC56'] = '\u064A\u062D';
  18588. t['\uFC57'] = '\u064A\u062E';
  18589. t['\uFC58'] = '\u064A\u0645';
  18590. t['\uFC59'] = '\u064A\u0649';
  18591. t['\uFC5A'] = '\u064A\u064A';
  18592. t['\uFC5B'] = '\u0630\u0670';
  18593. t['\uFC5C'] = '\u0631\u0670';
  18594. t['\uFC5D'] = '\u0649\u0670';
  18595. t['\uFC5E'] = '\u0020\u064C\u0651';
  18596. t['\uFC5F'] = '\u0020\u064D\u0651';
  18597. t['\uFC60'] = '\u0020\u064E\u0651';
  18598. t['\uFC61'] = '\u0020\u064F\u0651';
  18599. t['\uFC62'] = '\u0020\u0650\u0651';
  18600. t['\uFC63'] = '\u0020\u0651\u0670';
  18601. t['\uFC64'] = '\u0626\u0631';
  18602. t['\uFC65'] = '\u0626\u0632';
  18603. t['\uFC66'] = '\u0626\u0645';
  18604. t['\uFC67'] = '\u0626\u0646';
  18605. t['\uFC68'] = '\u0626\u0649';
  18606. t['\uFC69'] = '\u0626\u064A';
  18607. t['\uFC6A'] = '\u0628\u0631';
  18608. t['\uFC6B'] = '\u0628\u0632';
  18609. t['\uFC6C'] = '\u0628\u0645';
  18610. t['\uFC6D'] = '\u0628\u0646';
  18611. t['\uFC6E'] = '\u0628\u0649';
  18612. t['\uFC6F'] = '\u0628\u064A';
  18613. t['\uFC70'] = '\u062A\u0631';
  18614. t['\uFC71'] = '\u062A\u0632';
  18615. t['\uFC72'] = '\u062A\u0645';
  18616. t['\uFC73'] = '\u062A\u0646';
  18617. t['\uFC74'] = '\u062A\u0649';
  18618. t['\uFC75'] = '\u062A\u064A';
  18619. t['\uFC76'] = '\u062B\u0631';
  18620. t['\uFC77'] = '\u062B\u0632';
  18621. t['\uFC78'] = '\u062B\u0645';
  18622. t['\uFC79'] = '\u062B\u0646';
  18623. t['\uFC7A'] = '\u062B\u0649';
  18624. t['\uFC7B'] = '\u062B\u064A';
  18625. t['\uFC7C'] = '\u0641\u0649';
  18626. t['\uFC7D'] = '\u0641\u064A';
  18627. t['\uFC7E'] = '\u0642\u0649';
  18628. t['\uFC7F'] = '\u0642\u064A';
  18629. t['\uFC80'] = '\u0643\u0627';
  18630. t['\uFC81'] = '\u0643\u0644';
  18631. t['\uFC82'] = '\u0643\u0645';
  18632. t['\uFC83'] = '\u0643\u0649';
  18633. t['\uFC84'] = '\u0643\u064A';
  18634. t['\uFC85'] = '\u0644\u0645';
  18635. t['\uFC86'] = '\u0644\u0649';
  18636. t['\uFC87'] = '\u0644\u064A';
  18637. t['\uFC88'] = '\u0645\u0627';
  18638. t['\uFC89'] = '\u0645\u0645';
  18639. t['\uFC8A'] = '\u0646\u0631';
  18640. t['\uFC8B'] = '\u0646\u0632';
  18641. t['\uFC8C'] = '\u0646\u0645';
  18642. t['\uFC8D'] = '\u0646\u0646';
  18643. t['\uFC8E'] = '\u0646\u0649';
  18644. t['\uFC8F'] = '\u0646\u064A';
  18645. t['\uFC90'] = '\u0649\u0670';
  18646. t['\uFC91'] = '\u064A\u0631';
  18647. t['\uFC92'] = '\u064A\u0632';
  18648. t['\uFC93'] = '\u064A\u0645';
  18649. t['\uFC94'] = '\u064A\u0646';
  18650. t['\uFC95'] = '\u064A\u0649';
  18651. t['\uFC96'] = '\u064A\u064A';
  18652. t['\uFC97'] = '\u0626\u062C';
  18653. t['\uFC98'] = '\u0626\u062D';
  18654. t['\uFC99'] = '\u0626\u062E';
  18655. t['\uFC9A'] = '\u0626\u0645';
  18656. t['\uFC9B'] = '\u0626\u0647';
  18657. t['\uFC9C'] = '\u0628\u062C';
  18658. t['\uFC9D'] = '\u0628\u062D';
  18659. t['\uFC9E'] = '\u0628\u062E';
  18660. t['\uFC9F'] = '\u0628\u0645';
  18661. t['\uFCA0'] = '\u0628\u0647';
  18662. t['\uFCA1'] = '\u062A\u062C';
  18663. t['\uFCA2'] = '\u062A\u062D';
  18664. t['\uFCA3'] = '\u062A\u062E';
  18665. t['\uFCA4'] = '\u062A\u0645';
  18666. t['\uFCA5'] = '\u062A\u0647';
  18667. t['\uFCA6'] = '\u062B\u0645';
  18668. t['\uFCA7'] = '\u062C\u062D';
  18669. t['\uFCA8'] = '\u062C\u0645';
  18670. t['\uFCA9'] = '\u062D\u062C';
  18671. t['\uFCAA'] = '\u062D\u0645';
  18672. t['\uFCAB'] = '\u062E\u062C';
  18673. t['\uFCAC'] = '\u062E\u0645';
  18674. t['\uFCAD'] = '\u0633\u062C';
  18675. t['\uFCAE'] = '\u0633\u062D';
  18676. t['\uFCAF'] = '\u0633\u062E';
  18677. t['\uFCB0'] = '\u0633\u0645';
  18678. t['\uFCB1'] = '\u0635\u062D';
  18679. t['\uFCB2'] = '\u0635\u062E';
  18680. t['\uFCB3'] = '\u0635\u0645';
  18681. t['\uFCB4'] = '\u0636\u062C';
  18682. t['\uFCB5'] = '\u0636\u062D';
  18683. t['\uFCB6'] = '\u0636\u062E';
  18684. t['\uFCB7'] = '\u0636\u0645';
  18685. t['\uFCB8'] = '\u0637\u062D';
  18686. t['\uFCB9'] = '\u0638\u0645';
  18687. t['\uFCBA'] = '\u0639\u062C';
  18688. t['\uFCBB'] = '\u0639\u0645';
  18689. t['\uFCBC'] = '\u063A\u062C';
  18690. t['\uFCBD'] = '\u063A\u0645';
  18691. t['\uFCBE'] = '\u0641\u062C';
  18692. t['\uFCBF'] = '\u0641\u062D';
  18693. t['\uFCC0'] = '\u0641\u062E';
  18694. t['\uFCC1'] = '\u0641\u0645';
  18695. t['\uFCC2'] = '\u0642\u062D';
  18696. t['\uFCC3'] = '\u0642\u0645';
  18697. t['\uFCC4'] = '\u0643\u062C';
  18698. t['\uFCC5'] = '\u0643\u062D';
  18699. t['\uFCC6'] = '\u0643\u062E';
  18700. t['\uFCC7'] = '\u0643\u0644';
  18701. t['\uFCC8'] = '\u0643\u0645';
  18702. t['\uFCC9'] = '\u0644\u062C';
  18703. t['\uFCCA'] = '\u0644\u062D';
  18704. t['\uFCCB'] = '\u0644\u062E';
  18705. t['\uFCCC'] = '\u0644\u0645';
  18706. t['\uFCCD'] = '\u0644\u0647';
  18707. t['\uFCCE'] = '\u0645\u062C';
  18708. t['\uFCCF'] = '\u0645\u062D';
  18709. t['\uFCD0'] = '\u0645\u062E';
  18710. t['\uFCD1'] = '\u0645\u0645';
  18711. t['\uFCD2'] = '\u0646\u062C';
  18712. t['\uFCD3'] = '\u0646\u062D';
  18713. t['\uFCD4'] = '\u0646\u062E';
  18714. t['\uFCD5'] = '\u0646\u0645';
  18715. t['\uFCD6'] = '\u0646\u0647';
  18716. t['\uFCD7'] = '\u0647\u062C';
  18717. t['\uFCD8'] = '\u0647\u0645';
  18718. t['\uFCD9'] = '\u0647\u0670';
  18719. t['\uFCDA'] = '\u064A\u062C';
  18720. t['\uFCDB'] = '\u064A\u062D';
  18721. t['\uFCDC'] = '\u064A\u062E';
  18722. t['\uFCDD'] = '\u064A\u0645';
  18723. t['\uFCDE'] = '\u064A\u0647';
  18724. t['\uFCDF'] = '\u0626\u0645';
  18725. t['\uFCE0'] = '\u0626\u0647';
  18726. t['\uFCE1'] = '\u0628\u0645';
  18727. t['\uFCE2'] = '\u0628\u0647';
  18728. t['\uFCE3'] = '\u062A\u0645';
  18729. t['\uFCE4'] = '\u062A\u0647';
  18730. t['\uFCE5'] = '\u062B\u0645';
  18731. t['\uFCE6'] = '\u062B\u0647';
  18732. t['\uFCE7'] = '\u0633\u0645';
  18733. t['\uFCE8'] = '\u0633\u0647';
  18734. t['\uFCE9'] = '\u0634\u0645';
  18735. t['\uFCEA'] = '\u0634\u0647';
  18736. t['\uFCEB'] = '\u0643\u0644';
  18737. t['\uFCEC'] = '\u0643\u0645';
  18738. t['\uFCED'] = '\u0644\u0645';
  18739. t['\uFCEE'] = '\u0646\u0645';
  18740. t['\uFCEF'] = '\u0646\u0647';
  18741. t['\uFCF0'] = '\u064A\u0645';
  18742. t['\uFCF1'] = '\u064A\u0647';
  18743. t['\uFCF2'] = '\u0640\u064E\u0651';
  18744. t['\uFCF3'] = '\u0640\u064F\u0651';
  18745. t['\uFCF4'] = '\u0640\u0650\u0651';
  18746. t['\uFCF5'] = '\u0637\u0649';
  18747. t['\uFCF6'] = '\u0637\u064A';
  18748. t['\uFCF7'] = '\u0639\u0649';
  18749. t['\uFCF8'] = '\u0639\u064A';
  18750. t['\uFCF9'] = '\u063A\u0649';
  18751. t['\uFCFA'] = '\u063A\u064A';
  18752. t['\uFCFB'] = '\u0633\u0649';
  18753. t['\uFCFC'] = '\u0633\u064A';
  18754. t['\uFCFD'] = '\u0634\u0649';
  18755. t['\uFCFE'] = '\u0634\u064A';
  18756. t['\uFCFF'] = '\u062D\u0649';
  18757. t['\uFD00'] = '\u062D\u064A';
  18758. t['\uFD01'] = '\u062C\u0649';
  18759. t['\uFD02'] = '\u062C\u064A';
  18760. t['\uFD03'] = '\u062E\u0649';
  18761. t['\uFD04'] = '\u062E\u064A';
  18762. t['\uFD05'] = '\u0635\u0649';
  18763. t['\uFD06'] = '\u0635\u064A';
  18764. t['\uFD07'] = '\u0636\u0649';
  18765. t['\uFD08'] = '\u0636\u064A';
  18766. t['\uFD09'] = '\u0634\u062C';
  18767. t['\uFD0A'] = '\u0634\u062D';
  18768. t['\uFD0B'] = '\u0634\u062E';
  18769. t['\uFD0C'] = '\u0634\u0645';
  18770. t['\uFD0D'] = '\u0634\u0631';
  18771. t['\uFD0E'] = '\u0633\u0631';
  18772. t['\uFD0F'] = '\u0635\u0631';
  18773. t['\uFD10'] = '\u0636\u0631';
  18774. t['\uFD11'] = '\u0637\u0649';
  18775. t['\uFD12'] = '\u0637\u064A';
  18776. t['\uFD13'] = '\u0639\u0649';
  18777. t['\uFD14'] = '\u0639\u064A';
  18778. t['\uFD15'] = '\u063A\u0649';
  18779. t['\uFD16'] = '\u063A\u064A';
  18780. t['\uFD17'] = '\u0633\u0649';
  18781. t['\uFD18'] = '\u0633\u064A';
  18782. t['\uFD19'] = '\u0634\u0649';
  18783. t['\uFD1A'] = '\u0634\u064A';
  18784. t['\uFD1B'] = '\u062D\u0649';
  18785. t['\uFD1C'] = '\u062D\u064A';
  18786. t['\uFD1D'] = '\u062C\u0649';
  18787. t['\uFD1E'] = '\u062C\u064A';
  18788. t['\uFD1F'] = '\u062E\u0649';
  18789. t['\uFD20'] = '\u062E\u064A';
  18790. t['\uFD21'] = '\u0635\u0649';
  18791. t['\uFD22'] = '\u0635\u064A';
  18792. t['\uFD23'] = '\u0636\u0649';
  18793. t['\uFD24'] = '\u0636\u064A';
  18794. t['\uFD25'] = '\u0634\u062C';
  18795. t['\uFD26'] = '\u0634\u062D';
  18796. t['\uFD27'] = '\u0634\u062E';
  18797. t['\uFD28'] = '\u0634\u0645';
  18798. t['\uFD29'] = '\u0634\u0631';
  18799. t['\uFD2A'] = '\u0633\u0631';
  18800. t['\uFD2B'] = '\u0635\u0631';
  18801. t['\uFD2C'] = '\u0636\u0631';
  18802. t['\uFD2D'] = '\u0634\u062C';
  18803. t['\uFD2E'] = '\u0634\u062D';
  18804. t['\uFD2F'] = '\u0634\u062E';
  18805. t['\uFD30'] = '\u0634\u0645';
  18806. t['\uFD31'] = '\u0633\u0647';
  18807. t['\uFD32'] = '\u0634\u0647';
  18808. t['\uFD33'] = '\u0637\u0645';
  18809. t['\uFD34'] = '\u0633\u062C';
  18810. t['\uFD35'] = '\u0633\u062D';
  18811. t['\uFD36'] = '\u0633\u062E';
  18812. t['\uFD37'] = '\u0634\u062C';
  18813. t['\uFD38'] = '\u0634\u062D';
  18814. t['\uFD39'] = '\u0634\u062E';
  18815. t['\uFD3A'] = '\u0637\u0645';
  18816. t['\uFD3B'] = '\u0638\u0645';
  18817. t['\uFD3C'] = '\u0627\u064B';
  18818. t['\uFD3D'] = '\u0627\u064B';
  18819. t['\uFD50'] = '\u062A\u062C\u0645';
  18820. t['\uFD51'] = '\u062A\u062D\u062C';
  18821. t['\uFD52'] = '\u062A\u062D\u062C';
  18822. t['\uFD53'] = '\u062A\u062D\u0645';
  18823. t['\uFD54'] = '\u062A\u062E\u0645';
  18824. t['\uFD55'] = '\u062A\u0645\u062C';
  18825. t['\uFD56'] = '\u062A\u0645\u062D';
  18826. t['\uFD57'] = '\u062A\u0645\u062E';
  18827. t['\uFD58'] = '\u062C\u0645\u062D';
  18828. t['\uFD59'] = '\u062C\u0645\u062D';
  18829. t['\uFD5A'] = '\u062D\u0645\u064A';
  18830. t['\uFD5B'] = '\u062D\u0645\u0649';
  18831. t['\uFD5C'] = '\u0633\u062D\u062C';
  18832. t['\uFD5D'] = '\u0633\u062C\u062D';
  18833. t['\uFD5E'] = '\u0633\u062C\u0649';
  18834. t['\uFD5F'] = '\u0633\u0645\u062D';
  18835. t['\uFD60'] = '\u0633\u0645\u062D';
  18836. t['\uFD61'] = '\u0633\u0645\u062C';
  18837. t['\uFD62'] = '\u0633\u0645\u0645';
  18838. t['\uFD63'] = '\u0633\u0645\u0645';
  18839. t['\uFD64'] = '\u0635\u062D\u062D';
  18840. t['\uFD65'] = '\u0635\u062D\u062D';
  18841. t['\uFD66'] = '\u0635\u0645\u0645';
  18842. t['\uFD67'] = '\u0634\u062D\u0645';
  18843. t['\uFD68'] = '\u0634\u062D\u0645';
  18844. t['\uFD69'] = '\u0634\u062C\u064A';
  18845. t['\uFD6A'] = '\u0634\u0645\u062E';
  18846. t['\uFD6B'] = '\u0634\u0645\u062E';
  18847. t['\uFD6C'] = '\u0634\u0645\u0645';
  18848. t['\uFD6D'] = '\u0634\u0645\u0645';
  18849. t['\uFD6E'] = '\u0636\u062D\u0649';
  18850. t['\uFD6F'] = '\u0636\u062E\u0645';
  18851. t['\uFD70'] = '\u0636\u062E\u0645';
  18852. t['\uFD71'] = '\u0637\u0645\u062D';
  18853. t['\uFD72'] = '\u0637\u0645\u062D';
  18854. t['\uFD73'] = '\u0637\u0645\u0645';
  18855. t['\uFD74'] = '\u0637\u0645\u064A';
  18856. t['\uFD75'] = '\u0639\u062C\u0645';
  18857. t['\uFD76'] = '\u0639\u0645\u0645';
  18858. t['\uFD77'] = '\u0639\u0645\u0645';
  18859. t['\uFD78'] = '\u0639\u0645\u0649';
  18860. t['\uFD79'] = '\u063A\u0645\u0645';
  18861. t['\uFD7A'] = '\u063A\u0645\u064A';
  18862. t['\uFD7B'] = '\u063A\u0645\u0649';
  18863. t['\uFD7C'] = '\u0641\u062E\u0645';
  18864. t['\uFD7D'] = '\u0641\u062E\u0645';
  18865. t['\uFD7E'] = '\u0642\u0645\u062D';
  18866. t['\uFD7F'] = '\u0642\u0645\u0645';
  18867. t['\uFD80'] = '\u0644\u062D\u0645';
  18868. t['\uFD81'] = '\u0644\u062D\u064A';
  18869. t['\uFD82'] = '\u0644\u062D\u0649';
  18870. t['\uFD83'] = '\u0644\u062C\u062C';
  18871. t['\uFD84'] = '\u0644\u062C\u062C';
  18872. t['\uFD85'] = '\u0644\u062E\u0645';
  18873. t['\uFD86'] = '\u0644\u062E\u0645';
  18874. t['\uFD87'] = '\u0644\u0645\u062D';
  18875. t['\uFD88'] = '\u0644\u0645\u062D';
  18876. t['\uFD89'] = '\u0645\u062D\u062C';
  18877. t['\uFD8A'] = '\u0645\u062D\u0645';
  18878. t['\uFD8B'] = '\u0645\u062D\u064A';
  18879. t['\uFD8C'] = '\u0645\u062C\u062D';
  18880. t['\uFD8D'] = '\u0645\u062C\u0645';
  18881. t['\uFD8E'] = '\u0645\u062E\u062C';
  18882. t['\uFD8F'] = '\u0645\u062E\u0645';
  18883. t['\uFD92'] = '\u0645\u062C\u062E';
  18884. t['\uFD93'] = '\u0647\u0645\u062C';
  18885. t['\uFD94'] = '\u0647\u0645\u0645';
  18886. t['\uFD95'] = '\u0646\u062D\u0645';
  18887. t['\uFD96'] = '\u0646\u062D\u0649';
  18888. t['\uFD97'] = '\u0646\u062C\u0645';
  18889. t['\uFD98'] = '\u0646\u062C\u0645';
  18890. t['\uFD99'] = '\u0646\u062C\u0649';
  18891. t['\uFD9A'] = '\u0646\u0645\u064A';
  18892. t['\uFD9B'] = '\u0646\u0645\u0649';
  18893. t['\uFD9C'] = '\u064A\u0645\u0645';
  18894. t['\uFD9D'] = '\u064A\u0645\u0645';
  18895. t['\uFD9E'] = '\u0628\u062E\u064A';
  18896. t['\uFD9F'] = '\u062A\u062C\u064A';
  18897. t['\uFDA0'] = '\u062A\u062C\u0649';
  18898. t['\uFDA1'] = '\u062A\u062E\u064A';
  18899. t['\uFDA2'] = '\u062A\u062E\u0649';
  18900. t['\uFDA3'] = '\u062A\u0645\u064A';
  18901. t['\uFDA4'] = '\u062A\u0645\u0649';
  18902. t['\uFDA5'] = '\u062C\u0645\u064A';
  18903. t['\uFDA6'] = '\u062C\u062D\u0649';
  18904. t['\uFDA7'] = '\u062C\u0645\u0649';
  18905. t['\uFDA8'] = '\u0633\u062E\u0649';
  18906. t['\uFDA9'] = '\u0635\u062D\u064A';
  18907. t['\uFDAA'] = '\u0634\u062D\u064A';
  18908. t['\uFDAB'] = '\u0636\u062D\u064A';
  18909. t['\uFDAC'] = '\u0644\u062C\u064A';
  18910. t['\uFDAD'] = '\u0644\u0645\u064A';
  18911. t['\uFDAE'] = '\u064A\u062D\u064A';
  18912. t['\uFDAF'] = '\u064A\u062C\u064A';
  18913. t['\uFDB0'] = '\u064A\u0645\u064A';
  18914. t['\uFDB1'] = '\u0645\u0645\u064A';
  18915. t['\uFDB2'] = '\u0642\u0645\u064A';
  18916. t['\uFDB3'] = '\u0646\u062D\u064A';
  18917. t['\uFDB4'] = '\u0642\u0645\u062D';
  18918. t['\uFDB5'] = '\u0644\u062D\u0645';
  18919. t['\uFDB6'] = '\u0639\u0645\u064A';
  18920. t['\uFDB7'] = '\u0643\u0645\u064A';
  18921. t['\uFDB8'] = '\u0646\u062C\u062D';
  18922. t['\uFDB9'] = '\u0645\u062E\u064A';
  18923. t['\uFDBA'] = '\u0644\u062C\u0645';
  18924. t['\uFDBB'] = '\u0643\u0645\u0645';
  18925. t['\uFDBC'] = '\u0644\u062C\u0645';
  18926. t['\uFDBD'] = '\u0646\u062C\u062D';
  18927. t['\uFDBE'] = '\u062C\u062D\u064A';
  18928. t['\uFDBF'] = '\u062D\u062C\u064A';
  18929. t['\uFDC0'] = '\u0645\u062C\u064A';
  18930. t['\uFDC1'] = '\u0641\u0645\u064A';
  18931. t['\uFDC2'] = '\u0628\u062D\u064A';
  18932. t['\uFDC3'] = '\u0643\u0645\u0645';
  18933. t['\uFDC4'] = '\u0639\u062C\u0645';
  18934. t['\uFDC5'] = '\u0635\u0645\u0645';
  18935. t['\uFDC6'] = '\u0633\u062E\u064A';
  18936. t['\uFDC7'] = '\u0646\u062C\u064A';
  18937. t['\uFE49'] = '\u203E';
  18938. t['\uFE4A'] = '\u203E';
  18939. t['\uFE4B'] = '\u203E';
  18940. t['\uFE4C'] = '\u203E';
  18941. t['\uFE4D'] = '\u005F';
  18942. t['\uFE4E'] = '\u005F';
  18943. t['\uFE4F'] = '\u005F';
  18944. t['\uFE80'] = '\u0621';
  18945. t['\uFE81'] = '\u0622';
  18946. t['\uFE82'] = '\u0622';
  18947. t['\uFE83'] = '\u0623';
  18948. t['\uFE84'] = '\u0623';
  18949. t['\uFE85'] = '\u0624';
  18950. t['\uFE86'] = '\u0624';
  18951. t['\uFE87'] = '\u0625';
  18952. t['\uFE88'] = '\u0625';
  18953. t['\uFE89'] = '\u0626';
  18954. t['\uFE8A'] = '\u0626';
  18955. t['\uFE8B'] = '\u0626';
  18956. t['\uFE8C'] = '\u0626';
  18957. t['\uFE8D'] = '\u0627';
  18958. t['\uFE8E'] = '\u0627';
  18959. t['\uFE8F'] = '\u0628';
  18960. t['\uFE90'] = '\u0628';
  18961. t['\uFE91'] = '\u0628';
  18962. t['\uFE92'] = '\u0628';
  18963. t['\uFE93'] = '\u0629';
  18964. t['\uFE94'] = '\u0629';
  18965. t['\uFE95'] = '\u062A';
  18966. t['\uFE96'] = '\u062A';
  18967. t['\uFE97'] = '\u062A';
  18968. t['\uFE98'] = '\u062A';
  18969. t['\uFE99'] = '\u062B';
  18970. t['\uFE9A'] = '\u062B';
  18971. t['\uFE9B'] = '\u062B';
  18972. t['\uFE9C'] = '\u062B';
  18973. t['\uFE9D'] = '\u062C';
  18974. t['\uFE9E'] = '\u062C';
  18975. t['\uFE9F'] = '\u062C';
  18976. t['\uFEA0'] = '\u062C';
  18977. t['\uFEA1'] = '\u062D';
  18978. t['\uFEA2'] = '\u062D';
  18979. t['\uFEA3'] = '\u062D';
  18980. t['\uFEA4'] = '\u062D';
  18981. t['\uFEA5'] = '\u062E';
  18982. t['\uFEA6'] = '\u062E';
  18983. t['\uFEA7'] = '\u062E';
  18984. t['\uFEA8'] = '\u062E';
  18985. t['\uFEA9'] = '\u062F';
  18986. t['\uFEAA'] = '\u062F';
  18987. t['\uFEAB'] = '\u0630';
  18988. t['\uFEAC'] = '\u0630';
  18989. t['\uFEAD'] = '\u0631';
  18990. t['\uFEAE'] = '\u0631';
  18991. t['\uFEAF'] = '\u0632';
  18992. t['\uFEB0'] = '\u0632';
  18993. t['\uFEB1'] = '\u0633';
  18994. t['\uFEB2'] = '\u0633';
  18995. t['\uFEB3'] = '\u0633';
  18996. t['\uFEB4'] = '\u0633';
  18997. t['\uFEB5'] = '\u0634';
  18998. t['\uFEB6'] = '\u0634';
  18999. t['\uFEB7'] = '\u0634';
  19000. t['\uFEB8'] = '\u0634';
  19001. t['\uFEB9'] = '\u0635';
  19002. t['\uFEBA'] = '\u0635';
  19003. t['\uFEBB'] = '\u0635';
  19004. t['\uFEBC'] = '\u0635';
  19005. t['\uFEBD'] = '\u0636';
  19006. t['\uFEBE'] = '\u0636';
  19007. t['\uFEBF'] = '\u0636';
  19008. t['\uFEC0'] = '\u0636';
  19009. t['\uFEC1'] = '\u0637';
  19010. t['\uFEC2'] = '\u0637';
  19011. t['\uFEC3'] = '\u0637';
  19012. t['\uFEC4'] = '\u0637';
  19013. t['\uFEC5'] = '\u0638';
  19014. t['\uFEC6'] = '\u0638';
  19015. t['\uFEC7'] = '\u0638';
  19016. t['\uFEC8'] = '\u0638';
  19017. t['\uFEC9'] = '\u0639';
  19018. t['\uFECA'] = '\u0639';
  19019. t['\uFECB'] = '\u0639';
  19020. t['\uFECC'] = '\u0639';
  19021. t['\uFECD'] = '\u063A';
  19022. t['\uFECE'] = '\u063A';
  19023. t['\uFECF'] = '\u063A';
  19024. t['\uFED0'] = '\u063A';
  19025. t['\uFED1'] = '\u0641';
  19026. t['\uFED2'] = '\u0641';
  19027. t['\uFED3'] = '\u0641';
  19028. t['\uFED4'] = '\u0641';
  19029. t['\uFED5'] = '\u0642';
  19030. t['\uFED6'] = '\u0642';
  19031. t['\uFED7'] = '\u0642';
  19032. t['\uFED8'] = '\u0642';
  19033. t['\uFED9'] = '\u0643';
  19034. t['\uFEDA'] = '\u0643';
  19035. t['\uFEDB'] = '\u0643';
  19036. t['\uFEDC'] = '\u0643';
  19037. t['\uFEDD'] = '\u0644';
  19038. t['\uFEDE'] = '\u0644';
  19039. t['\uFEDF'] = '\u0644';
  19040. t['\uFEE0'] = '\u0644';
  19041. t['\uFEE1'] = '\u0645';
  19042. t['\uFEE2'] = '\u0645';
  19043. t['\uFEE3'] = '\u0645';
  19044. t['\uFEE4'] = '\u0645';
  19045. t['\uFEE5'] = '\u0646';
  19046. t['\uFEE6'] = '\u0646';
  19047. t['\uFEE7'] = '\u0646';
  19048. t['\uFEE8'] = '\u0646';
  19049. t['\uFEE9'] = '\u0647';
  19050. t['\uFEEA'] = '\u0647';
  19051. t['\uFEEB'] = '\u0647';
  19052. t['\uFEEC'] = '\u0647';
  19053. t['\uFEED'] = '\u0648';
  19054. t['\uFEEE'] = '\u0648';
  19055. t['\uFEEF'] = '\u0649';
  19056. t['\uFEF0'] = '\u0649';
  19057. t['\uFEF1'] = '\u064A';
  19058. t['\uFEF2'] = '\u064A';
  19059. t['\uFEF3'] = '\u064A';
  19060. t['\uFEF4'] = '\u064A';
  19061. t['\uFEF5'] = '\u0644\u0622';
  19062. t['\uFEF6'] = '\u0644\u0622';
  19063. t['\uFEF7'] = '\u0644\u0623';
  19064. t['\uFEF8'] = '\u0644\u0623';
  19065. t['\uFEF9'] = '\u0644\u0625';
  19066. t['\uFEFA'] = '\u0644\u0625';
  19067. t['\uFEFB'] = '\u0644\u0627';
  19068. t['\uFEFC'] = '\u0644\u0627';
  19069. });
  19070. function reverseIfRtl(chars) {
  19071. var charsLength = chars.length;
  19072. //reverse an arabic ligature
  19073. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  19074. return chars;
  19075. }
  19076. var s = '';
  19077. for (var ii = charsLength - 1; ii >= 0; ii--) {
  19078. s += chars[ii];
  19079. }
  19080. return s;
  19081. }
  19082. exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues;
  19083. exports.reverseIfRtl = reverseIfRtl;
  19084. exports.getUnicodeRangeFor = getUnicodeRangeFor;
  19085. exports.getNormalizedUnicodes = getNormalizedUnicodes;
  19086. exports.getUnicodeForGlyph = getUnicodeForGlyph;
  19087. }));
  19088. (function (root, factory) {
  19089. {
  19090. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  19091. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  19092. root.pdfjsCoreJpx);
  19093. }
  19094. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  19095. coreJpx) {
  19096. var Util = sharedUtil.Util;
  19097. var error = sharedUtil.error;
  19098. var info = sharedUtil.info;
  19099. var isInt = sharedUtil.isInt;
  19100. var isArray = sharedUtil.isArray;
  19101. var createObjectURL = sharedUtil.createObjectURL;
  19102. var shadow = sharedUtil.shadow;
  19103. var warn = sharedUtil.warn;
  19104. var isSpace = sharedUtil.isSpace;
  19105. var Dict = corePrimitives.Dict;
  19106. var isDict = corePrimitives.isDict;
  19107. var Jbig2Image = coreJbig2.Jbig2Image;
  19108. var JpegImage = coreJpg.JpegImage;
  19109. var JpxImage = coreJpx.JpxImage;
  19110. var Stream = (function StreamClosure() {
  19111. function Stream(arrayBuffer, start, length, dict) {
  19112. this.bytes = (arrayBuffer instanceof Uint8Array ?
  19113. arrayBuffer : new Uint8Array(arrayBuffer));
  19114. this.start = start || 0;
  19115. this.pos = this.start;
  19116. this.end = (start + length) || this.bytes.length;
  19117. this.dict = dict;
  19118. }
  19119. // required methods for a stream. if a particular stream does not
  19120. // implement these, an error should be thrown
  19121. Stream.prototype = {
  19122. get length() {
  19123. return this.end - this.start;
  19124. },
  19125. get isEmpty() {
  19126. return this.length === 0;
  19127. },
  19128. getByte: function Stream_getByte() {
  19129. if (this.pos >= this.end) {
  19130. return -1;
  19131. }
  19132. return this.bytes[this.pos++];
  19133. },
  19134. getUint16: function Stream_getUint16() {
  19135. var b0 = this.getByte();
  19136. var b1 = this.getByte();
  19137. if (b0 === -1 || b1 === -1) {
  19138. return -1;
  19139. }
  19140. return (b0 << 8) + b1;
  19141. },
  19142. getInt32: function Stream_getInt32() {
  19143. var b0 = this.getByte();
  19144. var b1 = this.getByte();
  19145. var b2 = this.getByte();
  19146. var b3 = this.getByte();
  19147. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  19148. },
  19149. // returns subarray of original buffer
  19150. // should only be read
  19151. getBytes: function Stream_getBytes(length) {
  19152. var bytes = this.bytes;
  19153. var pos = this.pos;
  19154. var strEnd = this.end;
  19155. if (!length) {
  19156. return bytes.subarray(pos, strEnd);
  19157. }
  19158. var end = pos + length;
  19159. if (end > strEnd) {
  19160. end = strEnd;
  19161. }
  19162. this.pos = end;
  19163. return bytes.subarray(pos, end);
  19164. },
  19165. peekByte: function Stream_peekByte() {
  19166. var peekedByte = this.getByte();
  19167. this.pos--;
  19168. return peekedByte;
  19169. },
  19170. peekBytes: function Stream_peekBytes(length) {
  19171. var bytes = this.getBytes(length);
  19172. this.pos -= bytes.length;
  19173. return bytes;
  19174. },
  19175. skip: function Stream_skip(n) {
  19176. if (!n) {
  19177. n = 1;
  19178. }
  19179. this.pos += n;
  19180. },
  19181. reset: function Stream_reset() {
  19182. this.pos = this.start;
  19183. },
  19184. moveStart: function Stream_moveStart() {
  19185. this.start = this.pos;
  19186. },
  19187. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  19188. return new Stream(this.bytes.buffer, start, length, dict);
  19189. },
  19190. isStream: true
  19191. };
  19192. return Stream;
  19193. })();
  19194. var StringStream = (function StringStreamClosure() {
  19195. function StringStream(str) {
  19196. var length = str.length;
  19197. var bytes = new Uint8Array(length);
  19198. for (var n = 0; n < length; ++n) {
  19199. bytes[n] = str.charCodeAt(n);
  19200. }
  19201. Stream.call(this, bytes);
  19202. }
  19203. StringStream.prototype = Stream.prototype;
  19204. return StringStream;
  19205. })();
  19206. // super class for the decoding streams
  19207. var DecodeStream = (function DecodeStreamClosure() {
  19208. // Lots of DecodeStreams are created whose buffers are never used. For these
  19209. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  19210. // having special cases that would be required if we used |null| for an empty
  19211. // buffer.
  19212. var emptyBuffer = new Uint8Array(0);
  19213. function DecodeStream(maybeMinBufferLength) {
  19214. this.pos = 0;
  19215. this.bufferLength = 0;
  19216. this.eof = false;
  19217. this.buffer = emptyBuffer;
  19218. this.minBufferLength = 512;
  19219. if (maybeMinBufferLength) {
  19220. // Compute the first power of two that is as big as maybeMinBufferLength.
  19221. while (this.minBufferLength < maybeMinBufferLength) {
  19222. this.minBufferLength *= 2;
  19223. }
  19224. }
  19225. }
  19226. DecodeStream.prototype = {
  19227. get isEmpty() {
  19228. while (!this.eof && this.bufferLength === 0) {
  19229. this.readBlock();
  19230. }
  19231. return this.bufferLength === 0;
  19232. },
  19233. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  19234. var buffer = this.buffer;
  19235. if (requested <= buffer.byteLength) {
  19236. return buffer;
  19237. }
  19238. var size = this.minBufferLength;
  19239. while (size < requested) {
  19240. size *= 2;
  19241. }
  19242. var buffer2 = new Uint8Array(size);
  19243. buffer2.set(buffer);
  19244. return (this.buffer = buffer2);
  19245. },
  19246. getByte: function DecodeStream_getByte() {
  19247. var pos = this.pos;
  19248. while (this.bufferLength <= pos) {
  19249. if (this.eof) {
  19250. return -1;
  19251. }
  19252. this.readBlock();
  19253. }
  19254. return this.buffer[this.pos++];
  19255. },
  19256. getUint16: function DecodeStream_getUint16() {
  19257. var b0 = this.getByte();
  19258. var b1 = this.getByte();
  19259. if (b0 === -1 || b1 === -1) {
  19260. return -1;
  19261. }
  19262. return (b0 << 8) + b1;
  19263. },
  19264. getInt32: function DecodeStream_getInt32() {
  19265. var b0 = this.getByte();
  19266. var b1 = this.getByte();
  19267. var b2 = this.getByte();
  19268. var b3 = this.getByte();
  19269. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  19270. },
  19271. getBytes: function DecodeStream_getBytes(length) {
  19272. var end, pos = this.pos;
  19273. if (length) {
  19274. this.ensureBuffer(pos + length);
  19275. end = pos + length;
  19276. while (!this.eof && this.bufferLength < end) {
  19277. this.readBlock();
  19278. }
  19279. var bufEnd = this.bufferLength;
  19280. if (end > bufEnd) {
  19281. end = bufEnd;
  19282. }
  19283. } else {
  19284. while (!this.eof) {
  19285. this.readBlock();
  19286. }
  19287. end = this.bufferLength;
  19288. }
  19289. this.pos = end;
  19290. return this.buffer.subarray(pos, end);
  19291. },
  19292. peekByte: function DecodeStream_peekByte() {
  19293. var peekedByte = this.getByte();
  19294. this.pos--;
  19295. return peekedByte;
  19296. },
  19297. peekBytes: function DecodeStream_peekBytes(length) {
  19298. var bytes = this.getBytes(length);
  19299. this.pos -= bytes.length;
  19300. return bytes;
  19301. },
  19302. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  19303. var end = start + length;
  19304. while (this.bufferLength <= end && !this.eof) {
  19305. this.readBlock();
  19306. }
  19307. return new Stream(this.buffer, start, length, dict);
  19308. },
  19309. skip: function DecodeStream_skip(n) {
  19310. if (!n) {
  19311. n = 1;
  19312. }
  19313. this.pos += n;
  19314. },
  19315. reset: function DecodeStream_reset() {
  19316. this.pos = 0;
  19317. },
  19318. getBaseStreams: function DecodeStream_getBaseStreams() {
  19319. if (this.str && this.str.getBaseStreams) {
  19320. return this.str.getBaseStreams();
  19321. }
  19322. return [];
  19323. }
  19324. };
  19325. return DecodeStream;
  19326. })();
  19327. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  19328. function StreamsSequenceStream(streams) {
  19329. this.streams = streams;
  19330. DecodeStream.call(this, /* maybeLength = */ null);
  19331. }
  19332. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  19333. StreamsSequenceStream.prototype.readBlock =
  19334. function streamSequenceStreamReadBlock() {
  19335. var streams = this.streams;
  19336. if (streams.length === 0) {
  19337. this.eof = true;
  19338. return;
  19339. }
  19340. var stream = streams.shift();
  19341. var chunk = stream.getBytes();
  19342. var bufferLength = this.bufferLength;
  19343. var newLength = bufferLength + chunk.length;
  19344. var buffer = this.ensureBuffer(newLength);
  19345. buffer.set(chunk, bufferLength);
  19346. this.bufferLength = newLength;
  19347. };
  19348. StreamsSequenceStream.prototype.getBaseStreams =
  19349. function StreamsSequenceStream_getBaseStreams() {
  19350. var baseStreams = [];
  19351. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  19352. var stream = this.streams[i];
  19353. if (stream.getBaseStreams) {
  19354. Util.appendToArray(baseStreams, stream.getBaseStreams());
  19355. }
  19356. }
  19357. return baseStreams;
  19358. };
  19359. return StreamsSequenceStream;
  19360. })();
  19361. var FlateStream = (function FlateStreamClosure() {
  19362. var codeLenCodeMap = new Int32Array([
  19363. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  19364. ]);
  19365. var lengthDecode = new Int32Array([
  19366. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  19367. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  19368. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  19369. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  19370. ]);
  19371. var distDecode = new Int32Array([
  19372. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  19373. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  19374. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  19375. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  19376. ]);
  19377. var fixedLitCodeTab = [new Int32Array([
  19378. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  19379. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  19380. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  19381. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  19382. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  19383. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  19384. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  19385. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  19386. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  19387. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  19388. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  19389. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  19390. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  19391. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  19392. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  19393. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  19394. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  19395. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  19396. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  19397. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  19398. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  19399. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  19400. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  19401. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  19402. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  19403. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  19404. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  19405. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  19406. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  19407. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  19408. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  19409. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  19410. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  19411. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  19412. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  19413. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  19414. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  19415. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  19416. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  19417. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  19418. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  19419. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  19420. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  19421. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  19422. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  19423. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  19424. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  19425. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  19426. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  19427. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  19428. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  19429. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  19430. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  19431. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  19432. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  19433. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  19434. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  19435. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  19436. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  19437. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  19438. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  19439. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  19440. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  19441. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  19442. ]), 9];
  19443. var fixedDistCodeTab = [new Int32Array([
  19444. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  19445. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  19446. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  19447. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  19448. ]), 5];
  19449. function FlateStream(str, maybeLength) {
  19450. this.str = str;
  19451. this.dict = str.dict;
  19452. var cmf = str.getByte();
  19453. var flg = str.getByte();
  19454. if (cmf === -1 || flg === -1) {
  19455. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  19456. }
  19457. if ((cmf & 0x0f) !== 0x08) {
  19458. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  19459. }
  19460. if ((((cmf << 8) + flg) % 31) !== 0) {
  19461. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  19462. }
  19463. if (flg & 0x20) {
  19464. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  19465. }
  19466. this.codeSize = 0;
  19467. this.codeBuf = 0;
  19468. DecodeStream.call(this, maybeLength);
  19469. }
  19470. FlateStream.prototype = Object.create(DecodeStream.prototype);
  19471. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  19472. var str = this.str;
  19473. var codeSize = this.codeSize;
  19474. var codeBuf = this.codeBuf;
  19475. var b;
  19476. while (codeSize < bits) {
  19477. if ((b = str.getByte()) === -1) {
  19478. error('Bad encoding in flate stream');
  19479. }
  19480. codeBuf |= b << codeSize;
  19481. codeSize += 8;
  19482. }
  19483. b = codeBuf & ((1 << bits) - 1);
  19484. this.codeBuf = codeBuf >> bits;
  19485. this.codeSize = codeSize -= bits;
  19486. return b;
  19487. };
  19488. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  19489. var str = this.str;
  19490. var codes = table[0];
  19491. var maxLen = table[1];
  19492. var codeSize = this.codeSize;
  19493. var codeBuf = this.codeBuf;
  19494. var b;
  19495. while (codeSize < maxLen) {
  19496. if ((b = str.getByte()) === -1) {
  19497. // premature end of stream. code might however still be valid.
  19498. // codeSize < codeLen check below guards against incomplete codeVal.
  19499. break;
  19500. }
  19501. codeBuf |= (b << codeSize);
  19502. codeSize += 8;
  19503. }
  19504. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  19505. var codeLen = code >> 16;
  19506. var codeVal = code & 0xffff;
  19507. if (codeLen < 1 || codeSize < codeLen) {
  19508. error('Bad encoding in flate stream');
  19509. }
  19510. this.codeBuf = (codeBuf >> codeLen);
  19511. this.codeSize = (codeSize - codeLen);
  19512. return codeVal;
  19513. };
  19514. FlateStream.prototype.generateHuffmanTable =
  19515. function flateStreamGenerateHuffmanTable(lengths) {
  19516. var n = lengths.length;
  19517. // find max code length
  19518. var maxLen = 0;
  19519. var i;
  19520. for (i = 0; i < n; ++i) {
  19521. if (lengths[i] > maxLen) {
  19522. maxLen = lengths[i];
  19523. }
  19524. }
  19525. // build the table
  19526. var size = 1 << maxLen;
  19527. var codes = new Int32Array(size);
  19528. for (var len = 1, code = 0, skip = 2;
  19529. len <= maxLen;
  19530. ++len, code <<= 1, skip <<= 1) {
  19531. for (var val = 0; val < n; ++val) {
  19532. if (lengths[val] === len) {
  19533. // bit-reverse the code
  19534. var code2 = 0;
  19535. var t = code;
  19536. for (i = 0; i < len; ++i) {
  19537. code2 = (code2 << 1) | (t & 1);
  19538. t >>= 1;
  19539. }
  19540. // fill the table entries
  19541. for (i = code2; i < size; i += skip) {
  19542. codes[i] = (len << 16) | val;
  19543. }
  19544. ++code;
  19545. }
  19546. }
  19547. }
  19548. return [codes, maxLen];
  19549. };
  19550. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  19551. var buffer, len;
  19552. var str = this.str;
  19553. // read block header
  19554. var hdr = this.getBits(3);
  19555. if (hdr & 1) {
  19556. this.eof = true;
  19557. }
  19558. hdr >>= 1;
  19559. if (hdr === 0) { // uncompressed block
  19560. var b;
  19561. if ((b = str.getByte()) === -1) {
  19562. error('Bad block header in flate stream');
  19563. }
  19564. var blockLen = b;
  19565. if ((b = str.getByte()) === -1) {
  19566. error('Bad block header in flate stream');
  19567. }
  19568. blockLen |= (b << 8);
  19569. if ((b = str.getByte()) === -1) {
  19570. error('Bad block header in flate stream');
  19571. }
  19572. var check = b;
  19573. if ((b = str.getByte()) === -1) {
  19574. error('Bad block header in flate stream');
  19575. }
  19576. check |= (b << 8);
  19577. if (check !== (~blockLen & 0xffff) &&
  19578. (blockLen !== 0 || check !== 0)) {
  19579. // Ignoring error for bad "empty" block (see issue 1277)
  19580. error('Bad uncompressed block length in flate stream');
  19581. }
  19582. this.codeBuf = 0;
  19583. this.codeSize = 0;
  19584. var bufferLength = this.bufferLength;
  19585. buffer = this.ensureBuffer(bufferLength + blockLen);
  19586. var end = bufferLength + blockLen;
  19587. this.bufferLength = end;
  19588. if (blockLen === 0) {
  19589. if (str.peekByte() === -1) {
  19590. this.eof = true;
  19591. }
  19592. } else {
  19593. for (var n = bufferLength; n < end; ++n) {
  19594. if ((b = str.getByte()) === -1) {
  19595. this.eof = true;
  19596. break;
  19597. }
  19598. buffer[n] = b;
  19599. }
  19600. }
  19601. return;
  19602. }
  19603. var litCodeTable;
  19604. var distCodeTable;
  19605. if (hdr === 1) { // compressed block, fixed codes
  19606. litCodeTable = fixedLitCodeTab;
  19607. distCodeTable = fixedDistCodeTab;
  19608. } else if (hdr === 2) { // compressed block, dynamic codes
  19609. var numLitCodes = this.getBits(5) + 257;
  19610. var numDistCodes = this.getBits(5) + 1;
  19611. var numCodeLenCodes = this.getBits(4) + 4;
  19612. // build the code lengths code table
  19613. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  19614. var i;
  19615. for (i = 0; i < numCodeLenCodes; ++i) {
  19616. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  19617. }
  19618. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  19619. // build the literal and distance code tables
  19620. len = 0;
  19621. i = 0;
  19622. var codes = numLitCodes + numDistCodes;
  19623. var codeLengths = new Uint8Array(codes);
  19624. var bitsLength, bitsOffset, what;
  19625. while (i < codes) {
  19626. var code = this.getCode(codeLenCodeTab);
  19627. if (code === 16) {
  19628. bitsLength = 2; bitsOffset = 3; what = len;
  19629. } else if (code === 17) {
  19630. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  19631. } else if (code === 18) {
  19632. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  19633. } else {
  19634. codeLengths[i++] = len = code;
  19635. continue;
  19636. }
  19637. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  19638. while (repeatLength-- > 0) {
  19639. codeLengths[i++] = what;
  19640. }
  19641. }
  19642. litCodeTable =
  19643. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  19644. distCodeTable =
  19645. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  19646. } else {
  19647. error('Unknown block type in flate stream');
  19648. }
  19649. buffer = this.buffer;
  19650. var limit = buffer ? buffer.length : 0;
  19651. var pos = this.bufferLength;
  19652. while (true) {
  19653. var code1 = this.getCode(litCodeTable);
  19654. if (code1 < 256) {
  19655. if (pos + 1 >= limit) {
  19656. buffer = this.ensureBuffer(pos + 1);
  19657. limit = buffer.length;
  19658. }
  19659. buffer[pos++] = code1;
  19660. continue;
  19661. }
  19662. if (code1 === 256) {
  19663. this.bufferLength = pos;
  19664. return;
  19665. }
  19666. code1 -= 257;
  19667. code1 = lengthDecode[code1];
  19668. var code2 = code1 >> 16;
  19669. if (code2 > 0) {
  19670. code2 = this.getBits(code2);
  19671. }
  19672. len = (code1 & 0xffff) + code2;
  19673. code1 = this.getCode(distCodeTable);
  19674. code1 = distDecode[code1];
  19675. code2 = code1 >> 16;
  19676. if (code2 > 0) {
  19677. code2 = this.getBits(code2);
  19678. }
  19679. var dist = (code1 & 0xffff) + code2;
  19680. if (pos + len >= limit) {
  19681. buffer = this.ensureBuffer(pos + len);
  19682. limit = buffer.length;
  19683. }
  19684. for (var k = 0; k < len; ++k, ++pos) {
  19685. buffer[pos] = buffer[pos - dist];
  19686. }
  19687. }
  19688. };
  19689. return FlateStream;
  19690. })();
  19691. var PredictorStream = (function PredictorStreamClosure() {
  19692. function PredictorStream(str, maybeLength, params) {
  19693. if (!isDict(params)) {
  19694. return str; // no prediction
  19695. }
  19696. var predictor = this.predictor = params.get('Predictor') || 1;
  19697. if (predictor <= 1) {
  19698. return str; // no prediction
  19699. }
  19700. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  19701. error('Unsupported predictor: ' + predictor);
  19702. }
  19703. if (predictor === 2) {
  19704. this.readBlock = this.readBlockTiff;
  19705. } else {
  19706. this.readBlock = this.readBlockPng;
  19707. }
  19708. this.str = str;
  19709. this.dict = str.dict;
  19710. var colors = this.colors = params.get('Colors') || 1;
  19711. var bits = this.bits = params.get('BitsPerComponent') || 8;
  19712. var columns = this.columns = params.get('Columns') || 1;
  19713. this.pixBytes = (colors * bits + 7) >> 3;
  19714. this.rowBytes = (columns * colors * bits + 7) >> 3;
  19715. DecodeStream.call(this, maybeLength);
  19716. return this;
  19717. }
  19718. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  19719. PredictorStream.prototype.readBlockTiff =
  19720. function predictorStreamReadBlockTiff() {
  19721. var rowBytes = this.rowBytes;
  19722. var bufferLength = this.bufferLength;
  19723. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  19724. var bits = this.bits;
  19725. var colors = this.colors;
  19726. var rawBytes = this.str.getBytes(rowBytes);
  19727. this.eof = !rawBytes.length;
  19728. if (this.eof) {
  19729. return;
  19730. }
  19731. var inbuf = 0, outbuf = 0;
  19732. var inbits = 0, outbits = 0;
  19733. var pos = bufferLength;
  19734. var i;
  19735. if (bits === 1) {
  19736. for (i = 0; i < rowBytes; ++i) {
  19737. var c = rawBytes[i];
  19738. inbuf = (inbuf << 8) | c;
  19739. // bitwise addition is exclusive or
  19740. // first shift inbuf and then add
  19741. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  19742. // truncate inbuf (assumes colors < 16)
  19743. inbuf &= 0xFFFF;
  19744. }
  19745. } else if (bits === 8) {
  19746. for (i = 0; i < colors; ++i) {
  19747. buffer[pos++] = rawBytes[i];
  19748. }
  19749. for (; i < rowBytes; ++i) {
  19750. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  19751. pos++;
  19752. }
  19753. } else {
  19754. var compArray = new Uint8Array(colors + 1);
  19755. var bitMask = (1 << bits) - 1;
  19756. var j = 0, k = bufferLength;
  19757. var columns = this.columns;
  19758. for (i = 0; i < columns; ++i) {
  19759. for (var kk = 0; kk < colors; ++kk) {
  19760. if (inbits < bits) {
  19761. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  19762. inbits += 8;
  19763. }
  19764. compArray[kk] = (compArray[kk] +
  19765. (inbuf >> (inbits - bits))) & bitMask;
  19766. inbits -= bits;
  19767. outbuf = (outbuf << bits) | compArray[kk];
  19768. outbits += bits;
  19769. if (outbits >= 8) {
  19770. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  19771. outbits -= 8;
  19772. }
  19773. }
  19774. }
  19775. if (outbits > 0) {
  19776. buffer[k++] = (outbuf << (8 - outbits)) +
  19777. (inbuf & ((1 << (8 - outbits)) - 1));
  19778. }
  19779. }
  19780. this.bufferLength += rowBytes;
  19781. };
  19782. PredictorStream.prototype.readBlockPng =
  19783. function predictorStreamReadBlockPng() {
  19784. var rowBytes = this.rowBytes;
  19785. var pixBytes = this.pixBytes;
  19786. var predictor = this.str.getByte();
  19787. var rawBytes = this.str.getBytes(rowBytes);
  19788. this.eof = !rawBytes.length;
  19789. if (this.eof) {
  19790. return;
  19791. }
  19792. var bufferLength = this.bufferLength;
  19793. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  19794. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  19795. if (prevRow.length === 0) {
  19796. prevRow = new Uint8Array(rowBytes);
  19797. }
  19798. var i, j = bufferLength, up, c;
  19799. switch (predictor) {
  19800. case 0:
  19801. for (i = 0; i < rowBytes; ++i) {
  19802. buffer[j++] = rawBytes[i];
  19803. }
  19804. break;
  19805. case 1:
  19806. for (i = 0; i < pixBytes; ++i) {
  19807. buffer[j++] = rawBytes[i];
  19808. }
  19809. for (; i < rowBytes; ++i) {
  19810. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  19811. j++;
  19812. }
  19813. break;
  19814. case 2:
  19815. for (i = 0; i < rowBytes; ++i) {
  19816. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  19817. }
  19818. break;
  19819. case 3:
  19820. for (i = 0; i < pixBytes; ++i) {
  19821. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  19822. }
  19823. for (; i < rowBytes; ++i) {
  19824. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  19825. rawBytes[i]) & 0xFF;
  19826. j++;
  19827. }
  19828. break;
  19829. case 4:
  19830. // we need to save the up left pixels values. the simplest way
  19831. // is to create a new buffer
  19832. for (i = 0; i < pixBytes; ++i) {
  19833. up = prevRow[i];
  19834. c = rawBytes[i];
  19835. buffer[j++] = up + c;
  19836. }
  19837. for (; i < rowBytes; ++i) {
  19838. up = prevRow[i];
  19839. var upLeft = prevRow[i - pixBytes];
  19840. var left = buffer[j - pixBytes];
  19841. var p = left + up - upLeft;
  19842. var pa = p - left;
  19843. if (pa < 0) {
  19844. pa = -pa;
  19845. }
  19846. var pb = p - up;
  19847. if (pb < 0) {
  19848. pb = -pb;
  19849. }
  19850. var pc = p - upLeft;
  19851. if (pc < 0) {
  19852. pc = -pc;
  19853. }
  19854. c = rawBytes[i];
  19855. if (pa <= pb && pa <= pc) {
  19856. buffer[j++] = left + c;
  19857. } else if (pb <= pc) {
  19858. buffer[j++] = up + c;
  19859. } else {
  19860. buffer[j++] = upLeft + c;
  19861. }
  19862. }
  19863. break;
  19864. default:
  19865. error('Unsupported predictor: ' + predictor);
  19866. }
  19867. this.bufferLength += rowBytes;
  19868. };
  19869. return PredictorStream;
  19870. })();
  19871. /**
  19872. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  19873. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  19874. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  19875. * a library to decode these images and the stream behaves like all the other
  19876. * DecodeStreams.
  19877. */
  19878. var JpegStream = (function JpegStreamClosure() {
  19879. function JpegStream(stream, maybeLength, dict) {
  19880. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  19881. // Note: this seems to mainly affect inline images.
  19882. var ch;
  19883. while ((ch = stream.getByte()) !== -1) {
  19884. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  19885. stream.skip(-1); // Reset the stream position to the SOI.
  19886. break;
  19887. }
  19888. }
  19889. this.stream = stream;
  19890. this.maybeLength = maybeLength;
  19891. this.dict = dict;
  19892. DecodeStream.call(this, maybeLength);
  19893. }
  19894. JpegStream.prototype = Object.create(DecodeStream.prototype);
  19895. Object.defineProperty(JpegStream.prototype, 'bytes', {
  19896. get: function JpegStream_bytes() {
  19897. // If this.maybeLength is null, we'll get the entire stream.
  19898. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  19899. },
  19900. configurable: true
  19901. });
  19902. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  19903. if (this.bufferLength) {
  19904. return;
  19905. }
  19906. var jpegImage = new JpegImage();
  19907. // Checking if values need to be transformed before conversion.
  19908. var decodeArr = this.dict.getArray('Decode', 'D');
  19909. if (this.forceRGB && isArray(decodeArr)) {
  19910. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  19911. var decodeArrLength = decodeArr.length;
  19912. var transform = new Int32Array(decodeArrLength);
  19913. var transformNeeded = false;
  19914. var maxValue = (1 << bitsPerComponent) - 1;
  19915. for (var i = 0; i < decodeArrLength; i += 2) {
  19916. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  19917. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  19918. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  19919. transformNeeded = true;
  19920. }
  19921. }
  19922. if (transformNeeded) {
  19923. jpegImage.decodeTransform = transform;
  19924. }
  19925. }
  19926. // Fetching the 'ColorTransform' entry, if it exists.
  19927. var decodeParams = this.dict.get('DecodeParms', 'DP');
  19928. if (isDict(decodeParams)) {
  19929. var colorTransform = decodeParams.get('ColorTransform');
  19930. if (isInt(colorTransform)) {
  19931. jpegImage.colorTransform = colorTransform;
  19932. }
  19933. }
  19934. jpegImage.parse(this.bytes);
  19935. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  19936. this.forceRGB);
  19937. this.buffer = data;
  19938. this.bufferLength = data.length;
  19939. this.eof = true;
  19940. };
  19941. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  19942. this.ensureBuffer();
  19943. return this.buffer;
  19944. };
  19945. JpegStream.prototype.getIR = function JpegStream_getIR(forceDataSchema) {
  19946. return createObjectURL(this.bytes, 'image/jpeg', forceDataSchema);
  19947. };
  19948. return JpegStream;
  19949. })();
  19950. /**
  19951. * For JPEG 2000's we use a library to decode these images and
  19952. * the stream behaves like all the other DecodeStreams.
  19953. */
  19954. var JpxStream = (function JpxStreamClosure() {
  19955. function JpxStream(stream, maybeLength, dict) {
  19956. this.stream = stream;
  19957. this.maybeLength = maybeLength;
  19958. this.dict = dict;
  19959. DecodeStream.call(this, maybeLength);
  19960. }
  19961. JpxStream.prototype = Object.create(DecodeStream.prototype);
  19962. Object.defineProperty(JpxStream.prototype, 'bytes', {
  19963. get: function JpxStream_bytes() {
  19964. // If this.maybeLength is null, we'll get the entire stream.
  19965. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  19966. },
  19967. configurable: true
  19968. });
  19969. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  19970. if (this.bufferLength) {
  19971. return;
  19972. }
  19973. var jpxImage = new JpxImage();
  19974. jpxImage.parse(this.bytes);
  19975. var width = jpxImage.width;
  19976. var height = jpxImage.height;
  19977. var componentsCount = jpxImage.componentsCount;
  19978. var tileCount = jpxImage.tiles.length;
  19979. if (tileCount === 1) {
  19980. this.buffer = jpxImage.tiles[0].items;
  19981. } else {
  19982. var data = new Uint8Array(width * height * componentsCount);
  19983. for (var k = 0; k < tileCount; k++) {
  19984. var tileComponents = jpxImage.tiles[k];
  19985. var tileWidth = tileComponents.width;
  19986. var tileHeight = tileComponents.height;
  19987. var tileLeft = tileComponents.left;
  19988. var tileTop = tileComponents.top;
  19989. var src = tileComponents.items;
  19990. var srcPosition = 0;
  19991. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  19992. var imgRowSize = width * componentsCount;
  19993. var tileRowSize = tileWidth * componentsCount;
  19994. for (var j = 0; j < tileHeight; j++) {
  19995. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  19996. data.set(rowBytes, dataPosition);
  19997. srcPosition += tileRowSize;
  19998. dataPosition += imgRowSize;
  19999. }
  20000. }
  20001. this.buffer = data;
  20002. }
  20003. this.bufferLength = this.buffer.length;
  20004. this.eof = true;
  20005. };
  20006. return JpxStream;
  20007. })();
  20008. /**
  20009. * For JBIG2's we use a library to decode these images and
  20010. * the stream behaves like all the other DecodeStreams.
  20011. */
  20012. var Jbig2Stream = (function Jbig2StreamClosure() {
  20013. function Jbig2Stream(stream, maybeLength, dict) {
  20014. this.stream = stream;
  20015. this.maybeLength = maybeLength;
  20016. this.dict = dict;
  20017. DecodeStream.call(this, maybeLength);
  20018. }
  20019. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  20020. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  20021. get: function Jbig2Stream_bytes() {
  20022. // If this.maybeLength is null, we'll get the entire stream.
  20023. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  20024. },
  20025. configurable: true
  20026. });
  20027. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  20028. if (this.bufferLength) {
  20029. return;
  20030. }
  20031. var jbig2Image = new Jbig2Image();
  20032. var chunks = [];
  20033. var decodeParams = this.dict.getArray('DecodeParms', 'DP');
  20034. // According to the PDF specification, DecodeParms can be either
  20035. // a dictionary, or an array whose elements are dictionaries.
  20036. if (isArray(decodeParams)) {
  20037. if (decodeParams.length > 1) {
  20038. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  20039. 'not supported.');
  20040. }
  20041. decodeParams = decodeParams[0];
  20042. }
  20043. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  20044. var globalsStream = decodeParams.get('JBIG2Globals');
  20045. var globals = globalsStream.getBytes();
  20046. chunks.push({data: globals, start: 0, end: globals.length});
  20047. }
  20048. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  20049. var data = jbig2Image.parseChunks(chunks);
  20050. var dataLength = data.length;
  20051. // JBIG2 had black as 1 and white as 0, inverting the colors
  20052. for (var i = 0; i < dataLength; i++) {
  20053. data[i] ^= 0xFF;
  20054. }
  20055. this.buffer = data;
  20056. this.bufferLength = dataLength;
  20057. this.eof = true;
  20058. };
  20059. return Jbig2Stream;
  20060. })();
  20061. var DecryptStream = (function DecryptStreamClosure() {
  20062. function DecryptStream(str, maybeLength, decrypt) {
  20063. this.str = str;
  20064. this.dict = str.dict;
  20065. this.decrypt = decrypt;
  20066. this.nextChunk = null;
  20067. this.initialized = false;
  20068. DecodeStream.call(this, maybeLength);
  20069. }
  20070. var chunkSize = 512;
  20071. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  20072. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  20073. var chunk;
  20074. if (this.initialized) {
  20075. chunk = this.nextChunk;
  20076. } else {
  20077. chunk = this.str.getBytes(chunkSize);
  20078. this.initialized = true;
  20079. }
  20080. if (!chunk || chunk.length === 0) {
  20081. this.eof = true;
  20082. return;
  20083. }
  20084. this.nextChunk = this.str.getBytes(chunkSize);
  20085. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  20086. var decrypt = this.decrypt;
  20087. chunk = decrypt(chunk, !hasMoreData);
  20088. var bufferLength = this.bufferLength;
  20089. var i, n = chunk.length;
  20090. var buffer = this.ensureBuffer(bufferLength + n);
  20091. for (i = 0; i < n; i++) {
  20092. buffer[bufferLength++] = chunk[i];
  20093. }
  20094. this.bufferLength = bufferLength;
  20095. };
  20096. return DecryptStream;
  20097. })();
  20098. var Ascii85Stream = (function Ascii85StreamClosure() {
  20099. function Ascii85Stream(str, maybeLength) {
  20100. this.str = str;
  20101. this.dict = str.dict;
  20102. this.input = new Uint8Array(5);
  20103. // Most streams increase in size when decoded, but Ascii85 streams
  20104. // typically shrink by ~20%.
  20105. if (maybeLength) {
  20106. maybeLength = 0.8 * maybeLength;
  20107. }
  20108. DecodeStream.call(this, maybeLength);
  20109. }
  20110. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  20111. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  20112. var TILDA_CHAR = 0x7E; // '~'
  20113. var Z_LOWER_CHAR = 0x7A; // 'z'
  20114. var EOF = -1;
  20115. var str = this.str;
  20116. var c = str.getByte();
  20117. while (isSpace(c)) {
  20118. c = str.getByte();
  20119. }
  20120. if (c === EOF || c === TILDA_CHAR) {
  20121. this.eof = true;
  20122. return;
  20123. }
  20124. var bufferLength = this.bufferLength, buffer;
  20125. var i;
  20126. // special code for z
  20127. if (c === Z_LOWER_CHAR) {
  20128. buffer = this.ensureBuffer(bufferLength + 4);
  20129. for (i = 0; i < 4; ++i) {
  20130. buffer[bufferLength + i] = 0;
  20131. }
  20132. this.bufferLength += 4;
  20133. } else {
  20134. var input = this.input;
  20135. input[0] = c;
  20136. for (i = 1; i < 5; ++i) {
  20137. c = str.getByte();
  20138. while (isSpace(c)) {
  20139. c = str.getByte();
  20140. }
  20141. input[i] = c;
  20142. if (c === EOF || c === TILDA_CHAR) {
  20143. break;
  20144. }
  20145. }
  20146. buffer = this.ensureBuffer(bufferLength + i - 1);
  20147. this.bufferLength += i - 1;
  20148. // partial ending;
  20149. if (i < 5) {
  20150. for (; i < 5; ++i) {
  20151. input[i] = 0x21 + 84;
  20152. }
  20153. this.eof = true;
  20154. }
  20155. var t = 0;
  20156. for (i = 0; i < 5; ++i) {
  20157. t = t * 85 + (input[i] - 0x21);
  20158. }
  20159. for (i = 3; i >= 0; --i) {
  20160. buffer[bufferLength + i] = t & 0xFF;
  20161. t >>= 8;
  20162. }
  20163. }
  20164. };
  20165. return Ascii85Stream;
  20166. })();
  20167. var AsciiHexStream = (function AsciiHexStreamClosure() {
  20168. function AsciiHexStream(str, maybeLength) {
  20169. this.str = str;
  20170. this.dict = str.dict;
  20171. this.firstDigit = -1;
  20172. // Most streams increase in size when decoded, but AsciiHex streams shrink
  20173. // by 50%.
  20174. if (maybeLength) {
  20175. maybeLength = 0.5 * maybeLength;
  20176. }
  20177. DecodeStream.call(this, maybeLength);
  20178. }
  20179. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  20180. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  20181. var UPSTREAM_BLOCK_SIZE = 8000;
  20182. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  20183. if (!bytes.length) {
  20184. this.eof = true;
  20185. return;
  20186. }
  20187. var maxDecodeLength = (bytes.length + 1) >> 1;
  20188. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  20189. var bufferLength = this.bufferLength;
  20190. var firstDigit = this.firstDigit;
  20191. for (var i = 0, ii = bytes.length; i < ii; i++) {
  20192. var ch = bytes[i], digit;
  20193. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  20194. digit = ch & 0x0F;
  20195. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  20196. // 'A'-'Z', 'a'-'z'
  20197. digit = (ch & 0x0F) + 9;
  20198. } else if (ch === 0x3E) { // '>'
  20199. this.eof = true;
  20200. break;
  20201. } else { // probably whitespace
  20202. continue; // ignoring
  20203. }
  20204. if (firstDigit < 0) {
  20205. firstDigit = digit;
  20206. } else {
  20207. buffer[bufferLength++] = (firstDigit << 4) | digit;
  20208. firstDigit = -1;
  20209. }
  20210. }
  20211. if (firstDigit >= 0 && this.eof) {
  20212. // incomplete byte
  20213. buffer[bufferLength++] = (firstDigit << 4);
  20214. firstDigit = -1;
  20215. }
  20216. this.firstDigit = firstDigit;
  20217. this.bufferLength = bufferLength;
  20218. };
  20219. return AsciiHexStream;
  20220. })();
  20221. var RunLengthStream = (function RunLengthStreamClosure() {
  20222. function RunLengthStream(str, maybeLength) {
  20223. this.str = str;
  20224. this.dict = str.dict;
  20225. DecodeStream.call(this, maybeLength);
  20226. }
  20227. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  20228. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  20229. // The repeatHeader has following format. The first byte defines type of run
  20230. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  20231. // (in addition to the second byte from the header), n = 129 through 255 -
  20232. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  20233. var repeatHeader = this.str.getBytes(2);
  20234. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  20235. this.eof = true;
  20236. return;
  20237. }
  20238. var buffer;
  20239. var bufferLength = this.bufferLength;
  20240. var n = repeatHeader[0];
  20241. if (n < 128) {
  20242. // copy n bytes
  20243. buffer = this.ensureBuffer(bufferLength + n + 1);
  20244. buffer[bufferLength++] = repeatHeader[1];
  20245. if (n > 0) {
  20246. var source = this.str.getBytes(n);
  20247. buffer.set(source, bufferLength);
  20248. bufferLength += n;
  20249. }
  20250. } else {
  20251. n = 257 - n;
  20252. var b = repeatHeader[1];
  20253. buffer = this.ensureBuffer(bufferLength + n + 1);
  20254. for (var i = 0; i < n; i++) {
  20255. buffer[bufferLength++] = b;
  20256. }
  20257. }
  20258. this.bufferLength = bufferLength;
  20259. };
  20260. return RunLengthStream;
  20261. })();
  20262. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  20263. var ccittEOL = -2;
  20264. var ccittEOF = -1;
  20265. var twoDimPass = 0;
  20266. var twoDimHoriz = 1;
  20267. var twoDimVert0 = 2;
  20268. var twoDimVertR1 = 3;
  20269. var twoDimVertL1 = 4;
  20270. var twoDimVertR2 = 5;
  20271. var twoDimVertL2 = 6;
  20272. var twoDimVertR3 = 7;
  20273. var twoDimVertL3 = 8;
  20274. var twoDimTable = [
  20275. [-1, -1], [-1, -1], // 000000x
  20276. [7, twoDimVertL3], // 0000010
  20277. [7, twoDimVertR3], // 0000011
  20278. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  20279. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  20280. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  20281. [4, twoDimPass], [4, twoDimPass],
  20282. [4, twoDimPass], [4, twoDimPass],
  20283. [4, twoDimPass], [4, twoDimPass],
  20284. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  20285. [3, twoDimHoriz], [3, twoDimHoriz],
  20286. [3, twoDimHoriz], [3, twoDimHoriz],
  20287. [3, twoDimHoriz], [3, twoDimHoriz],
  20288. [3, twoDimHoriz], [3, twoDimHoriz],
  20289. [3, twoDimHoriz], [3, twoDimHoriz],
  20290. [3, twoDimHoriz], [3, twoDimHoriz],
  20291. [3, twoDimHoriz], [3, twoDimHoriz],
  20292. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  20293. [3, twoDimVertL1], [3, twoDimVertL1],
  20294. [3, twoDimVertL1], [3, twoDimVertL1],
  20295. [3, twoDimVertL1], [3, twoDimVertL1],
  20296. [3, twoDimVertL1], [3, twoDimVertL1],
  20297. [3, twoDimVertL1], [3, twoDimVertL1],
  20298. [3, twoDimVertL1], [3, twoDimVertL1],
  20299. [3, twoDimVertL1], [3, twoDimVertL1],
  20300. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  20301. [3, twoDimVertR1], [3, twoDimVertR1],
  20302. [3, twoDimVertR1], [3, twoDimVertR1],
  20303. [3, twoDimVertR1], [3, twoDimVertR1],
  20304. [3, twoDimVertR1], [3, twoDimVertR1],
  20305. [3, twoDimVertR1], [3, twoDimVertR1],
  20306. [3, twoDimVertR1], [3, twoDimVertR1],
  20307. [3, twoDimVertR1], [3, twoDimVertR1],
  20308. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  20309. [1, twoDimVert0], [1, twoDimVert0],
  20310. [1, twoDimVert0], [1, twoDimVert0],
  20311. [1, twoDimVert0], [1, twoDimVert0],
  20312. [1, twoDimVert0], [1, twoDimVert0],
  20313. [1, twoDimVert0], [1, twoDimVert0],
  20314. [1, twoDimVert0], [1, twoDimVert0],
  20315. [1, twoDimVert0], [1, twoDimVert0],
  20316. [1, twoDimVert0], [1, twoDimVert0],
  20317. [1, twoDimVert0], [1, twoDimVert0],
  20318. [1, twoDimVert0], [1, twoDimVert0],
  20319. [1, twoDimVert0], [1, twoDimVert0],
  20320. [1, twoDimVert0], [1, twoDimVert0],
  20321. [1, twoDimVert0], [1, twoDimVert0],
  20322. [1, twoDimVert0], [1, twoDimVert0],
  20323. [1, twoDimVert0], [1, twoDimVert0],
  20324. [1, twoDimVert0], [1, twoDimVert0],
  20325. [1, twoDimVert0], [1, twoDimVert0],
  20326. [1, twoDimVert0], [1, twoDimVert0],
  20327. [1, twoDimVert0], [1, twoDimVert0],
  20328. [1, twoDimVert0], [1, twoDimVert0],
  20329. [1, twoDimVert0], [1, twoDimVert0],
  20330. [1, twoDimVert0], [1, twoDimVert0],
  20331. [1, twoDimVert0], [1, twoDimVert0],
  20332. [1, twoDimVert0], [1, twoDimVert0],
  20333. [1, twoDimVert0], [1, twoDimVert0],
  20334. [1, twoDimVert0], [1, twoDimVert0],
  20335. [1, twoDimVert0], [1, twoDimVert0],
  20336. [1, twoDimVert0], [1, twoDimVert0],
  20337. [1, twoDimVert0], [1, twoDimVert0],
  20338. [1, twoDimVert0], [1, twoDimVert0],
  20339. [1, twoDimVert0], [1, twoDimVert0]
  20340. ];
  20341. var whiteTable1 = [
  20342. [-1, -1], // 00000
  20343. [12, ccittEOL], // 00001
  20344. [-1, -1], [-1, -1], // 0001x
  20345. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  20346. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  20347. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  20348. [11, 1792], [11, 1792], // 1000x
  20349. [12, 1984], // 10010
  20350. [12, 2048], // 10011
  20351. [12, 2112], // 10100
  20352. [12, 2176], // 10101
  20353. [12, 2240], // 10110
  20354. [12, 2304], // 10111
  20355. [11, 1856], [11, 1856], // 1100x
  20356. [11, 1920], [11, 1920], // 1101x
  20357. [12, 2368], // 11100
  20358. [12, 2432], // 11101
  20359. [12, 2496], // 11110
  20360. [12, 2560] // 11111
  20361. ];
  20362. var whiteTable2 = [
  20363. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  20364. [8, 29], [8, 29], // 00000010x
  20365. [8, 30], [8, 30], // 00000011x
  20366. [8, 45], [8, 45], // 00000100x
  20367. [8, 46], [8, 46], // 00000101x
  20368. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  20369. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  20370. [8, 47], [8, 47], // 00001010x
  20371. [8, 48], [8, 48], // 00001011x
  20372. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  20373. [6, 13], [6, 13], [6, 13], [6, 13],
  20374. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  20375. [8, 33], [8, 33], // 00010010x
  20376. [8, 34], [8, 34], // 00010011x
  20377. [8, 35], [8, 35], // 00010100x
  20378. [8, 36], [8, 36], // 00010101x
  20379. [8, 37], [8, 37], // 00010110x
  20380. [8, 38], [8, 38], // 00010111x
  20381. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  20382. [8, 31], [8, 31], // 00011010x
  20383. [8, 32], [8, 32], // 00011011x
  20384. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  20385. [6, 1], [6, 1], [6, 1], [6, 1],
  20386. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  20387. [6, 12], [6, 12], [6, 12], [6, 12],
  20388. [8, 53], [8, 53], // 00100100x
  20389. [8, 54], [8, 54], // 00100101x
  20390. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  20391. [8, 39], [8, 39], // 00101000x
  20392. [8, 40], [8, 40], // 00101001x
  20393. [8, 41], [8, 41], // 00101010x
  20394. [8, 42], [8, 42], // 00101011x
  20395. [8, 43], [8, 43], // 00101100x
  20396. [8, 44], [8, 44], // 00101101x
  20397. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  20398. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  20399. [8, 61], [8, 61], // 00110010x
  20400. [8, 62], [8, 62], // 00110011x
  20401. [8, 63], [8, 63], // 00110100x
  20402. [8, 0], [8, 0], // 00110101x
  20403. [8, 320], [8, 320], // 00110110x
  20404. [8, 384], [8, 384], // 00110111x
  20405. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  20406. [5, 10], [5, 10], [5, 10], [5, 10],
  20407. [5, 10], [5, 10], [5, 10], [5, 10],
  20408. [5, 10], [5, 10], [5, 10], [5, 10],
  20409. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  20410. [5, 11], [5, 11], [5, 11], [5, 11],
  20411. [5, 11], [5, 11], [5, 11], [5, 11],
  20412. [5, 11], [5, 11], [5, 11], [5, 11],
  20413. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  20414. [8, 59], [8, 59], // 01001010x
  20415. [8, 60], [8, 60], // 01001011x
  20416. [9, 1472], // 010011000
  20417. [9, 1536], // 010011001
  20418. [9, 1600], // 010011010
  20419. [9, 1728], // 010011011
  20420. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  20421. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  20422. [8, 49], [8, 49], // 01010010x
  20423. [8, 50], [8, 50], // 01010011x
  20424. [8, 51], [8, 51], // 01010100x
  20425. [8, 52], [8, 52], // 01010101x
  20426. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  20427. [8, 55], [8, 55], // 01011000x
  20428. [8, 56], [8, 56], // 01011001x
  20429. [8, 57], [8, 57], // 01011010x
  20430. [8, 58], [8, 58], // 01011011x
  20431. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  20432. [6, 192], [6, 192], [6, 192], [6, 192],
  20433. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  20434. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  20435. [8, 448], [8, 448], // 01100100x
  20436. [8, 512], [8, 512], // 01100101x
  20437. [9, 704], // 011001100
  20438. [9, 768], // 011001101
  20439. [8, 640], [8, 640], // 01100111x
  20440. [8, 576], [8, 576], // 01101000x
  20441. [9, 832], // 011010010
  20442. [9, 896], // 011010011
  20443. [9, 960], // 011010100
  20444. [9, 1024], // 011010101
  20445. [9, 1088], // 011010110
  20446. [9, 1152], // 011010111
  20447. [9, 1216], // 011011000
  20448. [9, 1280], // 011011001
  20449. [9, 1344], // 011011010
  20450. [9, 1408], // 011011011
  20451. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  20452. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  20453. [4, 2], [4, 2], [4, 2], [4, 2],
  20454. [4, 2], [4, 2], [4, 2], [4, 2],
  20455. [4, 2], [4, 2], [4, 2], [4, 2],
  20456. [4, 2], [4, 2], [4, 2], [4, 2],
  20457. [4, 2], [4, 2], [4, 2], [4, 2],
  20458. [4, 2], [4, 2], [4, 2], [4, 2],
  20459. [4, 2], [4, 2], [4, 2], [4, 2],
  20460. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  20461. [4, 3], [4, 3], [4, 3], [4, 3],
  20462. [4, 3], [4, 3], [4, 3], [4, 3],
  20463. [4, 3], [4, 3], [4, 3], [4, 3],
  20464. [4, 3], [4, 3], [4, 3], [4, 3],
  20465. [4, 3], [4, 3], [4, 3], [4, 3],
  20466. [4, 3], [4, 3], [4, 3], [4, 3],
  20467. [4, 3], [4, 3], [4, 3], [4, 3],
  20468. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  20469. [5, 128], [5, 128], [5, 128], [5, 128],
  20470. [5, 128], [5, 128], [5, 128], [5, 128],
  20471. [5, 128], [5, 128], [5, 128], [5, 128],
  20472. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  20473. [5, 8], [5, 8], [5, 8], [5, 8],
  20474. [5, 8], [5, 8], [5, 8], [5, 8],
  20475. [5, 8], [5, 8], [5, 8], [5, 8],
  20476. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  20477. [5, 9], [5, 9], [5, 9], [5, 9],
  20478. [5, 9], [5, 9], [5, 9], [5, 9],
  20479. [5, 9], [5, 9], [5, 9], [5, 9],
  20480. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  20481. [6, 16], [6, 16], [6, 16], [6, 16],
  20482. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  20483. [6, 17], [6, 17], [6, 17], [6, 17],
  20484. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  20485. [4, 4], [4, 4], [4, 4], [4, 4],
  20486. [4, 4], [4, 4], [4, 4], [4, 4],
  20487. [4, 4], [4, 4], [4, 4], [4, 4],
  20488. [4, 4], [4, 4], [4, 4], [4, 4],
  20489. [4, 4], [4, 4], [4, 4], [4, 4],
  20490. [4, 4], [4, 4], [4, 4], [4, 4],
  20491. [4, 4], [4, 4], [4, 4], [4, 4],
  20492. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  20493. [4, 5], [4, 5], [4, 5], [4, 5],
  20494. [4, 5], [4, 5], [4, 5], [4, 5],
  20495. [4, 5], [4, 5], [4, 5], [4, 5],
  20496. [4, 5], [4, 5], [4, 5], [4, 5],
  20497. [4, 5], [4, 5], [4, 5], [4, 5],
  20498. [4, 5], [4, 5], [4, 5], [4, 5],
  20499. [4, 5], [4, 5], [4, 5], [4, 5],
  20500. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  20501. [6, 14], [6, 14], [6, 14], [6, 14],
  20502. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  20503. [6, 15], [6, 15], [6, 15], [6, 15],
  20504. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  20505. [5, 64], [5, 64], [5, 64], [5, 64],
  20506. [5, 64], [5, 64], [5, 64], [5, 64],
  20507. [5, 64], [5, 64], [5, 64], [5, 64],
  20508. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  20509. [4, 6], [4, 6], [4, 6], [4, 6],
  20510. [4, 6], [4, 6], [4, 6], [4, 6],
  20511. [4, 6], [4, 6], [4, 6], [4, 6],
  20512. [4, 6], [4, 6], [4, 6], [4, 6],
  20513. [4, 6], [4, 6], [4, 6], [4, 6],
  20514. [4, 6], [4, 6], [4, 6], [4, 6],
  20515. [4, 6], [4, 6], [4, 6], [4, 6],
  20516. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  20517. [4, 7], [4, 7], [4, 7], [4, 7],
  20518. [4, 7], [4, 7], [4, 7], [4, 7],
  20519. [4, 7], [4, 7], [4, 7], [4, 7],
  20520. [4, 7], [4, 7], [4, 7], [4, 7],
  20521. [4, 7], [4, 7], [4, 7], [4, 7],
  20522. [4, 7], [4, 7], [4, 7], [4, 7],
  20523. [4, 7], [4, 7], [4, 7], [4, 7]
  20524. ];
  20525. var blackTable1 = [
  20526. [-1, -1], [-1, -1], // 000000000000x
  20527. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  20528. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  20529. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  20530. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  20531. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  20532. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  20533. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  20534. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  20535. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  20536. [12, 1984], [12, 1984], // 000000010010x
  20537. [12, 2048], [12, 2048], // 000000010011x
  20538. [12, 2112], [12, 2112], // 000000010100x
  20539. [12, 2176], [12, 2176], // 000000010101x
  20540. [12, 2240], [12, 2240], // 000000010110x
  20541. [12, 2304], [12, 2304], // 000000010111x
  20542. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  20543. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  20544. [12, 2368], [12, 2368], // 000000011100x
  20545. [12, 2432], [12, 2432], // 000000011101x
  20546. [12, 2496], [12, 2496], // 000000011110x
  20547. [12, 2560], [12, 2560], // 000000011111x
  20548. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  20549. [10, 18], [10, 18], [10, 18], [10, 18],
  20550. [12, 52], [12, 52], // 000000100100x
  20551. [13, 640], // 0000001001010
  20552. [13, 704], // 0000001001011
  20553. [13, 768], // 0000001001100
  20554. [13, 832], // 0000001001101
  20555. [12, 55], [12, 55], // 000000100111x
  20556. [12, 56], [12, 56], // 000000101000x
  20557. [13, 1280], // 0000001010010
  20558. [13, 1344], // 0000001010011
  20559. [13, 1408], // 0000001010100
  20560. [13, 1472], // 0000001010101
  20561. [12, 59], [12, 59], // 000000101011x
  20562. [12, 60], [12, 60], // 000000101100x
  20563. [13, 1536], // 0000001011010
  20564. [13, 1600], // 0000001011011
  20565. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  20566. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  20567. [13, 1664], // 0000001100100
  20568. [13, 1728], // 0000001100101
  20569. [12, 320], [12, 320], // 000000110011x
  20570. [12, 384], [12, 384], // 000000110100x
  20571. [12, 448], [12, 448], // 000000110101x
  20572. [13, 512], // 0000001101100
  20573. [13, 576], // 0000001101101
  20574. [12, 53], [12, 53], // 000000110111x
  20575. [12, 54], [12, 54], // 000000111000x
  20576. [13, 896], // 0000001110010
  20577. [13, 960], // 0000001110011
  20578. [13, 1024], // 0000001110100
  20579. [13, 1088], // 0000001110101
  20580. [13, 1152], // 0000001110110
  20581. [13, 1216], // 0000001110111
  20582. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  20583. [10, 64], [10, 64], [10, 64], [10, 64]
  20584. ];
  20585. var blackTable2 = [
  20586. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  20587. [8, 13], [8, 13], [8, 13], [8, 13],
  20588. [8, 13], [8, 13], [8, 13], [8, 13],
  20589. [8, 13], [8, 13], [8, 13], [8, 13],
  20590. [11, 23], [11, 23], // 00000101000x
  20591. [12, 50], // 000001010010
  20592. [12, 51], // 000001010011
  20593. [12, 44], // 000001010100
  20594. [12, 45], // 000001010101
  20595. [12, 46], // 000001010110
  20596. [12, 47], // 000001010111
  20597. [12, 57], // 000001011000
  20598. [12, 58], // 000001011001
  20599. [12, 61], // 000001011010
  20600. [12, 256], // 000001011011
  20601. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  20602. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  20603. [12, 48], // 000001100100
  20604. [12, 49], // 000001100101
  20605. [12, 62], // 000001100110
  20606. [12, 63], // 000001100111
  20607. [12, 30], // 000001101000
  20608. [12, 31], // 000001101001
  20609. [12, 32], // 000001101010
  20610. [12, 33], // 000001101011
  20611. [12, 40], // 000001101100
  20612. [12, 41], // 000001101101
  20613. [11, 22], [11, 22], // 00000110111x
  20614. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  20615. [8, 14], [8, 14], [8, 14], [8, 14],
  20616. [8, 14], [8, 14], [8, 14], [8, 14],
  20617. [8, 14], [8, 14], [8, 14], [8, 14],
  20618. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  20619. [7, 10], [7, 10], [7, 10], [7, 10],
  20620. [7, 10], [7, 10], [7, 10], [7, 10],
  20621. [7, 10], [7, 10], [7, 10], [7, 10],
  20622. [7, 10], [7, 10], [7, 10], [7, 10],
  20623. [7, 10], [7, 10], [7, 10], [7, 10],
  20624. [7, 10], [7, 10], [7, 10], [7, 10],
  20625. [7, 10], [7, 10], [7, 10], [7, 10],
  20626. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  20627. [7, 11], [7, 11], [7, 11], [7, 11],
  20628. [7, 11], [7, 11], [7, 11], [7, 11],
  20629. [7, 11], [7, 11], [7, 11], [7, 11],
  20630. [7, 11], [7, 11], [7, 11], [7, 11],
  20631. [7, 11], [7, 11], [7, 11], [7, 11],
  20632. [7, 11], [7, 11], [7, 11], [7, 11],
  20633. [7, 11], [7, 11], [7, 11], [7, 11],
  20634. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  20635. [9, 15], [9, 15], [9, 15], [9, 15],
  20636. [12, 128], // 000011001000
  20637. [12, 192], // 000011001001
  20638. [12, 26], // 000011001010
  20639. [12, 27], // 000011001011
  20640. [12, 28], // 000011001100
  20641. [12, 29], // 000011001101
  20642. [11, 19], [11, 19], // 00001100111x
  20643. [11, 20], [11, 20], // 00001101000x
  20644. [12, 34], // 000011010010
  20645. [12, 35], // 000011010011
  20646. [12, 36], // 000011010100
  20647. [12, 37], // 000011010101
  20648. [12, 38], // 000011010110
  20649. [12, 39], // 000011010111
  20650. [11, 21], [11, 21], // 00001101100x
  20651. [12, 42], // 000011011010
  20652. [12, 43], // 000011011011
  20653. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  20654. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  20655. [7, 12], [7, 12], [7, 12], [7, 12],
  20656. [7, 12], [7, 12], [7, 12], [7, 12],
  20657. [7, 12], [7, 12], [7, 12], [7, 12],
  20658. [7, 12], [7, 12], [7, 12], [7, 12],
  20659. [7, 12], [7, 12], [7, 12], [7, 12],
  20660. [7, 12], [7, 12], [7, 12], [7, 12],
  20661. [7, 12], [7, 12], [7, 12], [7, 12]
  20662. ];
  20663. var blackTable3 = [
  20664. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  20665. [6, 9], // 000100
  20666. [6, 8], // 000101
  20667. [5, 7], [5, 7], // 00011x
  20668. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  20669. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  20670. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  20671. [3, 1], [3, 1], [3, 1], [3, 1],
  20672. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  20673. [3, 4], [3, 4], [3, 4], [3, 4],
  20674. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  20675. [2, 3], [2, 3], [2, 3], [2, 3],
  20676. [2, 3], [2, 3], [2, 3], [2, 3],
  20677. [2, 3], [2, 3], [2, 3], [2, 3],
  20678. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  20679. [2, 2], [2, 2], [2, 2], [2, 2],
  20680. [2, 2], [2, 2], [2, 2], [2, 2],
  20681. [2, 2], [2, 2], [2, 2], [2, 2]
  20682. ];
  20683. function CCITTFaxStream(str, maybeLength, params) {
  20684. this.str = str;
  20685. this.dict = str.dict;
  20686. params = params || Dict.empty;
  20687. this.encoding = params.get('K') || 0;
  20688. this.eoline = params.get('EndOfLine') || false;
  20689. this.byteAlign = params.get('EncodedByteAlign') || false;
  20690. this.columns = params.get('Columns') || 1728;
  20691. this.rows = params.get('Rows') || 0;
  20692. var eoblock = params.get('EndOfBlock');
  20693. if (eoblock === null || eoblock === undefined) {
  20694. eoblock = true;
  20695. }
  20696. this.eoblock = eoblock;
  20697. this.black = params.get('BlackIs1') || false;
  20698. this.codingLine = new Uint32Array(this.columns + 1);
  20699. this.refLine = new Uint32Array(this.columns + 2);
  20700. this.codingLine[0] = this.columns;
  20701. this.codingPos = 0;
  20702. this.row = 0;
  20703. this.nextLine2D = this.encoding < 0;
  20704. this.inputBits = 0;
  20705. this.inputBuf = 0;
  20706. this.outputBits = 0;
  20707. var code1;
  20708. while ((code1 = this.lookBits(12)) === 0) {
  20709. this.eatBits(1);
  20710. }
  20711. if (code1 === 1) {
  20712. this.eatBits(12);
  20713. }
  20714. if (this.encoding > 0) {
  20715. this.nextLine2D = !this.lookBits(1);
  20716. this.eatBits(1);
  20717. }
  20718. DecodeStream.call(this, maybeLength);
  20719. }
  20720. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  20721. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  20722. while (!this.eof) {
  20723. var c = this.lookChar();
  20724. this.ensureBuffer(this.bufferLength + 1);
  20725. this.buffer[this.bufferLength++] = c;
  20726. }
  20727. };
  20728. CCITTFaxStream.prototype.addPixels =
  20729. function ccittFaxStreamAddPixels(a1, blackPixels) {
  20730. var codingLine = this.codingLine;
  20731. var codingPos = this.codingPos;
  20732. if (a1 > codingLine[codingPos]) {
  20733. if (a1 > this.columns) {
  20734. info('row is wrong length');
  20735. this.err = true;
  20736. a1 = this.columns;
  20737. }
  20738. if ((codingPos & 1) ^ blackPixels) {
  20739. ++codingPos;
  20740. }
  20741. codingLine[codingPos] = a1;
  20742. }
  20743. this.codingPos = codingPos;
  20744. };
  20745. CCITTFaxStream.prototype.addPixelsNeg =
  20746. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  20747. var codingLine = this.codingLine;
  20748. var codingPos = this.codingPos;
  20749. if (a1 > codingLine[codingPos]) {
  20750. if (a1 > this.columns) {
  20751. info('row is wrong length');
  20752. this.err = true;
  20753. a1 = this.columns;
  20754. }
  20755. if ((codingPos & 1) ^ blackPixels) {
  20756. ++codingPos;
  20757. }
  20758. codingLine[codingPos] = a1;
  20759. } else if (a1 < codingLine[codingPos]) {
  20760. if (a1 < 0) {
  20761. info('invalid code');
  20762. this.err = true;
  20763. a1 = 0;
  20764. }
  20765. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  20766. --codingPos;
  20767. }
  20768. codingLine[codingPos] = a1;
  20769. }
  20770. this.codingPos = codingPos;
  20771. };
  20772. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  20773. var refLine = this.refLine;
  20774. var codingLine = this.codingLine;
  20775. var columns = this.columns;
  20776. var refPos, blackPixels, bits, i;
  20777. if (this.outputBits === 0) {
  20778. if (this.eof) {
  20779. return null;
  20780. }
  20781. this.err = false;
  20782. var code1, code2, code3;
  20783. if (this.nextLine2D) {
  20784. for (i = 0; codingLine[i] < columns; ++i) {
  20785. refLine[i] = codingLine[i];
  20786. }
  20787. refLine[i++] = columns;
  20788. refLine[i] = columns;
  20789. codingLine[0] = 0;
  20790. this.codingPos = 0;
  20791. refPos = 0;
  20792. blackPixels = 0;
  20793. while (codingLine[this.codingPos] < columns) {
  20794. code1 = this.getTwoDimCode();
  20795. switch (code1) {
  20796. case twoDimPass:
  20797. this.addPixels(refLine[refPos + 1], blackPixels);
  20798. if (refLine[refPos + 1] < columns) {
  20799. refPos += 2;
  20800. }
  20801. break;
  20802. case twoDimHoriz:
  20803. code1 = code2 = 0;
  20804. if (blackPixels) {
  20805. do {
  20806. code1 += (code3 = this.getBlackCode());
  20807. } while (code3 >= 64);
  20808. do {
  20809. code2 += (code3 = this.getWhiteCode());
  20810. } while (code3 >= 64);
  20811. } else {
  20812. do {
  20813. code1 += (code3 = this.getWhiteCode());
  20814. } while (code3 >= 64);
  20815. do {
  20816. code2 += (code3 = this.getBlackCode());
  20817. } while (code3 >= 64);
  20818. }
  20819. this.addPixels(codingLine[this.codingPos] +
  20820. code1, blackPixels);
  20821. if (codingLine[this.codingPos] < columns) {
  20822. this.addPixels(codingLine[this.codingPos] + code2,
  20823. blackPixels ^ 1);
  20824. }
  20825. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20826. refLine[refPos] < columns) {
  20827. refPos += 2;
  20828. }
  20829. break;
  20830. case twoDimVertR3:
  20831. this.addPixels(refLine[refPos] + 3, blackPixels);
  20832. blackPixels ^= 1;
  20833. if (codingLine[this.codingPos] < columns) {
  20834. ++refPos;
  20835. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20836. refLine[refPos] < columns) {
  20837. refPos += 2;
  20838. }
  20839. }
  20840. break;
  20841. case twoDimVertR2:
  20842. this.addPixels(refLine[refPos] + 2, blackPixels);
  20843. blackPixels ^= 1;
  20844. if (codingLine[this.codingPos] < columns) {
  20845. ++refPos;
  20846. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20847. refLine[refPos] < columns) {
  20848. refPos += 2;
  20849. }
  20850. }
  20851. break;
  20852. case twoDimVertR1:
  20853. this.addPixels(refLine[refPos] + 1, blackPixels);
  20854. blackPixels ^= 1;
  20855. if (codingLine[this.codingPos] < columns) {
  20856. ++refPos;
  20857. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20858. refLine[refPos] < columns) {
  20859. refPos += 2;
  20860. }
  20861. }
  20862. break;
  20863. case twoDimVert0:
  20864. this.addPixels(refLine[refPos], blackPixels);
  20865. blackPixels ^= 1;
  20866. if (codingLine[this.codingPos] < columns) {
  20867. ++refPos;
  20868. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20869. refLine[refPos] < columns) {
  20870. refPos += 2;
  20871. }
  20872. }
  20873. break;
  20874. case twoDimVertL3:
  20875. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  20876. blackPixels ^= 1;
  20877. if (codingLine[this.codingPos] < columns) {
  20878. if (refPos > 0) {
  20879. --refPos;
  20880. } else {
  20881. ++refPos;
  20882. }
  20883. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20884. refLine[refPos] < columns) {
  20885. refPos += 2;
  20886. }
  20887. }
  20888. break;
  20889. case twoDimVertL2:
  20890. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  20891. blackPixels ^= 1;
  20892. if (codingLine[this.codingPos] < columns) {
  20893. if (refPos > 0) {
  20894. --refPos;
  20895. } else {
  20896. ++refPos;
  20897. }
  20898. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20899. refLine[refPos] < columns) {
  20900. refPos += 2;
  20901. }
  20902. }
  20903. break;
  20904. case twoDimVertL1:
  20905. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  20906. blackPixels ^= 1;
  20907. if (codingLine[this.codingPos] < columns) {
  20908. if (refPos > 0) {
  20909. --refPos;
  20910. } else {
  20911. ++refPos;
  20912. }
  20913. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20914. refLine[refPos] < columns) {
  20915. refPos += 2;
  20916. }
  20917. }
  20918. break;
  20919. case ccittEOF:
  20920. this.addPixels(columns, 0);
  20921. this.eof = true;
  20922. break;
  20923. default:
  20924. info('bad 2d code');
  20925. this.addPixels(columns, 0);
  20926. this.err = true;
  20927. }
  20928. }
  20929. } else {
  20930. codingLine[0] = 0;
  20931. this.codingPos = 0;
  20932. blackPixels = 0;
  20933. while (codingLine[this.codingPos] < columns) {
  20934. code1 = 0;
  20935. if (blackPixels) {
  20936. do {
  20937. code1 += (code3 = this.getBlackCode());
  20938. } while (code3 >= 64);
  20939. } else {
  20940. do {
  20941. code1 += (code3 = this.getWhiteCode());
  20942. } while (code3 >= 64);
  20943. }
  20944. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  20945. blackPixels ^= 1;
  20946. }
  20947. }
  20948. var gotEOL = false;
  20949. if (this.byteAlign) {
  20950. this.inputBits &= ~7;
  20951. }
  20952. if (!this.eoblock && this.row === this.rows - 1) {
  20953. this.eof = true;
  20954. } else {
  20955. code1 = this.lookBits(12);
  20956. if (this.eoline) {
  20957. while (code1 !== ccittEOF && code1 !== 1) {
  20958. this.eatBits(1);
  20959. code1 = this.lookBits(12);
  20960. }
  20961. } else {
  20962. while (code1 === 0) {
  20963. this.eatBits(1);
  20964. code1 = this.lookBits(12);
  20965. }
  20966. }
  20967. if (code1 === 1) {
  20968. this.eatBits(12);
  20969. gotEOL = true;
  20970. } else if (code1 === ccittEOF) {
  20971. this.eof = true;
  20972. }
  20973. }
  20974. if (!this.eof && this.encoding > 0) {
  20975. this.nextLine2D = !this.lookBits(1);
  20976. this.eatBits(1);
  20977. }
  20978. if (this.eoblock && gotEOL && this.byteAlign) {
  20979. code1 = this.lookBits(12);
  20980. if (code1 === 1) {
  20981. this.eatBits(12);
  20982. if (this.encoding > 0) {
  20983. this.lookBits(1);
  20984. this.eatBits(1);
  20985. }
  20986. if (this.encoding >= 0) {
  20987. for (i = 0; i < 4; ++i) {
  20988. code1 = this.lookBits(12);
  20989. if (code1 !== 1) {
  20990. info('bad rtc code: ' + code1);
  20991. }
  20992. this.eatBits(12);
  20993. if (this.encoding > 0) {
  20994. this.lookBits(1);
  20995. this.eatBits(1);
  20996. }
  20997. }
  20998. }
  20999. this.eof = true;
  21000. }
  21001. } else if (this.err && this.eoline) {
  21002. while (true) {
  21003. code1 = this.lookBits(13);
  21004. if (code1 === ccittEOF) {
  21005. this.eof = true;
  21006. return null;
  21007. }
  21008. if ((code1 >> 1) === 1) {
  21009. break;
  21010. }
  21011. this.eatBits(1);
  21012. }
  21013. this.eatBits(12);
  21014. if (this.encoding > 0) {
  21015. this.eatBits(1);
  21016. this.nextLine2D = !(code1 & 1);
  21017. }
  21018. }
  21019. if (codingLine[0] > 0) {
  21020. this.outputBits = codingLine[this.codingPos = 0];
  21021. } else {
  21022. this.outputBits = codingLine[this.codingPos = 1];
  21023. }
  21024. this.row++;
  21025. }
  21026. var c;
  21027. if (this.outputBits >= 8) {
  21028. c = (this.codingPos & 1) ? 0 : 0xFF;
  21029. this.outputBits -= 8;
  21030. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  21031. this.codingPos++;
  21032. this.outputBits = (codingLine[this.codingPos] -
  21033. codingLine[this.codingPos - 1]);
  21034. }
  21035. } else {
  21036. bits = 8;
  21037. c = 0;
  21038. do {
  21039. if (this.outputBits > bits) {
  21040. c <<= bits;
  21041. if (!(this.codingPos & 1)) {
  21042. c |= 0xFF >> (8 - bits);
  21043. }
  21044. this.outputBits -= bits;
  21045. bits = 0;
  21046. } else {
  21047. c <<= this.outputBits;
  21048. if (!(this.codingPos & 1)) {
  21049. c |= 0xFF >> (8 - this.outputBits);
  21050. }
  21051. bits -= this.outputBits;
  21052. this.outputBits = 0;
  21053. if (codingLine[this.codingPos] < columns) {
  21054. this.codingPos++;
  21055. this.outputBits = (codingLine[this.codingPos] -
  21056. codingLine[this.codingPos - 1]);
  21057. } else if (bits > 0) {
  21058. c <<= bits;
  21059. bits = 0;
  21060. }
  21061. }
  21062. } while (bits);
  21063. }
  21064. if (this.black) {
  21065. c ^= 0xFF;
  21066. }
  21067. return c;
  21068. };
  21069. // This functions returns the code found from the table.
  21070. // The start and end parameters set the boundaries for searching the table.
  21071. // The limit parameter is optional. Function returns an array with three
  21072. // values. The first array element indicates whether a valid code is being
  21073. // returned. The second array element is the actual code. The third array
  21074. // element indicates whether EOF was reached.
  21075. CCITTFaxStream.prototype.findTableCode =
  21076. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  21077. var limitValue = limit || 0;
  21078. for (var i = start; i <= end; ++i) {
  21079. var code = this.lookBits(i);
  21080. if (code === ccittEOF) {
  21081. return [true, 1, false];
  21082. }
  21083. if (i < end) {
  21084. code <<= end - i;
  21085. }
  21086. if (!limitValue || code >= limitValue) {
  21087. var p = table[code - limitValue];
  21088. if (p[0] === i) {
  21089. this.eatBits(i);
  21090. return [true, p[1], true];
  21091. }
  21092. }
  21093. }
  21094. return [false, 0, false];
  21095. };
  21096. CCITTFaxStream.prototype.getTwoDimCode =
  21097. function ccittFaxStreamGetTwoDimCode() {
  21098. var code = 0;
  21099. var p;
  21100. if (this.eoblock) {
  21101. code = this.lookBits(7);
  21102. p = twoDimTable[code];
  21103. if (p && p[0] > 0) {
  21104. this.eatBits(p[0]);
  21105. return p[1];
  21106. }
  21107. } else {
  21108. var result = this.findTableCode(1, 7, twoDimTable);
  21109. if (result[0] && result[2]) {
  21110. return result[1];
  21111. }
  21112. }
  21113. info('Bad two dim code');
  21114. return ccittEOF;
  21115. };
  21116. CCITTFaxStream.prototype.getWhiteCode =
  21117. function ccittFaxStreamGetWhiteCode() {
  21118. var code = 0;
  21119. var p;
  21120. if (this.eoblock) {
  21121. code = this.lookBits(12);
  21122. if (code === ccittEOF) {
  21123. return 1;
  21124. }
  21125. if ((code >> 5) === 0) {
  21126. p = whiteTable1[code];
  21127. } else {
  21128. p = whiteTable2[code >> 3];
  21129. }
  21130. if (p[0] > 0) {
  21131. this.eatBits(p[0]);
  21132. return p[1];
  21133. }
  21134. } else {
  21135. var result = this.findTableCode(1, 9, whiteTable2);
  21136. if (result[0]) {
  21137. return result[1];
  21138. }
  21139. result = this.findTableCode(11, 12, whiteTable1);
  21140. if (result[0]) {
  21141. return result[1];
  21142. }
  21143. }
  21144. info('bad white code');
  21145. this.eatBits(1);
  21146. return 1;
  21147. };
  21148. CCITTFaxStream.prototype.getBlackCode =
  21149. function ccittFaxStreamGetBlackCode() {
  21150. var code, p;
  21151. if (this.eoblock) {
  21152. code = this.lookBits(13);
  21153. if (code === ccittEOF) {
  21154. return 1;
  21155. }
  21156. if ((code >> 7) === 0) {
  21157. p = blackTable1[code];
  21158. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  21159. p = blackTable2[(code >> 1) - 64];
  21160. } else {
  21161. p = blackTable3[code >> 7];
  21162. }
  21163. if (p[0] > 0) {
  21164. this.eatBits(p[0]);
  21165. return p[1];
  21166. }
  21167. } else {
  21168. var result = this.findTableCode(2, 6, blackTable3);
  21169. if (result[0]) {
  21170. return result[1];
  21171. }
  21172. result = this.findTableCode(7, 12, blackTable2, 64);
  21173. if (result[0]) {
  21174. return result[1];
  21175. }
  21176. result = this.findTableCode(10, 13, blackTable1);
  21177. if (result[0]) {
  21178. return result[1];
  21179. }
  21180. }
  21181. info('bad black code');
  21182. this.eatBits(1);
  21183. return 1;
  21184. };
  21185. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  21186. var c;
  21187. while (this.inputBits < n) {
  21188. if ((c = this.str.getByte()) === -1) {
  21189. if (this.inputBits === 0) {
  21190. return ccittEOF;
  21191. }
  21192. return ((this.inputBuf << (n - this.inputBits)) &
  21193. (0xFFFF >> (16 - n)));
  21194. }
  21195. this.inputBuf = (this.inputBuf << 8) | c;
  21196. this.inputBits += 8;
  21197. }
  21198. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  21199. };
  21200. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  21201. if ((this.inputBits -= n) < 0) {
  21202. this.inputBits = 0;
  21203. }
  21204. };
  21205. return CCITTFaxStream;
  21206. })();
  21207. var LZWStream = (function LZWStreamClosure() {
  21208. function LZWStream(str, maybeLength, earlyChange) {
  21209. this.str = str;
  21210. this.dict = str.dict;
  21211. this.cachedData = 0;
  21212. this.bitsCached = 0;
  21213. var maxLzwDictionarySize = 4096;
  21214. var lzwState = {
  21215. earlyChange: earlyChange,
  21216. codeLength: 9,
  21217. nextCode: 258,
  21218. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  21219. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  21220. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  21221. currentSequence: new Uint8Array(maxLzwDictionarySize),
  21222. currentSequenceLength: 0
  21223. };
  21224. for (var i = 0; i < 256; ++i) {
  21225. lzwState.dictionaryValues[i] = i;
  21226. lzwState.dictionaryLengths[i] = 1;
  21227. }
  21228. this.lzwState = lzwState;
  21229. DecodeStream.call(this, maybeLength);
  21230. }
  21231. LZWStream.prototype = Object.create(DecodeStream.prototype);
  21232. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  21233. var bitsCached = this.bitsCached;
  21234. var cachedData = this.cachedData;
  21235. while (bitsCached < n) {
  21236. var c = this.str.getByte();
  21237. if (c === -1) {
  21238. this.eof = true;
  21239. return null;
  21240. }
  21241. cachedData = (cachedData << 8) | c;
  21242. bitsCached += 8;
  21243. }
  21244. this.bitsCached = (bitsCached -= n);
  21245. this.cachedData = cachedData;
  21246. this.lastCode = null;
  21247. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  21248. };
  21249. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  21250. var blockSize = 512;
  21251. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  21252. var i, j, q;
  21253. var lzwState = this.lzwState;
  21254. if (!lzwState) {
  21255. return; // eof was found
  21256. }
  21257. var earlyChange = lzwState.earlyChange;
  21258. var nextCode = lzwState.nextCode;
  21259. var dictionaryValues = lzwState.dictionaryValues;
  21260. var dictionaryLengths = lzwState.dictionaryLengths;
  21261. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  21262. var codeLength = lzwState.codeLength;
  21263. var prevCode = lzwState.prevCode;
  21264. var currentSequence = lzwState.currentSequence;
  21265. var currentSequenceLength = lzwState.currentSequenceLength;
  21266. var decodedLength = 0;
  21267. var currentBufferLength = this.bufferLength;
  21268. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  21269. for (i = 0; i < blockSize; i++) {
  21270. var code = this.readBits(codeLength);
  21271. var hasPrev = currentSequenceLength > 0;
  21272. if (code < 256) {
  21273. currentSequence[0] = code;
  21274. currentSequenceLength = 1;
  21275. } else if (code >= 258) {
  21276. if (code < nextCode) {
  21277. currentSequenceLength = dictionaryLengths[code];
  21278. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  21279. currentSequence[j] = dictionaryValues[q];
  21280. q = dictionaryPrevCodes[q];
  21281. }
  21282. } else {
  21283. currentSequence[currentSequenceLength++] = currentSequence[0];
  21284. }
  21285. } else if (code === 256) {
  21286. codeLength = 9;
  21287. nextCode = 258;
  21288. currentSequenceLength = 0;
  21289. continue;
  21290. } else {
  21291. this.eof = true;
  21292. delete this.lzwState;
  21293. break;
  21294. }
  21295. if (hasPrev) {
  21296. dictionaryPrevCodes[nextCode] = prevCode;
  21297. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  21298. dictionaryValues[nextCode] = currentSequence[0];
  21299. nextCode++;
  21300. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  21301. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  21302. 0.6931471805599453 + 1, 12) | 0;
  21303. }
  21304. prevCode = code;
  21305. decodedLength += currentSequenceLength;
  21306. if (estimatedDecodedSize < decodedLength) {
  21307. do {
  21308. estimatedDecodedSize += decodedSizeDelta;
  21309. } while (estimatedDecodedSize < decodedLength);
  21310. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  21311. }
  21312. for (j = 0; j < currentSequenceLength; j++) {
  21313. buffer[currentBufferLength++] = currentSequence[j];
  21314. }
  21315. }
  21316. lzwState.nextCode = nextCode;
  21317. lzwState.codeLength = codeLength;
  21318. lzwState.prevCode = prevCode;
  21319. lzwState.currentSequenceLength = currentSequenceLength;
  21320. this.bufferLength = currentBufferLength;
  21321. };
  21322. return LZWStream;
  21323. })();
  21324. var NullStream = (function NullStreamClosure() {
  21325. function NullStream() {
  21326. Stream.call(this, new Uint8Array(0));
  21327. }
  21328. NullStream.prototype = Stream.prototype;
  21329. return NullStream;
  21330. })();
  21331. exports.Ascii85Stream = Ascii85Stream;
  21332. exports.AsciiHexStream = AsciiHexStream;
  21333. exports.CCITTFaxStream = CCITTFaxStream;
  21334. exports.DecryptStream = DecryptStream;
  21335. exports.DecodeStream = DecodeStream;
  21336. exports.FlateStream = FlateStream;
  21337. exports.Jbig2Stream = Jbig2Stream;
  21338. exports.JpegStream = JpegStream;
  21339. exports.JpxStream = JpxStream;
  21340. exports.NullStream = NullStream;
  21341. exports.PredictorStream = PredictorStream;
  21342. exports.RunLengthStream = RunLengthStream;
  21343. exports.Stream = Stream;
  21344. exports.StreamsSequenceStream = StreamsSequenceStream;
  21345. exports.StringStream = StringStream;
  21346. exports.LZWStream = LZWStream;
  21347. }));
  21348. (function (root, factory) {
  21349. {
  21350. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  21351. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  21352. }
  21353. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  21354. var PasswordException = sharedUtil.PasswordException;
  21355. var PasswordResponses = sharedUtil.PasswordResponses;
  21356. var bytesToString = sharedUtil.bytesToString;
  21357. var error = sharedUtil.error;
  21358. var isInt = sharedUtil.isInt;
  21359. var stringToBytes = sharedUtil.stringToBytes;
  21360. var utf8StringToString = sharedUtil.utf8StringToString;
  21361. var warn = sharedUtil.warn;
  21362. var Name = corePrimitives.Name;
  21363. var isName = corePrimitives.isName;
  21364. var isDict = corePrimitives.isDict;
  21365. var DecryptStream = coreStream.DecryptStream;
  21366. var ARCFourCipher = (function ARCFourCipherClosure() {
  21367. function ARCFourCipher(key) {
  21368. this.a = 0;
  21369. this.b = 0;
  21370. var s = new Uint8Array(256);
  21371. var i, j = 0, tmp, keyLength = key.length;
  21372. for (i = 0; i < 256; ++i) {
  21373. s[i] = i;
  21374. }
  21375. for (i = 0; i < 256; ++i) {
  21376. tmp = s[i];
  21377. j = (j + tmp + key[i % keyLength]) & 0xFF;
  21378. s[i] = s[j];
  21379. s[j] = tmp;
  21380. }
  21381. this.s = s;
  21382. }
  21383. ARCFourCipher.prototype = {
  21384. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  21385. var i, n = data.length, tmp, tmp2;
  21386. var a = this.a, b = this.b, s = this.s;
  21387. var output = new Uint8Array(n);
  21388. for (i = 0; i < n; ++i) {
  21389. a = (a + 1) & 0xFF;
  21390. tmp = s[a];
  21391. b = (b + tmp) & 0xFF;
  21392. tmp2 = s[b];
  21393. s[a] = tmp2;
  21394. s[b] = tmp;
  21395. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  21396. }
  21397. this.a = a;
  21398. this.b = b;
  21399. return output;
  21400. }
  21401. };
  21402. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  21403. return ARCFourCipher;
  21404. })();
  21405. var calculateMD5 = (function calculateMD5Closure() {
  21406. var r = new Uint8Array([
  21407. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  21408. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  21409. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  21410. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  21411. var k = new Int32Array([
  21412. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  21413. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  21414. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  21415. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  21416. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  21417. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  21418. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  21419. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  21420. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  21421. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  21422. -145523070, -1120210379, 718787259, -343485551]);
  21423. function hash(data, offset, length) {
  21424. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  21425. // pre-processing
  21426. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  21427. var padded = new Uint8Array(paddedLength);
  21428. var i, j, n;
  21429. for (i = 0; i < length; ++i) {
  21430. padded[i] = data[offset++];
  21431. }
  21432. padded[i++] = 0x80;
  21433. n = paddedLength - 8;
  21434. while (i < n) {
  21435. padded[i++] = 0;
  21436. }
  21437. padded[i++] = (length << 3) & 0xFF;
  21438. padded[i++] = (length >> 5) & 0xFF;
  21439. padded[i++] = (length >> 13) & 0xFF;
  21440. padded[i++] = (length >> 21) & 0xFF;
  21441. padded[i++] = (length >>> 29) & 0xFF;
  21442. padded[i++] = 0;
  21443. padded[i++] = 0;
  21444. padded[i++] = 0;
  21445. var w = new Int32Array(16);
  21446. for (i = 0; i < paddedLength;) {
  21447. for (j = 0; j < 16; ++j, i += 4) {
  21448. w[j] = (padded[i] | (padded[i + 1] << 8) |
  21449. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  21450. }
  21451. var a = h0, b = h1, c = h2, d = h3, f, g;
  21452. for (j = 0; j < 64; ++j) {
  21453. if (j < 16) {
  21454. f = (b & c) | ((~b) & d);
  21455. g = j;
  21456. } else if (j < 32) {
  21457. f = (d & b) | ((~d) & c);
  21458. g = (5 * j + 1) & 15;
  21459. } else if (j < 48) {
  21460. f = b ^ c ^ d;
  21461. g = (3 * j + 5) & 15;
  21462. } else {
  21463. f = c ^ (b | (~d));
  21464. g = (7 * j) & 15;
  21465. }
  21466. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  21467. d = c;
  21468. c = b;
  21469. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  21470. a = tmp;
  21471. }
  21472. h0 = (h0 + a) | 0;
  21473. h1 = (h1 + b) | 0;
  21474. h2 = (h2 + c) | 0;
  21475. h3 = (h3 + d) | 0;
  21476. }
  21477. return new Uint8Array([
  21478. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  21479. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  21480. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  21481. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  21482. ]);
  21483. }
  21484. return hash;
  21485. })();
  21486. var Word64 = (function Word64Closure() {
  21487. function Word64(highInteger, lowInteger) {
  21488. this.high = highInteger | 0;
  21489. this.low = lowInteger | 0;
  21490. }
  21491. Word64.prototype = {
  21492. and: function Word64_and(word) {
  21493. this.high &= word.high;
  21494. this.low &= word.low;
  21495. },
  21496. xor: function Word64_xor(word) {
  21497. this.high ^= word.high;
  21498. this.low ^= word.low;
  21499. },
  21500. or: function Word64_or(word) {
  21501. this.high |= word.high;
  21502. this.low |= word.low;
  21503. },
  21504. shiftRight: function Word64_shiftRight(places) {
  21505. if (places >= 32) {
  21506. this.low = (this.high >>> (places - 32)) | 0;
  21507. this.high = 0;
  21508. } else {
  21509. this.low = (this.low >>> places) | (this.high << (32 - places));
  21510. this.high = (this.high >>> places) | 0;
  21511. }
  21512. },
  21513. shiftLeft: function Word64_shiftLeft(places) {
  21514. if (places >= 32) {
  21515. this.high = this.low << (places - 32);
  21516. this.low = 0;
  21517. } else {
  21518. this.high = (this.high << places) | (this.low >>> (32 - places));
  21519. this.low = this.low << places;
  21520. }
  21521. },
  21522. rotateRight: function Word64_rotateRight(places) {
  21523. var low, high;
  21524. if (places & 32) {
  21525. high = this.low;
  21526. low = this.high;
  21527. } else {
  21528. low = this.low;
  21529. high = this.high;
  21530. }
  21531. places &= 31;
  21532. this.low = (low >>> places) | (high << (32 - places));
  21533. this.high = (high >>> places) | (low << (32 - places));
  21534. },
  21535. not: function Word64_not() {
  21536. this.high = ~this.high;
  21537. this.low = ~this.low;
  21538. },
  21539. add: function Word64_add(word) {
  21540. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  21541. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  21542. if (lowAdd > 0xFFFFFFFF) {
  21543. highAdd += 1;
  21544. }
  21545. this.low = lowAdd | 0;
  21546. this.high = highAdd | 0;
  21547. },
  21548. copyTo: function Word64_copyTo(bytes, offset) {
  21549. bytes[offset] = (this.high >>> 24) & 0xFF;
  21550. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  21551. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  21552. bytes[offset + 3] = this.high & 0xFF;
  21553. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  21554. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  21555. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  21556. bytes[offset + 7] = this.low & 0xFF;
  21557. },
  21558. assign: function Word64_assign(word) {
  21559. this.high = word.high;
  21560. this.low = word.low;
  21561. }
  21562. };
  21563. return Word64;
  21564. })();
  21565. var calculateSHA256 = (function calculateSHA256Closure() {
  21566. function rotr(x, n) {
  21567. return (x >>> n) | (x << 32 - n);
  21568. }
  21569. function ch(x, y, z) {
  21570. return (x & y) ^ (~x & z);
  21571. }
  21572. function maj(x, y, z) {
  21573. return (x & y) ^ (x & z) ^ (y & z);
  21574. }
  21575. function sigma(x) {
  21576. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  21577. }
  21578. function sigmaPrime(x) {
  21579. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  21580. }
  21581. function littleSigma(x) {
  21582. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  21583. }
  21584. function littleSigmaPrime(x) {
  21585. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  21586. }
  21587. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  21588. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  21589. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  21590. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  21591. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  21592. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  21593. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  21594. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  21595. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  21596. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  21597. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  21598. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  21599. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  21600. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  21601. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  21602. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  21603. function hash(data, offset, length) {
  21604. // initial hash values
  21605. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  21606. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  21607. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  21608. // pre-processing
  21609. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  21610. var padded = new Uint8Array(paddedLength);
  21611. var i, j, n;
  21612. for (i = 0; i < length; ++i) {
  21613. padded[i] = data[offset++];
  21614. }
  21615. padded[i++] = 0x80;
  21616. n = paddedLength - 8;
  21617. while (i < n) {
  21618. padded[i++] = 0;
  21619. }
  21620. padded[i++] = 0;
  21621. padded[i++] = 0;
  21622. padded[i++] = 0;
  21623. padded[i++] = (length >>> 29) & 0xFF;
  21624. padded[i++] = (length >> 21) & 0xFF;
  21625. padded[i++] = (length >> 13) & 0xFF;
  21626. padded[i++] = (length >> 5) & 0xFF;
  21627. padded[i++] = (length << 3) & 0xFF;
  21628. var w = new Uint32Array(64);
  21629. // for each 512 bit block
  21630. for (i = 0; i < paddedLength;) {
  21631. for (j = 0; j < 16; ++j) {
  21632. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  21633. (padded[i + 2] << 8) | (padded[i + 3]));
  21634. i += 4;
  21635. }
  21636. for (j = 16; j < 64; ++j) {
  21637. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  21638. littleSigma(w[j - 15]) + w[j - 16] | 0;
  21639. }
  21640. var a = h0, b = h1, c = h2, d = h3, e = h4,
  21641. f = h5, g = h6, h = h7, t1, t2;
  21642. for (j = 0; j < 64; ++j) {
  21643. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  21644. t2 = sigma(a) + maj(a, b, c);
  21645. h = g;
  21646. g = f;
  21647. f = e;
  21648. e = (d + t1) | 0;
  21649. d = c;
  21650. c = b;
  21651. b = a;
  21652. a = (t1 + t2) | 0;
  21653. }
  21654. h0 = (h0 + a) | 0;
  21655. h1 = (h1 + b) | 0;
  21656. h2 = (h2 + c) | 0;
  21657. h3 = (h3 + d) | 0;
  21658. h4 = (h4 + e) | 0;
  21659. h5 = (h5 + f) | 0;
  21660. h6 = (h6 + g) | 0;
  21661. h7 = (h7 + h) | 0;
  21662. }
  21663. return new Uint8Array([
  21664. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  21665. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  21666. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  21667. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  21668. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  21669. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  21670. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  21671. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  21672. ]);
  21673. }
  21674. return hash;
  21675. })();
  21676. var calculateSHA512 = (function calculateSHA512Closure() {
  21677. function ch(result, x, y, z, tmp) {
  21678. result.assign(x);
  21679. result.and(y);
  21680. tmp.assign(x);
  21681. tmp.not();
  21682. tmp.and(z);
  21683. result.xor(tmp);
  21684. }
  21685. function maj(result, x, y, z, tmp) {
  21686. result.assign(x);
  21687. result.and(y);
  21688. tmp.assign(x);
  21689. tmp.and(z);
  21690. result.xor(tmp);
  21691. tmp.assign(y);
  21692. tmp.and(z);
  21693. result.xor(tmp);
  21694. }
  21695. function sigma(result, x, tmp) {
  21696. result.assign(x);
  21697. result.rotateRight(28);
  21698. tmp.assign(x);
  21699. tmp.rotateRight(34);
  21700. result.xor(tmp);
  21701. tmp.assign(x);
  21702. tmp.rotateRight(39);
  21703. result.xor(tmp);
  21704. }
  21705. function sigmaPrime(result, x, tmp) {
  21706. result.assign(x);
  21707. result.rotateRight(14);
  21708. tmp.assign(x);
  21709. tmp.rotateRight(18);
  21710. result.xor(tmp);
  21711. tmp.assign(x);
  21712. tmp.rotateRight(41);
  21713. result.xor(tmp);
  21714. }
  21715. function littleSigma(result, x, tmp) {
  21716. result.assign(x);
  21717. result.rotateRight(1);
  21718. tmp.assign(x);
  21719. tmp.rotateRight(8);
  21720. result.xor(tmp);
  21721. tmp.assign(x);
  21722. tmp.shiftRight(7);
  21723. result.xor(tmp);
  21724. }
  21725. function littleSigmaPrime(result, x, tmp) {
  21726. result.assign(x);
  21727. result.rotateRight(19);
  21728. tmp.assign(x);
  21729. tmp.rotateRight(61);
  21730. result.xor(tmp);
  21731. tmp.assign(x);
  21732. tmp.shiftRight(6);
  21733. result.xor(tmp);
  21734. }
  21735. var k = [
  21736. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  21737. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  21738. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  21739. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  21740. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  21741. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  21742. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  21743. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  21744. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  21745. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  21746. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  21747. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  21748. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  21749. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  21750. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  21751. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  21752. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  21753. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  21754. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  21755. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  21756. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  21757. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  21758. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  21759. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  21760. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  21761. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  21762. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  21763. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  21764. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  21765. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  21766. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  21767. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  21768. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  21769. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  21770. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  21771. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  21772. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  21773. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  21774. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  21775. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  21776. function hash(data, offset, length, mode384) {
  21777. mode384 = !!mode384;
  21778. // initial hash values
  21779. var h0, h1, h2, h3, h4, h5, h6, h7;
  21780. if (!mode384) {
  21781. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  21782. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  21783. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  21784. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  21785. h4 = new Word64(0x510e527f, 0xade682d1);
  21786. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  21787. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  21788. h7 = new Word64(0x5be0cd19, 0x137e2179);
  21789. }
  21790. else {
  21791. // SHA384 is exactly the same
  21792. // except with different starting values and a trimmed result
  21793. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  21794. h1 = new Word64(0x629a292a, 0x367cd507);
  21795. h2 = new Word64(0x9159015a, 0x3070dd17);
  21796. h3 = new Word64(0x152fecd8, 0xf70e5939);
  21797. h4 = new Word64(0x67332667, 0xffc00b31);
  21798. h5 = new Word64(0x8eb44a87, 0x68581511);
  21799. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  21800. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  21801. }
  21802. // pre-processing
  21803. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  21804. var padded = new Uint8Array(paddedLength);
  21805. var i, j, n;
  21806. for (i = 0; i < length; ++i) {
  21807. padded[i] = data[offset++];
  21808. }
  21809. padded[i++] = 0x80;
  21810. n = paddedLength - 16;
  21811. while (i < n) {
  21812. padded[i++] = 0;
  21813. }
  21814. padded[i++] = 0;
  21815. padded[i++] = 0;
  21816. padded[i++] = 0;
  21817. padded[i++] = 0;
  21818. padded[i++] = 0;
  21819. padded[i++] = 0;
  21820. padded[i++] = 0;
  21821. padded[i++] = 0;
  21822. padded[i++] = 0;
  21823. padded[i++] = 0;
  21824. padded[i++] = 0;
  21825. padded[i++] = (length >>> 29) & 0xFF;
  21826. padded[i++] = (length >> 21) & 0xFF;
  21827. padded[i++] = (length >> 13) & 0xFF;
  21828. padded[i++] = (length >> 5) & 0xFF;
  21829. padded[i++] = (length << 3) & 0xFF;
  21830. var w = new Array(80);
  21831. for (i = 0; i < 80; i++) {
  21832. w[i] = new Word64(0, 0);
  21833. }
  21834. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  21835. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  21836. var g = new Word64(0, 0), h = new Word64(0, 0);
  21837. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  21838. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  21839. // for each 1024 bit block
  21840. for (i = 0; i < paddedLength;) {
  21841. for (j = 0; j < 16; ++j) {
  21842. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  21843. (padded[i + 2] << 8) | (padded[i + 3]);
  21844. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  21845. (padded[i + 6]) << 8 | (padded[i + 7]);
  21846. i += 8;
  21847. }
  21848. for (j = 16; j < 80; ++j) {
  21849. tmp3 = w[j];
  21850. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  21851. tmp3.add(w[j - 7]);
  21852. littleSigma(tmp1, w[j - 15], tmp2);
  21853. tmp3.add(tmp1);
  21854. tmp3.add(w[j - 16]);
  21855. }
  21856. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  21857. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  21858. for (j = 0; j < 80; ++j) {
  21859. t1.assign(h);
  21860. sigmaPrime(tmp1, e, tmp2);
  21861. t1.add(tmp1);
  21862. ch(tmp1, e, f, g, tmp2);
  21863. t1.add(tmp1);
  21864. t1.add(k[j]);
  21865. t1.add(w[j]);
  21866. sigma(t2, a, tmp2);
  21867. maj(tmp1, a, b, c, tmp2);
  21868. t2.add(tmp1);
  21869. tmp3 = h;
  21870. h = g;
  21871. g = f;
  21872. f = e;
  21873. d.add(t1);
  21874. e = d;
  21875. d = c;
  21876. c = b;
  21877. b = a;
  21878. tmp3.assign(t1);
  21879. tmp3.add(t2);
  21880. a = tmp3;
  21881. }
  21882. h0.add(a);
  21883. h1.add(b);
  21884. h2.add(c);
  21885. h3.add(d);
  21886. h4.add(e);
  21887. h5.add(f);
  21888. h6.add(g);
  21889. h7.add(h);
  21890. }
  21891. var result;
  21892. if (!mode384) {
  21893. result = new Uint8Array(64);
  21894. h0.copyTo(result,0);
  21895. h1.copyTo(result,8);
  21896. h2.copyTo(result,16);
  21897. h3.copyTo(result,24);
  21898. h4.copyTo(result,32);
  21899. h5.copyTo(result,40);
  21900. h6.copyTo(result,48);
  21901. h7.copyTo(result,56);
  21902. }
  21903. else {
  21904. result = new Uint8Array(48);
  21905. h0.copyTo(result,0);
  21906. h1.copyTo(result,8);
  21907. h2.copyTo(result,16);
  21908. h3.copyTo(result,24);
  21909. h4.copyTo(result,32);
  21910. h5.copyTo(result,40);
  21911. }
  21912. return result;
  21913. }
  21914. return hash;
  21915. })();
  21916. var calculateSHA384 = (function calculateSHA384Closure() {
  21917. function hash(data, offset, length) {
  21918. return calculateSHA512(data, offset, length, true);
  21919. }
  21920. return hash;
  21921. })();
  21922. var NullCipher = (function NullCipherClosure() {
  21923. function NullCipher() {
  21924. }
  21925. NullCipher.prototype = {
  21926. decryptBlock: function NullCipher_decryptBlock(data) {
  21927. return data;
  21928. }
  21929. };
  21930. return NullCipher;
  21931. })();
  21932. var AES128Cipher = (function AES128CipherClosure() {
  21933. var rcon = new Uint8Array([
  21934. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  21935. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  21936. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  21937. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  21938. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  21939. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  21940. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  21941. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  21942. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  21943. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  21944. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  21945. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  21946. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  21947. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  21948. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  21949. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  21950. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  21951. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  21952. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  21953. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  21954. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  21955. 0x74, 0xe8, 0xcb, 0x8d]);
  21956. var s = new Uint8Array([
  21957. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  21958. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  21959. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  21960. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  21961. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  21962. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  21963. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  21964. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  21965. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  21966. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  21967. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  21968. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  21969. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  21970. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  21971. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  21972. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  21973. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  21974. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  21975. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  21976. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  21977. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  21978. 0xb0, 0x54, 0xbb, 0x16]);
  21979. var inv_s = new Uint8Array([
  21980. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  21981. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  21982. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  21983. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  21984. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  21985. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  21986. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  21987. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  21988. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  21989. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  21990. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  21991. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  21992. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  21993. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  21994. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  21995. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  21996. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  21997. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  21998. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  21999. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  22000. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  22001. 0x55, 0x21, 0x0c, 0x7d]);
  22002. var mixCol = new Uint8Array(256);
  22003. for (var i = 0; i < 256; i++) {
  22004. if (i < 128) {
  22005. mixCol[i] = i << 1;
  22006. } else {
  22007. mixCol[i] = (i << 1) ^ 0x1b;
  22008. }
  22009. }
  22010. var mix = new Uint32Array([
  22011. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  22012. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  22013. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  22014. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  22015. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  22016. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  22017. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  22018. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  22019. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  22020. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  22021. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  22022. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  22023. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  22024. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  22025. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  22026. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  22027. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  22028. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  22029. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  22030. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  22031. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  22032. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  22033. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  22034. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  22035. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  22036. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  22037. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  22038. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  22039. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  22040. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  22041. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  22042. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  22043. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  22044. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  22045. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  22046. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  22047. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  22048. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  22049. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  22050. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  22051. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  22052. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  22053. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  22054. function expandKey128(cipherKey) {
  22055. var b = 176, result = new Uint8Array(b);
  22056. result.set(cipherKey);
  22057. for (var j = 16, i = 1; j < b; ++i) {
  22058. // RotWord
  22059. var t1 = result[j - 3], t2 = result[j - 2],
  22060. t3 = result[j - 1], t4 = result[j - 4];
  22061. // SubWord
  22062. t1 = s[t1];
  22063. t2 = s[t2];
  22064. t3 = s[t3];
  22065. t4 = s[t4];
  22066. // Rcon
  22067. t1 = t1 ^ rcon[i];
  22068. for (var n = 0; n < 4; ++n) {
  22069. result[j] = (t1 ^= result[j - 16]);
  22070. j++;
  22071. result[j] = (t2 ^= result[j - 16]);
  22072. j++;
  22073. result[j] = (t3 ^= result[j - 16]);
  22074. j++;
  22075. result[j] = (t4 ^= result[j - 16]);
  22076. j++;
  22077. }
  22078. }
  22079. return result;
  22080. }
  22081. function decrypt128(input, key) {
  22082. var state = new Uint8Array(16);
  22083. state.set(input);
  22084. var i, j, k;
  22085. var t, u, v;
  22086. // AddRoundKey
  22087. for (j = 0, k = 160; j < 16; ++j, ++k) {
  22088. state[j] ^= key[k];
  22089. }
  22090. for (i = 9; i >= 1; --i) {
  22091. // InvShiftRows
  22092. t = state[13];
  22093. state[13] = state[9];
  22094. state[9] = state[5];
  22095. state[5] = state[1];
  22096. state[1] = t;
  22097. t = state[14];
  22098. u = state[10];
  22099. state[14] = state[6];
  22100. state[10] = state[2];
  22101. state[6] = t;
  22102. state[2] = u;
  22103. t = state[15];
  22104. u = state[11];
  22105. v = state[7];
  22106. state[15] = state[3];
  22107. state[11] = t;
  22108. state[7] = u;
  22109. state[3] = v;
  22110. // InvSubBytes
  22111. for (j = 0; j < 16; ++j) {
  22112. state[j] = inv_s[state[j]];
  22113. }
  22114. // AddRoundKey
  22115. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  22116. state[j] ^= key[k];
  22117. }
  22118. // InvMixColumns
  22119. for (j = 0; j < 16; j += 4) {
  22120. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  22121. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  22122. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  22123. (s3 >>> 24) ^ (s3 << 8));
  22124. state[j] = (t >>> 24) & 0xFF;
  22125. state[j + 1] = (t >> 16) & 0xFF;
  22126. state[j + 2] = (t >> 8) & 0xFF;
  22127. state[j + 3] = t & 0xFF;
  22128. }
  22129. }
  22130. // InvShiftRows
  22131. t = state[13];
  22132. state[13] = state[9];
  22133. state[9] = state[5];
  22134. state[5] = state[1];
  22135. state[1] = t;
  22136. t = state[14];
  22137. u = state[10];
  22138. state[14] = state[6];
  22139. state[10] = state[2];
  22140. state[6] = t;
  22141. state[2] = u;
  22142. t = state[15];
  22143. u = state[11];
  22144. v = state[7];
  22145. state[15] = state[3];
  22146. state[11] = t;
  22147. state[7] = u;
  22148. state[3] = v;
  22149. for (j = 0; j < 16; ++j) {
  22150. // InvSubBytes
  22151. state[j] = inv_s[state[j]];
  22152. // AddRoundKey
  22153. state[j] ^= key[j];
  22154. }
  22155. return state;
  22156. }
  22157. function encrypt128(input, key) {
  22158. var t, u, v, k;
  22159. var state = new Uint8Array(16);
  22160. state.set(input);
  22161. for (j = 0; j < 16; ++j) {
  22162. // AddRoundKey
  22163. state[j] ^= key[j];
  22164. }
  22165. for (i = 1; i < 10; i++) {
  22166. //SubBytes
  22167. for (j = 0; j < 16; ++j) {
  22168. state[j] = s[state[j]];
  22169. }
  22170. //ShiftRows
  22171. v = state[1];
  22172. state[1] = state[5];
  22173. state[5] = state[9];
  22174. state[9] = state[13];
  22175. state[13] = v;
  22176. v = state[2];
  22177. u = state[6];
  22178. state[2] = state[10];
  22179. state[6] = state[14];
  22180. state[10] = v;
  22181. state[14] = u;
  22182. v = state[3];
  22183. u = state[7];
  22184. t = state[11];
  22185. state[3] = state[15];
  22186. state[7] = v;
  22187. state[11] = u;
  22188. state[15] = t;
  22189. //MixColumns
  22190. for (var j = 0; j < 16; j += 4) {
  22191. var s0 = state[j + 0], s1 = state[j + 1];
  22192. var s2 = state[j + 2], s3 = state[j + 3];
  22193. t = s0 ^ s1 ^ s2 ^ s3;
  22194. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  22195. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  22196. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  22197. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  22198. }
  22199. //AddRoundKey
  22200. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  22201. state[j] ^= key[k];
  22202. }
  22203. }
  22204. //SubBytes
  22205. for (j = 0; j < 16; ++j) {
  22206. state[j] = s[state[j]];
  22207. }
  22208. //ShiftRows
  22209. v = state[1];
  22210. state[1] = state[5];
  22211. state[5] = state[9];
  22212. state[9] = state[13];
  22213. state[13] = v;
  22214. v = state[2];
  22215. u = state[6];
  22216. state[2] = state[10];
  22217. state[6] = state[14];
  22218. state[10] = v;
  22219. state[14] = u;
  22220. v = state[3];
  22221. u = state[7];
  22222. t = state[11];
  22223. state[3] = state[15];
  22224. state[7] = v;
  22225. state[11] = u;
  22226. state[15] = t;
  22227. //AddRoundKey
  22228. for (j = 0, k = 160; j < 16; ++j, ++k) {
  22229. state[j] ^= key[k];
  22230. }
  22231. return state;
  22232. }
  22233. function AES128Cipher(key) {
  22234. this.key = expandKey128(key);
  22235. this.buffer = new Uint8Array(16);
  22236. this.bufferPosition = 0;
  22237. }
  22238. function decryptBlock2(data, finalize) {
  22239. var i, j, ii, sourceLength = data.length,
  22240. buffer = this.buffer, bufferLength = this.bufferPosition,
  22241. result = [], iv = this.iv;
  22242. for (i = 0; i < sourceLength; ++i) {
  22243. buffer[bufferLength] = data[i];
  22244. ++bufferLength;
  22245. if (bufferLength < 16) {
  22246. continue;
  22247. }
  22248. // buffer is full, decrypting
  22249. var plain = decrypt128(buffer, this.key);
  22250. // xor-ing the IV vector to get plain text
  22251. for (j = 0; j < 16; ++j) {
  22252. plain[j] ^= iv[j];
  22253. }
  22254. iv = buffer;
  22255. result.push(plain);
  22256. buffer = new Uint8Array(16);
  22257. bufferLength = 0;
  22258. }
  22259. // saving incomplete buffer
  22260. this.buffer = buffer;
  22261. this.bufferLength = bufferLength;
  22262. this.iv = iv;
  22263. if (result.length === 0) {
  22264. return new Uint8Array([]);
  22265. }
  22266. // combining plain text blocks into one
  22267. var outputLength = 16 * result.length;
  22268. if (finalize) {
  22269. // undo a padding that is described in RFC 2898
  22270. var lastBlock = result[result.length - 1];
  22271. var psLen = lastBlock[15];
  22272. if (psLen <= 16) {
  22273. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  22274. if (lastBlock[i] !== psLen) {
  22275. // Invalid padding, assume that the block has no padding.
  22276. psLen = 0;
  22277. break;
  22278. }
  22279. }
  22280. outputLength -= psLen;
  22281. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  22282. }
  22283. }
  22284. var output = new Uint8Array(outputLength);
  22285. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  22286. output.set(result[i], j);
  22287. }
  22288. return output;
  22289. }
  22290. AES128Cipher.prototype = {
  22291. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  22292. var i, sourceLength = data.length;
  22293. var buffer = this.buffer, bufferLength = this.bufferPosition;
  22294. // waiting for IV values -- they are at the start of the stream
  22295. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  22296. buffer[bufferLength] = data[i];
  22297. }
  22298. if (bufferLength < 16) {
  22299. // need more data
  22300. this.bufferLength = bufferLength;
  22301. return new Uint8Array([]);
  22302. }
  22303. this.iv = buffer;
  22304. this.buffer = new Uint8Array(16);
  22305. this.bufferLength = 0;
  22306. // starting decryption
  22307. this.decryptBlock = decryptBlock2;
  22308. return this.decryptBlock(data.subarray(16), finalize);
  22309. },
  22310. encrypt: function AES128Cipher_encrypt(data, iv) {
  22311. var i, j, ii, sourceLength = data.length,
  22312. buffer = this.buffer, bufferLength = this.bufferPosition,
  22313. result = [];
  22314. if (!iv) {
  22315. iv = new Uint8Array(16);
  22316. }
  22317. for (i = 0; i < sourceLength; ++i) {
  22318. buffer[bufferLength] = data[i];
  22319. ++bufferLength;
  22320. if (bufferLength < 16) {
  22321. continue;
  22322. }
  22323. for (j = 0; j < 16; ++j) {
  22324. buffer[j] ^= iv[j];
  22325. }
  22326. // buffer is full, encrypting
  22327. var cipher = encrypt128(buffer, this.key);
  22328. iv = cipher;
  22329. result.push(cipher);
  22330. buffer = new Uint8Array(16);
  22331. bufferLength = 0;
  22332. }
  22333. // saving incomplete buffer
  22334. this.buffer = buffer;
  22335. this.bufferLength = bufferLength;
  22336. this.iv = iv;
  22337. if (result.length === 0) {
  22338. return new Uint8Array([]);
  22339. }
  22340. // combining plain text blocks into one
  22341. var outputLength = 16 * result.length;
  22342. var output = new Uint8Array(outputLength);
  22343. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  22344. output.set(result[i], j);
  22345. }
  22346. return output;
  22347. }
  22348. };
  22349. return AES128Cipher;
  22350. })();
  22351. var AES256Cipher = (function AES256CipherClosure() {
  22352. var rcon = new Uint8Array([
  22353. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  22354. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  22355. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  22356. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  22357. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  22358. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  22359. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  22360. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  22361. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  22362. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  22363. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  22364. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  22365. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  22366. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  22367. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  22368. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  22369. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  22370. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  22371. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  22372. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  22373. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  22374. 0x74, 0xe8, 0xcb, 0x8d]);
  22375. var s = new Uint8Array([
  22376. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  22377. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  22378. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  22379. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  22380. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  22381. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  22382. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  22383. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  22384. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  22385. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  22386. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  22387. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  22388. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  22389. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  22390. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  22391. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  22392. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  22393. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  22394. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  22395. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  22396. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  22397. 0xb0, 0x54, 0xbb, 0x16]);
  22398. var inv_s = new Uint8Array([
  22399. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  22400. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  22401. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  22402. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  22403. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  22404. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  22405. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  22406. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  22407. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  22408. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  22409. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  22410. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  22411. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  22412. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  22413. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  22414. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  22415. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  22416. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  22417. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  22418. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  22419. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  22420. 0x55, 0x21, 0x0c, 0x7d]);
  22421. var mixCol = new Uint8Array(256);
  22422. for (var i = 0; i < 256; i++) {
  22423. if (i < 128) {
  22424. mixCol[i] = i << 1;
  22425. } else {
  22426. mixCol[i] = (i << 1) ^ 0x1b;
  22427. }
  22428. }
  22429. var mix = new Uint32Array([
  22430. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  22431. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  22432. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  22433. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  22434. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  22435. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  22436. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  22437. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  22438. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  22439. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  22440. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  22441. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  22442. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  22443. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  22444. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  22445. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  22446. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  22447. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  22448. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  22449. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  22450. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  22451. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  22452. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  22453. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  22454. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  22455. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  22456. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  22457. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  22458. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  22459. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  22460. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  22461. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  22462. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  22463. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  22464. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  22465. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  22466. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  22467. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  22468. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  22469. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  22470. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  22471. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  22472. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  22473. function expandKey256(cipherKey) {
  22474. var b = 240, result = new Uint8Array(b);
  22475. var r = 1;
  22476. result.set(cipherKey);
  22477. for (var j = 32, i = 1; j < b; ++i) {
  22478. if (j % 32 === 16) {
  22479. t1 = s[t1];
  22480. t2 = s[t2];
  22481. t3 = s[t3];
  22482. t4 = s[t4];
  22483. } else if (j % 32 === 0) {
  22484. // RotWord
  22485. var t1 = result[j - 3], t2 = result[j - 2],
  22486. t3 = result[j - 1], t4 = result[j - 4];
  22487. // SubWord
  22488. t1 = s[t1];
  22489. t2 = s[t2];
  22490. t3 = s[t3];
  22491. t4 = s[t4];
  22492. // Rcon
  22493. t1 = t1 ^ r;
  22494. if ((r <<= 1) >= 256) {
  22495. r = (r ^ 0x1b) & 0xFF;
  22496. }
  22497. }
  22498. for (var n = 0; n < 4; ++n) {
  22499. result[j] = (t1 ^= result[j - 32]);
  22500. j++;
  22501. result[j] = (t2 ^= result[j - 32]);
  22502. j++;
  22503. result[j] = (t3 ^= result[j - 32]);
  22504. j++;
  22505. result[j] = (t4 ^= result[j - 32]);
  22506. j++;
  22507. }
  22508. }
  22509. return result;
  22510. }
  22511. function decrypt256(input, key) {
  22512. var state = new Uint8Array(16);
  22513. state.set(input);
  22514. var i, j, k;
  22515. var t, u, v;
  22516. // AddRoundKey
  22517. for (j = 0, k = 224; j < 16; ++j, ++k) {
  22518. state[j] ^= key[k];
  22519. }
  22520. for (i = 13; i >= 1; --i) {
  22521. // InvShiftRows
  22522. t = state[13];
  22523. state[13] = state[9];
  22524. state[9] = state[5];
  22525. state[5] = state[1];
  22526. state[1] = t;
  22527. t = state[14];
  22528. u = state[10];
  22529. state[14] = state[6];
  22530. state[10] = state[2];
  22531. state[6] = t;
  22532. state[2] = u;
  22533. t = state[15];
  22534. u = state[11];
  22535. v = state[7];
  22536. state[15] = state[3];
  22537. state[11] = t;
  22538. state[7] = u;
  22539. state[3] = v;
  22540. // InvSubBytes
  22541. for (j = 0; j < 16; ++j) {
  22542. state[j] = inv_s[state[j]];
  22543. }
  22544. // AddRoundKey
  22545. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  22546. state[j] ^= key[k];
  22547. }
  22548. // InvMixColumns
  22549. for (j = 0; j < 16; j += 4) {
  22550. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  22551. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  22552. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  22553. (s3 >>> 24) ^ (s3 << 8));
  22554. state[j] = (t >>> 24) & 0xFF;
  22555. state[j + 1] = (t >> 16) & 0xFF;
  22556. state[j + 2] = (t >> 8) & 0xFF;
  22557. state[j + 3] = t & 0xFF;
  22558. }
  22559. }
  22560. // InvShiftRows
  22561. t = state[13];
  22562. state[13] = state[9];
  22563. state[9] = state[5];
  22564. state[5] = state[1];
  22565. state[1] = t;
  22566. t = state[14];
  22567. u = state[10];
  22568. state[14] = state[6];
  22569. state[10] = state[2];
  22570. state[6] = t;
  22571. state[2] = u;
  22572. t = state[15];
  22573. u = state[11];
  22574. v = state[7];
  22575. state[15] = state[3];
  22576. state[11] = t;
  22577. state[7] = u;
  22578. state[3] = v;
  22579. for (j = 0; j < 16; ++j) {
  22580. // InvSubBytes
  22581. state[j] = inv_s[state[j]];
  22582. // AddRoundKey
  22583. state[j] ^= key[j];
  22584. }
  22585. return state;
  22586. }
  22587. function encrypt256(input, key) {
  22588. var t, u, v, k;
  22589. var state = new Uint8Array(16);
  22590. state.set(input);
  22591. for (j = 0; j < 16; ++j) {
  22592. // AddRoundKey
  22593. state[j] ^= key[j];
  22594. }
  22595. for (i = 1; i < 14; i++) {
  22596. //SubBytes
  22597. for (j = 0; j < 16; ++j) {
  22598. state[j] = s[state[j]];
  22599. }
  22600. //ShiftRows
  22601. v = state[1];
  22602. state[1] = state[5];
  22603. state[5] = state[9];
  22604. state[9] = state[13];
  22605. state[13] = v;
  22606. v = state[2];
  22607. u = state[6];
  22608. state[2] = state[10];
  22609. state[6] = state[14];
  22610. state[10] = v;
  22611. state[14] = u;
  22612. v = state[3];
  22613. u = state[7];
  22614. t = state[11];
  22615. state[3] = state[15];
  22616. state[7] = v;
  22617. state[11] = u;
  22618. state[15] = t;
  22619. //MixColumns
  22620. for (var j = 0; j < 16; j += 4) {
  22621. var s0 = state[j + 0], s1 = state[j + 1];
  22622. var s2 = state[j + 2], s3 = state[j + 3];
  22623. t = s0 ^ s1 ^ s2 ^ s3;
  22624. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  22625. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  22626. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  22627. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  22628. }
  22629. //AddRoundKey
  22630. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  22631. state[j] ^= key[k];
  22632. }
  22633. }
  22634. //SubBytes
  22635. for (j = 0; j < 16; ++j) {
  22636. state[j] = s[state[j]];
  22637. }
  22638. //ShiftRows
  22639. v = state[1];
  22640. state[1] = state[5];
  22641. state[5] = state[9];
  22642. state[9] = state[13];
  22643. state[13] = v;
  22644. v = state[2];
  22645. u = state[6];
  22646. state[2] = state[10];
  22647. state[6] = state[14];
  22648. state[10] = v;
  22649. state[14] = u;
  22650. v = state[3];
  22651. u = state[7];
  22652. t = state[11];
  22653. state[3] = state[15];
  22654. state[7] = v;
  22655. state[11] = u;
  22656. state[15] = t;
  22657. //AddRoundKey
  22658. for (j = 0, k = 224; j < 16; ++j, ++k) {
  22659. state[j] ^= key[k];
  22660. }
  22661. return state;
  22662. }
  22663. function AES256Cipher(key) {
  22664. this.key = expandKey256(key);
  22665. this.buffer = new Uint8Array(16);
  22666. this.bufferPosition = 0;
  22667. }
  22668. function decryptBlock2(data, finalize) {
  22669. var i, j, ii, sourceLength = data.length,
  22670. buffer = this.buffer, bufferLength = this.bufferPosition,
  22671. result = [], iv = this.iv;
  22672. for (i = 0; i < sourceLength; ++i) {
  22673. buffer[bufferLength] = data[i];
  22674. ++bufferLength;
  22675. if (bufferLength < 16) {
  22676. continue;
  22677. }
  22678. // buffer is full, decrypting
  22679. var plain = decrypt256(buffer, this.key);
  22680. // xor-ing the IV vector to get plain text
  22681. for (j = 0; j < 16; ++j) {
  22682. plain[j] ^= iv[j];
  22683. }
  22684. iv = buffer;
  22685. result.push(plain);
  22686. buffer = new Uint8Array(16);
  22687. bufferLength = 0;
  22688. }
  22689. // saving incomplete buffer
  22690. this.buffer = buffer;
  22691. this.bufferLength = bufferLength;
  22692. this.iv = iv;
  22693. if (result.length === 0) {
  22694. return new Uint8Array([]);
  22695. }
  22696. // combining plain text blocks into one
  22697. var outputLength = 16 * result.length;
  22698. if (finalize) {
  22699. // undo a padding that is described in RFC 2898
  22700. var lastBlock = result[result.length - 1];
  22701. var psLen = lastBlock[15];
  22702. if (psLen <= 16) {
  22703. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  22704. if (lastBlock[i] !== psLen) {
  22705. // Invalid padding, assume that the block has no padding.
  22706. psLen = 0;
  22707. break;
  22708. }
  22709. }
  22710. outputLength -= psLen;
  22711. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  22712. }
  22713. }
  22714. var output = new Uint8Array(outputLength);
  22715. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  22716. output.set(result[i], j);
  22717. }
  22718. return output;
  22719. }
  22720. AES256Cipher.prototype = {
  22721. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  22722. var i, sourceLength = data.length;
  22723. var buffer = this.buffer, bufferLength = this.bufferPosition;
  22724. // if not supplied an IV wait for IV values
  22725. // they are at the start of the stream
  22726. if (iv) {
  22727. this.iv = iv;
  22728. } else {
  22729. for (i = 0; bufferLength < 16 &&
  22730. i < sourceLength; ++i, ++bufferLength) {
  22731. buffer[bufferLength] = data[i];
  22732. }
  22733. if (bufferLength < 16) {
  22734. //need more data
  22735. this.bufferLength = bufferLength;
  22736. return new Uint8Array([]);
  22737. }
  22738. this.iv = buffer;
  22739. data = data.subarray(16);
  22740. }
  22741. this.buffer = new Uint8Array(16);
  22742. this.bufferLength = 0;
  22743. // starting decryption
  22744. this.decryptBlock = decryptBlock2;
  22745. return this.decryptBlock(data, finalize);
  22746. },
  22747. encrypt: function AES256Cipher_encrypt(data, iv) {
  22748. var i, j, ii, sourceLength = data.length,
  22749. buffer = this.buffer, bufferLength = this.bufferPosition,
  22750. result = [];
  22751. if (!iv) {
  22752. iv = new Uint8Array(16);
  22753. }
  22754. for (i = 0; i < sourceLength; ++i) {
  22755. buffer[bufferLength] = data[i];
  22756. ++bufferLength;
  22757. if (bufferLength < 16) {
  22758. continue;
  22759. }
  22760. for (j = 0; j < 16; ++j) {
  22761. buffer[j] ^= iv[j];
  22762. }
  22763. // buffer is full, encrypting
  22764. var cipher = encrypt256(buffer, this.key);
  22765. this.iv = cipher;
  22766. result.push(cipher);
  22767. buffer = new Uint8Array(16);
  22768. bufferLength = 0;
  22769. }
  22770. // saving incomplete buffer
  22771. this.buffer = buffer;
  22772. this.bufferLength = bufferLength;
  22773. this.iv = iv;
  22774. if (result.length === 0) {
  22775. return new Uint8Array([]);
  22776. }
  22777. // combining plain text blocks into one
  22778. var outputLength = 16 * result.length;
  22779. var output = new Uint8Array(outputLength);
  22780. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  22781. output.set(result[i], j);
  22782. }
  22783. return output;
  22784. }
  22785. };
  22786. return AES256Cipher;
  22787. })();
  22788. var PDF17 = (function PDF17Closure() {
  22789. function compareByteArrays(array1, array2) {
  22790. if (array1.length !== array2.length) {
  22791. return false;
  22792. }
  22793. for (var i = 0; i < array1.length; i++) {
  22794. if (array1[i] !== array2[i]) {
  22795. return false;
  22796. }
  22797. }
  22798. return true;
  22799. }
  22800. function PDF17() {
  22801. }
  22802. PDF17.prototype = {
  22803. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  22804. ownerValidationSalt,
  22805. userBytes,
  22806. ownerPassword) {
  22807. var hashData = new Uint8Array(password.length + 56);
  22808. hashData.set(password, 0);
  22809. hashData.set(ownerValidationSalt, password.length);
  22810. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  22811. var result = calculateSHA256(hashData, 0, hashData.length);
  22812. return compareByteArrays(result, ownerPassword);
  22813. },
  22814. checkUserPassword: function PDF17_checkUserPassword(password,
  22815. userValidationSalt,
  22816. userPassword) {
  22817. var hashData = new Uint8Array(password.length + 8);
  22818. hashData.set(password, 0);
  22819. hashData.set(userValidationSalt, password.length);
  22820. var result = calculateSHA256(hashData, 0, hashData.length);
  22821. return compareByteArrays(result, userPassword);
  22822. },
  22823. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  22824. ownerEncryption) {
  22825. var hashData = new Uint8Array(password.length + 56);
  22826. hashData.set(password, 0);
  22827. hashData.set(ownerKeySalt, password.length);
  22828. hashData.set(userBytes, password.length + ownerKeySalt.length);
  22829. var key = calculateSHA256(hashData, 0, hashData.length);
  22830. var cipher = new AES256Cipher(key);
  22831. return cipher.decryptBlock(ownerEncryption,
  22832. false,
  22833. new Uint8Array(16));
  22834. },
  22835. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  22836. userEncryption) {
  22837. var hashData = new Uint8Array(password.length + 8);
  22838. hashData.set(password, 0);
  22839. hashData.set(userKeySalt, password.length);
  22840. //key is the decryption key for the UE string
  22841. var key = calculateSHA256(hashData, 0, hashData.length);
  22842. var cipher = new AES256Cipher(key);
  22843. return cipher.decryptBlock(userEncryption,
  22844. false,
  22845. new Uint8Array(16));
  22846. }
  22847. };
  22848. return PDF17;
  22849. })();
  22850. var PDF20 = (function PDF20Closure() {
  22851. function concatArrays(array1, array2) {
  22852. var t = new Uint8Array(array1.length + array2.length);
  22853. t.set(array1, 0);
  22854. t.set(array2, array1.length);
  22855. return t;
  22856. }
  22857. function calculatePDF20Hash(password, input, userBytes) {
  22858. //This refers to Algorithm 2.B as defined in ISO 32000-2
  22859. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  22860. var e = [0];
  22861. var i = 0;
  22862. while (i < 64 || e[e.length - 1] > i - 32) {
  22863. var arrayLength = password.length + k.length + userBytes.length;
  22864. var k1 = new Uint8Array(arrayLength * 64);
  22865. var array = concatArrays(password, k);
  22866. array = concatArrays(array, userBytes);
  22867. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  22868. k1.set(array, pos);
  22869. }
  22870. //AES128 CBC NO PADDING with
  22871. //first 16 bytes of k as the key and the second 16 as the iv.
  22872. var cipher = new AES128Cipher(k.subarray(0, 16));
  22873. e = cipher.encrypt(k1, k.subarray(16, 32));
  22874. //Now we have to take the first 16 bytes of an unsigned
  22875. //big endian integer... and compute the remainder
  22876. //modulo 3.... That is a fairly large number and
  22877. //JavaScript isn't going to handle that well...
  22878. //So we're using a trick that allows us to perform
  22879. //modulo math byte by byte
  22880. var remainder = 0;
  22881. for (var z = 0; z < 16; z++) {
  22882. remainder *= (256 % 3);
  22883. remainder %= 3;
  22884. remainder += ((e[z] >>> 0) % 3);
  22885. remainder %= 3;
  22886. }
  22887. if (remainder === 0) {
  22888. k = calculateSHA256(e, 0, e.length);
  22889. }
  22890. else if (remainder === 1) {
  22891. k = calculateSHA384(e, 0, e.length);
  22892. }
  22893. else if (remainder === 2) {
  22894. k = calculateSHA512(e, 0, e.length);
  22895. }
  22896. i++;
  22897. }
  22898. return k.subarray(0, 32);
  22899. }
  22900. function PDF20() {
  22901. }
  22902. function compareByteArrays(array1, array2) {
  22903. if (array1.length !== array2.length) {
  22904. return false;
  22905. }
  22906. for (var i = 0; i < array1.length; i++) {
  22907. if (array1[i] !== array2[i]) {
  22908. return false;
  22909. }
  22910. }
  22911. return true;
  22912. }
  22913. PDF20.prototype = {
  22914. hash: function PDF20_hash(password, concatBytes, userBytes) {
  22915. return calculatePDF20Hash(password, concatBytes, userBytes);
  22916. },
  22917. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  22918. ownerValidationSalt,
  22919. userBytes,
  22920. ownerPassword) {
  22921. var hashData = new Uint8Array(password.length + 56);
  22922. hashData.set(password, 0);
  22923. hashData.set(ownerValidationSalt, password.length);
  22924. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  22925. var result = calculatePDF20Hash(password, hashData, userBytes);
  22926. return compareByteArrays(result, ownerPassword);
  22927. },
  22928. checkUserPassword: function PDF20_checkUserPassword(password,
  22929. userValidationSalt,
  22930. userPassword) {
  22931. var hashData = new Uint8Array(password.length + 8);
  22932. hashData.set(password, 0);
  22933. hashData.set(userValidationSalt, password.length);
  22934. var result = calculatePDF20Hash(password, hashData, []);
  22935. return compareByteArrays(result, userPassword);
  22936. },
  22937. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  22938. ownerEncryption) {
  22939. var hashData = new Uint8Array(password.length + 56);
  22940. hashData.set(password, 0);
  22941. hashData.set(ownerKeySalt, password.length);
  22942. hashData.set(userBytes, password.length + ownerKeySalt.length);
  22943. var key = calculatePDF20Hash(password, hashData, userBytes);
  22944. var cipher = new AES256Cipher(key);
  22945. return cipher.decryptBlock(ownerEncryption,
  22946. false,
  22947. new Uint8Array(16));
  22948. },
  22949. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  22950. userEncryption) {
  22951. var hashData = new Uint8Array(password.length + 8);
  22952. hashData.set(password, 0);
  22953. hashData.set(userKeySalt, password.length);
  22954. //key is the decryption key for the UE string
  22955. var key = calculatePDF20Hash(password, hashData, []);
  22956. var cipher = new AES256Cipher(key);
  22957. return cipher.decryptBlock(userEncryption,
  22958. false,
  22959. new Uint8Array(16));
  22960. }
  22961. };
  22962. return PDF20;
  22963. })();
  22964. var CipherTransform = (function CipherTransformClosure() {
  22965. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  22966. this.stringCipherConstructor = stringCipherConstructor;
  22967. this.streamCipherConstructor = streamCipherConstructor;
  22968. }
  22969. CipherTransform.prototype = {
  22970. createStream: function CipherTransform_createStream(stream, length) {
  22971. var cipher = new this.streamCipherConstructor();
  22972. return new DecryptStream(stream, length,
  22973. function cipherTransformDecryptStream(data, finalize) {
  22974. return cipher.decryptBlock(data, finalize);
  22975. }
  22976. );
  22977. },
  22978. decryptString: function CipherTransform_decryptString(s) {
  22979. var cipher = new this.stringCipherConstructor();
  22980. var data = stringToBytes(s);
  22981. data = cipher.decryptBlock(data, true);
  22982. return bytesToString(data);
  22983. }
  22984. };
  22985. return CipherTransform;
  22986. })();
  22987. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  22988. var defaultPasswordBytes = new Uint8Array([
  22989. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  22990. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  22991. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  22992. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  22993. function createEncryptionKey20(revision, password, ownerPassword,
  22994. ownerValidationSalt, ownerKeySalt, uBytes,
  22995. userPassword, userValidationSalt, userKeySalt,
  22996. ownerEncryption, userEncryption, perms) {
  22997. if (password) {
  22998. var passwordLength = Math.min(127, password.length);
  22999. password = password.subarray(0, passwordLength);
  23000. } else {
  23001. password = [];
  23002. }
  23003. var pdfAlgorithm;
  23004. if (revision === 6) {
  23005. pdfAlgorithm = new PDF20();
  23006. } else {
  23007. pdfAlgorithm = new PDF17();
  23008. }
  23009. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  23010. userPassword)) {
  23011. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  23012. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  23013. ownerValidationSalt,
  23014. uBytes,
  23015. ownerPassword)) {
  23016. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  23017. ownerEncryption);
  23018. }
  23019. return null;
  23020. }
  23021. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  23022. flags, revision, keyLength, encryptMetadata) {
  23023. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  23024. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  23025. if (password) {
  23026. n = Math.min(32, password.length);
  23027. for (; i < n; ++i) {
  23028. hashData[i] = password[i];
  23029. }
  23030. }
  23031. j = 0;
  23032. while (i < 32) {
  23033. hashData[i++] = defaultPasswordBytes[j++];
  23034. }
  23035. // as now the padded password in the hashData[0..i]
  23036. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  23037. hashData[i++] = ownerPassword[j];
  23038. }
  23039. hashData[i++] = flags & 0xFF;
  23040. hashData[i++] = (flags >> 8) & 0xFF;
  23041. hashData[i++] = (flags >> 16) & 0xFF;
  23042. hashData[i++] = (flags >>> 24) & 0xFF;
  23043. for (j = 0, n = fileId.length; j < n; ++j) {
  23044. hashData[i++] = fileId[j];
  23045. }
  23046. if (revision >= 4 && !encryptMetadata) {
  23047. hashData[i++] = 0xFF;
  23048. hashData[i++] = 0xFF;
  23049. hashData[i++] = 0xFF;
  23050. hashData[i++] = 0xFF;
  23051. }
  23052. var hash = calculateMD5(hashData, 0, i);
  23053. var keyLengthInBytes = keyLength >> 3;
  23054. if (revision >= 3) {
  23055. for (j = 0; j < 50; ++j) {
  23056. hash = calculateMD5(hash, 0, keyLengthInBytes);
  23057. }
  23058. }
  23059. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  23060. var cipher, checkData;
  23061. if (revision >= 3) {
  23062. for (i = 0; i < 32; ++i) {
  23063. hashData[i] = defaultPasswordBytes[i];
  23064. }
  23065. for (j = 0, n = fileId.length; j < n; ++j) {
  23066. hashData[i++] = fileId[j];
  23067. }
  23068. cipher = new ARCFourCipher(encryptionKey);
  23069. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  23070. n = encryptionKey.length;
  23071. var derivedKey = new Uint8Array(n), k;
  23072. for (j = 1; j <= 19; ++j) {
  23073. for (k = 0; k < n; ++k) {
  23074. derivedKey[k] = encryptionKey[k] ^ j;
  23075. }
  23076. cipher = new ARCFourCipher(derivedKey);
  23077. checkData = cipher.encryptBlock(checkData);
  23078. }
  23079. for (j = 0, n = checkData.length; j < n; ++j) {
  23080. if (userPassword[j] !== checkData[j]) {
  23081. return null;
  23082. }
  23083. }
  23084. } else {
  23085. cipher = new ARCFourCipher(encryptionKey);
  23086. checkData = cipher.encryptBlock(defaultPasswordBytes);
  23087. for (j = 0, n = checkData.length; j < n; ++j) {
  23088. if (userPassword[j] !== checkData[j]) {
  23089. return null;
  23090. }
  23091. }
  23092. }
  23093. return encryptionKey;
  23094. }
  23095. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  23096. var hashData = new Uint8Array(32), i = 0, j, n;
  23097. n = Math.min(32, password.length);
  23098. for (; i < n; ++i) {
  23099. hashData[i] = password[i];
  23100. }
  23101. j = 0;
  23102. while (i < 32) {
  23103. hashData[i++] = defaultPasswordBytes[j++];
  23104. }
  23105. var hash = calculateMD5(hashData, 0, i);
  23106. var keyLengthInBytes = keyLength >> 3;
  23107. if (revision >= 3) {
  23108. for (j = 0; j < 50; ++j) {
  23109. hash = calculateMD5(hash, 0, hash.length);
  23110. }
  23111. }
  23112. var cipher, userPassword;
  23113. if (revision >= 3) {
  23114. userPassword = ownerPassword;
  23115. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  23116. for (j = 19; j >= 0; j--) {
  23117. for (k = 0; k < keyLengthInBytes; ++k) {
  23118. derivedKey[k] = hash[k] ^ j;
  23119. }
  23120. cipher = new ARCFourCipher(derivedKey);
  23121. userPassword = cipher.encryptBlock(userPassword);
  23122. }
  23123. } else {
  23124. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  23125. userPassword = cipher.encryptBlock(ownerPassword);
  23126. }
  23127. return userPassword;
  23128. }
  23129. var identityName = Name.get('Identity');
  23130. function CipherTransformFactory(dict, fileId, password) {
  23131. var filter = dict.get('Filter');
  23132. if (!isName(filter, 'Standard')) {
  23133. error('unknown encryption method');
  23134. }
  23135. this.dict = dict;
  23136. var algorithm = dict.get('V');
  23137. if (!isInt(algorithm) ||
  23138. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  23139. algorithm !== 5)) {
  23140. error('unsupported encryption algorithm');
  23141. }
  23142. this.algorithm = algorithm;
  23143. var keyLength = dict.get('Length');
  23144. if (!keyLength) {
  23145. // Spec asks to rely on encryption dictionary's Length entry, however
  23146. // some PDFs don't have it. Trying to recover.
  23147. if (algorithm <= 3) {
  23148. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  23149. keyLength = 40;
  23150. } else {
  23151. // Trying to find default handler -- it usually has Length.
  23152. var cfDict = dict.get('CF');
  23153. var streamCryptoName = dict.get('StmF');
  23154. if (isDict(cfDict) && isName(streamCryptoName)) {
  23155. var handlerDict = cfDict.get(streamCryptoName.name);
  23156. keyLength = (handlerDict && handlerDict.get('Length')) || 128;
  23157. if (keyLength < 40) {
  23158. // Sometimes it's incorrect value of bits, generators specify bytes.
  23159. keyLength <<= 3;
  23160. }
  23161. }
  23162. }
  23163. }
  23164. if (!isInt(keyLength) ||
  23165. keyLength < 40 || (keyLength % 8) !== 0) {
  23166. error('invalid key length');
  23167. }
  23168. // prepare keys
  23169. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  23170. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  23171. var flags = dict.get('P');
  23172. var revision = dict.get('R');
  23173. // meaningful when V is 4 or 5
  23174. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  23175. dict.get('EncryptMetadata') !== false);
  23176. this.encryptMetadata = encryptMetadata;
  23177. var fileIdBytes = stringToBytes(fileId);
  23178. var passwordBytes;
  23179. if (password) {
  23180. if (revision === 6) {
  23181. try {
  23182. password = utf8StringToString(password);
  23183. } catch (ex) {
  23184. warn('CipherTransformFactory: ' +
  23185. 'Unable to convert UTF8 encoded password.');
  23186. }
  23187. }
  23188. passwordBytes = stringToBytes(password);
  23189. }
  23190. var encryptionKey;
  23191. if (algorithm !== 5) {
  23192. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  23193. ownerPassword, userPassword, flags,
  23194. revision, keyLength, encryptMetadata);
  23195. }
  23196. else {
  23197. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  23198. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  23199. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  23200. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  23201. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  23202. var ownerEncryption = stringToBytes(dict.get('OE'));
  23203. var userEncryption = stringToBytes(dict.get('UE'));
  23204. var perms = stringToBytes(dict.get('Perms'));
  23205. encryptionKey =
  23206. createEncryptionKey20(revision, passwordBytes,
  23207. ownerPassword, ownerValidationSalt,
  23208. ownerKeySalt, uBytes,
  23209. userPassword, userValidationSalt,
  23210. userKeySalt, ownerEncryption,
  23211. userEncryption, perms);
  23212. }
  23213. if (!encryptionKey && !password) {
  23214. throw new PasswordException('No password given',
  23215. PasswordResponses.NEED_PASSWORD);
  23216. } else if (!encryptionKey && password) {
  23217. // Attempting use the password as an owner password
  23218. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  23219. revision, keyLength);
  23220. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  23221. ownerPassword, userPassword, flags,
  23222. revision, keyLength, encryptMetadata);
  23223. }
  23224. if (!encryptionKey) {
  23225. throw new PasswordException('Incorrect Password',
  23226. PasswordResponses.INCORRECT_PASSWORD);
  23227. }
  23228. this.encryptionKey = encryptionKey;
  23229. if (algorithm >= 4) {
  23230. this.cf = dict.get('CF');
  23231. this.stmf = dict.get('StmF') || identityName;
  23232. this.strf = dict.get('StrF') || identityName;
  23233. this.eff = dict.get('EFF') || this.stmf;
  23234. }
  23235. }
  23236. function buildObjectKey(num, gen, encryptionKey, isAes) {
  23237. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  23238. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  23239. key[i] = encryptionKey[i];
  23240. }
  23241. key[i++] = num & 0xFF;
  23242. key[i++] = (num >> 8) & 0xFF;
  23243. key[i++] = (num >> 16) & 0xFF;
  23244. key[i++] = gen & 0xFF;
  23245. key[i++] = (gen >> 8) & 0xFF;
  23246. if (isAes) {
  23247. key[i++] = 0x73;
  23248. key[i++] = 0x41;
  23249. key[i++] = 0x6C;
  23250. key[i++] = 0x54;
  23251. }
  23252. var hash = calculateMD5(key, 0, i);
  23253. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  23254. }
  23255. function buildCipherConstructor(cf, name, num, gen, key) {
  23256. var cryptFilter = cf.get(name.name);
  23257. var cfm;
  23258. if (cryptFilter !== null && cryptFilter !== undefined) {
  23259. cfm = cryptFilter.get('CFM');
  23260. }
  23261. if (!cfm || cfm.name === 'None') {
  23262. return function cipherTransformFactoryBuildCipherConstructorNone() {
  23263. return new NullCipher();
  23264. };
  23265. }
  23266. if ('V2' === cfm.name) {
  23267. return function cipherTransformFactoryBuildCipherConstructorV2() {
  23268. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  23269. };
  23270. }
  23271. if ('AESV2' === cfm.name) {
  23272. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  23273. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  23274. };
  23275. }
  23276. if ('AESV3' === cfm.name) {
  23277. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  23278. return new AES256Cipher(key);
  23279. };
  23280. }
  23281. error('Unknown crypto method');
  23282. }
  23283. CipherTransformFactory.prototype = {
  23284. createCipherTransform:
  23285. function CipherTransformFactory_createCipherTransform(num, gen) {
  23286. if (this.algorithm === 4 || this.algorithm === 5) {
  23287. return new CipherTransform(
  23288. buildCipherConstructor(this.cf, this.stmf,
  23289. num, gen, this.encryptionKey),
  23290. buildCipherConstructor(this.cf, this.strf,
  23291. num, gen, this.encryptionKey));
  23292. }
  23293. // algorithms 1 and 2
  23294. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  23295. var cipherConstructor = function buildCipherCipherConstructor() {
  23296. return new ARCFourCipher(key);
  23297. };
  23298. return new CipherTransform(cipherConstructor, cipherConstructor);
  23299. }
  23300. };
  23301. return CipherTransformFactory;
  23302. })();
  23303. exports.AES128Cipher = AES128Cipher;
  23304. exports.AES256Cipher = AES256Cipher;
  23305. exports.ARCFourCipher = ARCFourCipher;
  23306. exports.CipherTransformFactory = CipherTransformFactory;
  23307. exports.PDF17 = PDF17;
  23308. exports.PDF20 = PDF20;
  23309. exports.calculateMD5 = calculateMD5;
  23310. exports.calculateSHA256 = calculateSHA256;
  23311. exports.calculateSHA384 = calculateSHA384;
  23312. exports.calculateSHA512 = calculateSHA512;
  23313. }));
  23314. (function (root, factory) {
  23315. {
  23316. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  23317. root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings,
  23318. root.pdfjsCoreCFFParser);
  23319. }
  23320. }(this, function (exports, sharedUtil, coreStream, coreGlyphList,
  23321. coreEncodings, coreCFFParser) {
  23322. var Util = sharedUtil.Util;
  23323. var bytesToString = sharedUtil.bytesToString;
  23324. var error = sharedUtil.error;
  23325. var Stream = coreStream.Stream;
  23326. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  23327. var StandardEncoding = coreEncodings.StandardEncoding;
  23328. var CFFParser = coreCFFParser.CFFParser;
  23329. var FontRendererFactory = (function FontRendererFactoryClosure() {
  23330. function getLong(data, offset) {
  23331. return (data[offset] << 24) | (data[offset + 1] << 16) |
  23332. (data[offset + 2] << 8) | data[offset + 3];
  23333. }
  23334. function getUshort(data, offset) {
  23335. return (data[offset] << 8) | data[offset + 1];
  23336. }
  23337. function parseCmap(data, start, end) {
  23338. var offset = (getUshort(data, start + 2) === 1 ?
  23339. getLong(data, start + 8) : getLong(data, start + 16));
  23340. var format = getUshort(data, start + offset);
  23341. var length, ranges, p, i;
  23342. if (format === 4) {
  23343. length = getUshort(data, start + offset + 2);
  23344. var segCount = getUshort(data, start + offset + 6) >> 1;
  23345. p = start + offset + 14;
  23346. ranges = [];
  23347. for (i = 0; i < segCount; i++, p += 2) {
  23348. ranges[i] = {end: getUshort(data, p)};
  23349. }
  23350. p += 2;
  23351. for (i = 0; i < segCount; i++, p += 2) {
  23352. ranges[i].start = getUshort(data, p);
  23353. }
  23354. for (i = 0; i < segCount; i++, p += 2) {
  23355. ranges[i].idDelta = getUshort(data, p);
  23356. }
  23357. for (i = 0; i < segCount; i++, p += 2) {
  23358. var idOffset = getUshort(data, p);
  23359. if (idOffset === 0) {
  23360. continue;
  23361. }
  23362. ranges[i].ids = [];
  23363. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  23364. ranges[i].ids[j] = getUshort(data, p + idOffset);
  23365. idOffset += 2;
  23366. }
  23367. }
  23368. return ranges;
  23369. } else if (format === 12) {
  23370. length = getLong(data, start + offset + 4);
  23371. var groups = getLong(data, start + offset + 12);
  23372. p = start + offset + 16;
  23373. ranges = [];
  23374. for (i = 0; i < groups; i++) {
  23375. ranges.push({
  23376. start: getLong(data, p),
  23377. end: getLong(data, p + 4),
  23378. idDelta: getLong(data, p + 8) - getLong(data, p)
  23379. });
  23380. p += 12;
  23381. }
  23382. return ranges;
  23383. }
  23384. error('not supported cmap: ' + format);
  23385. }
  23386. function parseCff(data, start, end, seacAnalysisEnabled) {
  23387. var properties = {};
  23388. var parser = new CFFParser(new Stream(data, start, end - start),
  23389. properties, seacAnalysisEnabled);
  23390. var cff = parser.parse();
  23391. return {
  23392. glyphs: cff.charStrings.objects,
  23393. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  23394. cff.topDict.privateDict.subrsIndex.objects),
  23395. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  23396. };
  23397. }
  23398. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  23399. var itemSize, itemDecode;
  23400. if (isGlyphLocationsLong) {
  23401. itemSize = 4;
  23402. itemDecode = function fontItemDecodeLong(data, offset) {
  23403. return (data[offset] << 24) | (data[offset + 1] << 16) |
  23404. (data[offset + 2] << 8) | data[offset + 3];
  23405. };
  23406. } else {
  23407. itemSize = 2;
  23408. itemDecode = function fontItemDecode(data, offset) {
  23409. return (data[offset] << 9) | (data[offset + 1] << 1);
  23410. };
  23411. }
  23412. var glyphs = [];
  23413. var startOffset = itemDecode(loca, 0);
  23414. for (var j = itemSize; j < loca.length; j += itemSize) {
  23415. var endOffset = itemDecode(loca, j);
  23416. glyphs.push(glyf.subarray(startOffset, endOffset));
  23417. startOffset = endOffset;
  23418. }
  23419. return glyphs;
  23420. }
  23421. function lookupCmap(ranges, unicode) {
  23422. var code = unicode.charCodeAt(0), gid = 0;
  23423. var l = 0, r = ranges.length - 1;
  23424. while (l < r) {
  23425. var c = (l + r + 1) >> 1;
  23426. if (code < ranges[c].start) {
  23427. r = c - 1;
  23428. } else {
  23429. l = c;
  23430. }
  23431. }
  23432. if (ranges[l].start <= code && code <= ranges[l].end) {
  23433. gid = (ranges[l].idDelta + (ranges[l].ids ?
  23434. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  23435. }
  23436. return {
  23437. charCode: code,
  23438. glyphId: gid,
  23439. };
  23440. }
  23441. function compileGlyf(code, cmds, font) {
  23442. function moveTo(x, y) {
  23443. cmds.push({cmd: 'moveTo', args: [x, y]});
  23444. }
  23445. function lineTo(x, y) {
  23446. cmds.push({cmd: 'lineTo', args: [x, y]});
  23447. }
  23448. function quadraticCurveTo(xa, ya, x, y) {
  23449. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  23450. }
  23451. var i = 0;
  23452. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23453. var flags;
  23454. var x = 0, y = 0;
  23455. i += 10;
  23456. if (numberOfContours < 0) {
  23457. // composite glyph
  23458. do {
  23459. flags = (code[i] << 8) | code[i + 1];
  23460. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  23461. i += 4;
  23462. var arg1, arg2;
  23463. if ((flags & 0x01)) {
  23464. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23465. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  23466. i += 4;
  23467. } else {
  23468. arg1 = code[i++]; arg2 = code[i++];
  23469. }
  23470. if ((flags & 0x02)) {
  23471. x = arg1;
  23472. y = arg2;
  23473. } else {
  23474. x = 0; y = 0; // TODO "they are points" ?
  23475. }
  23476. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  23477. if ((flags & 0x08)) {
  23478. scaleX =
  23479. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  23480. i += 2;
  23481. } else if ((flags & 0x40)) {
  23482. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  23483. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  23484. i += 4;
  23485. } else if ((flags & 0x80)) {
  23486. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  23487. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  23488. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  23489. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  23490. i += 8;
  23491. }
  23492. var subglyph = font.glyphs[glyphIndex];
  23493. if (subglyph) {
  23494. cmds.push({cmd: 'save'});
  23495. cmds.push({cmd: 'transform',
  23496. args: [scaleX, scale01, scale10, scaleY, x, y]});
  23497. compileGlyf(subglyph, cmds, font);
  23498. cmds.push({cmd: 'restore'});
  23499. }
  23500. } while ((flags & 0x20));
  23501. } else {
  23502. // simple glyph
  23503. var endPtsOfContours = [];
  23504. var j, jj;
  23505. for (j = 0; j < numberOfContours; j++) {
  23506. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  23507. i += 2;
  23508. }
  23509. var instructionLength = (code[i] << 8) | code[i + 1];
  23510. i += 2 + instructionLength; // skipping the instructions
  23511. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  23512. var points = [];
  23513. while (points.length < numberOfPoints) {
  23514. flags = code[i++];
  23515. var repeat = 1;
  23516. if ((flags & 0x08)) {
  23517. repeat += code[i++];
  23518. }
  23519. while (repeat-- > 0) {
  23520. points.push({flags: flags});
  23521. }
  23522. }
  23523. for (j = 0; j < numberOfPoints; j++) {
  23524. switch (points[j].flags & 0x12) {
  23525. case 0x00:
  23526. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23527. i += 2;
  23528. break;
  23529. case 0x02:
  23530. x -= code[i++];
  23531. break;
  23532. case 0x12:
  23533. x += code[i++];
  23534. break;
  23535. }
  23536. points[j].x = x;
  23537. }
  23538. for (j = 0; j < numberOfPoints; j++) {
  23539. switch (points[j].flags & 0x24) {
  23540. case 0x00:
  23541. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23542. i += 2;
  23543. break;
  23544. case 0x04:
  23545. y -= code[i++];
  23546. break;
  23547. case 0x24:
  23548. y += code[i++];
  23549. break;
  23550. }
  23551. points[j].y = y;
  23552. }
  23553. var startPoint = 0;
  23554. for (i = 0; i < numberOfContours; i++) {
  23555. var endPoint = endPtsOfContours[i];
  23556. // contours might have implicit points, which is located in the middle
  23557. // between two neighboring off-curve points
  23558. var contour = points.slice(startPoint, endPoint + 1);
  23559. if ((contour[0].flags & 1)) {
  23560. contour.push(contour[0]); // using start point at the contour end
  23561. } else if ((contour[contour.length - 1].flags & 1)) {
  23562. // first is off-curve point, trying to use one from the end
  23563. contour.unshift(contour[contour.length - 1]);
  23564. } else {
  23565. // start and end are off-curve points, creating implicit one
  23566. var p = {
  23567. flags: 1,
  23568. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  23569. y: (contour[0].y + contour[contour.length - 1].y) / 2
  23570. };
  23571. contour.unshift(p);
  23572. contour.push(p);
  23573. }
  23574. moveTo(contour[0].x, contour[0].y);
  23575. for (j = 1, jj = contour.length; j < jj; j++) {
  23576. if ((contour[j].flags & 1)) {
  23577. lineTo(contour[j].x, contour[j].y);
  23578. } else if ((contour[j + 1].flags & 1)){
  23579. quadraticCurveTo(contour[j].x, contour[j].y,
  23580. contour[j + 1].x, contour[j + 1].y);
  23581. j++;
  23582. } else {
  23583. quadraticCurveTo(contour[j].x, contour[j].y,
  23584. (contour[j].x + contour[j + 1].x) / 2,
  23585. (contour[j].y + contour[j + 1].y) / 2);
  23586. }
  23587. }
  23588. startPoint = endPoint + 1;
  23589. }
  23590. }
  23591. }
  23592. function compileCharString(code, cmds, font) {
  23593. var stack = [];
  23594. var x = 0, y = 0;
  23595. var stems = 0;
  23596. function moveTo(x, y) {
  23597. cmds.push({cmd: 'moveTo', args: [x, y]});
  23598. }
  23599. function lineTo(x, y) {
  23600. cmds.push({cmd: 'lineTo', args: [x, y]});
  23601. }
  23602. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  23603. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  23604. }
  23605. function parse(code) {
  23606. var i = 0;
  23607. while (i < code.length) {
  23608. var stackClean = false;
  23609. var v = code[i++];
  23610. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  23611. switch (v) {
  23612. case 1: // hstem
  23613. stems += stack.length >> 1;
  23614. stackClean = true;
  23615. break;
  23616. case 3: // vstem
  23617. stems += stack.length >> 1;
  23618. stackClean = true;
  23619. break;
  23620. case 4: // vmoveto
  23621. y += stack.pop();
  23622. moveTo(x, y);
  23623. stackClean = true;
  23624. break;
  23625. case 5: // rlineto
  23626. while (stack.length > 0) {
  23627. x += stack.shift();
  23628. y += stack.shift();
  23629. lineTo(x, y);
  23630. }
  23631. break;
  23632. case 6: // hlineto
  23633. while (stack.length > 0) {
  23634. x += stack.shift();
  23635. lineTo(x, y);
  23636. if (stack.length === 0) {
  23637. break;
  23638. }
  23639. y += stack.shift();
  23640. lineTo(x, y);
  23641. }
  23642. break;
  23643. case 7: // vlineto
  23644. while (stack.length > 0) {
  23645. y += stack.shift();
  23646. lineTo(x, y);
  23647. if (stack.length === 0) {
  23648. break;
  23649. }
  23650. x += stack.shift();
  23651. lineTo(x, y);
  23652. }
  23653. break;
  23654. case 8: // rrcurveto
  23655. while (stack.length > 0) {
  23656. xa = x + stack.shift(); ya = y + stack.shift();
  23657. xb = xa + stack.shift(); yb = ya + stack.shift();
  23658. x = xb + stack.shift(); y = yb + stack.shift();
  23659. bezierCurveTo(xa, ya, xb, yb, x, y);
  23660. }
  23661. break;
  23662. case 10: // callsubr
  23663. n = stack.pop() + font.subrsBias;
  23664. subrCode = font.subrs[n];
  23665. if (subrCode) {
  23666. parse(subrCode);
  23667. }
  23668. break;
  23669. case 11: // return
  23670. return;
  23671. case 12:
  23672. v = code[i++];
  23673. switch (v) {
  23674. case 34: // flex
  23675. xa = x + stack.shift();
  23676. xb = xa + stack.shift(); y1 = y + stack.shift();
  23677. x = xb + stack.shift();
  23678. bezierCurveTo(xa, y, xb, y1, x, y1);
  23679. xa = x + stack.shift();
  23680. xb = xa + stack.shift();
  23681. x = xb + stack.shift();
  23682. bezierCurveTo(xa, y1, xb, y, x, y);
  23683. break;
  23684. case 35: // flex
  23685. xa = x + stack.shift(); ya = y + stack.shift();
  23686. xb = xa + stack.shift(); yb = ya + stack.shift();
  23687. x = xb + stack.shift(); y = yb + stack.shift();
  23688. bezierCurveTo(xa, ya, xb, yb, x, y);
  23689. xa = x + stack.shift(); ya = y + stack.shift();
  23690. xb = xa + stack.shift(); yb = ya + stack.shift();
  23691. x = xb + stack.shift(); y = yb + stack.shift();
  23692. bezierCurveTo(xa, ya, xb, yb, x, y);
  23693. stack.pop(); // fd
  23694. break;
  23695. case 36: // hflex1
  23696. xa = x + stack.shift(); y1 = y + stack.shift();
  23697. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  23698. x = xb + stack.shift();
  23699. bezierCurveTo(xa, y1, xb, y2, x, y2);
  23700. xa = x + stack.shift();
  23701. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  23702. x = xb + stack.shift();
  23703. bezierCurveTo(xa, y2, xb, y3, x, y);
  23704. break;
  23705. case 37: // flex1
  23706. var x0 = x, y0 = y;
  23707. xa = x + stack.shift(); ya = y + stack.shift();
  23708. xb = xa + stack.shift(); yb = ya + stack.shift();
  23709. x = xb + stack.shift(); y = yb + stack.shift();
  23710. bezierCurveTo(xa, ya, xb, yb, x, y);
  23711. xa = x + stack.shift(); ya = y + stack.shift();
  23712. xb = xa + stack.shift(); yb = ya + stack.shift();
  23713. x = xb; y = yb;
  23714. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  23715. x += stack.shift();
  23716. } else {
  23717. y += stack.shift();
  23718. }
  23719. bezierCurveTo(xa, ya, xb, yb, x, y);
  23720. break;
  23721. default:
  23722. error('unknown operator: 12 ' + v);
  23723. }
  23724. break;
  23725. case 14: // endchar
  23726. if (stack.length >= 4) {
  23727. var achar = stack.pop();
  23728. var bchar = stack.pop();
  23729. y = stack.pop();
  23730. x = stack.pop();
  23731. cmds.push({cmd: 'save'});
  23732. cmds.push({cmd: 'translate', args: [x, y]});
  23733. var cmap = lookupCmap(font.cmap, String.fromCharCode(
  23734. font.glyphNameMap[StandardEncoding[achar]]));
  23735. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  23736. cmds.push({cmd: 'restore'});
  23737. cmap = lookupCmap(font.cmap, String.fromCharCode(
  23738. font.glyphNameMap[StandardEncoding[bchar]]));
  23739. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  23740. }
  23741. return;
  23742. case 18: // hstemhm
  23743. stems += stack.length >> 1;
  23744. stackClean = true;
  23745. break;
  23746. case 19: // hintmask
  23747. stems += stack.length >> 1;
  23748. i += (stems + 7) >> 3;
  23749. stackClean = true;
  23750. break;
  23751. case 20: // cntrmask
  23752. stems += stack.length >> 1;
  23753. i += (stems + 7) >> 3;
  23754. stackClean = true;
  23755. break;
  23756. case 21: // rmoveto
  23757. y += stack.pop();
  23758. x += stack.pop();
  23759. moveTo(x, y);
  23760. stackClean = true;
  23761. break;
  23762. case 22: // hmoveto
  23763. x += stack.pop();
  23764. moveTo(x, y);
  23765. stackClean = true;
  23766. break;
  23767. case 23: // vstemhm
  23768. stems += stack.length >> 1;
  23769. stackClean = true;
  23770. break;
  23771. case 24: // rcurveline
  23772. while (stack.length > 2) {
  23773. xa = x + stack.shift(); ya = y + stack.shift();
  23774. xb = xa + stack.shift(); yb = ya + stack.shift();
  23775. x = xb + stack.shift(); y = yb + stack.shift();
  23776. bezierCurveTo(xa, ya, xb, yb, x, y);
  23777. }
  23778. x += stack.shift();
  23779. y += stack.shift();
  23780. lineTo(x, y);
  23781. break;
  23782. case 25: // rlinecurve
  23783. while (stack.length > 6) {
  23784. x += stack.shift();
  23785. y += stack.shift();
  23786. lineTo(x, y);
  23787. }
  23788. xa = x + stack.shift(); ya = y + stack.shift();
  23789. xb = xa + stack.shift(); yb = ya + stack.shift();
  23790. x = xb + stack.shift(); y = yb + stack.shift();
  23791. bezierCurveTo(xa, ya, xb, yb, x, y);
  23792. break;
  23793. case 26: // vvcurveto
  23794. if (stack.length % 2) {
  23795. x += stack.shift();
  23796. }
  23797. while (stack.length > 0) {
  23798. xa = x; ya = y + stack.shift();
  23799. xb = xa + stack.shift(); yb = ya + stack.shift();
  23800. x = xb; y = yb + stack.shift();
  23801. bezierCurveTo(xa, ya, xb, yb, x, y);
  23802. }
  23803. break;
  23804. case 27: // hhcurveto
  23805. if (stack.length % 2) {
  23806. y += stack.shift();
  23807. }
  23808. while (stack.length > 0) {
  23809. xa = x + stack.shift(); ya = y;
  23810. xb = xa + stack.shift(); yb = ya + stack.shift();
  23811. x = xb + stack.shift(); y = yb;
  23812. bezierCurveTo(xa, ya, xb, yb, x, y);
  23813. }
  23814. break;
  23815. case 28:
  23816. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  23817. i += 2;
  23818. break;
  23819. case 29: // callgsubr
  23820. n = stack.pop() + font.gsubrsBias;
  23821. subrCode = font.gsubrs[n];
  23822. if (subrCode) {
  23823. parse(subrCode);
  23824. }
  23825. break;
  23826. case 30: // vhcurveto
  23827. while (stack.length > 0) {
  23828. xa = x; ya = y + stack.shift();
  23829. xb = xa + stack.shift(); yb = ya + stack.shift();
  23830. x = xb + stack.shift();
  23831. y = yb + (stack.length === 1 ? stack.shift() : 0);
  23832. bezierCurveTo(xa, ya, xb, yb, x, y);
  23833. if (stack.length === 0) {
  23834. break;
  23835. }
  23836. xa = x + stack.shift(); ya = y;
  23837. xb = xa + stack.shift(); yb = ya + stack.shift();
  23838. y = yb + stack.shift();
  23839. x = xb + (stack.length === 1 ? stack.shift() : 0);
  23840. bezierCurveTo(xa, ya, xb, yb, x, y);
  23841. }
  23842. break;
  23843. case 31: // hvcurveto
  23844. while (stack.length > 0) {
  23845. xa = x + stack.shift(); ya = y;
  23846. xb = xa + stack.shift(); yb = ya + stack.shift();
  23847. y = yb + stack.shift();
  23848. x = xb + (stack.length === 1 ? stack.shift() : 0);
  23849. bezierCurveTo(xa, ya, xb, yb, x, y);
  23850. if (stack.length === 0) {
  23851. break;
  23852. }
  23853. xa = x; ya = y + stack.shift();
  23854. xb = xa + stack.shift(); yb = ya + stack.shift();
  23855. x = xb + stack.shift();
  23856. y = yb + (stack.length === 1 ? stack.shift() : 0);
  23857. bezierCurveTo(xa, ya, xb, yb, x, y);
  23858. }
  23859. break;
  23860. default:
  23861. if (v < 32) {
  23862. error('unknown operator: ' + v);
  23863. }
  23864. if (v < 247) {
  23865. stack.push(v - 139);
  23866. } else if (v < 251) {
  23867. stack.push((v - 247) * 256 + code[i++] + 108);
  23868. } else if (v < 255) {
  23869. stack.push(-(v - 251) * 256 - code[i++] - 108);
  23870. } else {
  23871. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  23872. (code[i + 2] << 8) | code[i + 3]) / 65536);
  23873. i += 4;
  23874. }
  23875. break;
  23876. }
  23877. if (stackClean) {
  23878. stack.length = 0;
  23879. }
  23880. }
  23881. }
  23882. parse(code);
  23883. }
  23884. var noop = '';
  23885. function CompiledFont(fontMatrix) {
  23886. this.compiledGlyphs = Object.create(null);
  23887. this.compiledCharCodeToGlyphId = Object.create(null);
  23888. this.fontMatrix = fontMatrix;
  23889. }
  23890. CompiledFont.prototype = {
  23891. getPathJs: function (unicode) {
  23892. var cmap = lookupCmap(this.cmap, unicode);
  23893. var fn = this.compiledGlyphs[cmap.glyphId];
  23894. if (!fn) {
  23895. fn = this.compileGlyph(this.glyphs[cmap.glyphId]);
  23896. this.compiledGlyphs[cmap.glyphId] = fn;
  23897. }
  23898. if (this.compiledCharCodeToGlyphId[cmap.charCode] === undefined) {
  23899. this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
  23900. }
  23901. return fn;
  23902. },
  23903. compileGlyph: function (code) {
  23904. if (!code || code.length === 0 || code[0] === 14) {
  23905. return noop;
  23906. }
  23907. var cmds = [];
  23908. cmds.push({cmd: 'save'});
  23909. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  23910. cmds.push({cmd: 'scale', args: ['size', '-size']});
  23911. this.compileGlyphImpl(code, cmds);
  23912. cmds.push({cmd: 'restore'});
  23913. return cmds;
  23914. },
  23915. compileGlyphImpl: function () {
  23916. error('Children classes should implement this.');
  23917. },
  23918. hasBuiltPath: function (unicode) {
  23919. var cmap = lookupCmap(this.cmap, unicode);
  23920. return (this.compiledGlyphs[cmap.glyphId] !== undefined &&
  23921. this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined);
  23922. }
  23923. };
  23924. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  23925. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  23926. CompiledFont.call(this, fontMatrix);
  23927. this.glyphs = glyphs;
  23928. this.cmap = cmap;
  23929. }
  23930. Util.inherit(TrueTypeCompiled, CompiledFont, {
  23931. compileGlyphImpl: function (code, cmds) {
  23932. compileGlyf(code, cmds, this);
  23933. }
  23934. });
  23935. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  23936. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  23937. CompiledFont.call(this, fontMatrix);
  23938. this.glyphs = cffInfo.glyphs;
  23939. this.gsubrs = cffInfo.gsubrs || [];
  23940. this.subrs = cffInfo.subrs || [];
  23941. this.cmap = cmap;
  23942. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  23943. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  23944. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  23945. this.subrsBias = (this.subrs.length < 1240 ?
  23946. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  23947. }
  23948. Util.inherit(Type2Compiled, CompiledFont, {
  23949. compileGlyphImpl: function (code, cmds) {
  23950. compileCharString(code, cmds, this);
  23951. }
  23952. });
  23953. return {
  23954. create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
  23955. var data = new Uint8Array(font.data);
  23956. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  23957. var numTables = getUshort(data, 4);
  23958. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  23959. var tag = bytesToString(data.subarray(p, p + 4));
  23960. var offset = getLong(data, p + 8);
  23961. var length = getLong(data, p + 12);
  23962. switch (tag) {
  23963. case 'cmap':
  23964. cmap = parseCmap(data, offset, offset + length);
  23965. break;
  23966. case 'glyf':
  23967. glyf = data.subarray(offset, offset + length);
  23968. break;
  23969. case 'loca':
  23970. loca = data.subarray(offset, offset + length);
  23971. break;
  23972. case 'head':
  23973. unitsPerEm = getUshort(data, offset + 18);
  23974. indexToLocFormat = getUshort(data, offset + 50);
  23975. break;
  23976. case 'CFF ':
  23977. cff = parseCff(data, offset, offset + length, seacAnalysisEnabled);
  23978. break;
  23979. }
  23980. }
  23981. if (glyf) {
  23982. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  23983. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  23984. return new TrueTypeCompiled(
  23985. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  23986. } else {
  23987. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  23988. }
  23989. }
  23990. };
  23991. })();
  23992. exports.FontRendererFactory = FontRendererFactory;
  23993. }));
  23994. (function (root, factory) {
  23995. {
  23996. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  23997. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  23998. }
  23999. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  24000. var MissingDataException = sharedUtil.MissingDataException;
  24001. var StreamType = sharedUtil.StreamType;
  24002. var assert = sharedUtil.assert;
  24003. var error = sharedUtil.error;
  24004. var info = sharedUtil.info;
  24005. var isArray = sharedUtil.isArray;
  24006. var isInt = sharedUtil.isInt;
  24007. var isNum = sharedUtil.isNum;
  24008. var isString = sharedUtil.isString;
  24009. var warn = sharedUtil.warn;
  24010. var Cmd = corePrimitives.Cmd;
  24011. var Dict = corePrimitives.Dict;
  24012. var Name = corePrimitives.Name;
  24013. var Ref = corePrimitives.Ref;
  24014. var isCmd = corePrimitives.isCmd;
  24015. var isDict = corePrimitives.isDict;
  24016. var isName = corePrimitives.isName;
  24017. var Ascii85Stream = coreStream.Ascii85Stream;
  24018. var AsciiHexStream = coreStream.AsciiHexStream;
  24019. var CCITTFaxStream = coreStream.CCITTFaxStream;
  24020. var FlateStream = coreStream.FlateStream;
  24021. var Jbig2Stream = coreStream.Jbig2Stream;
  24022. var JpegStream = coreStream.JpegStream;
  24023. var JpxStream = coreStream.JpxStream;
  24024. var LZWStream = coreStream.LZWStream;
  24025. var NullStream = coreStream.NullStream;
  24026. var PredictorStream = coreStream.PredictorStream;
  24027. var RunLengthStream = coreStream.RunLengthStream;
  24028. var EOF = {};
  24029. function isEOF(v) {
  24030. return (v === EOF);
  24031. }
  24032. var MAX_LENGTH_TO_CACHE = 1000;
  24033. var Parser = (function ParserClosure() {
  24034. function Parser(lexer, allowStreams, xref, recoveryMode) {
  24035. this.lexer = lexer;
  24036. this.allowStreams = allowStreams;
  24037. this.xref = xref;
  24038. this.recoveryMode = recoveryMode || false;
  24039. this.imageCache = Object.create(null);
  24040. this.refill();
  24041. }
  24042. Parser.prototype = {
  24043. refill: function Parser_refill() {
  24044. this.buf1 = this.lexer.getObj();
  24045. this.buf2 = this.lexer.getObj();
  24046. },
  24047. shift: function Parser_shift() {
  24048. if (isCmd(this.buf2, 'ID')) {
  24049. this.buf1 = this.buf2;
  24050. this.buf2 = null;
  24051. } else {
  24052. this.buf1 = this.buf2;
  24053. this.buf2 = this.lexer.getObj();
  24054. }
  24055. },
  24056. tryShift: function Parser_tryShift() {
  24057. try {
  24058. this.shift();
  24059. return true;
  24060. } catch (e) {
  24061. if (e instanceof MissingDataException) {
  24062. throw e;
  24063. }
  24064. // Upon failure, the caller should reset this.lexer.pos to a known good
  24065. // state and call this.shift() twice to reset the buffers.
  24066. return false;
  24067. }
  24068. },
  24069. getObj: function Parser_getObj(cipherTransform) {
  24070. var buf1 = this.buf1;
  24071. this.shift();
  24072. if (buf1 instanceof Cmd) {
  24073. switch (buf1.cmd) {
  24074. case 'BI': // inline image
  24075. return this.makeInlineImage(cipherTransform);
  24076. case '[': // array
  24077. var array = [];
  24078. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  24079. array.push(this.getObj(cipherTransform));
  24080. }
  24081. if (isEOF(this.buf1)) {
  24082. if (!this.recoveryMode) {
  24083. error('End of file inside array');
  24084. }
  24085. return array;
  24086. }
  24087. this.shift();
  24088. return array;
  24089. case '<<': // dictionary or stream
  24090. var dict = new Dict(this.xref);
  24091. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  24092. if (!isName(this.buf1)) {
  24093. info('Malformed dictionary: key must be a name object');
  24094. this.shift();
  24095. continue;
  24096. }
  24097. var key = this.buf1.name;
  24098. this.shift();
  24099. if (isEOF(this.buf1)) {
  24100. break;
  24101. }
  24102. dict.set(key, this.getObj(cipherTransform));
  24103. }
  24104. if (isEOF(this.buf1)) {
  24105. if (!this.recoveryMode) {
  24106. error('End of file inside dictionary');
  24107. }
  24108. return dict;
  24109. }
  24110. // Stream objects are not allowed inside content streams or
  24111. // object streams.
  24112. if (isCmd(this.buf2, 'stream')) {
  24113. return (this.allowStreams ?
  24114. this.makeStream(dict, cipherTransform) : dict);
  24115. }
  24116. this.shift();
  24117. return dict;
  24118. default: // simple object
  24119. return buf1;
  24120. }
  24121. }
  24122. if (isInt(buf1)) { // indirect reference or integer
  24123. var num = buf1;
  24124. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  24125. var ref = new Ref(num, this.buf1);
  24126. this.shift();
  24127. this.shift();
  24128. return ref;
  24129. }
  24130. return num;
  24131. }
  24132. if (isString(buf1)) { // string
  24133. var str = buf1;
  24134. if (cipherTransform) {
  24135. str = cipherTransform.decryptString(str);
  24136. }
  24137. return str;
  24138. }
  24139. // simple object
  24140. return buf1;
  24141. },
  24142. /**
  24143. * Find the end of the stream by searching for the /EI\s/.
  24144. * @returns {number} The inline stream length.
  24145. */
  24146. findDefaultInlineStreamEnd:
  24147. function Parser_findDefaultInlineStreamEnd(stream) {
  24148. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  24149. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  24150. while ((ch = stream.getByte()) !== -1) {
  24151. if (state === 0) {
  24152. state = (ch === E) ? 1 : 0;
  24153. } else if (state === 1) {
  24154. state = (ch === I) ? 2 : 0;
  24155. } else {
  24156. assert(state === 2);
  24157. if (ch === SPACE || ch === LF || ch === CR) {
  24158. // Let's check the next five bytes are ASCII... just be sure.
  24159. n = 5;
  24160. followingBytes = stream.peekBytes(n);
  24161. for (i = 0; i < n; i++) {
  24162. ch = followingBytes[i];
  24163. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  24164. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  24165. // it's binary stuff. Resetting the state.
  24166. state = 0;
  24167. break;
  24168. }
  24169. }
  24170. if (state === 2) {
  24171. break; // Finished!
  24172. }
  24173. } else {
  24174. state = 0;
  24175. }
  24176. }
  24177. }
  24178. return ((stream.pos - 4) - startPos);
  24179. },
  24180. /**
  24181. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  24182. * @returns {number} The inline stream length.
  24183. */
  24184. findDCTDecodeInlineStreamEnd:
  24185. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  24186. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  24187. while ((b = stream.getByte()) !== -1) {
  24188. if (b !== 0xFF) { // Not a valid marker.
  24189. continue;
  24190. }
  24191. switch (stream.getByte()) {
  24192. case 0x00: // Byte stuffing.
  24193. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  24194. break;
  24195. case 0xFF: // Fill byte.
  24196. // Avoid skipping a valid marker, resetting the stream position.
  24197. stream.skip(-1);
  24198. break;
  24199. case 0xD9: // EOI
  24200. foundEOI = true;
  24201. break;
  24202. case 0xC0: // SOF0
  24203. case 0xC1: // SOF1
  24204. case 0xC2: // SOF2
  24205. case 0xC3: // SOF3
  24206. case 0xC5: // SOF5
  24207. case 0xC6: // SOF6
  24208. case 0xC7: // SOF7
  24209. case 0xC9: // SOF9
  24210. case 0xCA: // SOF10
  24211. case 0xCB: // SOF11
  24212. case 0xCD: // SOF13
  24213. case 0xCE: // SOF14
  24214. case 0xCF: // SOF15
  24215. case 0xC4: // DHT
  24216. case 0xCC: // DAC
  24217. case 0xDA: // SOS
  24218. case 0xDB: // DQT
  24219. case 0xDC: // DNL
  24220. case 0xDD: // DRI
  24221. case 0xDE: // DHP
  24222. case 0xDF: // EXP
  24223. case 0xE0: // APP0
  24224. case 0xE1: // APP1
  24225. case 0xE2: // APP2
  24226. case 0xE3: // APP3
  24227. case 0xE4: // APP4
  24228. case 0xE5: // APP5
  24229. case 0xE6: // APP6
  24230. case 0xE7: // APP7
  24231. case 0xE8: // APP8
  24232. case 0xE9: // APP9
  24233. case 0xEA: // APP10
  24234. case 0xEB: // APP11
  24235. case 0xEC: // APP12
  24236. case 0xED: // APP13
  24237. case 0xEE: // APP14
  24238. case 0xEF: // APP15
  24239. case 0xFE: // COM
  24240. // The marker should be followed by the length of the segment.
  24241. markerLength = stream.getUint16();
  24242. if (markerLength > 2) {
  24243. // |markerLength| contains the byte length of the marker segment,
  24244. // including its own length (2 bytes) and excluding the marker.
  24245. stream.skip(markerLength - 2); // Jump to the next marker.
  24246. } else {
  24247. // The marker length is invalid, resetting the stream position.
  24248. stream.skip(-2);
  24249. }
  24250. break;
  24251. }
  24252. if (foundEOI) {
  24253. break;
  24254. }
  24255. }
  24256. length = stream.pos - startPos;
  24257. if (b === -1) {
  24258. warn('Inline DCTDecode image stream: ' +
  24259. 'EOI marker not found, searching for /EI/ instead.');
  24260. stream.skip(-length); // Reset the stream position.
  24261. return this.findDefaultInlineStreamEnd(stream);
  24262. }
  24263. this.inlineStreamSkipEI(stream);
  24264. return length;
  24265. },
  24266. /**
  24267. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  24268. * @returns {number} The inline stream length.
  24269. */
  24270. findASCII85DecodeInlineStreamEnd:
  24271. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  24272. var TILDE = 0x7E, GT = 0x3E;
  24273. var startPos = stream.pos, ch, length;
  24274. while ((ch = stream.getByte()) !== -1) {
  24275. if (ch === TILDE && stream.peekByte() === GT) {
  24276. stream.skip();
  24277. break;
  24278. }
  24279. }
  24280. length = stream.pos - startPos;
  24281. if (ch === -1) {
  24282. warn('Inline ASCII85Decode image stream: ' +
  24283. 'EOD marker not found, searching for /EI/ instead.');
  24284. stream.skip(-length); // Reset the stream position.
  24285. return this.findDefaultInlineStreamEnd(stream);
  24286. }
  24287. this.inlineStreamSkipEI(stream);
  24288. return length;
  24289. },
  24290. /**
  24291. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  24292. * @returns {number} The inline stream length.
  24293. */
  24294. findASCIIHexDecodeInlineStreamEnd:
  24295. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  24296. var GT = 0x3E;
  24297. var startPos = stream.pos, ch, length;
  24298. while ((ch = stream.getByte()) !== -1) {
  24299. if (ch === GT) {
  24300. break;
  24301. }
  24302. }
  24303. length = stream.pos - startPos;
  24304. if (ch === -1) {
  24305. warn('Inline ASCIIHexDecode image stream: ' +
  24306. 'EOD marker not found, searching for /EI/ instead.');
  24307. stream.skip(-length); // Reset the stream position.
  24308. return this.findDefaultInlineStreamEnd(stream);
  24309. }
  24310. this.inlineStreamSkipEI(stream);
  24311. return length;
  24312. },
  24313. /**
  24314. * Skip over the /EI/ for streams where we search for an EOD marker.
  24315. */
  24316. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  24317. var E = 0x45, I = 0x49;
  24318. var state = 0, ch;
  24319. while ((ch = stream.getByte()) !== -1) {
  24320. if (state === 0) {
  24321. state = (ch === E) ? 1 : 0;
  24322. } else if (state === 1) {
  24323. state = (ch === I) ? 2 : 0;
  24324. } else if (state === 2) {
  24325. break;
  24326. }
  24327. }
  24328. },
  24329. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  24330. var lexer = this.lexer;
  24331. var stream = lexer.stream;
  24332. // Parse dictionary.
  24333. var dict = new Dict(this.xref);
  24334. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  24335. if (!isName(this.buf1)) {
  24336. error('Dictionary key must be a name object');
  24337. }
  24338. var key = this.buf1.name;
  24339. this.shift();
  24340. if (isEOF(this.buf1)) {
  24341. break;
  24342. }
  24343. dict.set(key, this.getObj(cipherTransform));
  24344. }
  24345. // Extract the name of the first (i.e. the current) image filter.
  24346. var filter = dict.get('Filter', 'F'), filterName;
  24347. if (isName(filter)) {
  24348. filterName = filter.name;
  24349. } else if (isArray(filter) && isName(filter[0])) {
  24350. filterName = filter[0].name;
  24351. }
  24352. // Parse image stream.
  24353. var startPos = stream.pos, length, i, ii;
  24354. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  24355. length = this.findDCTDecodeInlineStreamEnd(stream);
  24356. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  24357. length = this.findASCII85DecodeInlineStreamEnd(stream);
  24358. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  24359. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  24360. } else {
  24361. length = this.findDefaultInlineStreamEnd(stream);
  24362. }
  24363. var imageStream = stream.makeSubStream(startPos, length, dict);
  24364. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  24365. // adler32 checksum.
  24366. var adler32;
  24367. if (length < MAX_LENGTH_TO_CACHE) {
  24368. var imageBytes = imageStream.getBytes();
  24369. imageStream.reset();
  24370. var a = 1;
  24371. var b = 0;
  24372. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  24373. // No modulo required in the loop if imageBytes.length < 5552.
  24374. a += imageBytes[i] & 0xff;
  24375. b += a;
  24376. }
  24377. adler32 = ((b % 65521) << 16) | (a % 65521);
  24378. if (this.imageCache.adler32 === adler32) {
  24379. this.buf2 = Cmd.get('EI');
  24380. this.shift();
  24381. this.imageCache[adler32].reset();
  24382. return this.imageCache[adler32];
  24383. }
  24384. }
  24385. if (cipherTransform) {
  24386. imageStream = cipherTransform.createStream(imageStream, length);
  24387. }
  24388. imageStream = this.filter(imageStream, dict, length);
  24389. imageStream.dict = dict;
  24390. if (adler32 !== undefined) {
  24391. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  24392. this.imageCache[adler32] = imageStream;
  24393. }
  24394. this.buf2 = Cmd.get('EI');
  24395. this.shift();
  24396. return imageStream;
  24397. },
  24398. makeStream: function Parser_makeStream(dict, cipherTransform) {
  24399. var lexer = this.lexer;
  24400. var stream = lexer.stream;
  24401. // get stream start position
  24402. lexer.skipToNextLine();
  24403. var pos = stream.pos - 1;
  24404. // get length
  24405. var length = dict.get('Length');
  24406. if (!isInt(length)) {
  24407. info('Bad ' + length + ' attribute in stream');
  24408. length = 0;
  24409. }
  24410. // skip over the stream data
  24411. stream.pos = pos + length;
  24412. lexer.nextChar();
  24413. // Shift '>>' and check whether the new object marks the end of the stream
  24414. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  24415. this.shift(); // 'stream'
  24416. } else {
  24417. // bad stream length, scanning for endstream
  24418. stream.pos = pos;
  24419. var SCAN_BLOCK_SIZE = 2048;
  24420. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  24421. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  24422. 0x61, 0x6D];
  24423. var skipped = 0, found = false, i, j;
  24424. while (stream.pos < stream.end) {
  24425. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  24426. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  24427. if (scanLength <= 0) {
  24428. break;
  24429. }
  24430. found = false;
  24431. i = 0;
  24432. while (i < scanLength) {
  24433. j = 0;
  24434. while (j < ENDSTREAM_SIGNATURE_LENGTH &&
  24435. scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  24436. j++;
  24437. }
  24438. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  24439. found = true;
  24440. break;
  24441. }
  24442. i++;
  24443. }
  24444. if (found) {
  24445. skipped += i;
  24446. stream.pos += i;
  24447. break;
  24448. }
  24449. skipped += scanLength;
  24450. stream.pos += scanLength;
  24451. }
  24452. if (!found) {
  24453. error('Missing endstream');
  24454. }
  24455. length = skipped;
  24456. lexer.nextChar();
  24457. this.shift();
  24458. this.shift();
  24459. }
  24460. this.shift(); // 'endstream'
  24461. stream = stream.makeSubStream(pos, length, dict);
  24462. if (cipherTransform) {
  24463. stream = cipherTransform.createStream(stream, length);
  24464. }
  24465. stream = this.filter(stream, dict, length);
  24466. stream.dict = dict;
  24467. return stream;
  24468. },
  24469. filter: function Parser_filter(stream, dict, length) {
  24470. var filter = dict.get('Filter', 'F');
  24471. var params = dict.get('DecodeParms', 'DP');
  24472. if (isName(filter)) {
  24473. return this.makeFilter(stream, filter.name, length, params);
  24474. }
  24475. var maybeLength = length;
  24476. if (isArray(filter)) {
  24477. var filterArray = filter;
  24478. var paramsArray = params;
  24479. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  24480. filter = filterArray[i];
  24481. if (!isName(filter)) {
  24482. error('Bad filter name: ' + filter);
  24483. }
  24484. params = null;
  24485. if (isArray(paramsArray) && (i in paramsArray)) {
  24486. params = paramsArray[i];
  24487. }
  24488. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  24489. // after the first stream the length variable is invalid
  24490. maybeLength = null;
  24491. }
  24492. }
  24493. return stream;
  24494. },
  24495. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  24496. if (stream.dict.get('Length') === 0 && !maybeLength) {
  24497. warn('Empty "' + name + '" stream.');
  24498. return new NullStream(stream);
  24499. }
  24500. try {
  24501. if (params && this.xref) {
  24502. params = this.xref.fetchIfRef(params);
  24503. }
  24504. var xrefStreamStats = this.xref.stats.streamTypes;
  24505. if (name === 'FlateDecode' || name === 'Fl') {
  24506. xrefStreamStats[StreamType.FLATE] = true;
  24507. if (params) {
  24508. return new PredictorStream(new FlateStream(stream, maybeLength),
  24509. maybeLength, params);
  24510. }
  24511. return new FlateStream(stream, maybeLength);
  24512. }
  24513. if (name === 'LZWDecode' || name === 'LZW') {
  24514. xrefStreamStats[StreamType.LZW] = true;
  24515. var earlyChange = 1;
  24516. if (params) {
  24517. if (params.has('EarlyChange')) {
  24518. earlyChange = params.get('EarlyChange');
  24519. }
  24520. return new PredictorStream(
  24521. new LZWStream(stream, maybeLength, earlyChange),
  24522. maybeLength, params);
  24523. }
  24524. return new LZWStream(stream, maybeLength, earlyChange);
  24525. }
  24526. if (name === 'DCTDecode' || name === 'DCT') {
  24527. xrefStreamStats[StreamType.DCT] = true;
  24528. return new JpegStream(stream, maybeLength, stream.dict);
  24529. }
  24530. if (name === 'JPXDecode' || name === 'JPX') {
  24531. xrefStreamStats[StreamType.JPX] = true;
  24532. return new JpxStream(stream, maybeLength, stream.dict);
  24533. }
  24534. if (name === 'ASCII85Decode' || name === 'A85') {
  24535. xrefStreamStats[StreamType.A85] = true;
  24536. return new Ascii85Stream(stream, maybeLength);
  24537. }
  24538. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  24539. xrefStreamStats[StreamType.AHX] = true;
  24540. return new AsciiHexStream(stream, maybeLength);
  24541. }
  24542. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  24543. xrefStreamStats[StreamType.CCF] = true;
  24544. return new CCITTFaxStream(stream, maybeLength, params);
  24545. }
  24546. if (name === 'RunLengthDecode' || name === 'RL') {
  24547. xrefStreamStats[StreamType.RL] = true;
  24548. return new RunLengthStream(stream, maybeLength);
  24549. }
  24550. if (name === 'JBIG2Decode') {
  24551. xrefStreamStats[StreamType.JBIG] = true;
  24552. return new Jbig2Stream(stream, maybeLength, stream.dict);
  24553. }
  24554. warn('filter "' + name + '" not supported yet');
  24555. return stream;
  24556. } catch (ex) {
  24557. if (ex instanceof MissingDataException) {
  24558. throw ex;
  24559. }
  24560. warn('Invalid stream: \"' + ex + '\"');
  24561. return new NullStream(stream);
  24562. }
  24563. }
  24564. };
  24565. return Parser;
  24566. })();
  24567. var Lexer = (function LexerClosure() {
  24568. function Lexer(stream, knownCommands) {
  24569. this.stream = stream;
  24570. this.nextChar();
  24571. // While lexing, we build up many strings one char at a time. Using += for
  24572. // this can result in lots of garbage strings. It's better to build an
  24573. // array of single-char strings and then join() them together at the end.
  24574. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  24575. // purpose uses less memory than using a new array for each string.
  24576. this.strBuf = [];
  24577. // The PDFs might have "glued" commands with other commands, operands or
  24578. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  24579. // commands and their prefixes. The prefixes are built the following way:
  24580. // if there a command that is a prefix of the other valid command or
  24581. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  24582. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  24583. // other commands or literals as a prefix. The knowCommands is optional.
  24584. this.knownCommands = knownCommands;
  24585. }
  24586. // A '1' in this array means the character is white space. A '1' or
  24587. // '2' means the character ends a name or command.
  24588. var specialChars = [
  24589. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  24590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  24591. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  24592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  24593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  24594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  24595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  24596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  24597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  24598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  24599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  24600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  24601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  24602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  24603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  24604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  24605. ];
  24606. function toHexDigit(ch) {
  24607. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  24608. return ch & 0x0F;
  24609. }
  24610. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  24611. // 'A'-'F', 'a'-'f'
  24612. return (ch & 0x0F) + 9;
  24613. }
  24614. return -1;
  24615. }
  24616. Lexer.prototype = {
  24617. nextChar: function Lexer_nextChar() {
  24618. return (this.currentChar = this.stream.getByte());
  24619. },
  24620. peekChar: function Lexer_peekChar() {
  24621. return this.stream.peekByte();
  24622. },
  24623. getNumber: function Lexer_getNumber() {
  24624. var ch = this.currentChar;
  24625. var eNotation = false;
  24626. var divideBy = 0; // different from 0 if it's a floating point value
  24627. var sign = 1;
  24628. if (ch === 0x2D) { // '-'
  24629. sign = -1;
  24630. ch = this.nextChar();
  24631. if (ch === 0x2D) { // '-'
  24632. // Ignore double negative (this is consistent with Adobe Reader).
  24633. ch = this.nextChar();
  24634. }
  24635. } else if (ch === 0x2B) { // '+'
  24636. ch = this.nextChar();
  24637. }
  24638. if (ch === 0x2E) { // '.'
  24639. divideBy = 10;
  24640. ch = this.nextChar();
  24641. }
  24642. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  24643. error('Invalid number: ' + String.fromCharCode(ch));
  24644. return 0;
  24645. }
  24646. var baseValue = ch - 0x30; // '0'
  24647. var powerValue = 0;
  24648. var powerValueSign = 1;
  24649. while ((ch = this.nextChar()) >= 0) {
  24650. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  24651. var currentDigit = ch - 0x30; // '0'
  24652. if (eNotation) { // We are after an 'e' or 'E'
  24653. powerValue = powerValue * 10 + currentDigit;
  24654. } else {
  24655. if (divideBy !== 0) { // We are after a point
  24656. divideBy *= 10;
  24657. }
  24658. baseValue = baseValue * 10 + currentDigit;
  24659. }
  24660. } else if (ch === 0x2E) { // '.'
  24661. if (divideBy === 0) {
  24662. divideBy = 1;
  24663. } else {
  24664. // A number can have only one '.'
  24665. break;
  24666. }
  24667. } else if (ch === 0x2D) { // '-'
  24668. // ignore minus signs in the middle of numbers to match
  24669. // Adobe's behavior
  24670. warn('Badly formatted number');
  24671. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  24672. // 'E' can be either a scientific notation or the beginning of a new
  24673. // operator
  24674. ch = this.peekChar();
  24675. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  24676. powerValueSign = (ch === 0x2D) ? -1 : 1;
  24677. this.nextChar(); // Consume the sign character
  24678. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  24679. // The 'E' must be the beginning of a new operator
  24680. break;
  24681. }
  24682. eNotation = true;
  24683. } else {
  24684. // the last character doesn't belong to us
  24685. break;
  24686. }
  24687. }
  24688. if (divideBy !== 0) {
  24689. baseValue /= divideBy;
  24690. }
  24691. if (eNotation) {
  24692. baseValue *= Math.pow(10, powerValueSign * powerValue);
  24693. }
  24694. return sign * baseValue;
  24695. },
  24696. getString: function Lexer_getString() {
  24697. var numParen = 1;
  24698. var done = false;
  24699. var strBuf = this.strBuf;
  24700. strBuf.length = 0;
  24701. var ch = this.nextChar();
  24702. while (true) {
  24703. var charBuffered = false;
  24704. switch (ch | 0) {
  24705. case -1:
  24706. warn('Unterminated string');
  24707. done = true;
  24708. break;
  24709. case 0x28: // '('
  24710. ++numParen;
  24711. strBuf.push('(');
  24712. break;
  24713. case 0x29: // ')'
  24714. if (--numParen === 0) {
  24715. this.nextChar(); // consume strings ')'
  24716. done = true;
  24717. } else {
  24718. strBuf.push(')');
  24719. }
  24720. break;
  24721. case 0x5C: // '\\'
  24722. ch = this.nextChar();
  24723. switch (ch) {
  24724. case -1:
  24725. warn('Unterminated string');
  24726. done = true;
  24727. break;
  24728. case 0x6E: // 'n'
  24729. strBuf.push('\n');
  24730. break;
  24731. case 0x72: // 'r'
  24732. strBuf.push('\r');
  24733. break;
  24734. case 0x74: // 't'
  24735. strBuf.push('\t');
  24736. break;
  24737. case 0x62: // 'b'
  24738. strBuf.push('\b');
  24739. break;
  24740. case 0x66: // 'f'
  24741. strBuf.push('\f');
  24742. break;
  24743. case 0x5C: // '\'
  24744. case 0x28: // '('
  24745. case 0x29: // ')'
  24746. strBuf.push(String.fromCharCode(ch));
  24747. break;
  24748. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  24749. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  24750. var x = ch & 0x0F;
  24751. ch = this.nextChar();
  24752. charBuffered = true;
  24753. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  24754. x = (x << 3) + (ch & 0x0F);
  24755. ch = this.nextChar();
  24756. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  24757. charBuffered = false;
  24758. x = (x << 3) + (ch & 0x0F);
  24759. }
  24760. }
  24761. strBuf.push(String.fromCharCode(x));
  24762. break;
  24763. case 0x0D: // CR
  24764. if (this.peekChar() === 0x0A) { // LF
  24765. this.nextChar();
  24766. }
  24767. break;
  24768. case 0x0A: // LF
  24769. break;
  24770. default:
  24771. strBuf.push(String.fromCharCode(ch));
  24772. break;
  24773. }
  24774. break;
  24775. default:
  24776. strBuf.push(String.fromCharCode(ch));
  24777. break;
  24778. }
  24779. if (done) {
  24780. break;
  24781. }
  24782. if (!charBuffered) {
  24783. ch = this.nextChar();
  24784. }
  24785. }
  24786. return strBuf.join('');
  24787. },
  24788. getName: function Lexer_getName() {
  24789. var ch, previousCh;
  24790. var strBuf = this.strBuf;
  24791. strBuf.length = 0;
  24792. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  24793. if (ch === 0x23) { // '#'
  24794. ch = this.nextChar();
  24795. if (specialChars[ch]) {
  24796. warn('Lexer_getName: ' +
  24797. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  24798. strBuf.push('#');
  24799. break;
  24800. }
  24801. var x = toHexDigit(ch);
  24802. if (x !== -1) {
  24803. previousCh = ch;
  24804. ch = this.nextChar();
  24805. var x2 = toHexDigit(ch);
  24806. if (x2 === -1) {
  24807. warn('Lexer_getName: Illegal digit (' +
  24808. String.fromCharCode(ch) +') in hexadecimal number.');
  24809. strBuf.push('#', String.fromCharCode(previousCh));
  24810. if (specialChars[ch]) {
  24811. break;
  24812. }
  24813. strBuf.push(String.fromCharCode(ch));
  24814. continue;
  24815. }
  24816. strBuf.push(String.fromCharCode((x << 4) | x2));
  24817. } else {
  24818. strBuf.push('#', String.fromCharCode(ch));
  24819. }
  24820. } else {
  24821. strBuf.push(String.fromCharCode(ch));
  24822. }
  24823. }
  24824. if (strBuf.length > 127) {
  24825. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  24826. }
  24827. return Name.get(strBuf.join(''));
  24828. },
  24829. getHexString: function Lexer_getHexString() {
  24830. var strBuf = this.strBuf;
  24831. strBuf.length = 0;
  24832. var ch = this.currentChar;
  24833. var isFirstHex = true;
  24834. var firstDigit;
  24835. var secondDigit;
  24836. while (true) {
  24837. if (ch < 0) {
  24838. warn('Unterminated hex string');
  24839. break;
  24840. } else if (ch === 0x3E) { // '>'
  24841. this.nextChar();
  24842. break;
  24843. } else if (specialChars[ch] === 1) {
  24844. ch = this.nextChar();
  24845. continue;
  24846. } else {
  24847. if (isFirstHex) {
  24848. firstDigit = toHexDigit(ch);
  24849. if (firstDigit === -1) {
  24850. warn('Ignoring invalid character "' + ch + '" in hex string');
  24851. ch = this.nextChar();
  24852. continue;
  24853. }
  24854. } else {
  24855. secondDigit = toHexDigit(ch);
  24856. if (secondDigit === -1) {
  24857. warn('Ignoring invalid character "' + ch + '" in hex string');
  24858. ch = this.nextChar();
  24859. continue;
  24860. }
  24861. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  24862. }
  24863. isFirstHex = !isFirstHex;
  24864. ch = this.nextChar();
  24865. }
  24866. }
  24867. return strBuf.join('');
  24868. },
  24869. getObj: function Lexer_getObj() {
  24870. // skip whitespace and comments
  24871. var comment = false;
  24872. var ch = this.currentChar;
  24873. while (true) {
  24874. if (ch < 0) {
  24875. return EOF;
  24876. }
  24877. if (comment) {
  24878. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  24879. comment = false;
  24880. }
  24881. } else if (ch === 0x25) { // '%'
  24882. comment = true;
  24883. } else if (specialChars[ch] !== 1) {
  24884. break;
  24885. }
  24886. ch = this.nextChar();
  24887. }
  24888. // start reading token
  24889. switch (ch | 0) {
  24890. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  24891. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  24892. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  24893. return this.getNumber();
  24894. case 0x28: // '('
  24895. return this.getString();
  24896. case 0x2F: // '/'
  24897. return this.getName();
  24898. // array punctuation
  24899. case 0x5B: // '['
  24900. this.nextChar();
  24901. return Cmd.get('[');
  24902. case 0x5D: // ']'
  24903. this.nextChar();
  24904. return Cmd.get(']');
  24905. // hex string or dict punctuation
  24906. case 0x3C: // '<'
  24907. ch = this.nextChar();
  24908. if (ch === 0x3C) {
  24909. // dict punctuation
  24910. this.nextChar();
  24911. return Cmd.get('<<');
  24912. }
  24913. return this.getHexString();
  24914. // dict punctuation
  24915. case 0x3E: // '>'
  24916. ch = this.nextChar();
  24917. if (ch === 0x3E) {
  24918. this.nextChar();
  24919. return Cmd.get('>>');
  24920. }
  24921. return Cmd.get('>');
  24922. case 0x7B: // '{'
  24923. this.nextChar();
  24924. return Cmd.get('{');
  24925. case 0x7D: // '}'
  24926. this.nextChar();
  24927. return Cmd.get('}');
  24928. case 0x29: // ')'
  24929. error('Illegal character: ' + ch);
  24930. break;
  24931. }
  24932. // command
  24933. var str = String.fromCharCode(ch);
  24934. var knownCommands = this.knownCommands;
  24935. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  24936. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  24937. // stop if known command is found and next character does not make
  24938. // the str a command
  24939. var possibleCommand = str + String.fromCharCode(ch);
  24940. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  24941. break;
  24942. }
  24943. if (str.length === 128) {
  24944. error('Command token too long: ' + str.length);
  24945. }
  24946. str = possibleCommand;
  24947. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  24948. }
  24949. if (str === 'true') {
  24950. return true;
  24951. }
  24952. if (str === 'false') {
  24953. return false;
  24954. }
  24955. if (str === 'null') {
  24956. return null;
  24957. }
  24958. return Cmd.get(str);
  24959. },
  24960. skipToNextLine: function Lexer_skipToNextLine() {
  24961. var ch = this.currentChar;
  24962. while (ch >= 0) {
  24963. if (ch === 0x0D) { // CR
  24964. ch = this.nextChar();
  24965. if (ch === 0x0A) { // LF
  24966. this.nextChar();
  24967. }
  24968. break;
  24969. } else if (ch === 0x0A) { // LF
  24970. this.nextChar();
  24971. break;
  24972. }
  24973. ch = this.nextChar();
  24974. }
  24975. }
  24976. };
  24977. return Lexer;
  24978. })();
  24979. var Linearization = {
  24980. create: function LinearizationCreate(stream) {
  24981. function getInt(name, allowZeroValue) {
  24982. var obj = linDict.get(name);
  24983. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  24984. return obj;
  24985. }
  24986. throw new Error('The "' + name + '" parameter in the linearization ' +
  24987. 'dictionary is invalid.');
  24988. }
  24989. function getHints() {
  24990. var hints = linDict.get('H'), hintsLength, item;
  24991. if (isArray(hints) &&
  24992. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  24993. for (var index = 0; index < hintsLength; index++) {
  24994. if (!(isInt(item = hints[index]) && item > 0)) {
  24995. throw new Error('Hint (' + index +
  24996. ') in the linearization dictionary is invalid.');
  24997. }
  24998. }
  24999. return hints;
  25000. }
  25001. throw new Error('Hint array in the linearization dictionary is invalid.');
  25002. }
  25003. var parser = new Parser(new Lexer(stream), false, null);
  25004. var obj1 = parser.getObj();
  25005. var obj2 = parser.getObj();
  25006. var obj3 = parser.getObj();
  25007. var linDict = parser.getObj();
  25008. var obj, length;
  25009. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  25010. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  25011. return null; // No valid linearization dictionary found.
  25012. } else if ((length = getInt('L')) !== stream.length) {
  25013. throw new Error('The "L" parameter in the linearization dictionary ' +
  25014. 'does not equal the stream length.');
  25015. }
  25016. return {
  25017. length: length,
  25018. hints: getHints(),
  25019. objectNumberFirst: getInt('O'),
  25020. endFirst: getInt('E'),
  25021. numPages: getInt('N'),
  25022. mainXRefEntriesOffset: getInt('T'),
  25023. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  25024. };
  25025. }
  25026. };
  25027. exports.EOF = EOF;
  25028. exports.Lexer = Lexer;
  25029. exports.Linearization = Linearization;
  25030. exports.Parser = Parser;
  25031. exports.isEOF = isEOF;
  25032. }));
  25033. (function (root, factory) {
  25034. {
  25035. factory((root.pdfjsCoreType1Parser = {}), root.pdfjsSharedUtil,
  25036. root.pdfjsCoreStream, root.pdfjsCoreEncodings);
  25037. }
  25038. }(this, function (exports, sharedUtil, coreStream, coreEncodings) {
  25039. var warn = sharedUtil.warn;
  25040. var isSpace = sharedUtil.isSpace;
  25041. var Stream = coreStream.Stream;
  25042. var getEncoding = coreEncodings.getEncoding;
  25043. // Hinting is currently disabled due to unknown problems on windows
  25044. // in tracemonkey and various other pdfs with type1 fonts.
  25045. var HINTING_ENABLED = false;
  25046. /*
  25047. * CharStrings are encoded following the the CharString Encoding sequence
  25048. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  25049. * The value in a byte indicates a command, a number, or subsequent bytes
  25050. * that are to be interpreted in a special way.
  25051. *
  25052. * CharString Number Encoding:
  25053. * A CharString byte containing the values from 32 through 255 inclusive
  25054. * indicate an integer. These values are decoded in four ranges.
  25055. *
  25056. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  25057. * indicate the integer v - 139. Thus, the integer values from -107 through
  25058. * 107 inclusive may be encoded in single byte.
  25059. *
  25060. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  25061. * indicates an integer involving the next byte, w, according to the formula:
  25062. * [(v - 247) x 256] + w + 108
  25063. *
  25064. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  25065. * indicates an integer involving the next byte, w, according to the formula:
  25066. * -[(v - 251) * 256] - w - 108
  25067. *
  25068. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  25069. * are a two complement signed integer. The first of these bytes contains the
  25070. * highest order bits, the second byte contains the next higher order bits
  25071. * and the fourth byte contain the lowest order bits.
  25072. *
  25073. *
  25074. * CharString Command Encoding:
  25075. * CharStrings commands are encoded in 1 or 2 bytes.
  25076. *
  25077. * Single byte commands are encoded in 1 byte that contains a value between
  25078. * 0 and 31 inclusive.
  25079. * If a command byte contains the value 12, then the value in the next byte
  25080. * indicates a command. This "escape" mechanism allows many extra commands
  25081. * to be encoded and this encoding technique helps to minimize the length of
  25082. * the charStrings.
  25083. */
  25084. var Type1CharString = (function Type1CharStringClosure() {
  25085. var COMMAND_MAP = {
  25086. 'hstem': [1],
  25087. 'vstem': [3],
  25088. 'vmoveto': [4],
  25089. 'rlineto': [5],
  25090. 'hlineto': [6],
  25091. 'vlineto': [7],
  25092. 'rrcurveto': [8],
  25093. 'callsubr': [10],
  25094. 'flex': [12, 35],
  25095. 'drop' : [12, 18],
  25096. 'endchar': [14],
  25097. 'rmoveto': [21],
  25098. 'hmoveto': [22],
  25099. 'vhcurveto': [30],
  25100. 'hvcurveto': [31]
  25101. };
  25102. function Type1CharString() {
  25103. this.width = 0;
  25104. this.lsb = 0;
  25105. this.flexing = false;
  25106. this.output = [];
  25107. this.stack = [];
  25108. }
  25109. Type1CharString.prototype = {
  25110. convert: function Type1CharString_convert(encoded, subrs,
  25111. seacAnalysisEnabled) {
  25112. var count = encoded.length;
  25113. var error = false;
  25114. var wx, sbx, subrNumber;
  25115. for (var i = 0; i < count; i++) {
  25116. var value = encoded[i];
  25117. if (value < 32) {
  25118. if (value === 12) {
  25119. value = (value << 8) + encoded[++i];
  25120. }
  25121. switch (value) {
  25122. case 1: // hstem
  25123. if (!HINTING_ENABLED) {
  25124. this.stack = [];
  25125. break;
  25126. }
  25127. error = this.executeCommand(2, COMMAND_MAP.hstem);
  25128. break;
  25129. case 3: // vstem
  25130. if (!HINTING_ENABLED) {
  25131. this.stack = [];
  25132. break;
  25133. }
  25134. error = this.executeCommand(2, COMMAND_MAP.vstem);
  25135. break;
  25136. case 4: // vmoveto
  25137. if (this.flexing) {
  25138. if (this.stack.length < 1) {
  25139. error = true;
  25140. break;
  25141. }
  25142. // Add the dx for flex and but also swap the values so they are
  25143. // the right order.
  25144. var dy = this.stack.pop();
  25145. this.stack.push(0, dy);
  25146. break;
  25147. }
  25148. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  25149. break;
  25150. case 5: // rlineto
  25151. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  25152. break;
  25153. case 6: // hlineto
  25154. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  25155. break;
  25156. case 7: // vlineto
  25157. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  25158. break;
  25159. case 8: // rrcurveto
  25160. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  25161. break;
  25162. case 9: // closepath
  25163. // closepath is a Type1 command that does not take argument and is
  25164. // useless in Type2 and it can simply be ignored.
  25165. this.stack = [];
  25166. break;
  25167. case 10: // callsubr
  25168. if (this.stack.length < 1) {
  25169. error = true;
  25170. break;
  25171. }
  25172. subrNumber = this.stack.pop();
  25173. error = this.convert(subrs[subrNumber], subrs,
  25174. seacAnalysisEnabled);
  25175. break;
  25176. case 11: // return
  25177. return error;
  25178. case 13: // hsbw
  25179. if (this.stack.length < 2) {
  25180. error = true;
  25181. break;
  25182. }
  25183. // To convert to type2 we have to move the width value to the
  25184. // first part of the charstring and then use hmoveto with lsb.
  25185. wx = this.stack.pop();
  25186. sbx = this.stack.pop();
  25187. this.lsb = sbx;
  25188. this.width = wx;
  25189. this.stack.push(wx, sbx);
  25190. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  25191. break;
  25192. case 14: // endchar
  25193. this.output.push(COMMAND_MAP.endchar[0]);
  25194. break;
  25195. case 21: // rmoveto
  25196. if (this.flexing) {
  25197. break;
  25198. }
  25199. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  25200. break;
  25201. case 22: // hmoveto
  25202. if (this.flexing) {
  25203. // Add the dy for flex.
  25204. this.stack.push(0);
  25205. break;
  25206. }
  25207. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  25208. break;
  25209. case 30: // vhcurveto
  25210. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  25211. break;
  25212. case 31: // hvcurveto
  25213. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  25214. break;
  25215. case (12 << 8) + 0: // dotsection
  25216. // dotsection is a Type1 command to specify some hinting feature
  25217. // for dots that do not take a parameter and it can safely be
  25218. // ignored for Type2.
  25219. this.stack = [];
  25220. break;
  25221. case (12 << 8) + 1: // vstem3
  25222. if (!HINTING_ENABLED) {
  25223. this.stack = [];
  25224. break;
  25225. }
  25226. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  25227. // multiple parameters, so instead of returning [vh]stem3 take a
  25228. // shortcut and return [vhstem] instead.
  25229. error = this.executeCommand(2, COMMAND_MAP.vstem);
  25230. break;
  25231. case (12 << 8) + 2: // hstem3
  25232. if (!HINTING_ENABLED) {
  25233. this.stack = [];
  25234. break;
  25235. }
  25236. // See vstem3.
  25237. error = this.executeCommand(2, COMMAND_MAP.hstem);
  25238. break;
  25239. case (12 << 8) + 6: // seac
  25240. // seac is like type 2's special endchar but it doesn't use the
  25241. // first argument asb, so remove it.
  25242. if (seacAnalysisEnabled) {
  25243. this.seac = this.stack.splice(-4, 4);
  25244. error = this.executeCommand(0, COMMAND_MAP.endchar);
  25245. } else {
  25246. error = this.executeCommand(4, COMMAND_MAP.endchar);
  25247. }
  25248. break;
  25249. case (12 << 8) + 7: // sbw
  25250. if (this.stack.length < 4) {
  25251. error = true;
  25252. break;
  25253. }
  25254. // To convert to type2 we have to move the width value to the
  25255. // first part of the charstring and then use rmoveto with
  25256. // (dx, dy). The height argument will not be used for vmtx and
  25257. // vhea tables reconstruction -- ignoring it.
  25258. var wy = this.stack.pop();
  25259. wx = this.stack.pop();
  25260. var sby = this.stack.pop();
  25261. sbx = this.stack.pop();
  25262. this.lsb = sbx;
  25263. this.width = wx;
  25264. this.stack.push(wx, sbx, sby);
  25265. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  25266. break;
  25267. case (12 << 8) + 12: // div
  25268. if (this.stack.length < 2) {
  25269. error = true;
  25270. break;
  25271. }
  25272. var num2 = this.stack.pop();
  25273. var num1 = this.stack.pop();
  25274. this.stack.push(num1 / num2);
  25275. break;
  25276. case (12 << 8) + 16: // callothersubr
  25277. if (this.stack.length < 2) {
  25278. error = true;
  25279. break;
  25280. }
  25281. subrNumber = this.stack.pop();
  25282. var numArgs = this.stack.pop();
  25283. if (subrNumber === 0 && numArgs === 3) {
  25284. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  25285. this.stack.push(
  25286. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  25287. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  25288. flexArgs[4], // bcp2x
  25289. flexArgs[5], // bcp2y
  25290. flexArgs[6], // p2x
  25291. flexArgs[7], // p2y
  25292. flexArgs[8], // bcp3x
  25293. flexArgs[9], // bcp3y
  25294. flexArgs[10], // bcp4x
  25295. flexArgs[11], // bcp4y
  25296. flexArgs[12], // p3x
  25297. flexArgs[13], // p3y
  25298. flexArgs[14] // flexDepth
  25299. // 15 = finalx unused by flex
  25300. // 16 = finaly unused by flex
  25301. );
  25302. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  25303. this.flexing = false;
  25304. this.stack.push(flexArgs[15], flexArgs[16]);
  25305. } else if (subrNumber === 1 && numArgs === 0) {
  25306. this.flexing = true;
  25307. }
  25308. break;
  25309. case (12 << 8) + 17: // pop
  25310. // Ignore this since it is only used with othersubr.
  25311. break;
  25312. case (12 << 8) + 33: // setcurrentpoint
  25313. // Ignore for now.
  25314. this.stack = [];
  25315. break;
  25316. default:
  25317. warn('Unknown type 1 charstring command of "' + value + '"');
  25318. break;
  25319. }
  25320. if (error) {
  25321. break;
  25322. }
  25323. continue;
  25324. } else if (value <= 246) {
  25325. value = value - 139;
  25326. } else if (value <= 250) {
  25327. value = ((value - 247) * 256) + encoded[++i] + 108;
  25328. } else if (value <= 254) {
  25329. value = -((value - 251) * 256) - encoded[++i] - 108;
  25330. } else {
  25331. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  25332. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  25333. }
  25334. this.stack.push(value);
  25335. }
  25336. return error;
  25337. },
  25338. executeCommand: function(howManyArgs, command, keepStack) {
  25339. var stackLength = this.stack.length;
  25340. if (howManyArgs > stackLength) {
  25341. return true;
  25342. }
  25343. var start = stackLength - howManyArgs;
  25344. for (var i = start; i < stackLength; i++) {
  25345. var value = this.stack[i];
  25346. if (value === (value | 0)) { // int
  25347. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  25348. } else { // fixed point
  25349. value = (65536 * value) | 0;
  25350. this.output.push(255,
  25351. (value >> 24) & 0xFF,
  25352. (value >> 16) & 0xFF,
  25353. (value >> 8) & 0xFF,
  25354. value & 0xFF);
  25355. }
  25356. }
  25357. this.output.push.apply(this.output, command);
  25358. if (keepStack) {
  25359. this.stack.splice(start, howManyArgs);
  25360. } else {
  25361. this.stack.length = 0;
  25362. }
  25363. return false;
  25364. }
  25365. };
  25366. return Type1CharString;
  25367. })();
  25368. /*
  25369. * Type1Parser encapsulate the needed code for parsing a Type1 font
  25370. * program. Some of its logic depends on the Type2 charstrings
  25371. * structure.
  25372. * Note: this doesn't really parse the font since that would require evaluation
  25373. * of PostScript, but it is possible in most cases to extract what we need
  25374. * without a full parse.
  25375. */
  25376. var Type1Parser = (function Type1ParserClosure() {
  25377. /*
  25378. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  25379. * of Plaintext Bytes. The function took a key as a parameter which can be
  25380. * for decrypting the eexec block of for decoding charStrings.
  25381. */
  25382. var EEXEC_ENCRYPT_KEY = 55665;
  25383. var CHAR_STRS_ENCRYPT_KEY = 4330;
  25384. function isHexDigit(code) {
  25385. return code >= 48 && code <= 57 || // '0'-'9'
  25386. code >= 65 && code <= 70 || // 'A'-'F'
  25387. code >= 97 && code <= 102; // 'a'-'f'
  25388. }
  25389. function decrypt(data, key, discardNumber) {
  25390. if (discardNumber >= data.length) {
  25391. return new Uint8Array(0);
  25392. }
  25393. var r = key | 0, c1 = 52845, c2 = 22719, i, j;
  25394. for (i = 0; i < discardNumber; i++) {
  25395. r = ((data[i] + r) * c1 + c2) & ((1 << 16) - 1);
  25396. }
  25397. var count = data.length - discardNumber;
  25398. var decrypted = new Uint8Array(count);
  25399. for (i = discardNumber, j = 0; j < count; i++, j++) {
  25400. var value = data[i];
  25401. decrypted[j] = value ^ (r >> 8);
  25402. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  25403. }
  25404. return decrypted;
  25405. }
  25406. function decryptAscii(data, key, discardNumber) {
  25407. var r = key | 0, c1 = 52845, c2 = 22719;
  25408. var count = data.length, maybeLength = count >>> 1;
  25409. var decrypted = new Uint8Array(maybeLength);
  25410. var i, j;
  25411. for (i = 0, j = 0; i < count; i++) {
  25412. var digit1 = data[i];
  25413. if (!isHexDigit(digit1)) {
  25414. continue;
  25415. }
  25416. i++;
  25417. var digit2;
  25418. while (i < count && !isHexDigit(digit2 = data[i])) {
  25419. i++;
  25420. }
  25421. if (i < count) {
  25422. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  25423. decrypted[j++] = value ^ (r >> 8);
  25424. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  25425. }
  25426. }
  25427. return Array.prototype.slice.call(decrypted, discardNumber, j);
  25428. }
  25429. function isSpecial(c) {
  25430. return c === 0x2F || // '/'
  25431. c === 0x5B || c === 0x5D || // '[', ']'
  25432. c === 0x7B || c === 0x7D || // '{', '}'
  25433. c === 0x28 || c === 0x29; // '(', ')'
  25434. }
  25435. function Type1Parser(stream, encrypted, seacAnalysisEnabled) {
  25436. if (encrypted) {
  25437. var data = stream.getBytes();
  25438. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  25439. isHexDigit(data[2]) && isHexDigit(data[3]));
  25440. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  25441. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  25442. }
  25443. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  25444. this.stream = stream;
  25445. this.nextChar();
  25446. }
  25447. Type1Parser.prototype = {
  25448. readNumberArray: function Type1Parser_readNumberArray() {
  25449. this.getToken(); // read '[' or '{' (arrays can start with either)
  25450. var array = [];
  25451. while (true) {
  25452. var token = this.getToken();
  25453. if (token === null || token === ']' || token === '}') {
  25454. break;
  25455. }
  25456. array.push(parseFloat(token || 0));
  25457. }
  25458. return array;
  25459. },
  25460. readNumber: function Type1Parser_readNumber() {
  25461. var token = this.getToken();
  25462. return parseFloat(token || 0);
  25463. },
  25464. readInt: function Type1Parser_readInt() {
  25465. // Use '| 0' to prevent setting a double into length such as the double
  25466. // does not flow into the loop variable.
  25467. var token = this.getToken();
  25468. return parseInt(token || 0, 10) | 0;
  25469. },
  25470. readBoolean: function Type1Parser_readBoolean() {
  25471. var token = this.getToken();
  25472. // Use 1 and 0 since that's what type2 charstrings use.
  25473. return token === 'true' ? 1 : 0;
  25474. },
  25475. nextChar : function Type1_nextChar() {
  25476. return (this.currentChar = this.stream.getByte());
  25477. },
  25478. getToken: function Type1Parser_getToken() {
  25479. // Eat whitespace and comments.
  25480. var comment = false;
  25481. var ch = this.currentChar;
  25482. while (true) {
  25483. if (ch === -1) {
  25484. return null;
  25485. }
  25486. if (comment) {
  25487. if (ch === 0x0A || ch === 0x0D) {
  25488. comment = false;
  25489. }
  25490. } else if (ch === 0x25) { // '%'
  25491. comment = true;
  25492. } else if (!isSpace(ch)) {
  25493. break;
  25494. }
  25495. ch = this.nextChar();
  25496. }
  25497. if (isSpecial(ch)) {
  25498. this.nextChar();
  25499. return String.fromCharCode(ch);
  25500. }
  25501. var token = '';
  25502. do {
  25503. token += String.fromCharCode(ch);
  25504. ch = this.nextChar();
  25505. } while (ch >= 0 && !isSpace(ch) && !isSpecial(ch));
  25506. return token;
  25507. },
  25508. /*
  25509. * Returns an object containing a Subrs array and a CharStrings
  25510. * array extracted from and eexec encrypted block of data
  25511. */
  25512. extractFontProgram: function Type1Parser_extractFontProgram() {
  25513. var stream = this.stream;
  25514. var subrs = [], charstrings = [];
  25515. var privateData = Object.create(null);
  25516. privateData['lenIV'] = 4;
  25517. var program = {
  25518. subrs: [],
  25519. charstrings: [],
  25520. properties: {
  25521. 'privateData': privateData
  25522. }
  25523. };
  25524. var token, length, data, lenIV, encoded;
  25525. while ((token = this.getToken()) !== null) {
  25526. if (token !== '/') {
  25527. continue;
  25528. }
  25529. token = this.getToken();
  25530. switch (token) {
  25531. case 'CharStrings':
  25532. // The number immediately following CharStrings must be greater or
  25533. // equal to the number of CharStrings.
  25534. this.getToken();
  25535. this.getToken(); // read in 'dict'
  25536. this.getToken(); // read in 'dup'
  25537. this.getToken(); // read in 'begin'
  25538. while(true) {
  25539. token = this.getToken();
  25540. if (token === null || token === 'end') {
  25541. break;
  25542. }
  25543. if (token !== '/') {
  25544. continue;
  25545. }
  25546. var glyph = this.getToken();
  25547. length = this.readInt();
  25548. this.getToken(); // read in 'RD' or '-|'
  25549. data = stream.makeSubStream(stream.pos, length);
  25550. lenIV = program.properties.privateData['lenIV'];
  25551. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  25552. // Skip past the required space and binary data.
  25553. stream.skip(length);
  25554. this.nextChar();
  25555. token = this.getToken(); // read in 'ND' or '|-'
  25556. if (token === 'noaccess') {
  25557. this.getToken(); // read in 'def'
  25558. }
  25559. charstrings.push({
  25560. glyph: glyph,
  25561. encoded: encoded
  25562. });
  25563. }
  25564. break;
  25565. case 'Subrs':
  25566. var num = this.readInt();
  25567. this.getToken(); // read in 'array'
  25568. while ((token = this.getToken()) === 'dup') {
  25569. var index = this.readInt();
  25570. length = this.readInt();
  25571. this.getToken(); // read in 'RD' or '-|'
  25572. data = stream.makeSubStream(stream.pos, length);
  25573. lenIV = program.properties.privateData['lenIV'];
  25574. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  25575. // Skip past the required space and binary data.
  25576. stream.skip(length);
  25577. this.nextChar();
  25578. token = this.getToken(); // read in 'NP' or '|'
  25579. if (token === 'noaccess') {
  25580. this.getToken(); // read in 'put'
  25581. }
  25582. subrs[index] = encoded;
  25583. }
  25584. break;
  25585. case 'BlueValues':
  25586. case 'OtherBlues':
  25587. case 'FamilyBlues':
  25588. case 'FamilyOtherBlues':
  25589. var blueArray = this.readNumberArray();
  25590. // *Blue* values may contain invalid data: disables reading of
  25591. // those values when hinting is disabled.
  25592. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  25593. HINTING_ENABLED) {
  25594. program.properties.privateData[token] = blueArray;
  25595. }
  25596. break;
  25597. case 'StemSnapH':
  25598. case 'StemSnapV':
  25599. program.properties.privateData[token] = this.readNumberArray();
  25600. break;
  25601. case 'StdHW':
  25602. case 'StdVW':
  25603. program.properties.privateData[token] =
  25604. this.readNumberArray()[0];
  25605. break;
  25606. case 'BlueShift':
  25607. case 'lenIV':
  25608. case 'BlueFuzz':
  25609. case 'BlueScale':
  25610. case 'LanguageGroup':
  25611. case 'ExpansionFactor':
  25612. program.properties.privateData[token] = this.readNumber();
  25613. break;
  25614. case 'ForceBold':
  25615. program.properties.privateData[token] = this.readBoolean();
  25616. break;
  25617. }
  25618. }
  25619. for (var i = 0; i < charstrings.length; i++) {
  25620. glyph = charstrings[i].glyph;
  25621. encoded = charstrings[i].encoded;
  25622. var charString = new Type1CharString();
  25623. var error = charString.convert(encoded, subrs,
  25624. this.seacAnalysisEnabled);
  25625. var output = charString.output;
  25626. if (error) {
  25627. // It seems when FreeType encounters an error while evaluating a glyph
  25628. // that it completely ignores the glyph so we'll mimic that behaviour
  25629. // here and put an endchar to make the validator happy.
  25630. output = [14];
  25631. }
  25632. program.charstrings.push({
  25633. glyphName: glyph,
  25634. charstring: output,
  25635. width: charString.width,
  25636. lsb: charString.lsb,
  25637. seac: charString.seac
  25638. });
  25639. }
  25640. return program;
  25641. },
  25642. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  25643. var token;
  25644. while ((token = this.getToken()) !== null) {
  25645. if (token !== '/') {
  25646. continue;
  25647. }
  25648. token = this.getToken();
  25649. switch (token) {
  25650. case 'FontMatrix':
  25651. var matrix = this.readNumberArray();
  25652. properties.fontMatrix = matrix;
  25653. break;
  25654. case 'Encoding':
  25655. var encodingArg = this.getToken();
  25656. var encoding;
  25657. if (!/^\d+$/.test(encodingArg)) {
  25658. // encoding name is specified
  25659. encoding = getEncoding(encodingArg);
  25660. } else {
  25661. encoding = [];
  25662. var size = parseInt(encodingArg, 10) | 0;
  25663. this.getToken(); // read in 'array'
  25664. for (var j = 0; j < size; j++) {
  25665. token = this.getToken();
  25666. // skipping till first dup or def (e.g. ignoring for statement)
  25667. while (token !== 'dup' && token !== 'def') {
  25668. token = this.getToken();
  25669. if (token === null) {
  25670. return; // invalid header
  25671. }
  25672. }
  25673. if (token === 'def') {
  25674. break; // read all array data
  25675. }
  25676. var index = this.readInt();
  25677. this.getToken(); // read in '/'
  25678. var glyph = this.getToken();
  25679. encoding[index] = glyph;
  25680. this.getToken(); // read the in 'put'
  25681. }
  25682. }
  25683. properties.builtInEncoding = encoding;
  25684. break;
  25685. case 'FontBBox':
  25686. var fontBBox = this.readNumberArray();
  25687. // adjusting ascent/descent
  25688. properties.ascent = fontBBox[3];
  25689. properties.descent = fontBBox[1];
  25690. properties.ascentScaled = true;
  25691. break;
  25692. }
  25693. }
  25694. }
  25695. };
  25696. return Type1Parser;
  25697. })();
  25698. exports.Type1Parser = Type1Parser;
  25699. }));
  25700. (function (root, factory) {
  25701. {
  25702. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  25703. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  25704. }
  25705. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  25706. var Util = sharedUtil.Util;
  25707. var assert = sharedUtil.assert;
  25708. var warn = sharedUtil.warn;
  25709. var error = sharedUtil.error;
  25710. var isInt = sharedUtil.isInt;
  25711. var isString = sharedUtil.isString;
  25712. var MissingDataException = sharedUtil.MissingDataException;
  25713. var isName = corePrimitives.isName;
  25714. var isCmd = corePrimitives.isCmd;
  25715. var isStream = corePrimitives.isStream;
  25716. var StringStream = coreStream.StringStream;
  25717. var Lexer = coreParser.Lexer;
  25718. var isEOF = coreParser.isEOF;
  25719. var BUILT_IN_CMAPS = [
  25720. // << Start unicode maps.
  25721. 'Adobe-GB1-UCS2',
  25722. 'Adobe-CNS1-UCS2',
  25723. 'Adobe-Japan1-UCS2',
  25724. 'Adobe-Korea1-UCS2',
  25725. // >> End unicode maps.
  25726. '78-EUC-H',
  25727. '78-EUC-V',
  25728. '78-H',
  25729. '78-RKSJ-H',
  25730. '78-RKSJ-V',
  25731. '78-V',
  25732. '78ms-RKSJ-H',
  25733. '78ms-RKSJ-V',
  25734. '83pv-RKSJ-H',
  25735. '90ms-RKSJ-H',
  25736. '90ms-RKSJ-V',
  25737. '90msp-RKSJ-H',
  25738. '90msp-RKSJ-V',
  25739. '90pv-RKSJ-H',
  25740. '90pv-RKSJ-V',
  25741. 'Add-H',
  25742. 'Add-RKSJ-H',
  25743. 'Add-RKSJ-V',
  25744. 'Add-V',
  25745. 'Adobe-CNS1-0',
  25746. 'Adobe-CNS1-1',
  25747. 'Adobe-CNS1-2',
  25748. 'Adobe-CNS1-3',
  25749. 'Adobe-CNS1-4',
  25750. 'Adobe-CNS1-5',
  25751. 'Adobe-CNS1-6',
  25752. 'Adobe-GB1-0',
  25753. 'Adobe-GB1-1',
  25754. 'Adobe-GB1-2',
  25755. 'Adobe-GB1-3',
  25756. 'Adobe-GB1-4',
  25757. 'Adobe-GB1-5',
  25758. 'Adobe-Japan1-0',
  25759. 'Adobe-Japan1-1',
  25760. 'Adobe-Japan1-2',
  25761. 'Adobe-Japan1-3',
  25762. 'Adobe-Japan1-4',
  25763. 'Adobe-Japan1-5',
  25764. 'Adobe-Japan1-6',
  25765. 'Adobe-Korea1-0',
  25766. 'Adobe-Korea1-1',
  25767. 'Adobe-Korea1-2',
  25768. 'B5-H',
  25769. 'B5-V',
  25770. 'B5pc-H',
  25771. 'B5pc-V',
  25772. 'CNS-EUC-H',
  25773. 'CNS-EUC-V',
  25774. 'CNS1-H',
  25775. 'CNS1-V',
  25776. 'CNS2-H',
  25777. 'CNS2-V',
  25778. 'ETHK-B5-H',
  25779. 'ETHK-B5-V',
  25780. 'ETen-B5-H',
  25781. 'ETen-B5-V',
  25782. 'ETenms-B5-H',
  25783. 'ETenms-B5-V',
  25784. 'EUC-H',
  25785. 'EUC-V',
  25786. 'Ext-H',
  25787. 'Ext-RKSJ-H',
  25788. 'Ext-RKSJ-V',
  25789. 'Ext-V',
  25790. 'GB-EUC-H',
  25791. 'GB-EUC-V',
  25792. 'GB-H',
  25793. 'GB-V',
  25794. 'GBK-EUC-H',
  25795. 'GBK-EUC-V',
  25796. 'GBK2K-H',
  25797. 'GBK2K-V',
  25798. 'GBKp-EUC-H',
  25799. 'GBKp-EUC-V',
  25800. 'GBT-EUC-H',
  25801. 'GBT-EUC-V',
  25802. 'GBT-H',
  25803. 'GBT-V',
  25804. 'GBTpc-EUC-H',
  25805. 'GBTpc-EUC-V',
  25806. 'GBpc-EUC-H',
  25807. 'GBpc-EUC-V',
  25808. 'H',
  25809. 'HKdla-B5-H',
  25810. 'HKdla-B5-V',
  25811. 'HKdlb-B5-H',
  25812. 'HKdlb-B5-V',
  25813. 'HKgccs-B5-H',
  25814. 'HKgccs-B5-V',
  25815. 'HKm314-B5-H',
  25816. 'HKm314-B5-V',
  25817. 'HKm471-B5-H',
  25818. 'HKm471-B5-V',
  25819. 'HKscs-B5-H',
  25820. 'HKscs-B5-V',
  25821. 'Hankaku',
  25822. 'Hiragana',
  25823. 'KSC-EUC-H',
  25824. 'KSC-EUC-V',
  25825. 'KSC-H',
  25826. 'KSC-Johab-H',
  25827. 'KSC-Johab-V',
  25828. 'KSC-V',
  25829. 'KSCms-UHC-H',
  25830. 'KSCms-UHC-HW-H',
  25831. 'KSCms-UHC-HW-V',
  25832. 'KSCms-UHC-V',
  25833. 'KSCpc-EUC-H',
  25834. 'KSCpc-EUC-V',
  25835. 'Katakana',
  25836. 'NWP-H',
  25837. 'NWP-V',
  25838. 'RKSJ-H',
  25839. 'RKSJ-V',
  25840. 'Roman',
  25841. 'UniCNS-UCS2-H',
  25842. 'UniCNS-UCS2-V',
  25843. 'UniCNS-UTF16-H',
  25844. 'UniCNS-UTF16-V',
  25845. 'UniCNS-UTF32-H',
  25846. 'UniCNS-UTF32-V',
  25847. 'UniCNS-UTF8-H',
  25848. 'UniCNS-UTF8-V',
  25849. 'UniGB-UCS2-H',
  25850. 'UniGB-UCS2-V',
  25851. 'UniGB-UTF16-H',
  25852. 'UniGB-UTF16-V',
  25853. 'UniGB-UTF32-H',
  25854. 'UniGB-UTF32-V',
  25855. 'UniGB-UTF8-H',
  25856. 'UniGB-UTF8-V',
  25857. 'UniJIS-UCS2-H',
  25858. 'UniJIS-UCS2-HW-H',
  25859. 'UniJIS-UCS2-HW-V',
  25860. 'UniJIS-UCS2-V',
  25861. 'UniJIS-UTF16-H',
  25862. 'UniJIS-UTF16-V',
  25863. 'UniJIS-UTF32-H',
  25864. 'UniJIS-UTF32-V',
  25865. 'UniJIS-UTF8-H',
  25866. 'UniJIS-UTF8-V',
  25867. 'UniJIS2004-UTF16-H',
  25868. 'UniJIS2004-UTF16-V',
  25869. 'UniJIS2004-UTF32-H',
  25870. 'UniJIS2004-UTF32-V',
  25871. 'UniJIS2004-UTF8-H',
  25872. 'UniJIS2004-UTF8-V',
  25873. 'UniJISPro-UCS2-HW-V',
  25874. 'UniJISPro-UCS2-V',
  25875. 'UniJISPro-UTF8-V',
  25876. 'UniJISX0213-UTF32-H',
  25877. 'UniJISX0213-UTF32-V',
  25878. 'UniJISX02132004-UTF32-H',
  25879. 'UniJISX02132004-UTF32-V',
  25880. 'UniKS-UCS2-H',
  25881. 'UniKS-UCS2-V',
  25882. 'UniKS-UTF16-H',
  25883. 'UniKS-UTF16-V',
  25884. 'UniKS-UTF32-H',
  25885. 'UniKS-UTF32-V',
  25886. 'UniKS-UTF8-H',
  25887. 'UniKS-UTF8-V',
  25888. 'V',
  25889. 'WP-Symbol'];
  25890. // CMap, not to be confused with TrueType's cmap.
  25891. var CMap = (function CMapClosure() {
  25892. function CMap(builtInCMap) {
  25893. // Codespace ranges are stored as follows:
  25894. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  25895. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  25896. this.codespaceRanges = [[], [], [], []];
  25897. this.numCodespaceRanges = 0;
  25898. // Map entries have one of two forms.
  25899. // - cid chars are 16-bit unsigned integers, stored as integers.
  25900. // - bf chars are variable-length byte sequences, stored as strings, with
  25901. // one byte per character.
  25902. this._map = [];
  25903. this.name = '';
  25904. this.vertical = false;
  25905. this.useCMap = null;
  25906. this.builtInCMap = builtInCMap;
  25907. }
  25908. CMap.prototype = {
  25909. addCodespaceRange: function(n, low, high) {
  25910. this.codespaceRanges[n - 1].push(low, high);
  25911. this.numCodespaceRanges++;
  25912. },
  25913. mapCidRange: function(low, high, dstLow) {
  25914. while (low <= high) {
  25915. this._map[low++] = dstLow++;
  25916. }
  25917. },
  25918. mapBfRange: function(low, high, dstLow) {
  25919. var lastByte = dstLow.length - 1;
  25920. while (low <= high) {
  25921. this._map[low++] = dstLow;
  25922. // Only the last byte has to be incremented.
  25923. dstLow = dstLow.substr(0, lastByte) +
  25924. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  25925. }
  25926. },
  25927. mapBfRangeToArray: function(low, high, array) {
  25928. var i = 0, ii = array.length;
  25929. while (low <= high && i < ii) {
  25930. this._map[low] = array[i++];
  25931. ++low;
  25932. }
  25933. },
  25934. // This is used for both bf and cid chars.
  25935. mapOne: function(src, dst) {
  25936. this._map[src] = dst;
  25937. },
  25938. lookup: function(code) {
  25939. return this._map[code];
  25940. },
  25941. contains: function(code) {
  25942. return this._map[code] !== undefined;
  25943. },
  25944. forEach: function(callback) {
  25945. // Most maps have fewer than 65536 entries, and for those we use normal
  25946. // array iteration. But really sparse tables are possible -- e.g. with
  25947. // indices in the *billions*. For such tables we use for..in, which isn't
  25948. // ideal because it stringifies the indices for all present elements, but
  25949. // it does avoid iterating over every undefined entry.
  25950. var map = this._map;
  25951. var length = map.length;
  25952. var i;
  25953. if (length <= 0x10000) {
  25954. for (i = 0; i < length; i++) {
  25955. if (map[i] !== undefined) {
  25956. callback(i, map[i]);
  25957. }
  25958. }
  25959. } else {
  25960. for (i in this._map) {
  25961. callback(i, map[i]);
  25962. }
  25963. }
  25964. },
  25965. charCodeOf: function(value) {
  25966. return this._map.indexOf(value);
  25967. },
  25968. getMap: function() {
  25969. return this._map;
  25970. },
  25971. readCharCode: function(str, offset, out) {
  25972. var c = 0;
  25973. var codespaceRanges = this.codespaceRanges;
  25974. var codespaceRangesLen = this.codespaceRanges.length;
  25975. // 9.7.6.2 CMap Mapping
  25976. // The code length is at most 4.
  25977. for (var n = 0; n < codespaceRangesLen; n++) {
  25978. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  25979. // Check each codespace range to see if it falls within.
  25980. var codespaceRange = codespaceRanges[n];
  25981. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  25982. var low = codespaceRange[k++];
  25983. var high = codespaceRange[k++];
  25984. if (c >= low && c <= high) {
  25985. out.charcode = c;
  25986. out.length = n + 1;
  25987. return;
  25988. }
  25989. }
  25990. }
  25991. out.charcode = 0;
  25992. out.length = 1;
  25993. },
  25994. get length() {
  25995. return this._map.length;
  25996. },
  25997. get isIdentityCMap() {
  25998. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  25999. return false;
  26000. }
  26001. if (this._map.length !== 0x10000) {
  26002. return false;
  26003. }
  26004. for (var i = 0; i < 0x10000; i++) {
  26005. if (this._map[i] !== i) {
  26006. return false;
  26007. }
  26008. }
  26009. return true;
  26010. }
  26011. };
  26012. return CMap;
  26013. })();
  26014. // A special case of CMap, where the _map array implicitly has a length of
  26015. // 65536 and each element is equal to its index.
  26016. var IdentityCMap = (function IdentityCMapClosure() {
  26017. function IdentityCMap(vertical, n) {
  26018. CMap.call(this);
  26019. this.vertical = vertical;
  26020. this.addCodespaceRange(n, 0, 0xffff);
  26021. }
  26022. Util.inherit(IdentityCMap, CMap, {});
  26023. IdentityCMap.prototype = {
  26024. addCodespaceRange: CMap.prototype.addCodespaceRange,
  26025. mapCidRange: function(low, high, dstLow) {
  26026. error('should not call mapCidRange');
  26027. },
  26028. mapBfRange: function(low, high, dstLow) {
  26029. error('should not call mapBfRange');
  26030. },
  26031. mapBfRangeToArray: function(low, high, array) {
  26032. error('should not call mapBfRangeToArray');
  26033. },
  26034. mapOne: function(src, dst) {
  26035. error('should not call mapCidOne');
  26036. },
  26037. lookup: function(code) {
  26038. return (isInt(code) && code <= 0xffff) ? code : undefined;
  26039. },
  26040. contains: function(code) {
  26041. return isInt(code) && code <= 0xffff;
  26042. },
  26043. forEach: function(callback) {
  26044. for (var i = 0; i <= 0xffff; i++) {
  26045. callback(i, i);
  26046. }
  26047. },
  26048. charCodeOf: function(value) {
  26049. return (isInt(value) && value <= 0xffff) ? value : -1;
  26050. },
  26051. getMap: function() {
  26052. // Sometimes identity maps must be instantiated, but it's rare.
  26053. var map = new Array(0x10000);
  26054. for (var i = 0; i <= 0xffff; i++) {
  26055. map[i] = i;
  26056. }
  26057. return map;
  26058. },
  26059. readCharCode: CMap.prototype.readCharCode,
  26060. get length() {
  26061. return 0x10000;
  26062. },
  26063. get isIdentityCMap() {
  26064. error('should not access .isIdentityCMap');
  26065. }
  26066. };
  26067. return IdentityCMap;
  26068. })();
  26069. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  26070. function fetchBinaryData(url) {
  26071. return new Promise(function (resolve, reject) {
  26072. var request = new XMLHttpRequest();
  26073. request.open('GET', url, true);
  26074. request.responseType = 'arraybuffer';
  26075. request.onreadystatechange = function () {
  26076. if (request.readyState === XMLHttpRequest.DONE) {
  26077. if (!request.response || request.status !== 200 &&
  26078. request.status !== 0) {
  26079. reject(new Error('Unable to get binary cMap at: ' + url));
  26080. } else {
  26081. resolve(new Uint8Array(request.response));
  26082. }
  26083. }
  26084. };
  26085. request.send(null);
  26086. });
  26087. }
  26088. function hexToInt(a, size) {
  26089. var n = 0;
  26090. for (var i = 0; i <= size; i++) {
  26091. n = (n << 8) | a[i];
  26092. }
  26093. return n >>> 0;
  26094. }
  26095. function hexToStr(a, size) {
  26096. // This code is hot. Special-case some common values to avoid creating an
  26097. // object with subarray().
  26098. if (size === 1) {
  26099. return String.fromCharCode(a[0], a[1]);
  26100. }
  26101. if (size === 3) {
  26102. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  26103. }
  26104. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  26105. }
  26106. function addHex(a, b, size) {
  26107. var c = 0;
  26108. for (var i = size; i >= 0; i--) {
  26109. c += a[i] + b[i];
  26110. a[i] = c & 255;
  26111. c >>= 8;
  26112. }
  26113. }
  26114. function incHex(a, size) {
  26115. var c = 1;
  26116. for (var i = size; i >= 0 && c > 0; i--) {
  26117. c += a[i];
  26118. a[i] = c & 255;
  26119. c >>= 8;
  26120. }
  26121. }
  26122. var MAX_NUM_SIZE = 16;
  26123. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  26124. function BinaryCMapStream(data) {
  26125. this.buffer = data;
  26126. this.pos = 0;
  26127. this.end = data.length;
  26128. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  26129. }
  26130. BinaryCMapStream.prototype = {
  26131. readByte: function () {
  26132. if (this.pos >= this.end) {
  26133. return -1;
  26134. }
  26135. return this.buffer[this.pos++];
  26136. },
  26137. readNumber: function () {
  26138. var n = 0;
  26139. var last;
  26140. do {
  26141. var b = this.readByte();
  26142. if (b < 0) {
  26143. error('unexpected EOF in bcmap');
  26144. }
  26145. last = !(b & 0x80);
  26146. n = (n << 7) | (b & 0x7F);
  26147. } while (!last);
  26148. return n;
  26149. },
  26150. readSigned: function () {
  26151. var n = this.readNumber();
  26152. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  26153. },
  26154. readHex: function (num, size) {
  26155. num.set(this.buffer.subarray(this.pos,
  26156. this.pos + size + 1));
  26157. this.pos += size + 1;
  26158. },
  26159. readHexNumber: function (num, size) {
  26160. var last;
  26161. var stack = this.tmpBuf, sp = 0;
  26162. do {
  26163. var b = this.readByte();
  26164. if (b < 0) {
  26165. error('unexpected EOF in bcmap');
  26166. }
  26167. last = !(b & 0x80);
  26168. stack[sp++] = b & 0x7F;
  26169. } while (!last);
  26170. var i = size, buffer = 0, bufferSize = 0;
  26171. while (i >= 0) {
  26172. while (bufferSize < 8 && stack.length > 0) {
  26173. buffer = (stack[--sp] << bufferSize) | buffer;
  26174. bufferSize += 7;
  26175. }
  26176. num[i] = buffer & 255;
  26177. i--;
  26178. buffer >>= 8;
  26179. bufferSize -= 8;
  26180. }
  26181. },
  26182. readHexSigned: function (num, size) {
  26183. this.readHexNumber(num, size);
  26184. var sign = num[size] & 1 ? 255 : 0;
  26185. var c = 0;
  26186. for (var i = 0; i <= size; i++) {
  26187. c = ((c & 1) << 8) | num[i];
  26188. num[i] = (c >> 1) ^ sign;
  26189. }
  26190. },
  26191. readString: function () {
  26192. var len = this.readNumber();
  26193. var s = '';
  26194. for (var i = 0; i < len; i++) {
  26195. s += String.fromCharCode(this.readNumber());
  26196. }
  26197. return s;
  26198. }
  26199. };
  26200. function processBinaryCMap(url, cMap, extend) {
  26201. return fetchBinaryData(url).then(function (data) {
  26202. var stream = new BinaryCMapStream(data);
  26203. var header = stream.readByte();
  26204. cMap.vertical = !!(header & 1);
  26205. var useCMap = null;
  26206. var start = new Uint8Array(MAX_NUM_SIZE);
  26207. var end = new Uint8Array(MAX_NUM_SIZE);
  26208. var char = new Uint8Array(MAX_NUM_SIZE);
  26209. var charCode = new Uint8Array(MAX_NUM_SIZE);
  26210. var tmp = new Uint8Array(MAX_NUM_SIZE);
  26211. var code;
  26212. var b;
  26213. while ((b = stream.readByte()) >= 0) {
  26214. var type = b >> 5;
  26215. if (type === 7) { // metadata, e.g. comment or usecmap
  26216. switch (b & 0x1F) {
  26217. case 0:
  26218. stream.readString(); // skipping comment
  26219. break;
  26220. case 1:
  26221. useCMap = stream.readString();
  26222. break;
  26223. }
  26224. continue;
  26225. }
  26226. var sequence = !!(b & 0x10);
  26227. var dataSize = b & 15;
  26228. assert(dataSize + 1 <= MAX_NUM_SIZE);
  26229. var ucs2DataSize = 1;
  26230. var subitemsCount = stream.readNumber();
  26231. var i;
  26232. switch (type) {
  26233. case 0: // codespacerange
  26234. stream.readHex(start, dataSize);
  26235. stream.readHexNumber(end, dataSize);
  26236. addHex(end, start, dataSize);
  26237. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  26238. hexToInt(end, dataSize));
  26239. for (i = 1; i < subitemsCount; i++) {
  26240. incHex(end, dataSize);
  26241. stream.readHexNumber(start, dataSize);
  26242. addHex(start, end, dataSize);
  26243. stream.readHexNumber(end, dataSize);
  26244. addHex(end, start, dataSize);
  26245. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  26246. hexToInt(end, dataSize));
  26247. }
  26248. break;
  26249. case 1: // notdefrange
  26250. stream.readHex(start, dataSize);
  26251. stream.readHexNumber(end, dataSize);
  26252. addHex(end, start, dataSize);
  26253. code = stream.readNumber();
  26254. // undefined range, skipping
  26255. for (i = 1; i < subitemsCount; i++) {
  26256. incHex(end, dataSize);
  26257. stream.readHexNumber(start, dataSize);
  26258. addHex(start, end, dataSize);
  26259. stream.readHexNumber(end, dataSize);
  26260. addHex(end, start, dataSize);
  26261. code = stream.readNumber();
  26262. // nop
  26263. }
  26264. break;
  26265. case 2: // cidchar
  26266. stream.readHex(char, dataSize);
  26267. code = stream.readNumber();
  26268. cMap.mapOne(hexToInt(char, dataSize), code);
  26269. for (i = 1; i < subitemsCount; i++) {
  26270. incHex(char, dataSize);
  26271. if (!sequence) {
  26272. stream.readHexNumber(tmp, dataSize);
  26273. addHex(char, tmp, dataSize);
  26274. }
  26275. code = stream.readSigned() + (code + 1);
  26276. cMap.mapOne(hexToInt(char, dataSize), code);
  26277. }
  26278. break;
  26279. case 3: // cidrange
  26280. stream.readHex(start, dataSize);
  26281. stream.readHexNumber(end, dataSize);
  26282. addHex(end, start, dataSize);
  26283. code = stream.readNumber();
  26284. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  26285. code);
  26286. for (i = 1; i < subitemsCount; i++) {
  26287. incHex(end, dataSize);
  26288. if (!sequence) {
  26289. stream.readHexNumber(start, dataSize);
  26290. addHex(start, end, dataSize);
  26291. } else {
  26292. start.set(end);
  26293. }
  26294. stream.readHexNumber(end, dataSize);
  26295. addHex(end, start, dataSize);
  26296. code = stream.readNumber();
  26297. cMap.mapCidRange(hexToInt(start, dataSize),
  26298. hexToInt(end, dataSize), code);
  26299. }
  26300. break;
  26301. case 4: // bfchar
  26302. stream.readHex(char, ucs2DataSize);
  26303. stream.readHex(charCode, dataSize);
  26304. cMap.mapOne(hexToInt(char, ucs2DataSize),
  26305. hexToStr(charCode, dataSize));
  26306. for (i = 1; i < subitemsCount; i++) {
  26307. incHex(char, ucs2DataSize);
  26308. if (!sequence) {
  26309. stream.readHexNumber(tmp, ucs2DataSize);
  26310. addHex(char, tmp, ucs2DataSize);
  26311. }
  26312. incHex(charCode, dataSize);
  26313. stream.readHexSigned(tmp, dataSize);
  26314. addHex(charCode, tmp, dataSize);
  26315. cMap.mapOne(hexToInt(char, ucs2DataSize),
  26316. hexToStr(charCode, dataSize));
  26317. }
  26318. break;
  26319. case 5: // bfrange
  26320. stream.readHex(start, ucs2DataSize);
  26321. stream.readHexNumber(end, ucs2DataSize);
  26322. addHex(end, start, ucs2DataSize);
  26323. stream.readHex(charCode, dataSize);
  26324. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  26325. hexToInt(end, ucs2DataSize),
  26326. hexToStr(charCode, dataSize));
  26327. for (i = 1; i < subitemsCount; i++) {
  26328. incHex(end, ucs2DataSize);
  26329. if (!sequence) {
  26330. stream.readHexNumber(start, ucs2DataSize);
  26331. addHex(start, end, ucs2DataSize);
  26332. } else {
  26333. start.set(end);
  26334. }
  26335. stream.readHexNumber(end, ucs2DataSize);
  26336. addHex(end, start, ucs2DataSize);
  26337. stream.readHex(charCode, dataSize);
  26338. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  26339. hexToInt(end, ucs2DataSize),
  26340. hexToStr(charCode, dataSize));
  26341. }
  26342. break;
  26343. default:
  26344. error('Unknown type: ' + type);
  26345. break;
  26346. }
  26347. }
  26348. if (useCMap) {
  26349. return extend(useCMap);
  26350. }
  26351. return cMap;
  26352. });
  26353. }
  26354. function BinaryCMapReader() {}
  26355. BinaryCMapReader.prototype = {
  26356. read: processBinaryCMap
  26357. };
  26358. return BinaryCMapReader;
  26359. })();
  26360. var CMapFactory = (function CMapFactoryClosure() {
  26361. function strToInt(str) {
  26362. var a = 0;
  26363. for (var i = 0; i < str.length; i++) {
  26364. a = (a << 8) | str.charCodeAt(i);
  26365. }
  26366. return a >>> 0;
  26367. }
  26368. function expectString(obj) {
  26369. if (!isString(obj)) {
  26370. error('Malformed CMap: expected string.');
  26371. }
  26372. }
  26373. function expectInt(obj) {
  26374. if (!isInt(obj)) {
  26375. error('Malformed CMap: expected int.');
  26376. }
  26377. }
  26378. function parseBfChar(cMap, lexer) {
  26379. while (true) {
  26380. var obj = lexer.getObj();
  26381. if (isEOF(obj)) {
  26382. break;
  26383. }
  26384. if (isCmd(obj, 'endbfchar')) {
  26385. return;
  26386. }
  26387. expectString(obj);
  26388. var src = strToInt(obj);
  26389. obj = lexer.getObj();
  26390. // TODO are /dstName used?
  26391. expectString(obj);
  26392. var dst = obj;
  26393. cMap.mapOne(src, dst);
  26394. }
  26395. }
  26396. function parseBfRange(cMap, lexer) {
  26397. while (true) {
  26398. var obj = lexer.getObj();
  26399. if (isEOF(obj)) {
  26400. break;
  26401. }
  26402. if (isCmd(obj, 'endbfrange')) {
  26403. return;
  26404. }
  26405. expectString(obj);
  26406. var low = strToInt(obj);
  26407. obj = lexer.getObj();
  26408. expectString(obj);
  26409. var high = strToInt(obj);
  26410. obj = lexer.getObj();
  26411. if (isInt(obj) || isString(obj)) {
  26412. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  26413. cMap.mapBfRange(low, high, dstLow);
  26414. } else if (isCmd(obj, '[')) {
  26415. obj = lexer.getObj();
  26416. var array = [];
  26417. while (!isCmd(obj, ']') && !isEOF(obj)) {
  26418. array.push(obj);
  26419. obj = lexer.getObj();
  26420. }
  26421. cMap.mapBfRangeToArray(low, high, array);
  26422. } else {
  26423. break;
  26424. }
  26425. }
  26426. error('Invalid bf range.');
  26427. }
  26428. function parseCidChar(cMap, lexer) {
  26429. while (true) {
  26430. var obj = lexer.getObj();
  26431. if (isEOF(obj)) {
  26432. break;
  26433. }
  26434. if (isCmd(obj, 'endcidchar')) {
  26435. return;
  26436. }
  26437. expectString(obj);
  26438. var src = strToInt(obj);
  26439. obj = lexer.getObj();
  26440. expectInt(obj);
  26441. var dst = obj;
  26442. cMap.mapOne(src, dst);
  26443. }
  26444. }
  26445. function parseCidRange(cMap, lexer) {
  26446. while (true) {
  26447. var obj = lexer.getObj();
  26448. if (isEOF(obj)) {
  26449. break;
  26450. }
  26451. if (isCmd(obj, 'endcidrange')) {
  26452. return;
  26453. }
  26454. expectString(obj);
  26455. var low = strToInt(obj);
  26456. obj = lexer.getObj();
  26457. expectString(obj);
  26458. var high = strToInt(obj);
  26459. obj = lexer.getObj();
  26460. expectInt(obj);
  26461. var dstLow = obj;
  26462. cMap.mapCidRange(low, high, dstLow);
  26463. }
  26464. }
  26465. function parseCodespaceRange(cMap, lexer) {
  26466. while (true) {
  26467. var obj = lexer.getObj();
  26468. if (isEOF(obj)) {
  26469. break;
  26470. }
  26471. if (isCmd(obj, 'endcodespacerange')) {
  26472. return;
  26473. }
  26474. if (!isString(obj)) {
  26475. break;
  26476. }
  26477. var low = strToInt(obj);
  26478. obj = lexer.getObj();
  26479. if (!isString(obj)) {
  26480. break;
  26481. }
  26482. var high = strToInt(obj);
  26483. cMap.addCodespaceRange(obj.length, low, high);
  26484. }
  26485. error('Invalid codespace range.');
  26486. }
  26487. function parseWMode(cMap, lexer) {
  26488. var obj = lexer.getObj();
  26489. if (isInt(obj)) {
  26490. cMap.vertical = !!obj;
  26491. }
  26492. }
  26493. function parseCMapName(cMap, lexer) {
  26494. var obj = lexer.getObj();
  26495. if (isName(obj) && isString(obj.name)) {
  26496. cMap.name = obj.name;
  26497. }
  26498. }
  26499. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  26500. var previous;
  26501. var embededUseCMap;
  26502. objLoop: while (true) {
  26503. try {
  26504. var obj = lexer.getObj();
  26505. if (isEOF(obj)) {
  26506. break;
  26507. } else if (isName(obj)) {
  26508. if (obj.name === 'WMode') {
  26509. parseWMode(cMap, lexer);
  26510. } else if (obj.name === 'CMapName') {
  26511. parseCMapName(cMap, lexer);
  26512. }
  26513. previous = obj;
  26514. } else if (isCmd(obj)) {
  26515. switch (obj.cmd) {
  26516. case 'endcmap':
  26517. break objLoop;
  26518. case 'usecmap':
  26519. if (isName(previous)) {
  26520. embededUseCMap = previous.name;
  26521. }
  26522. break;
  26523. case 'begincodespacerange':
  26524. parseCodespaceRange(cMap, lexer);
  26525. break;
  26526. case 'beginbfchar':
  26527. parseBfChar(cMap, lexer);
  26528. break;
  26529. case 'begincidchar':
  26530. parseCidChar(cMap, lexer);
  26531. break;
  26532. case 'beginbfrange':
  26533. parseBfRange(cMap, lexer);
  26534. break;
  26535. case 'begincidrange':
  26536. parseCidRange(cMap, lexer);
  26537. break;
  26538. }
  26539. }
  26540. } catch (ex) {
  26541. if (ex instanceof MissingDataException) {
  26542. throw ex;
  26543. }
  26544. warn('Invalid cMap data: ' + ex);
  26545. continue;
  26546. }
  26547. }
  26548. if (!useCMap && embededUseCMap) {
  26549. // Load the usecmap definition from the file only if there wasn't one
  26550. // specified.
  26551. useCMap = embededUseCMap;
  26552. }
  26553. if (useCMap) {
  26554. return extendCMap(cMap, builtInCMapParams, useCMap);
  26555. }
  26556. return Promise.resolve(cMap);
  26557. }
  26558. function extendCMap(cMap, builtInCMapParams, useCMap) {
  26559. return createBuiltInCMap(useCMap, builtInCMapParams).then(
  26560. function(newCMap) {
  26561. cMap.useCMap = newCMap;
  26562. // If there aren't any code space ranges defined clone all the parent ones
  26563. // into this cMap.
  26564. if (cMap.numCodespaceRanges === 0) {
  26565. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  26566. for (var i = 0; i < useCodespaceRanges.length; i++) {
  26567. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  26568. }
  26569. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  26570. }
  26571. // Merge the map into the current one, making sure not to override
  26572. // any previously defined entries.
  26573. cMap.useCMap.forEach(function(key, value) {
  26574. if (!cMap.contains(key)) {
  26575. cMap.mapOne(key, cMap.useCMap.lookup(key));
  26576. }
  26577. });
  26578. return cMap;
  26579. });
  26580. }
  26581. function parseBinaryCMap(name, builtInCMapParams) {
  26582. var url = builtInCMapParams.url + name + '.bcmap';
  26583. var cMap = new CMap(true);
  26584. return new BinaryCMapReader().read(url, cMap, function (useCMap) {
  26585. return extendCMap(cMap, builtInCMapParams, useCMap);
  26586. });
  26587. }
  26588. function createBuiltInCMap(name, builtInCMapParams) {
  26589. if (name === 'Identity-H') {
  26590. return Promise.resolve(new IdentityCMap(false, 2));
  26591. } else if (name === 'Identity-V') {
  26592. return Promise.resolve(new IdentityCMap(true, 2));
  26593. }
  26594. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  26595. return Promise.reject(new Error('Unknown cMap name: ' + name));
  26596. }
  26597. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  26598. if (builtInCMapParams.packed) {
  26599. return parseBinaryCMap(name, builtInCMapParams);
  26600. }
  26601. return new Promise(function (resolve, reject) {
  26602. var url = builtInCMapParams.url + name;
  26603. var request = new XMLHttpRequest();
  26604. request.onreadystatechange = function () {
  26605. if (request.readyState === XMLHttpRequest.DONE) {
  26606. if (request.status === 200 || request.status === 0) {
  26607. var cMap = new CMap(true);
  26608. var lexer = new Lexer(new StringStream(request.responseText));
  26609. parseCMap(cMap, lexer, builtInCMapParams, null).then(
  26610. function (parsedCMap) {
  26611. resolve(parsedCMap);
  26612. });
  26613. } else {
  26614. reject(new Error('Unable to get cMap at: ' + url));
  26615. }
  26616. }
  26617. };
  26618. request.open('GET', url, true);
  26619. request.send(null);
  26620. });
  26621. }
  26622. return {
  26623. create: function (encoding, builtInCMapParams, useCMap) {
  26624. if (isName(encoding)) {
  26625. return createBuiltInCMap(encoding.name, builtInCMapParams);
  26626. } else if (isStream(encoding)) {
  26627. var cMap = new CMap();
  26628. var lexer = new Lexer(encoding);
  26629. return parseCMap(cMap, lexer, builtInCMapParams, useCMap).then(
  26630. function (parsedCMap) {
  26631. if (parsedCMap.isIdentityCMap) {
  26632. return createBuiltInCMap(parsedCMap.name, builtInCMapParams);
  26633. }
  26634. return parsedCMap;
  26635. });
  26636. }
  26637. return Promise.reject(new Error('Encoding required.'));
  26638. }
  26639. };
  26640. })();
  26641. exports.CMap = CMap;
  26642. exports.CMapFactory = CMapFactory;
  26643. exports.IdentityCMap = IdentityCMap;
  26644. }));
  26645. (function (root, factory) {
  26646. {
  26647. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  26648. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreGlyphList,
  26649. root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings,
  26650. root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode,
  26651. root.pdfjsCoreType1Parser, root.pdfjsCoreCFFParser);
  26652. }
  26653. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  26654. coreGlyphList, coreFontRenderer, coreEncodings,
  26655. coreStandardFonts, coreUnicode, coreType1Parser,
  26656. coreCFFParser) {
  26657. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  26658. var FontType = sharedUtil.FontType;
  26659. var assert = sharedUtil.assert;
  26660. var bytesToString = sharedUtil.bytesToString;
  26661. var error = sharedUtil.error;
  26662. var info = sharedUtil.info;
  26663. var isArray = sharedUtil.isArray;
  26664. var isInt = sharedUtil.isInt;
  26665. var isNum = sharedUtil.isNum;
  26666. var readUint32 = sharedUtil.readUint32;
  26667. var shadow = sharedUtil.shadow;
  26668. var string32 = sharedUtil.string32;
  26669. var warn = sharedUtil.warn;
  26670. var MissingDataException = sharedUtil.MissingDataException;
  26671. var isSpace = sharedUtil.isSpace;
  26672. var Stream = coreStream.Stream;
  26673. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  26674. var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
  26675. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  26676. var StandardEncoding = coreEncodings.StandardEncoding;
  26677. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  26678. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  26679. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  26680. var getEncoding = coreEncodings.getEncoding;
  26681. var getStdFontMap = coreStandardFonts.getStdFontMap;
  26682. var getNonStdFontMap = coreStandardFonts.getNonStdFontMap;
  26683. var getGlyphMapForStandardFonts = coreStandardFonts.getGlyphMapForStandardFonts;
  26684. var getSupplementalGlyphMapForArialBlack =
  26685. coreStandardFonts.getSupplementalGlyphMapForArialBlack;
  26686. var getUnicodeRangeFor = coreUnicode.getUnicodeRangeFor;
  26687. var mapSpecialUnicodeValues = coreUnicode.mapSpecialUnicodeValues;
  26688. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  26689. var Type1Parser = coreType1Parser.Type1Parser;
  26690. var CFFStandardStrings = coreCFFParser.CFFStandardStrings;
  26691. var CFFParser = coreCFFParser.CFFParser;
  26692. var CFFCompiler = coreCFFParser.CFFCompiler;
  26693. var CFF = coreCFFParser.CFF;
  26694. var CFFHeader = coreCFFParser.CFFHeader;
  26695. var CFFTopDict = coreCFFParser.CFFTopDict;
  26696. var CFFPrivateDict = coreCFFParser.CFFPrivateDict;
  26697. var CFFStrings = coreCFFParser.CFFStrings;
  26698. var CFFIndex = coreCFFParser.CFFIndex;
  26699. var CFFCharset = coreCFFParser.CFFCharset;
  26700. // Unicode Private Use Area
  26701. var PRIVATE_USE_OFFSET_START = 0xE000;
  26702. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  26703. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  26704. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  26705. // except for Type 3 fonts
  26706. var PDF_GLYPH_SPACE_UNITS = 1000;
  26707. // Accented charactars are not displayed properly on Windows, using this flag
  26708. // to control analysis of seac charstrings.
  26709. var SEAC_ANALYSIS_ENABLED = false;
  26710. var FontFlags = {
  26711. FixedPitch: 1,
  26712. Serif: 2,
  26713. Symbolic: 4,
  26714. Script: 8,
  26715. Nonsymbolic: 32,
  26716. Italic: 64,
  26717. AllCap: 65536,
  26718. SmallCap: 131072,
  26719. ForceBold: 262144
  26720. };
  26721. var MacStandardGlyphOrdering = [
  26722. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  26723. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  26724. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  26725. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  26726. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  26727. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  26728. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  26729. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  26730. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  26731. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  26732. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  26733. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  26734. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  26735. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  26736. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  26737. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  26738. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  26739. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  26740. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  26741. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  26742. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  26743. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  26744. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  26745. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  26746. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  26747. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  26748. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  26749. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  26750. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  26751. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  26752. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  26753. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  26754. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  26755. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  26756. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  26757. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  26758. function adjustWidths(properties) {
  26759. if (!properties.fontMatrix) {
  26760. return;
  26761. }
  26762. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  26763. return;
  26764. }
  26765. // adjusting width to fontMatrix scale
  26766. var scale = 0.001 / properties.fontMatrix[0];
  26767. var glyphsWidths = properties.widths;
  26768. for (var glyph in glyphsWidths) {
  26769. glyphsWidths[glyph] *= scale;
  26770. }
  26771. properties.defaultWidth *= scale;
  26772. }
  26773. function adjustToUnicode(properties, builtInEncoding) {
  26774. if (properties.hasIncludedToUnicodeMap) {
  26775. return; // The font dictionary has a `ToUnicode` entry.
  26776. }
  26777. if (properties.hasEncoding) {
  26778. return; // The font dictionary has an `Encoding` entry.
  26779. }
  26780. if (builtInEncoding === properties.defaultEncoding) {
  26781. return; // No point in trying to adjust `toUnicode` if the encodings match.
  26782. }
  26783. if (properties.toUnicode instanceof IdentityToUnicodeMap) {
  26784. return;
  26785. }
  26786. var toUnicode = [], glyphsUnicodeMap = getGlyphsUnicode();
  26787. for (var charCode in builtInEncoding) {
  26788. var glyphName = builtInEncoding[charCode];
  26789. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  26790. if (unicode !== -1) {
  26791. toUnicode[charCode] = String.fromCharCode(unicode);
  26792. }
  26793. }
  26794. properties.toUnicode.amend(toUnicode);
  26795. }
  26796. function getFontType(type, subtype) {
  26797. switch (type) {
  26798. case 'Type1':
  26799. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  26800. case 'CIDFontType0':
  26801. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  26802. FontType.CIDFONTTYPE0;
  26803. case 'OpenType':
  26804. return FontType.OPENTYPE;
  26805. case 'TrueType':
  26806. return FontType.TRUETYPE;
  26807. case 'CIDFontType2':
  26808. return FontType.CIDFONTTYPE2;
  26809. case 'MMType1':
  26810. return FontType.MMTYPE1;
  26811. case 'Type0':
  26812. return FontType.TYPE0;
  26813. default:
  26814. return FontType.UNKNOWN;
  26815. }
  26816. }
  26817. // Some bad PDF generators, e.g. Scribus PDF, include glyph names
  26818. // in a 'uniXXXX' format -- attempting to recover proper ones.
  26819. function recoverGlyphName(name, glyphsUnicodeMap) {
  26820. if (glyphsUnicodeMap[name] !== undefined) {
  26821. return name;
  26822. }
  26823. // The glyph name is non-standard, trying to recover.
  26824. var unicode = getUnicodeForGlyph(name, glyphsUnicodeMap);
  26825. if (unicode !== -1) {
  26826. for (var key in glyphsUnicodeMap) {
  26827. if (glyphsUnicodeMap[key] === unicode) {
  26828. return key;
  26829. }
  26830. }
  26831. }
  26832. info('Unable to recover a standard glyph name for: ' + name);
  26833. return name;
  26834. }
  26835. var Glyph = (function GlyphClosure() {
  26836. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  26837. isSpace, isInFont) {
  26838. this.fontChar = fontChar;
  26839. this.unicode = unicode;
  26840. this.accent = accent;
  26841. this.width = width;
  26842. this.vmetric = vmetric;
  26843. this.operatorListId = operatorListId;
  26844. this.isSpace = isSpace;
  26845. this.isInFont = isInFont;
  26846. }
  26847. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  26848. vmetric, operatorListId, isSpace,
  26849. isInFont) {
  26850. return this.fontChar === fontChar &&
  26851. this.unicode === unicode &&
  26852. this.accent === accent &&
  26853. this.width === width &&
  26854. this.vmetric === vmetric &&
  26855. this.operatorListId === operatorListId &&
  26856. this.isSpace === isSpace &&
  26857. this.isInFont === isInFont;
  26858. };
  26859. return Glyph;
  26860. })();
  26861. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  26862. function ToUnicodeMap(cmap) {
  26863. // The elements of this._map can be integers or strings, depending on how
  26864. // |cmap| was created.
  26865. this._map = cmap;
  26866. }
  26867. ToUnicodeMap.prototype = {
  26868. get length() {
  26869. return this._map.length;
  26870. },
  26871. forEach: function(callback) {
  26872. for (var charCode in this._map) {
  26873. callback(charCode, this._map[charCode].charCodeAt(0));
  26874. }
  26875. },
  26876. has: function(i) {
  26877. return this._map[i] !== undefined;
  26878. },
  26879. get: function(i) {
  26880. return this._map[i];
  26881. },
  26882. charCodeOf: function(v) {
  26883. return this._map.indexOf(v);
  26884. },
  26885. amend: function (map) {
  26886. for (var charCode in map) {
  26887. this._map[charCode] = map[charCode];
  26888. }
  26889. },
  26890. };
  26891. return ToUnicodeMap;
  26892. })();
  26893. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  26894. function IdentityToUnicodeMap(firstChar, lastChar) {
  26895. this.firstChar = firstChar;
  26896. this.lastChar = lastChar;
  26897. }
  26898. IdentityToUnicodeMap.prototype = {
  26899. get length() {
  26900. return (this.lastChar + 1) - this.firstChar;
  26901. },
  26902. forEach: function (callback) {
  26903. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  26904. callback(i, i);
  26905. }
  26906. },
  26907. has: function (i) {
  26908. return this.firstChar <= i && i <= this.lastChar;
  26909. },
  26910. get: function (i) {
  26911. if (this.firstChar <= i && i <= this.lastChar) {
  26912. return String.fromCharCode(i);
  26913. }
  26914. return undefined;
  26915. },
  26916. charCodeOf: function (v) {
  26917. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  26918. },
  26919. amend: function (map) {
  26920. error('Should not call amend()');
  26921. },
  26922. };
  26923. return IdentityToUnicodeMap;
  26924. })();
  26925. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  26926. function writeInt16(dest, offset, num) {
  26927. dest[offset] = (num >> 8) & 0xFF;
  26928. dest[offset + 1] = num & 0xFF;
  26929. }
  26930. function writeInt32(dest, offset, num) {
  26931. dest[offset] = (num >> 24) & 0xFF;
  26932. dest[offset + 1] = (num >> 16) & 0xFF;
  26933. dest[offset + 2] = (num >> 8) & 0xFF;
  26934. dest[offset + 3] = num & 0xFF;
  26935. }
  26936. function writeData(dest, offset, data) {
  26937. var i, ii;
  26938. if (data instanceof Uint8Array) {
  26939. dest.set(data, offset);
  26940. } else if (typeof data === 'string') {
  26941. for (i = 0, ii = data.length; i < ii; i++) {
  26942. dest[offset++] = data.charCodeAt(i) & 0xFF;
  26943. }
  26944. } else {
  26945. // treating everything else as array
  26946. for (i = 0, ii = data.length; i < ii; i++) {
  26947. dest[offset++] = data[i] & 0xFF;
  26948. }
  26949. }
  26950. }
  26951. function OpenTypeFileBuilder(sfnt) {
  26952. this.sfnt = sfnt;
  26953. this.tables = Object.create(null);
  26954. }
  26955. OpenTypeFileBuilder.getSearchParams =
  26956. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  26957. var maxPower2 = 1, log2 = 0;
  26958. while ((maxPower2 ^ entriesCount) > maxPower2) {
  26959. maxPower2 <<= 1;
  26960. log2++;
  26961. }
  26962. var searchRange = maxPower2 * entrySize;
  26963. return {
  26964. range: searchRange,
  26965. entry: log2,
  26966. rangeShift: entrySize * entriesCount - searchRange
  26967. };
  26968. };
  26969. var OTF_HEADER_SIZE = 12;
  26970. var OTF_TABLE_ENTRY_SIZE = 16;
  26971. OpenTypeFileBuilder.prototype = {
  26972. toArray: function OpenTypeFileBuilder_toArray() {
  26973. var sfnt = this.sfnt;
  26974. // Tables needs to be written by ascendant alphabetic order
  26975. var tables = this.tables;
  26976. var tablesNames = Object.keys(tables);
  26977. tablesNames.sort();
  26978. var numTables = tablesNames.length;
  26979. var i, j, jj, table, tableName;
  26980. // layout the tables data
  26981. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  26982. var tableOffsets = [offset];
  26983. for (i = 0; i < numTables; i++) {
  26984. table = tables[tablesNames[i]];
  26985. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  26986. offset += paddedLength;
  26987. tableOffsets.push(offset);
  26988. }
  26989. var file = new Uint8Array(offset);
  26990. // write the table data first (mostly for checksum)
  26991. for (i = 0; i < numTables; i++) {
  26992. table = tables[tablesNames[i]];
  26993. writeData(file, tableOffsets[i], table);
  26994. }
  26995. // sfnt version (4 bytes)
  26996. if (sfnt === 'true') {
  26997. // Windows hates the Mac TrueType sfnt version number
  26998. sfnt = string32(0x00010000);
  26999. }
  27000. file[0] = sfnt.charCodeAt(0) & 0xFF;
  27001. file[1] = sfnt.charCodeAt(1) & 0xFF;
  27002. file[2] = sfnt.charCodeAt(2) & 0xFF;
  27003. file[3] = sfnt.charCodeAt(3) & 0xFF;
  27004. // numTables (2 bytes)
  27005. writeInt16(file, 4, numTables);
  27006. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  27007. // searchRange (2 bytes)
  27008. writeInt16(file, 6, searchParams.range);
  27009. // entrySelector (2 bytes)
  27010. writeInt16(file, 8, searchParams.entry);
  27011. // rangeShift (2 bytes)
  27012. writeInt16(file, 10, searchParams.rangeShift);
  27013. offset = OTF_HEADER_SIZE;
  27014. // writing table entries
  27015. for (i = 0; i < numTables; i++) {
  27016. tableName = tablesNames[i];
  27017. file[offset] = tableName.charCodeAt(0) & 0xFF;
  27018. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  27019. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  27020. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  27021. // checksum
  27022. var checksum = 0;
  27023. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  27024. var quad = readUint32(file, j);
  27025. checksum = (checksum + quad) >>> 0;
  27026. }
  27027. writeInt32(file, offset + 4, checksum);
  27028. // offset
  27029. writeInt32(file, offset + 8, tableOffsets[i]);
  27030. // length
  27031. writeInt32(file, offset + 12, tables[tableName].length);
  27032. offset += OTF_TABLE_ENTRY_SIZE;
  27033. }
  27034. return file;
  27035. },
  27036. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  27037. if (tag in this.tables) {
  27038. throw new Error('Table ' + tag + ' already exists');
  27039. }
  27040. this.tables[tag] = data;
  27041. }
  27042. };
  27043. return OpenTypeFileBuilder;
  27044. })();
  27045. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  27046. // issues when they are painted on the canvas, e.g. complex-script shaping or
  27047. // control/whitespace characters. The ranges are listed in pairs: the first item
  27048. // is a code of the first problematic code, the second one is the next
  27049. // non-problematic code. The ranges must be in sorted order.
  27050. var ProblematicCharRanges = new Int32Array([
  27051. // Control characters.
  27052. 0x0000, 0x0020,
  27053. 0x007F, 0x00A1,
  27054. 0x00AD, 0x00AE,
  27055. // Chars that is used in complex-script shaping.
  27056. 0x0600, 0x0780,
  27057. 0x08A0, 0x10A0,
  27058. 0x1780, 0x1800,
  27059. 0x1C00, 0x1C50,
  27060. // General punctuation chars.
  27061. 0x2000, 0x2010,
  27062. 0x2011, 0x2012,
  27063. 0x2028, 0x2030,
  27064. 0x205F, 0x2070,
  27065. 0x25CC, 0x25CD,
  27066. 0x3000, 0x3001,
  27067. // Chars that is used in complex-script shaping.
  27068. 0xAA60, 0xAA80,
  27069. // Specials Unicode block.
  27070. 0xFFF0, 0x10000
  27071. ]);
  27072. /**
  27073. * 'Font' is the class the outside world should use, it encapsulate all the font
  27074. * decoding logics whatever type it is (assuming the font type is supported).
  27075. *
  27076. * For example to read a Type1 font and to attach it to the document:
  27077. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  27078. * type1Font.bind();
  27079. */
  27080. var Font = (function FontClosure() {
  27081. function Font(name, file, properties) {
  27082. var charCode, glyphName, unicode;
  27083. this.name = name;
  27084. this.loadedName = properties.loadedName;
  27085. this.isType3Font = properties.isType3Font;
  27086. this.sizes = [];
  27087. this.missingFile = false;
  27088. this.glyphCache = Object.create(null);
  27089. var names = name.split('+');
  27090. names = names.length > 1 ? names[1] : names[0];
  27091. names = names.split(/[-,_]/g)[0];
  27092. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  27093. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  27094. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  27095. var type = properties.type;
  27096. var subtype = properties.subtype;
  27097. this.type = type;
  27098. this.fallbackName = (this.isMonospace ? 'monospace' :
  27099. (this.isSerifFont ? 'serif' : 'sans-serif'));
  27100. this.differences = properties.differences;
  27101. this.widths = properties.widths;
  27102. this.defaultWidth = properties.defaultWidth;
  27103. this.composite = properties.composite;
  27104. this.wideChars = properties.wideChars;
  27105. this.cMap = properties.cMap;
  27106. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  27107. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  27108. this.fontMatrix = properties.fontMatrix;
  27109. this.bbox = properties.bbox;
  27110. this.toUnicode = properties.toUnicode;
  27111. this.toFontChar = [];
  27112. if (properties.type === 'Type3') {
  27113. for (charCode = 0; charCode < 256; charCode++) {
  27114. this.toFontChar[charCode] = (this.differences[charCode] ||
  27115. properties.defaultEncoding[charCode]);
  27116. }
  27117. this.fontType = FontType.TYPE3;
  27118. return;
  27119. }
  27120. this.cidEncoding = properties.cidEncoding;
  27121. this.vertical = properties.vertical;
  27122. if (this.vertical) {
  27123. this.vmetrics = properties.vmetrics;
  27124. this.defaultVMetrics = properties.defaultVMetrics;
  27125. }
  27126. var glyphsUnicodeMap;
  27127. if (!file || file.isEmpty) {
  27128. if (file) {
  27129. // Some bad PDF generators will include empty font files,
  27130. // attempting to recover by assuming that no file exists.
  27131. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  27132. }
  27133. this.missingFile = true;
  27134. // The file data is not specified. Trying to fix the font name
  27135. // to be used with the canvas.font.
  27136. var fontName = name.replace(/[,_]/g, '-');
  27137. var stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap();
  27138. var isStandardFont = !!stdFontMap[fontName] ||
  27139. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  27140. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  27141. this.bold = (fontName.search(/bold/gi) !== -1);
  27142. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  27143. (fontName.search(/italic/gi) !== -1));
  27144. // Use 'name' instead of 'fontName' here because the original
  27145. // name ArialBlack for example will be replaced by Helvetica.
  27146. this.black = (name.search(/Black/g) !== -1);
  27147. // if at least one width is present, remeasure all chars when exists
  27148. this.remeasure = Object.keys(this.widths).length > 0;
  27149. if (isStandardFont && type === 'CIDFontType2' &&
  27150. properties.cidEncoding.indexOf('Identity-') === 0) {
  27151. var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
  27152. // Standard fonts might be embedded as CID font without glyph mapping.
  27153. // Building one based on GlyphMapForStandardFonts.
  27154. var map = [];
  27155. for (charCode in GlyphMapForStandardFonts) {
  27156. map[+charCode] = GlyphMapForStandardFonts[charCode];
  27157. }
  27158. if (/ArialBlack/i.test(name)) {
  27159. var SupplementalGlyphMapForArialBlack =
  27160. getSupplementalGlyphMapForArialBlack();
  27161. for (charCode in SupplementalGlyphMapForArialBlack) {
  27162. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  27163. }
  27164. }
  27165. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  27166. if (!isIdentityUnicode) {
  27167. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  27168. map[+charCode] = unicodeCharCode;
  27169. });
  27170. }
  27171. this.toFontChar = map;
  27172. this.toUnicode = new ToUnicodeMap(map);
  27173. } else if (/Symbol/i.test(fontName)) {
  27174. this.toFontChar = buildToFontChar(SymbolSetEncoding, getGlyphsUnicode(),
  27175. properties.differences);
  27176. } else if (/Dingbats/i.test(fontName)) {
  27177. if (/Wingdings/i.test(name)) {
  27178. warn('Non-embedded Wingdings font, falling back to ZapfDingbats.');
  27179. }
  27180. this.toFontChar = buildToFontChar(ZapfDingbatsEncoding,
  27181. getDingbatsGlyphsUnicode(),
  27182. properties.differences);
  27183. } else if (isStandardFont) {
  27184. this.toFontChar = buildToFontChar(properties.defaultEncoding,
  27185. getGlyphsUnicode(),
  27186. properties.differences);
  27187. } else {
  27188. glyphsUnicodeMap = getGlyphsUnicode();
  27189. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  27190. if (!this.composite) {
  27191. glyphName = (properties.differences[charCode] ||
  27192. properties.defaultEncoding[charCode]);
  27193. unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  27194. if (unicode !== -1) {
  27195. unicodeCharCode = unicode;
  27196. }
  27197. }
  27198. this.toFontChar[charCode] = unicodeCharCode;
  27199. }.bind(this));
  27200. }
  27201. this.loadedName = fontName.split('-')[0];
  27202. this.loading = false;
  27203. this.fontType = getFontType(type, subtype);
  27204. return;
  27205. }
  27206. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  27207. if (subtype === 'Type1C') {
  27208. if (type !== 'Type1' && type !== 'MMType1') {
  27209. // Some TrueType fonts by mistake claim Type1C
  27210. if (isTrueTypeFile(file)) {
  27211. subtype = 'TrueType';
  27212. } else {
  27213. type = 'Type1';
  27214. }
  27215. } else if (isOpenTypeFile(file)) {
  27216. // Sometimes the type/subtype can be a complete lie (see issue7598.pdf).
  27217. type = subtype = 'OpenType';
  27218. }
  27219. }
  27220. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  27221. type = 'CIDFontType0';
  27222. }
  27223. if (subtype === 'OpenType') {
  27224. type = 'OpenType';
  27225. }
  27226. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  27227. if (type === 'CIDFontType0') {
  27228. if (isType1File(file)) {
  27229. subtype = 'CIDFontType0';
  27230. } else if (isOpenTypeFile(file)) {
  27231. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  27232. type = subtype = 'OpenType';
  27233. } else {
  27234. subtype = 'CIDFontType0C';
  27235. }
  27236. }
  27237. var data;
  27238. switch (type) {
  27239. case 'MMType1':
  27240. info('MMType1 font (' + name + '), falling back to Type1.');
  27241. /* falls through */
  27242. case 'Type1':
  27243. case 'CIDFontType0':
  27244. this.mimetype = 'font/opentype';
  27245. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  27246. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  27247. adjustWidths(properties);
  27248. // Wrap the CFF data inside an OTF font file
  27249. data = this.convert(name, cff, properties);
  27250. break;
  27251. case 'OpenType':
  27252. case 'TrueType':
  27253. case 'CIDFontType2':
  27254. this.mimetype = 'font/opentype';
  27255. // Repair the TrueType file. It is can be damaged in the point of
  27256. // view of the sanitizer
  27257. data = this.checkAndRepair(name, file, properties);
  27258. if (this.isOpenType) {
  27259. adjustWidths(properties);
  27260. type = 'OpenType';
  27261. }
  27262. break;
  27263. default:
  27264. error('Font ' + type + ' is not supported');
  27265. break;
  27266. }
  27267. this.data = data;
  27268. this.fontType = getFontType(type, subtype);
  27269. // Transfer some properties again that could change during font conversion
  27270. this.fontMatrix = properties.fontMatrix;
  27271. this.widths = properties.widths;
  27272. this.defaultWidth = properties.defaultWidth;
  27273. this.toUnicode = properties.toUnicode;
  27274. this.encoding = properties.baseEncoding;
  27275. this.seacMap = properties.seacMap;
  27276. this.loading = true;
  27277. }
  27278. Font.getFontID = (function () {
  27279. var ID = 1;
  27280. return function Font_getFontID() {
  27281. return String(ID++);
  27282. };
  27283. })();
  27284. function int16(b0, b1) {
  27285. return (b0 << 8) + b1;
  27286. }
  27287. function signedInt16(b0, b1) {
  27288. var value = (b0 << 8) + b1;
  27289. return value & (1 << 15) ? value - 0x10000 : value;
  27290. }
  27291. function int32(b0, b1, b2, b3) {
  27292. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  27293. }
  27294. function string16(value) {
  27295. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  27296. }
  27297. function safeString16(value) {
  27298. // clamp value to the 16-bit int range
  27299. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  27300. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  27301. }
  27302. function isTrueTypeFile(file) {
  27303. var header = file.peekBytes(4);
  27304. return readUint32(header, 0) === 0x00010000;
  27305. }
  27306. function isOpenTypeFile(file) {
  27307. var header = file.peekBytes(4);
  27308. return bytesToString(header) === 'OTTO';
  27309. }
  27310. function isType1File(file) {
  27311. var header = file.peekBytes(2);
  27312. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  27313. if (header[0] === 0x25 && header[1] === 0x21) {
  27314. return true;
  27315. }
  27316. // ... obviously some fonts violate that part of the specification,
  27317. // please refer to the comment in |Type1Font| below.
  27318. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  27319. return true;
  27320. }
  27321. return false;
  27322. }
  27323. function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
  27324. var toFontChar = [], unicode;
  27325. for (var i = 0, ii = encoding.length; i < ii; i++) {
  27326. unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap);
  27327. if (unicode !== -1) {
  27328. toFontChar[i] = unicode;
  27329. }
  27330. }
  27331. for (var charCode in differences) {
  27332. unicode = getUnicodeForGlyph(differences[charCode], glyphsUnicodeMap);
  27333. if (unicode !== -1) {
  27334. toFontChar[+charCode] = unicode;
  27335. }
  27336. }
  27337. return toFontChar;
  27338. }
  27339. /**
  27340. * Helper function for `adjustMapping`.
  27341. * @return {boolean}
  27342. */
  27343. function isProblematicUnicodeLocation(code) {
  27344. // Using binary search to find a range start.
  27345. var i = 0, j = ProblematicCharRanges.length - 1;
  27346. while (i < j) {
  27347. var c = (i + j + 1) >> 1;
  27348. if (code < ProblematicCharRanges[c]) {
  27349. j = c - 1;
  27350. } else {
  27351. i = c;
  27352. }
  27353. }
  27354. // Even index means code in problematic range.
  27355. return !(i & 1);
  27356. }
  27357. /**
  27358. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  27359. * with their unicode value. It also moves char codes that are in known
  27360. * problematic locations.
  27361. * @return {Object} Two properties:
  27362. * 'toFontChar' - maps original char codes(the value that will be read
  27363. * from commands such as show text) to the char codes that will be used in the
  27364. * font that we build
  27365. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  27366. */
  27367. function adjustMapping(charCodeToGlyphId, properties) {
  27368. var toUnicode = properties.toUnicode;
  27369. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  27370. var isIdentityUnicode =
  27371. properties.toUnicode instanceof IdentityToUnicodeMap;
  27372. var newMap = Object.create(null);
  27373. var toFontChar = [];
  27374. var usedFontCharCodes = [];
  27375. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  27376. for (var originalCharCode in charCodeToGlyphId) {
  27377. originalCharCode |= 0;
  27378. var glyphId = charCodeToGlyphId[originalCharCode];
  27379. var fontCharCode = originalCharCode;
  27380. // First try to map the value to a unicode position if a non identity map
  27381. // was created.
  27382. var hasUnicodeValue = false;
  27383. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  27384. hasUnicodeValue = true;
  27385. var unicode = toUnicode.get(fontCharCode);
  27386. // TODO: Try to map ligatures to the correct spot.
  27387. if (unicode.length === 1) {
  27388. fontCharCode = unicode.charCodeAt(0);
  27389. }
  27390. }
  27391. // Try to move control characters, special characters and already mapped
  27392. // characters to the private use area since they will not be drawn by
  27393. // canvas if left in their current position. Also, move characters if the
  27394. // font was symbolic and there is only an identity unicode map since the
  27395. // characters probably aren't in the correct position (fixes an issue
  27396. // with firefox and thuluthfont).
  27397. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  27398. isProblematicUnicodeLocation(fontCharCode) ||
  27399. (isSymbolic && !hasUnicodeValue)) &&
  27400. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  27401. // Loop to try and find a free spot in the private use area.
  27402. do {
  27403. fontCharCode = nextAvailableFontCharCode++;
  27404. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  27405. fontCharCode = 0xF020;
  27406. nextAvailableFontCharCode = fontCharCode + 1;
  27407. }
  27408. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  27409. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  27410. }
  27411. newMap[fontCharCode] = glyphId;
  27412. toFontChar[originalCharCode] = fontCharCode;
  27413. usedFontCharCodes[fontCharCode] = true;
  27414. }
  27415. return {
  27416. toFontChar: toFontChar,
  27417. charCodeToGlyphId: newMap,
  27418. nextAvailableFontCharCode: nextAvailableFontCharCode
  27419. };
  27420. }
  27421. function getRanges(glyphs, numGlyphs) {
  27422. // Array.sort() sorts by characters, not numerically, so convert to an
  27423. // array of characters.
  27424. var codes = [];
  27425. for (var charCode in glyphs) {
  27426. // Remove an invalid glyph ID mappings to make OTS happy.
  27427. if (glyphs[charCode] >= numGlyphs) {
  27428. continue;
  27429. }
  27430. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  27431. }
  27432. codes.sort(function fontGetRangesSort(a, b) {
  27433. return a.fontCharCode - b.fontCharCode;
  27434. });
  27435. // Split the sorted codes into ranges.
  27436. var ranges = [];
  27437. var length = codes.length;
  27438. for (var n = 0; n < length; ) {
  27439. var start = codes[n].fontCharCode;
  27440. var codeIndices = [codes[n].glyphId];
  27441. ++n;
  27442. var end = start;
  27443. while (n < length && end + 1 === codes[n].fontCharCode) {
  27444. codeIndices.push(codes[n].glyphId);
  27445. ++end;
  27446. ++n;
  27447. if (end === 0xFFFF) {
  27448. break;
  27449. }
  27450. }
  27451. ranges.push([start, end, codeIndices]);
  27452. }
  27453. return ranges;
  27454. }
  27455. function createCmapTable(glyphs, numGlyphs) {
  27456. var ranges = getRanges(glyphs, numGlyphs);
  27457. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  27458. var cmap = '\x00\x00' + // version
  27459. string16(numTables) + // numTables
  27460. '\x00\x03' + // platformID
  27461. '\x00\x01' + // encodingID
  27462. string32(4 + numTables * 8); // start of the table record
  27463. var i, ii, j, jj;
  27464. for (i = ranges.length - 1; i >= 0; --i) {
  27465. if (ranges[i][0] <= 0xFFFF) { break; }
  27466. }
  27467. var bmpLength = i + 1;
  27468. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  27469. ranges[i][1] = 0xFFFE;
  27470. }
  27471. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  27472. var segCount = bmpLength + trailingRangesCount;
  27473. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  27474. // Fill up the 4 parallel arrays describing the segments.
  27475. var startCount = '';
  27476. var endCount = '';
  27477. var idDeltas = '';
  27478. var idRangeOffsets = '';
  27479. var glyphsIds = '';
  27480. var bias = 0;
  27481. var range, start, end, codes;
  27482. for (i = 0, ii = bmpLength; i < ii; i++) {
  27483. range = ranges[i];
  27484. start = range[0];
  27485. end = range[1];
  27486. startCount += string16(start);
  27487. endCount += string16(end);
  27488. codes = range[2];
  27489. var contiguous = true;
  27490. for (j = 1, jj = codes.length; j < jj; ++j) {
  27491. if (codes[j] !== codes[j - 1] + 1) {
  27492. contiguous = false;
  27493. break;
  27494. }
  27495. }
  27496. if (!contiguous) {
  27497. var offset = (segCount - i) * 2 + bias * 2;
  27498. bias += (end - start + 1);
  27499. idDeltas += string16(0);
  27500. idRangeOffsets += string16(offset);
  27501. for (j = 0, jj = codes.length; j < jj; ++j) {
  27502. glyphsIds += string16(codes[j]);
  27503. }
  27504. } else {
  27505. var startCode = codes[0];
  27506. idDeltas += string16((startCode - start) & 0xFFFF);
  27507. idRangeOffsets += string16(0);
  27508. }
  27509. }
  27510. if (trailingRangesCount > 0) {
  27511. endCount += '\xFF\xFF';
  27512. startCount += '\xFF\xFF';
  27513. idDeltas += '\x00\x01';
  27514. idRangeOffsets += '\x00\x00';
  27515. }
  27516. var format314 = '\x00\x00' + // language
  27517. string16(2 * segCount) +
  27518. string16(searchParams.range) +
  27519. string16(searchParams.entry) +
  27520. string16(searchParams.rangeShift) +
  27521. endCount + '\x00\x00' + startCount +
  27522. idDeltas + idRangeOffsets + glyphsIds;
  27523. var format31012 = '';
  27524. var header31012 = '';
  27525. if (numTables > 1) {
  27526. cmap += '\x00\x03' + // platformID
  27527. '\x00\x0A' + // encodingID
  27528. string32(4 + numTables * 8 +
  27529. 4 + format314.length); // start of the table record
  27530. format31012 = '';
  27531. for (i = 0, ii = ranges.length; i < ii; i++) {
  27532. range = ranges[i];
  27533. start = range[0];
  27534. codes = range[2];
  27535. var code = codes[0];
  27536. for (j = 1, jj = codes.length; j < jj; ++j) {
  27537. if (codes[j] !== codes[j - 1] + 1) {
  27538. end = range[0] + j - 1;
  27539. format31012 += string32(start) + // startCharCode
  27540. string32(end) + // endCharCode
  27541. string32(code); // startGlyphID
  27542. start = end + 1;
  27543. code = codes[j];
  27544. }
  27545. }
  27546. format31012 += string32(start) + // startCharCode
  27547. string32(range[1]) + // endCharCode
  27548. string32(code); // startGlyphID
  27549. }
  27550. header31012 = '\x00\x0C' + // format
  27551. '\x00\x00' + // reserved
  27552. string32(format31012.length + 16) + // length
  27553. '\x00\x00\x00\x00' + // language
  27554. string32(format31012.length / 12); // nGroups
  27555. }
  27556. return cmap + '\x00\x04' + // format
  27557. string16(format314.length + 4) + // length
  27558. format314 + header31012 + format31012;
  27559. }
  27560. function validateOS2Table(os2) {
  27561. var stream = new Stream(os2.data);
  27562. var version = stream.getUint16();
  27563. // TODO verify all OS/2 tables fields, but currently we validate only those
  27564. // that give us issues
  27565. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  27566. var selection = stream.getUint16();
  27567. if (version < 4 && (selection & 0x0300)) {
  27568. return false;
  27569. }
  27570. var firstChar = stream.getUint16();
  27571. var lastChar = stream.getUint16();
  27572. if (firstChar > lastChar) {
  27573. return false;
  27574. }
  27575. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  27576. var usWinAscent = stream.getUint16();
  27577. if (usWinAscent === 0) { // makes font unreadable by windows
  27578. return false;
  27579. }
  27580. // OS/2 appears to be valid, resetting some fields
  27581. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  27582. return true;
  27583. }
  27584. function createOS2Table(properties, charstrings, override) {
  27585. override = override || {
  27586. unitsPerEm: 0,
  27587. yMax: 0,
  27588. yMin: 0,
  27589. ascent: 0,
  27590. descent: 0
  27591. };
  27592. var ulUnicodeRange1 = 0;
  27593. var ulUnicodeRange2 = 0;
  27594. var ulUnicodeRange3 = 0;
  27595. var ulUnicodeRange4 = 0;
  27596. var firstCharIndex = null;
  27597. var lastCharIndex = 0;
  27598. if (charstrings) {
  27599. for (var code in charstrings) {
  27600. code |= 0;
  27601. if (firstCharIndex > code || !firstCharIndex) {
  27602. firstCharIndex = code;
  27603. }
  27604. if (lastCharIndex < code) {
  27605. lastCharIndex = code;
  27606. }
  27607. var position = getUnicodeRangeFor(code);
  27608. if (position < 32) {
  27609. ulUnicodeRange1 |= 1 << position;
  27610. } else if (position < 64) {
  27611. ulUnicodeRange2 |= 1 << position - 32;
  27612. } else if (position < 96) {
  27613. ulUnicodeRange3 |= 1 << position - 64;
  27614. } else if (position < 123) {
  27615. ulUnicodeRange4 |= 1 << position - 96;
  27616. } else {
  27617. error('Unicode ranges Bits > 123 are reserved for internal usage');
  27618. }
  27619. }
  27620. } else {
  27621. // TODO
  27622. firstCharIndex = 0;
  27623. lastCharIndex = 255;
  27624. }
  27625. var bbox = properties.bbox || [0, 0, 0, 0];
  27626. var unitsPerEm = (override.unitsPerEm ||
  27627. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  27628. // if the font units differ to the PDF glyph space units
  27629. // then scale up the values
  27630. var scale = (properties.ascentScaled ? 1.0 :
  27631. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  27632. var typoAscent = (override.ascent ||
  27633. Math.round(scale * (properties.ascent || bbox[3])));
  27634. var typoDescent = (override.descent ||
  27635. Math.round(scale * (properties.descent || bbox[1])));
  27636. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  27637. typoDescent = -typoDescent; // fixing incorrect descent
  27638. }
  27639. var winAscent = override.yMax || typoAscent;
  27640. var winDescent = -override.yMin || -typoDescent;
  27641. return '\x00\x03' + // version
  27642. '\x02\x24' + // xAvgCharWidth
  27643. '\x01\xF4' + // usWeightClass
  27644. '\x00\x05' + // usWidthClass
  27645. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  27646. '\x02\x8A' + // ySubscriptXSize
  27647. '\x02\xBB' + // ySubscriptYSize
  27648. '\x00\x00' + // ySubscriptXOffset
  27649. '\x00\x8C' + // ySubscriptYOffset
  27650. '\x02\x8A' + // ySuperScriptXSize
  27651. '\x02\xBB' + // ySuperScriptYSize
  27652. '\x00\x00' + // ySuperScriptXOffset
  27653. '\x01\xDF' + // ySuperScriptYOffset
  27654. '\x00\x31' + // yStrikeOutSize
  27655. '\x01\x02' + // yStrikeOutPosition
  27656. '\x00\x00' + // sFamilyClass
  27657. '\x00\x00\x06' +
  27658. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  27659. '\x00\x00\x00\x00\x00\x00' + // Panose
  27660. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  27661. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  27662. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  27663. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  27664. '\x2A\x32\x31\x2A' + // achVendID
  27665. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  27666. string16(firstCharIndex ||
  27667. properties.firstChar) + // usFirstCharIndex
  27668. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  27669. string16(typoAscent) + // sTypoAscender
  27670. string16(typoDescent) + // sTypoDescender
  27671. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  27672. string16(winAscent) + // usWinAscent
  27673. string16(winDescent) + // usWinDescent
  27674. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  27675. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  27676. string16(properties.xHeight) + // sxHeight
  27677. string16(properties.capHeight) + // sCapHeight
  27678. string16(0) + // usDefaultChar
  27679. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  27680. '\x00\x03'; // usMaxContext
  27681. }
  27682. function createPostTable(properties) {
  27683. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  27684. return ('\x00\x03\x00\x00' + // Version number
  27685. string32(angle) + // italicAngle
  27686. '\x00\x00' + // underlinePosition
  27687. '\x00\x00' + // underlineThickness
  27688. string32(properties.fixedPitch) + // isFixedPitch
  27689. '\x00\x00\x00\x00' + // minMemType42
  27690. '\x00\x00\x00\x00' + // maxMemType42
  27691. '\x00\x00\x00\x00' + // minMemType1
  27692. '\x00\x00\x00\x00'); // maxMemType1
  27693. }
  27694. function createNameTable(name, proto) {
  27695. if (!proto) {
  27696. proto = [[], []]; // no strings and unicode strings
  27697. }
  27698. var strings = [
  27699. proto[0][0] || 'Original licence', // 0.Copyright
  27700. proto[0][1] || name, // 1.Font family
  27701. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  27702. proto[0][3] || 'uniqueID', // 3.Unique ID
  27703. proto[0][4] || name, // 4.Full font name
  27704. proto[0][5] || 'Version 0.11', // 5.Version
  27705. proto[0][6] || '', // 6.Postscript name
  27706. proto[0][7] || 'Unknown', // 7.Trademark
  27707. proto[0][8] || 'Unknown', // 8.Manufacturer
  27708. proto[0][9] || 'Unknown' // 9.Designer
  27709. ];
  27710. // Mac want 1-byte per character strings while Windows want
  27711. // 2-bytes per character, so duplicate the names table
  27712. var stringsUnicode = [];
  27713. var i, ii, j, jj, str;
  27714. for (i = 0, ii = strings.length; i < ii; i++) {
  27715. str = proto[1][i] || strings[i];
  27716. var strBufUnicode = [];
  27717. for (j = 0, jj = str.length; j < jj; j++) {
  27718. strBufUnicode.push(string16(str.charCodeAt(j)));
  27719. }
  27720. stringsUnicode.push(strBufUnicode.join(''));
  27721. }
  27722. var names = [strings, stringsUnicode];
  27723. var platforms = ['\x00\x01', '\x00\x03'];
  27724. var encodings = ['\x00\x00', '\x00\x01'];
  27725. var languages = ['\x00\x00', '\x04\x09'];
  27726. var namesRecordCount = strings.length * platforms.length;
  27727. var nameTable =
  27728. '\x00\x00' + // format
  27729. string16(namesRecordCount) + // Number of names Record
  27730. string16(namesRecordCount * 12 + 6); // Storage
  27731. // Build the name records field
  27732. var strOffset = 0;
  27733. for (i = 0, ii = platforms.length; i < ii; i++) {
  27734. var strs = names[i];
  27735. for (j = 0, jj = strs.length; j < jj; j++) {
  27736. str = strs[j];
  27737. var nameRecord =
  27738. platforms[i] + // platform ID
  27739. encodings[i] + // encoding ID
  27740. languages[i] + // language ID
  27741. string16(j) + // name ID
  27742. string16(str.length) +
  27743. string16(strOffset);
  27744. nameTable += nameRecord;
  27745. strOffset += str.length;
  27746. }
  27747. }
  27748. nameTable += strings.join('') + stringsUnicode.join('');
  27749. return nameTable;
  27750. }
  27751. Font.prototype = {
  27752. name: null,
  27753. font: null,
  27754. mimetype: null,
  27755. encoding: null,
  27756. get renderer() {
  27757. var renderer = FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
  27758. return shadow(this, 'renderer', renderer);
  27759. },
  27760. exportData: function Font_exportData() {
  27761. // TODO remove enumerating of the properties, e.g. hardcode exact names.
  27762. var data = {};
  27763. for (var i in this) {
  27764. if (this.hasOwnProperty(i)) {
  27765. data[i] = this[i];
  27766. }
  27767. }
  27768. return data;
  27769. },
  27770. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  27771. function readTableEntry(file) {
  27772. var tag = bytesToString(file.getBytes(4));
  27773. var checksum = file.getInt32() >>> 0;
  27774. var offset = file.getInt32() >>> 0;
  27775. var length = file.getInt32() >>> 0;
  27776. // Read the table associated data
  27777. var previousPosition = file.pos;
  27778. file.pos = file.start ? file.start : 0;
  27779. file.skip(offset);
  27780. var data = file.getBytes(length);
  27781. file.pos = previousPosition;
  27782. if (tag === 'head') {
  27783. // clearing checksum adjustment
  27784. data[8] = data[9] = data[10] = data[11] = 0;
  27785. data[17] |= 0x20; //Set font optimized for cleartype flag
  27786. }
  27787. return {
  27788. tag: tag,
  27789. checksum: checksum,
  27790. length: length,
  27791. offset: offset,
  27792. data: data
  27793. };
  27794. }
  27795. function readOpenTypeHeader(ttf) {
  27796. return {
  27797. version: bytesToString(ttf.getBytes(4)),
  27798. numTables: ttf.getUint16(),
  27799. searchRange: ttf.getUint16(),
  27800. entrySelector: ttf.getUint16(),
  27801. rangeShift: ttf.getUint16()
  27802. };
  27803. }
  27804. /**
  27805. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  27806. * PDF spec
  27807. */
  27808. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  27809. if (!cmap) {
  27810. warn('No cmap table available.');
  27811. return {
  27812. platformId: -1,
  27813. encodingId: -1,
  27814. mappings: [],
  27815. hasShortCmap: false
  27816. };
  27817. }
  27818. var segment;
  27819. var start = (font.start ? font.start : 0) + cmap.offset;
  27820. font.pos = start;
  27821. var version = font.getUint16();
  27822. var numTables = font.getUint16();
  27823. var potentialTable;
  27824. var canBreak = false;
  27825. // There's an order of preference in terms of which cmap subtable to
  27826. // use:
  27827. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  27828. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  27829. // The following takes advantage of the fact that the tables are sorted
  27830. // to work.
  27831. for (var i = 0; i < numTables; i++) {
  27832. var platformId = font.getUint16();
  27833. var encodingId = font.getUint16();
  27834. var offset = font.getInt32() >>> 0;
  27835. var useTable = false;
  27836. if (platformId === 0 && encodingId === 0) {
  27837. useTable = true;
  27838. // Continue the loop since there still may be a higher priority
  27839. // table.
  27840. } else if (platformId === 1 && encodingId === 0) {
  27841. useTable = true;
  27842. // Continue the loop since there still may be a higher priority
  27843. // table.
  27844. } else if (platformId === 3 && encodingId === 1 &&
  27845. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  27846. useTable = true;
  27847. if (!isSymbolicFont) {
  27848. canBreak = true;
  27849. }
  27850. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  27851. useTable = true;
  27852. canBreak = true;
  27853. }
  27854. if (useTable) {
  27855. potentialTable = {
  27856. platformId: platformId,
  27857. encodingId: encodingId,
  27858. offset: offset
  27859. };
  27860. }
  27861. if (canBreak) {
  27862. break;
  27863. }
  27864. }
  27865. if (potentialTable) {
  27866. font.pos = start + potentialTable.offset;
  27867. }
  27868. if (!potentialTable || font.peekByte() === -1) {
  27869. warn('Could not find a preferred cmap table.');
  27870. return {
  27871. platformId: -1,
  27872. encodingId: -1,
  27873. mappings: [],
  27874. hasShortCmap: false
  27875. };
  27876. }
  27877. var format = font.getUint16();
  27878. var length = font.getUint16();
  27879. var language = font.getUint16();
  27880. var hasShortCmap = false;
  27881. var mappings = [];
  27882. var j, glyphId;
  27883. // TODO(mack): refactor this cmap subtable reading logic out
  27884. if (format === 0) {
  27885. for (j = 0; j < 256; j++) {
  27886. var index = font.getByte();
  27887. if (!index) {
  27888. continue;
  27889. }
  27890. mappings.push({
  27891. charCode: j,
  27892. glyphId: index
  27893. });
  27894. }
  27895. hasShortCmap = true;
  27896. } else if (format === 4) {
  27897. // re-creating the table in format 4 since the encoding
  27898. // might be changed
  27899. var segCount = (font.getUint16() >> 1);
  27900. font.getBytes(6); // skipping range fields
  27901. var segIndex, segments = [];
  27902. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27903. segments.push({ end: font.getUint16() });
  27904. }
  27905. font.getUint16();
  27906. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27907. segments[segIndex].start = font.getUint16();
  27908. }
  27909. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27910. segments[segIndex].delta = font.getUint16();
  27911. }
  27912. var offsetsCount = 0;
  27913. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27914. segment = segments[segIndex];
  27915. var rangeOffset = font.getUint16();
  27916. if (!rangeOffset) {
  27917. segment.offsetIndex = -1;
  27918. continue;
  27919. }
  27920. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  27921. segment.offsetIndex = offsetIndex;
  27922. offsetsCount = Math.max(offsetsCount, offsetIndex +
  27923. segment.end - segment.start + 1);
  27924. }
  27925. var offsets = [];
  27926. for (j = 0; j < offsetsCount; j++) {
  27927. offsets.push(font.getUint16());
  27928. }
  27929. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27930. segment = segments[segIndex];
  27931. start = segment.start;
  27932. var end = segment.end;
  27933. var delta = segment.delta;
  27934. offsetIndex = segment.offsetIndex;
  27935. for (j = start; j <= end; j++) {
  27936. if (j === 0xFFFF) {
  27937. continue;
  27938. }
  27939. glyphId = (offsetIndex < 0 ?
  27940. j : offsets[offsetIndex + j - start]);
  27941. glyphId = (glyphId + delta) & 0xFFFF;
  27942. if (glyphId === 0) {
  27943. continue;
  27944. }
  27945. mappings.push({
  27946. charCode: j,
  27947. glyphId: glyphId
  27948. });
  27949. }
  27950. }
  27951. } else if (format === 6) {
  27952. // Format 6 is a 2-bytes dense mapping, which means the font data
  27953. // lives glue together even if they are pretty far in the unicode
  27954. // table. (This looks weird, so I can have missed something), this
  27955. // works on Linux but seems to fails on Mac so let's rewrite the
  27956. // cmap table to a 3-1-4 style
  27957. var firstCode = font.getUint16();
  27958. var entryCount = font.getUint16();
  27959. for (j = 0; j < entryCount; j++) {
  27960. glyphId = font.getUint16();
  27961. var charCode = firstCode + j;
  27962. mappings.push({
  27963. charCode: charCode,
  27964. glyphId: glyphId
  27965. });
  27966. }
  27967. } else {
  27968. warn('cmap table has unsupported format: ' + format);
  27969. return {
  27970. platformId: -1,
  27971. encodingId: -1,
  27972. mappings: [],
  27973. hasShortCmap: false
  27974. };
  27975. }
  27976. // removing duplicate entries
  27977. mappings.sort(function (a, b) {
  27978. return a.charCode - b.charCode;
  27979. });
  27980. for (i = 1; i < mappings.length; i++) {
  27981. if (mappings[i - 1].charCode === mappings[i].charCode) {
  27982. mappings.splice(i, 1);
  27983. i--;
  27984. }
  27985. }
  27986. return {
  27987. platformId: potentialTable.platformId,
  27988. encodingId: potentialTable.encodingId,
  27989. mappings: mappings,
  27990. hasShortCmap: hasShortCmap
  27991. };
  27992. }
  27993. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  27994. if (!header) {
  27995. if (metrics) {
  27996. metrics.data = null;
  27997. }
  27998. return;
  27999. }
  28000. font.pos = (font.start ? font.start : 0) + header.offset;
  28001. font.pos += header.length - 2;
  28002. var numOfMetrics = font.getUint16();
  28003. if (numOfMetrics > numGlyphs) {
  28004. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  28005. 'greater than the numGlyphs (' + numGlyphs + ')');
  28006. // Reduce numOfMetrics if it is greater than numGlyphs
  28007. numOfMetrics = numGlyphs;
  28008. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  28009. header.data[35] = numOfMetrics & 0x00ff;
  28010. }
  28011. var numOfSidebearings = numGlyphs - numOfMetrics;
  28012. var numMissing = numOfSidebearings -
  28013. ((metrics.length - numOfMetrics * 4) >> 1);
  28014. if (numMissing > 0) {
  28015. // For each missing glyph, we set both the width and lsb to 0 (zero).
  28016. // Since we need to add two properties for each glyph, this explains
  28017. // the use of |numMissing * 2| when initializing the typed array.
  28018. var entries = new Uint8Array(metrics.length + numMissing * 2);
  28019. entries.set(metrics.data);
  28020. metrics.data = entries;
  28021. }
  28022. }
  28023. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  28024. hintsValid) {
  28025. if (sourceEnd - sourceStart <= 12) {
  28026. // glyph with data less than 12 is invalid one
  28027. return 0;
  28028. }
  28029. var glyf = source.subarray(sourceStart, sourceEnd);
  28030. var contoursCount = (glyf[0] << 8) | glyf[1];
  28031. if (contoursCount & 0x8000) {
  28032. // complex glyph, writing as is
  28033. dest.set(glyf, destStart);
  28034. return glyf.length;
  28035. }
  28036. var i, j = 10, flagsCount = 0;
  28037. for (i = 0; i < contoursCount; i++) {
  28038. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  28039. flagsCount = endPoint + 1;
  28040. j += 2;
  28041. }
  28042. // skipping instructions
  28043. var instructionsStart = j;
  28044. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  28045. j += 2 + instructionsLength;
  28046. var instructionsEnd = j;
  28047. // validating flags
  28048. var coordinatesLength = 0;
  28049. for (i = 0; i < flagsCount; i++) {
  28050. var flag = glyf[j++];
  28051. if (flag & 0xC0) {
  28052. // reserved flags must be zero, cleaning up
  28053. glyf[j - 1] = flag & 0x3F;
  28054. }
  28055. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  28056. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  28057. coordinatesLength += xyLength;
  28058. if (flag & 8) {
  28059. var repeat = glyf[j++];
  28060. i += repeat;
  28061. coordinatesLength += repeat * xyLength;
  28062. }
  28063. }
  28064. // glyph without coordinates will be rejected
  28065. if (coordinatesLength === 0) {
  28066. return 0;
  28067. }
  28068. var glyphDataLength = j + coordinatesLength;
  28069. if (glyphDataLength > glyf.length) {
  28070. // not enough data for coordinates
  28071. return 0;
  28072. }
  28073. if (!hintsValid && instructionsLength > 0) {
  28074. dest.set(glyf.subarray(0, instructionsStart), destStart);
  28075. dest.set([0, 0], destStart + instructionsStart);
  28076. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  28077. destStart + instructionsStart + 2);
  28078. glyphDataLength -= instructionsLength;
  28079. if (glyf.length - glyphDataLength > 3) {
  28080. glyphDataLength = (glyphDataLength + 3) & ~3;
  28081. }
  28082. return glyphDataLength;
  28083. }
  28084. if (glyf.length - glyphDataLength > 3) {
  28085. // truncating and aligning to 4 bytes the long glyph data
  28086. glyphDataLength = (glyphDataLength + 3) & ~3;
  28087. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  28088. return glyphDataLength;
  28089. }
  28090. // glyph data is fine
  28091. dest.set(glyf, destStart);
  28092. return glyf.length;
  28093. }
  28094. function sanitizeHead(head, numGlyphs, locaLength) {
  28095. var data = head.data;
  28096. // Validate version:
  28097. // Should always be 0x00010000
  28098. var version = int32(data[0], data[1], data[2], data[3]);
  28099. if (version >> 16 !== 1) {
  28100. info('Attempting to fix invalid version in head table: ' + version);
  28101. data[0] = 0;
  28102. data[1] = 1;
  28103. data[2] = 0;
  28104. data[3] = 0;
  28105. }
  28106. var indexToLocFormat = int16(data[50], data[51]);
  28107. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  28108. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  28109. indexToLocFormat);
  28110. // The value of indexToLocFormat should be 0 if the loca table
  28111. // consists of short offsets, and should be 1 if the loca table
  28112. // consists of long offsets.
  28113. //
  28114. // The number of entries in the loca table should be numGlyphs + 1.
  28115. //
  28116. // Using this information, we can work backwards to deduce if the
  28117. // size of each offset in the loca table, and thus figure out the
  28118. // appropriate value for indexToLocFormat.
  28119. var numGlyphsPlusOne = numGlyphs + 1;
  28120. if (locaLength === numGlyphsPlusOne << 1) {
  28121. // 0x0000 indicates the loca table consists of short offsets
  28122. data[50] = 0;
  28123. data[51] = 0;
  28124. } else if (locaLength === numGlyphsPlusOne << 2) {
  28125. // 0x0001 indicates the loca table consists of long offsets
  28126. data[50] = 0;
  28127. data[51] = 1;
  28128. } else {
  28129. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  28130. }
  28131. }
  28132. }
  28133. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  28134. isGlyphLocationsLong, hintsValid,
  28135. dupFirstEntry) {
  28136. var itemSize, itemDecode, itemEncode;
  28137. if (isGlyphLocationsLong) {
  28138. itemSize = 4;
  28139. itemDecode = function fontItemDecodeLong(data, offset) {
  28140. return (data[offset] << 24) | (data[offset + 1] << 16) |
  28141. (data[offset + 2] << 8) | data[offset + 3];
  28142. };
  28143. itemEncode = function fontItemEncodeLong(data, offset, value) {
  28144. data[offset] = (value >>> 24) & 0xFF;
  28145. data[offset + 1] = (value >> 16) & 0xFF;
  28146. data[offset + 2] = (value >> 8) & 0xFF;
  28147. data[offset + 3] = value & 0xFF;
  28148. };
  28149. } else {
  28150. itemSize = 2;
  28151. itemDecode = function fontItemDecode(data, offset) {
  28152. return (data[offset] << 9) | (data[offset + 1] << 1);
  28153. };
  28154. itemEncode = function fontItemEncode(data, offset, value) {
  28155. data[offset] = (value >> 9) & 0xFF;
  28156. data[offset + 1] = (value >> 1) & 0xFF;
  28157. };
  28158. }
  28159. var locaData = loca.data;
  28160. var locaDataSize = itemSize * (1 + numGlyphs);
  28161. // is loca.data too short or long?
  28162. if (locaData.length !== locaDataSize) {
  28163. locaData = new Uint8Array(locaDataSize);
  28164. locaData.set(loca.data.subarray(0, locaDataSize));
  28165. loca.data = locaData;
  28166. }
  28167. // removing the invalid glyphs
  28168. var oldGlyfData = glyf.data;
  28169. var oldGlyfDataLength = oldGlyfData.length;
  28170. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  28171. var startOffset = itemDecode(locaData, 0);
  28172. var writeOffset = 0;
  28173. var missingGlyphData = Object.create(null);
  28174. itemEncode(locaData, 0, writeOffset);
  28175. var i, j;
  28176. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  28177. var endOffset = itemDecode(locaData, j);
  28178. if (endOffset > oldGlyfDataLength &&
  28179. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  28180. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  28181. // the glyf table size, which makes last glyph out of range.
  28182. endOffset = oldGlyfDataLength;
  28183. }
  28184. if (endOffset > oldGlyfDataLength) {
  28185. // glyph end offset points outside glyf data, rejecting the glyph
  28186. itemEncode(locaData, j, writeOffset);
  28187. startOffset = endOffset;
  28188. continue;
  28189. }
  28190. if (startOffset === endOffset) {
  28191. missingGlyphData[i] = true;
  28192. }
  28193. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  28194. newGlyfData, writeOffset, hintsValid);
  28195. writeOffset += newLength;
  28196. itemEncode(locaData, j, writeOffset);
  28197. startOffset = endOffset;
  28198. }
  28199. if (writeOffset === 0) {
  28200. // glyf table cannot be empty -- redoing the glyf and loca tables
  28201. // to have single glyph with one point
  28202. var simpleGlyph = new Uint8Array(
  28203. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  28204. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  28205. itemEncode(locaData, j, simpleGlyph.length);
  28206. }
  28207. glyf.data = simpleGlyph;
  28208. return missingGlyphData;
  28209. }
  28210. if (dupFirstEntry) {
  28211. var firstEntryLength = itemDecode(locaData, itemSize);
  28212. if (newGlyfData.length > firstEntryLength + writeOffset) {
  28213. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  28214. } else {
  28215. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  28216. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  28217. }
  28218. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  28219. itemEncode(loca.data, locaData.length - itemSize,
  28220. writeOffset + firstEntryLength);
  28221. } else {
  28222. glyf.data = newGlyfData.subarray(0, writeOffset);
  28223. }
  28224. return missingGlyphData;
  28225. }
  28226. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  28227. var start = (font.start ? font.start : 0) + post.offset;
  28228. font.pos = start;
  28229. var length = post.length, end = start + length;
  28230. var version = font.getInt32();
  28231. // skip rest to the tables
  28232. font.getBytes(28);
  28233. var glyphNames;
  28234. var valid = true;
  28235. var i;
  28236. switch (version) {
  28237. case 0x00010000:
  28238. glyphNames = MacStandardGlyphOrdering;
  28239. break;
  28240. case 0x00020000:
  28241. var numGlyphs = font.getUint16();
  28242. if (numGlyphs !== maxpNumGlyphs) {
  28243. valid = false;
  28244. break;
  28245. }
  28246. var glyphNameIndexes = [];
  28247. for (i = 0; i < numGlyphs; ++i) {
  28248. var index = font.getUint16();
  28249. if (index >= 32768) {
  28250. valid = false;
  28251. break;
  28252. }
  28253. glyphNameIndexes.push(index);
  28254. }
  28255. if (!valid) {
  28256. break;
  28257. }
  28258. var customNames = [];
  28259. var strBuf = [];
  28260. while (font.pos < end) {
  28261. var stringLength = font.getByte();
  28262. strBuf.length = stringLength;
  28263. for (i = 0; i < stringLength; ++i) {
  28264. strBuf[i] = String.fromCharCode(font.getByte());
  28265. }
  28266. customNames.push(strBuf.join(''));
  28267. }
  28268. glyphNames = [];
  28269. for (i = 0; i < numGlyphs; ++i) {
  28270. var j = glyphNameIndexes[i];
  28271. if (j < 258) {
  28272. glyphNames.push(MacStandardGlyphOrdering[j]);
  28273. continue;
  28274. }
  28275. glyphNames.push(customNames[j - 258]);
  28276. }
  28277. break;
  28278. case 0x00030000:
  28279. break;
  28280. default:
  28281. warn('Unknown/unsupported post table version ' + version);
  28282. valid = false;
  28283. if (properties.defaultEncoding) {
  28284. glyphNames = properties.defaultEncoding;
  28285. }
  28286. break;
  28287. }
  28288. properties.glyphNames = glyphNames;
  28289. return valid;
  28290. }
  28291. function readNameTable(nameTable) {
  28292. var start = (font.start ? font.start : 0) + nameTable.offset;
  28293. font.pos = start;
  28294. var names = [[], []];
  28295. var length = nameTable.length, end = start + length;
  28296. var format = font.getUint16();
  28297. var FORMAT_0_HEADER_LENGTH = 6;
  28298. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  28299. // unsupported name table format or table "too" small
  28300. return names;
  28301. }
  28302. var numRecords = font.getUint16();
  28303. var stringsStart = font.getUint16();
  28304. var records = [];
  28305. var NAME_RECORD_LENGTH = 12;
  28306. var i, ii;
  28307. for (i = 0; i < numRecords &&
  28308. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  28309. var r = {
  28310. platform: font.getUint16(),
  28311. encoding: font.getUint16(),
  28312. language: font.getUint16(),
  28313. name: font.getUint16(),
  28314. length: font.getUint16(),
  28315. offset: font.getUint16()
  28316. };
  28317. // using only Macintosh and Windows platform/encoding names
  28318. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  28319. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  28320. records.push(r);
  28321. }
  28322. }
  28323. for (i = 0, ii = records.length; i < ii; i++) {
  28324. var record = records[i];
  28325. if (record.length <= 0) {
  28326. continue; // Nothing to process, ignoring.
  28327. }
  28328. var pos = start + stringsStart + record.offset;
  28329. if (pos + record.length > end) {
  28330. continue; // outside of name table, ignoring
  28331. }
  28332. font.pos = pos;
  28333. var nameIndex = record.name;
  28334. if (record.encoding) {
  28335. // unicode
  28336. var str = '';
  28337. for (var j = 0, jj = record.length; j < jj; j += 2) {
  28338. str += String.fromCharCode(font.getUint16());
  28339. }
  28340. names[1][nameIndex] = str;
  28341. } else {
  28342. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  28343. }
  28344. }
  28345. return names;
  28346. }
  28347. var TTOpsStackDeltas = [
  28348. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  28349. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  28350. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  28351. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  28352. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  28353. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  28354. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  28355. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  28356. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  28357. // 0xC0-DF == -1 and 0xE0-FF == -2
  28358. function sanitizeTTProgram(table, ttContext) {
  28359. var data = table.data;
  28360. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  28361. var stack = [];
  28362. var callstack = [];
  28363. var functionsCalled = [];
  28364. var tooComplexToFollowFunctions =
  28365. ttContext.tooComplexToFollowFunctions;
  28366. var inFDEF = false, ifLevel = 0, inELSE = 0;
  28367. for (var ii = data.length; i < ii;) {
  28368. var op = data[i++];
  28369. // The TrueType instruction set docs can be found at
  28370. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  28371. if (op === 0x40) { // NPUSHB - pushes n bytes
  28372. n = data[i++];
  28373. if (inFDEF || inELSE) {
  28374. i += n;
  28375. } else {
  28376. for (j = 0; j < n; j++) {
  28377. stack.push(data[i++]);
  28378. }
  28379. }
  28380. } else if (op === 0x41) { // NPUSHW - pushes n words
  28381. n = data[i++];
  28382. if (inFDEF || inELSE) {
  28383. i += n * 2;
  28384. } else {
  28385. for (j = 0; j < n; j++) {
  28386. b = data[i++];
  28387. stack.push((b << 8) | data[i++]);
  28388. }
  28389. }
  28390. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  28391. n = op - 0xB0 + 1;
  28392. if (inFDEF || inELSE) {
  28393. i += n;
  28394. } else {
  28395. for (j = 0; j < n; j++) {
  28396. stack.push(data[i++]);
  28397. }
  28398. }
  28399. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  28400. n = op - 0xB8 + 1;
  28401. if (inFDEF || inELSE) {
  28402. i += n * 2;
  28403. } else {
  28404. for (j = 0; j < n; j++) {
  28405. b = data[i++];
  28406. stack.push((b << 8) | data[i++]);
  28407. }
  28408. }
  28409. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  28410. if (!inFDEF && !inELSE) {
  28411. // collecting inforamtion about which functions are used
  28412. funcId = stack[stack.length - 1];
  28413. ttContext.functionsUsed[funcId] = true;
  28414. if (funcId in ttContext.functionsStackDeltas) {
  28415. stack.length += ttContext.functionsStackDeltas[funcId];
  28416. } else if (funcId in ttContext.functionsDefined &&
  28417. functionsCalled.indexOf(funcId) < 0) {
  28418. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  28419. functionsCalled.push(funcId);
  28420. pc = ttContext.functionsDefined[funcId];
  28421. if (!pc) {
  28422. warn('TT: CALL non-existent function');
  28423. ttContext.hintsValid = false;
  28424. return;
  28425. }
  28426. data = pc.data;
  28427. i = pc.i;
  28428. }
  28429. }
  28430. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  28431. if (inFDEF || inELSE) {
  28432. warn('TT: nested FDEFs not allowed');
  28433. tooComplexToFollowFunctions = true;
  28434. }
  28435. inFDEF = true;
  28436. // collecting inforamtion about which functions are defined
  28437. lastDeff = i;
  28438. funcId = stack.pop();
  28439. ttContext.functionsDefined[funcId] = {data: data, i: i};
  28440. } else if (op === 0x2D) { // ENDF - end of function
  28441. if (inFDEF) {
  28442. inFDEF = false;
  28443. lastEndf = i;
  28444. } else {
  28445. pc = callstack.pop();
  28446. if (!pc) {
  28447. warn('TT: ENDF bad stack');
  28448. ttContext.hintsValid = false;
  28449. return;
  28450. }
  28451. funcId = functionsCalled.pop();
  28452. data = pc.data;
  28453. i = pc.i;
  28454. ttContext.functionsStackDeltas[funcId] =
  28455. stack.length - pc.stackTop;
  28456. }
  28457. } else if (op === 0x89) { // IDEF - instruction definition
  28458. if (inFDEF || inELSE) {
  28459. warn('TT: nested IDEFs not allowed');
  28460. tooComplexToFollowFunctions = true;
  28461. }
  28462. inFDEF = true;
  28463. // recording it as a function to track ENDF
  28464. lastDeff = i;
  28465. } else if (op === 0x58) { // IF
  28466. ++ifLevel;
  28467. } else if (op === 0x1B) { // ELSE
  28468. inELSE = ifLevel;
  28469. } else if (op === 0x59) { // EIF
  28470. if (inELSE === ifLevel) {
  28471. inELSE = 0;
  28472. }
  28473. --ifLevel;
  28474. } else if (op === 0x1C) { // JMPR
  28475. if (!inFDEF && !inELSE) {
  28476. var offset = stack[stack.length - 1];
  28477. // only jumping forward to prevent infinite loop
  28478. if (offset > 0) {
  28479. i += offset - 1;
  28480. }
  28481. }
  28482. }
  28483. // Adjusting stack not extactly, but just enough to get function id
  28484. if (!inFDEF && !inELSE) {
  28485. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  28486. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  28487. if (op >= 0x71 && op <= 0x75) {
  28488. n = stack.pop();
  28489. if (n === n) {
  28490. stackDelta = -n * 2;
  28491. }
  28492. }
  28493. while (stackDelta < 0 && stack.length > 0) {
  28494. stack.pop();
  28495. stackDelta++;
  28496. }
  28497. while (stackDelta > 0) {
  28498. stack.push(NaN); // pushing any number into stack
  28499. stackDelta--;
  28500. }
  28501. }
  28502. }
  28503. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  28504. var content = [data];
  28505. if (i > data.length) {
  28506. content.push(new Uint8Array(i - data.length));
  28507. }
  28508. if (lastDeff > lastEndf) {
  28509. warn('TT: complementing a missing function tail');
  28510. // new function definition started, but not finished
  28511. // complete function by [CLEAR, ENDF]
  28512. content.push(new Uint8Array([0x22, 0x2D]));
  28513. }
  28514. foldTTTable(table, content);
  28515. }
  28516. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  28517. if (ttContext.tooComplexToFollowFunctions) {
  28518. return;
  28519. }
  28520. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  28521. warn('TT: more functions defined than expected');
  28522. ttContext.hintsValid = false;
  28523. return;
  28524. }
  28525. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  28526. if (j > maxFunctionDefs) {
  28527. warn('TT: invalid function id: ' + j);
  28528. ttContext.hintsValid = false;
  28529. return;
  28530. }
  28531. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  28532. warn('TT: undefined function: ' + j);
  28533. ttContext.hintsValid = false;
  28534. return;
  28535. }
  28536. }
  28537. }
  28538. function foldTTTable(table, content) {
  28539. if (content.length > 1) {
  28540. // concatenating the content items
  28541. var newLength = 0;
  28542. var j, jj;
  28543. for (j = 0, jj = content.length; j < jj; j++) {
  28544. newLength += content[j].length;
  28545. }
  28546. newLength = (newLength + 3) & ~3;
  28547. var result = new Uint8Array(newLength);
  28548. var pos = 0;
  28549. for (j = 0, jj = content.length; j < jj; j++) {
  28550. result.set(content[j], pos);
  28551. pos += content[j].length;
  28552. }
  28553. table.data = result;
  28554. table.length = newLength;
  28555. }
  28556. }
  28557. function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) {
  28558. var ttContext = {
  28559. functionsDefined: [],
  28560. functionsUsed: [],
  28561. functionsStackDeltas: [],
  28562. tooComplexToFollowFunctions: false,
  28563. hintsValid: true
  28564. };
  28565. if (fpgm) {
  28566. sanitizeTTProgram(fpgm, ttContext);
  28567. }
  28568. if (prep) {
  28569. sanitizeTTProgram(prep, ttContext);
  28570. }
  28571. if (fpgm) {
  28572. checkInvalidFunctions(ttContext, maxFunctionDefs);
  28573. }
  28574. if (cvt && (cvt.length & 1)) {
  28575. var cvtData = new Uint8Array(cvt.length + 1);
  28576. cvtData.set(cvt.data);
  28577. cvt.data = cvtData;
  28578. }
  28579. return ttContext.hintsValid;
  28580. }
  28581. // The following steps modify the original font data, making copy
  28582. font = new Stream(new Uint8Array(font.getBytes()));
  28583. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  28584. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  28585. var header = readOpenTypeHeader(font);
  28586. var numTables = header.numTables;
  28587. var cff, cffFile;
  28588. var tables = Object.create(null);
  28589. tables['OS/2'] = null;
  28590. tables['cmap'] = null;
  28591. tables['head'] = null;
  28592. tables['hhea'] = null;
  28593. tables['hmtx'] = null;
  28594. tables['maxp'] = null;
  28595. tables['name'] = null;
  28596. tables['post'] = null;
  28597. var table;
  28598. for (var i = 0; i < numTables; i++) {
  28599. table = readTableEntry(font);
  28600. if (VALID_TABLES.indexOf(table.tag) < 0) {
  28601. continue; // skipping table if it's not a required or optional table
  28602. }
  28603. if (table.length === 0) {
  28604. continue; // skipping empty tables
  28605. }
  28606. tables[table.tag] = table;
  28607. }
  28608. var isTrueType = !tables['CFF '];
  28609. if (!isTrueType) {
  28610. // OpenType font
  28611. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  28612. !tables['head'] || !tables['hhea'] || !tables['maxp'] ||
  28613. !tables['post']) {
  28614. // no major tables: throwing everything at CFFFont
  28615. cffFile = new Stream(tables['CFF '].data);
  28616. cff = new CFFFont(cffFile, properties);
  28617. adjustWidths(properties);
  28618. return this.convert(name, cff, properties);
  28619. }
  28620. delete tables['glyf'];
  28621. delete tables['loca'];
  28622. delete tables['fpgm'];
  28623. delete tables['prep'];
  28624. delete tables['cvt '];
  28625. this.isOpenType = true;
  28626. } else {
  28627. if (!tables['loca']) {
  28628. error('Required "loca" table is not found');
  28629. }
  28630. if (!tables['glyf']) {
  28631. warn('Required "glyf" table is not found -- trying to recover.');
  28632. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  28633. tables['glyf'] = {
  28634. tag: 'glyf',
  28635. data: new Uint8Array(0),
  28636. };
  28637. }
  28638. this.isOpenType = false;
  28639. }
  28640. if (!tables['maxp']) {
  28641. error('Required "maxp" table is not found');
  28642. }
  28643. font.pos = (font.start || 0) + tables['maxp'].offset;
  28644. var version = font.getInt32();
  28645. var numGlyphs = font.getUint16();
  28646. var maxFunctionDefs = 0;
  28647. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  28648. // maxZones can be invalid
  28649. font.pos += 8;
  28650. var maxZones = font.getUint16();
  28651. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  28652. tables['maxp'].data[14] = 0;
  28653. tables['maxp'].data[15] = 2;
  28654. }
  28655. font.pos += 4;
  28656. maxFunctionDefs = font.getUint16();
  28657. }
  28658. var dupFirstEntry = false;
  28659. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  28660. properties.toUnicode.get(0) > '\u0000') {
  28661. // oracle's defect (see 3427), duplicating first entry
  28662. dupFirstEntry = true;
  28663. numGlyphs++;
  28664. tables['maxp'].data[4] = numGlyphs >> 8;
  28665. tables['maxp'].data[5] = numGlyphs & 255;
  28666. }
  28667. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'],
  28668. tables['cvt '], maxFunctionDefs);
  28669. if (!hintsValid) {
  28670. delete tables['fpgm'];
  28671. delete tables['prep'];
  28672. delete tables['cvt '];
  28673. }
  28674. // Ensure the hmtx table contains the advance width and
  28675. // sidebearings information for numGlyphs in the maxp table
  28676. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  28677. if (!tables['head']) {
  28678. error('Required "head" table is not found');
  28679. }
  28680. sanitizeHead(tables['head'], numGlyphs,
  28681. isTrueType ? tables['loca'].length : 0);
  28682. var missingGlyphs = Object.create(null);
  28683. if (isTrueType) {
  28684. var isGlyphLocationsLong = int16(tables['head'].data[50],
  28685. tables['head'].data[51]);
  28686. missingGlyphs = sanitizeGlyphLocations(tables['loca'], tables['glyf'],
  28687. numGlyphs, isGlyphLocationsLong,
  28688. hintsValid, dupFirstEntry);
  28689. }
  28690. if (!tables['hhea']) {
  28691. error('Required "hhea" table is not found');
  28692. }
  28693. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  28694. // Sometimes it's 0. That needs to be fixed
  28695. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  28696. tables['hhea'].data[10] = 0xFF;
  28697. tables['hhea'].data[11] = 0xFF;
  28698. }
  28699. // Extract some more font properties from the OpenType head and
  28700. // hhea tables; yMin and descent value are always negative.
  28701. var metricsOverride = {
  28702. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  28703. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  28704. yMin: signedInt16(tables['head'].data[38], tables['head'].data[39]),
  28705. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  28706. descent: signedInt16(tables['hhea'].data[6], tables['hhea'].data[7])
  28707. };
  28708. // PDF FontDescriptor metrics lie -- using data from actual font.
  28709. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  28710. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  28711. // The 'post' table has glyphs names.
  28712. if (tables['post']) {
  28713. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  28714. if (!valid) {
  28715. tables['post'] = null;
  28716. }
  28717. }
  28718. var charCodeToGlyphId = [], charCode;
  28719. var toUnicode = properties.toUnicode, widths = properties.widths;
  28720. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  28721. toUnicode.length === 0x10000);
  28722. // Helper function to try to skip mapping of empty glyphs.
  28723. // Note: In some cases, just relying on the glyph data doesn't work,
  28724. // hence we also use a few heuristics to fix various PDF files.
  28725. function hasGlyph(glyphId, charCode, widthCode) {
  28726. if (!missingGlyphs[glyphId]) {
  28727. return true;
  28728. }
  28729. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  28730. return true;
  28731. }
  28732. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  28733. return true;
  28734. }
  28735. return false;
  28736. }
  28737. if (properties.type === 'CIDFontType2') {
  28738. var cidToGidMap = properties.cidToGidMap || [];
  28739. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  28740. properties.cMap.forEach(function(charCode, cid) {
  28741. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  28742. var glyphId = -1;
  28743. if (isCidToGidMapEmpty) {
  28744. glyphId = cid;
  28745. } else if (cidToGidMap[cid] !== undefined) {
  28746. glyphId = cidToGidMap[cid];
  28747. }
  28748. if (glyphId >= 0 && glyphId < numGlyphs &&
  28749. hasGlyph(glyphId, charCode, cid)) {
  28750. charCodeToGlyphId[charCode] = glyphId;
  28751. }
  28752. });
  28753. if (dupFirstEntry && (isCidToGidMapEmpty || !charCodeToGlyphId[0])) {
  28754. // We don't duplicate the first entry in the `charCodeToGlyphId` map
  28755. // if the font has a `CIDToGIDMap` which has already mapped the first
  28756. // entry to a non-zero `glyphId` (fixes issue7544.pdf).
  28757. charCodeToGlyphId[0] = numGlyphs - 1;
  28758. }
  28759. } else {
  28760. // Most of the following logic in this code branch is based on the
  28761. // 9.6.6.4 of the PDF spec.
  28762. var cmapTable = readCmapTable(tables['cmap'], font, this.isSymbolicFont,
  28763. properties.hasEncoding);
  28764. var cmapPlatformId = cmapTable.platformId;
  28765. var cmapEncodingId = cmapTable.encodingId;
  28766. var cmapMappings = cmapTable.mappings;
  28767. var cmapMappingsLength = cmapMappings.length;
  28768. // The spec seems to imply that if the font is symbolic the encoding
  28769. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  28770. // where the the font is symbolic and it has an encoding.
  28771. if (properties.hasEncoding &&
  28772. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  28773. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  28774. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  28775. !!getEncoding(properties.baseEncodingName))) { // Temporary hack
  28776. // When no preferred cmap table was found and |baseEncodingName| is
  28777. // one of the predefined encodings, we seem to obtain a better
  28778. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  28779. // TODO: Note that this is a hack which should be removed as soon as
  28780. // we have proper support for more exotic cmap tables.
  28781. var baseEncoding = [];
  28782. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  28783. properties.baseEncodingName === 'WinAnsiEncoding') {
  28784. baseEncoding = getEncoding(properties.baseEncodingName);
  28785. }
  28786. var glyphsUnicodeMap = getGlyphsUnicode();
  28787. for (charCode = 0; charCode < 256; charCode++) {
  28788. var glyphName, standardGlyphName;
  28789. if (this.differences && charCode in this.differences) {
  28790. glyphName = this.differences[charCode];
  28791. } else if (charCode in baseEncoding &&
  28792. baseEncoding[charCode] !== '') {
  28793. glyphName = baseEncoding[charCode];
  28794. } else {
  28795. glyphName = StandardEncoding[charCode];
  28796. }
  28797. if (!glyphName) {
  28798. continue;
  28799. }
  28800. // Ensure that non-standard glyph names are resolved to valid ones.
  28801. standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  28802. var unicodeOrCharCode, isUnicode = false;
  28803. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  28804. unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName];
  28805. isUnicode = true;
  28806. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  28807. // TODO: the encoding needs to be updated with mac os table.
  28808. unicodeOrCharCode = MacRomanEncoding.indexOf(standardGlyphName);
  28809. }
  28810. var found = false;
  28811. for (i = 0; i < cmapMappingsLength; ++i) {
  28812. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  28813. continue;
  28814. }
  28815. var code = isUnicode ? charCode : unicodeOrCharCode;
  28816. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  28817. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  28818. found = true;
  28819. break;
  28820. }
  28821. }
  28822. if (!found && properties.glyphNames) {
  28823. // Try to map using the post table.
  28824. var glyphId = properties.glyphNames.indexOf(glyphName);
  28825. // The post table ought to use the same kind of glyph names as the
  28826. // `differences` array, but check the standard ones as a fallback.
  28827. if (glyphId === -1 && standardGlyphName !== glyphName) {
  28828. glyphId = properties.glyphNames.indexOf(standardGlyphName);
  28829. }
  28830. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  28831. charCodeToGlyphId[charCode] = glyphId;
  28832. found = true;
  28833. }
  28834. }
  28835. if (!found) {
  28836. charCodeToGlyphId[charCode] = 0; // notdef
  28837. }
  28838. }
  28839. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  28840. // Default Unicode semantics, use the charcodes as is.
  28841. for (i = 0; i < cmapMappingsLength; ++i) {
  28842. charCodeToGlyphId[cmapMappings[i].charCode] =
  28843. cmapMappings[i].glyphId;
  28844. }
  28845. } else {
  28846. // For (3, 0) cmap tables:
  28847. // The charcode key being stored in charCodeToGlyphId is the lower
  28848. // byte of the two-byte charcodes of the cmap table since according to
  28849. // the spec: 'each byte from the string shall be prepended with the
  28850. // high byte of the range [of charcodes in the cmap table], to form
  28851. // a two-byte character, which shall be used to select the
  28852. // associated glyph description from the subtable'.
  28853. //
  28854. // For (1, 0) cmap tables:
  28855. // 'single bytes from the string shall be used to look up the
  28856. // associated glyph descriptions from the subtable'. This means
  28857. // charcodes in the cmap will be single bytes, so no-op since
  28858. // glyph.charCode & 0xFF === glyph.charCode
  28859. for (i = 0; i < cmapMappingsLength; ++i) {
  28860. charCode = cmapMappings[i].charCode & 0xFF;
  28861. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  28862. }
  28863. }
  28864. }
  28865. if (charCodeToGlyphId.length === 0) {
  28866. // defines at least one glyph
  28867. charCodeToGlyphId[0] = 0;
  28868. }
  28869. // Converting glyphs and ids into font's cmap table
  28870. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  28871. this.toFontChar = newMapping.toFontChar;
  28872. tables['cmap'] = {
  28873. tag: 'cmap',
  28874. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  28875. };
  28876. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  28877. tables['OS/2'] = {
  28878. tag: 'OS/2',
  28879. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  28880. metricsOverride)
  28881. };
  28882. }
  28883. // Rewrite the 'post' table if needed
  28884. if (!tables['post']) {
  28885. tables['post'] = {
  28886. tag: 'post',
  28887. data: createPostTable(properties)
  28888. };
  28889. }
  28890. if (!isTrueType) {
  28891. try {
  28892. // Trying to repair CFF file
  28893. cffFile = new Stream(tables['CFF '].data);
  28894. var parser = new CFFParser(cffFile, properties,
  28895. SEAC_ANALYSIS_ENABLED);
  28896. cff = parser.parse();
  28897. var compiler = new CFFCompiler(cff);
  28898. tables['CFF '].data = compiler.compile();
  28899. } catch (e) {
  28900. warn('Failed to compile font ' + properties.loadedName);
  28901. }
  28902. }
  28903. // Re-creating 'name' table
  28904. if (!tables['name']) {
  28905. tables['name'] = {
  28906. tag: 'name',
  28907. data: createNameTable(this.name)
  28908. };
  28909. } else {
  28910. // ... using existing 'name' table as prototype
  28911. var namePrototype = readNameTable(tables['name']);
  28912. tables['name'].data = createNameTable(name, namePrototype);
  28913. }
  28914. var builder = new OpenTypeFileBuilder(header.version);
  28915. for (var tableTag in tables) {
  28916. builder.addTable(tableTag, tables[tableTag].data);
  28917. }
  28918. return builder.toArray();
  28919. },
  28920. convert: function Font_convert(fontName, font, properties) {
  28921. // TODO: Check the charstring widths to determine this.
  28922. properties.fixedPitch = false;
  28923. if (properties.builtInEncoding) {
  28924. // For Type1 fonts that do not include either `ToUnicode` or `Encoding`
  28925. // data, attempt to use the `builtInEncoding` to improve text selection.
  28926. adjustToUnicode(properties, properties.builtInEncoding);
  28927. }
  28928. var mapping = font.getGlyphMapping(properties);
  28929. var newMapping = adjustMapping(mapping, properties);
  28930. this.toFontChar = newMapping.toFontChar;
  28931. var numGlyphs = font.numGlyphs;
  28932. function getCharCodes(charCodeToGlyphId, glyphId) {
  28933. var charCodes = null;
  28934. for (var charCode in charCodeToGlyphId) {
  28935. if (glyphId === charCodeToGlyphId[charCode]) {
  28936. if (!charCodes) {
  28937. charCodes = [];
  28938. }
  28939. charCodes.push(charCode | 0);
  28940. }
  28941. }
  28942. return charCodes;
  28943. }
  28944. function createCharCode(charCodeToGlyphId, glyphId) {
  28945. for (var charCode in charCodeToGlyphId) {
  28946. if (glyphId === charCodeToGlyphId[charCode]) {
  28947. return charCode | 0;
  28948. }
  28949. }
  28950. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  28951. glyphId;
  28952. return newMapping.nextAvailableFontCharCode++;
  28953. }
  28954. var seacs = font.seacs;
  28955. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  28956. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  28957. var charset = font.getCharset();
  28958. var seacMap = Object.create(null);
  28959. for (var glyphId in seacs) {
  28960. glyphId |= 0;
  28961. var seac = seacs[glyphId];
  28962. var baseGlyphName = StandardEncoding[seac[2]];
  28963. var accentGlyphName = StandardEncoding[seac[3]];
  28964. var baseGlyphId = charset.indexOf(baseGlyphName);
  28965. var accentGlyphId = charset.indexOf(accentGlyphName);
  28966. if (baseGlyphId < 0 || accentGlyphId < 0) {
  28967. continue;
  28968. }
  28969. var accentOffset = {
  28970. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  28971. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  28972. };
  28973. var charCodes = getCharCodes(mapping, glyphId);
  28974. if (!charCodes) {
  28975. // There's no point in mapping it if the char code was never mapped
  28976. // to begin with.
  28977. continue;
  28978. }
  28979. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  28980. var charCode = charCodes[i];
  28981. // Find a fontCharCode that maps to the base and accent glyphs.
  28982. // If one doesn't exists, create it.
  28983. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  28984. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  28985. baseGlyphId);
  28986. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  28987. accentGlyphId);
  28988. seacMap[charCode] = {
  28989. baseFontCharCode: baseFontCharCode,
  28990. accentFontCharCode: accentFontCharCode,
  28991. accentOffset: accentOffset
  28992. };
  28993. }
  28994. }
  28995. properties.seacMap = seacMap;
  28996. }
  28997. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  28998. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  28999. // PostScript Font Program
  29000. builder.addTable('CFF ', font.data);
  29001. // OS/2 and Windows Specific metrics
  29002. builder.addTable('OS/2', createOS2Table(properties,
  29003. newMapping.charCodeToGlyphId));
  29004. // Character to glyphs mapping
  29005. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  29006. numGlyphs));
  29007. // Font header
  29008. builder.addTable('head',
  29009. '\x00\x01\x00\x00' + // Version number
  29010. '\x00\x00\x10\x00' + // fontRevision
  29011. '\x00\x00\x00\x00' + // checksumAdjustement
  29012. '\x5F\x0F\x3C\xF5' + // magicNumber
  29013. '\x00\x00' + // Flags
  29014. safeString16(unitsPerEm) + // unitsPerEM
  29015. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  29016. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  29017. '\x00\x00' + // xMin
  29018. safeString16(properties.descent) + // yMin
  29019. '\x0F\xFF' + // xMax
  29020. safeString16(properties.ascent) + // yMax
  29021. string16(properties.italicAngle ? 2 : 0) + // macStyle
  29022. '\x00\x11' + // lowestRecPPEM
  29023. '\x00\x00' + // fontDirectionHint
  29024. '\x00\x00' + // indexToLocFormat
  29025. '\x00\x00'); // glyphDataFormat
  29026. // Horizontal header
  29027. builder.addTable('hhea',
  29028. '\x00\x01\x00\x00' + // Version number
  29029. safeString16(properties.ascent) + // Typographic Ascent
  29030. safeString16(properties.descent) + // Typographic Descent
  29031. '\x00\x00' + // Line Gap
  29032. '\xFF\xFF' + // advanceWidthMax
  29033. '\x00\x00' + // minLeftSidebearing
  29034. '\x00\x00' + // minRightSidebearing
  29035. '\x00\x00' + // xMaxExtent
  29036. safeString16(properties.capHeight) + // caretSlopeRise
  29037. safeString16(Math.tan(properties.italicAngle) *
  29038. properties.xHeight) + // caretSlopeRun
  29039. '\x00\x00' + // caretOffset
  29040. '\x00\x00' + // -reserved-
  29041. '\x00\x00' + // -reserved-
  29042. '\x00\x00' + // -reserved-
  29043. '\x00\x00' + // -reserved-
  29044. '\x00\x00' + // metricDataFormat
  29045. string16(numGlyphs)); // Number of HMetrics
  29046. // Horizontal metrics
  29047. builder.addTable('hmtx', (function fontFieldsHmtx() {
  29048. var charstrings = font.charstrings;
  29049. var cffWidths = font.cff ? font.cff.widths : null;
  29050. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  29051. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  29052. var width = 0;
  29053. if (charstrings) {
  29054. var charstring = charstrings[i - 1];
  29055. width = 'width' in charstring ? charstring.width : 0;
  29056. } else if (cffWidths) {
  29057. width = Math.ceil(cffWidths[i] || 0);
  29058. }
  29059. hmtx += string16(width) + string16(0);
  29060. }
  29061. return hmtx;
  29062. })());
  29063. // Maximum profile
  29064. builder.addTable('maxp',
  29065. '\x00\x00\x50\x00' + // Version number
  29066. string16(numGlyphs)); // Num of glyphs
  29067. // Naming tables
  29068. builder.addTable('name', createNameTable(fontName));
  29069. // PostScript information
  29070. builder.addTable('post', createPostTable(properties));
  29071. return builder.toArray();
  29072. },
  29073. get spaceWidth() {
  29074. if ('_shadowWidth' in this) {
  29075. return this._shadowWidth;
  29076. }
  29077. // trying to estimate space character width
  29078. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i', 'I'];
  29079. var width;
  29080. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  29081. var glyphName = possibleSpaceReplacements[i];
  29082. // if possible, getting width by glyph name
  29083. if (glyphName in this.widths) {
  29084. width = this.widths[glyphName];
  29085. break;
  29086. }
  29087. var glyphsUnicodeMap = getGlyphsUnicode();
  29088. var glyphUnicode = glyphsUnicodeMap[glyphName];
  29089. // finding the charcode via unicodeToCID map
  29090. var charcode = 0;
  29091. if (this.composite) {
  29092. if (this.cMap.contains(glyphUnicode)) {
  29093. charcode = this.cMap.lookup(glyphUnicode);
  29094. }
  29095. }
  29096. // ... via toUnicode map
  29097. if (!charcode && this.toUnicode) {
  29098. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  29099. }
  29100. // setting it to unicode if negative or undefined
  29101. if (charcode <= 0) {
  29102. charcode = glyphUnicode;
  29103. }
  29104. // trying to get width via charcode
  29105. width = this.widths[charcode];
  29106. if (width) {
  29107. break; // the non-zero width found
  29108. }
  29109. }
  29110. width = width || this.defaultWidth;
  29111. // Do not shadow the property here. See discussion:
  29112. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  29113. this._shadowWidth = width;
  29114. return width;
  29115. },
  29116. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  29117. var fontCharCode, width, operatorListId;
  29118. var widthCode = charcode;
  29119. if (this.cMap && this.cMap.contains(charcode)) {
  29120. widthCode = this.cMap.lookup(charcode);
  29121. }
  29122. width = this.widths[widthCode];
  29123. width = isNum(width) ? width : this.defaultWidth;
  29124. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  29125. var unicode = this.toUnicode.get(charcode) || charcode;
  29126. if (typeof unicode === 'number') {
  29127. unicode = String.fromCharCode(unicode);
  29128. }
  29129. var isInFont = charcode in this.toFontChar;
  29130. // First try the toFontChar map, if it's not there then try falling
  29131. // back to the char code.
  29132. fontCharCode = this.toFontChar[charcode] || charcode;
  29133. if (this.missingFile) {
  29134. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  29135. }
  29136. if (this.isType3Font) {
  29137. // Font char code in this case is actually a glyph name.
  29138. operatorListId = fontCharCode;
  29139. }
  29140. var accent = null;
  29141. if (this.seacMap && this.seacMap[charcode]) {
  29142. isInFont = true;
  29143. var seac = this.seacMap[charcode];
  29144. fontCharCode = seac.baseFontCharCode;
  29145. accent = {
  29146. fontChar: String.fromCharCode(seac.accentFontCharCode),
  29147. offset: seac.accentOffset
  29148. };
  29149. }
  29150. var fontChar = String.fromCharCode(fontCharCode);
  29151. var glyph = this.glyphCache[charcode];
  29152. if (!glyph ||
  29153. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  29154. operatorListId, isSpace, isInFont)) {
  29155. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  29156. operatorListId, isSpace, isInFont);
  29157. this.glyphCache[charcode] = glyph;
  29158. }
  29159. return glyph;
  29160. },
  29161. charsToGlyphs: function Font_charsToGlyphs(chars) {
  29162. var charsCache = this.charsCache;
  29163. var glyphs, glyph, charcode;
  29164. // if we translated this string before, just grab it from the cache
  29165. if (charsCache) {
  29166. glyphs = charsCache[chars];
  29167. if (glyphs) {
  29168. return glyphs;
  29169. }
  29170. }
  29171. // lazily create the translation cache
  29172. if (!charsCache) {
  29173. charsCache = this.charsCache = Object.create(null);
  29174. }
  29175. glyphs = [];
  29176. var charsCacheKey = chars;
  29177. var i = 0, ii;
  29178. if (this.cMap) {
  29179. // composite fonts have multi-byte strings convert the string from
  29180. // single-byte to multi-byte
  29181. var c = Object.create(null);
  29182. while (i < chars.length) {
  29183. this.cMap.readCharCode(chars, i, c);
  29184. charcode = c.charcode;
  29185. var length = c.length;
  29186. i += length;
  29187. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  29188. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  29189. glyph = this.charToGlyph(charcode, isSpace);
  29190. glyphs.push(glyph);
  29191. }
  29192. } else {
  29193. for (i = 0, ii = chars.length; i < ii; ++i) {
  29194. charcode = chars.charCodeAt(i);
  29195. glyph = this.charToGlyph(charcode, charcode === 0x20);
  29196. glyphs.push(glyph);
  29197. }
  29198. }
  29199. // Enter the translated string into the cache
  29200. return (charsCache[charsCacheKey] = glyphs);
  29201. }
  29202. };
  29203. return Font;
  29204. })();
  29205. var ErrorFont = (function ErrorFontClosure() {
  29206. function ErrorFont(error) {
  29207. this.error = error;
  29208. this.loadedName = 'g_font_error';
  29209. this.loading = false;
  29210. }
  29211. ErrorFont.prototype = {
  29212. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  29213. return [];
  29214. },
  29215. exportData: function ErrorFont_exportData() {
  29216. return {error: this.error};
  29217. }
  29218. };
  29219. return ErrorFont;
  29220. })();
  29221. /**
  29222. * Shared logic for building a char code to glyph id mapping for Type1 and
  29223. * simple CFF fonts. See section 9.6.6.2 of the spec.
  29224. * @param {Object} properties Font properties object.
  29225. * @param {Object} builtInEncoding The encoding contained within the actual font
  29226. * data.
  29227. * @param {Array} glyphNames Array of glyph names where the index is the
  29228. * glyph ID.
  29229. * @returns {Object} A char code to glyph ID map.
  29230. */
  29231. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  29232. var charCodeToGlyphId = Object.create(null);
  29233. var glyphId, charCode, baseEncoding;
  29234. if (properties.baseEncodingName) {
  29235. // If a valid base encoding name was used, the mapping is initialized with
  29236. // that.
  29237. baseEncoding = getEncoding(properties.baseEncodingName);
  29238. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  29239. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  29240. if (glyphId >= 0) {
  29241. charCodeToGlyphId[charCode] = glyphId;
  29242. } else {
  29243. charCodeToGlyphId[charCode] = 0; // notdef
  29244. }
  29245. }
  29246. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  29247. // For a symbolic font the encoding should be the fonts built-in
  29248. // encoding.
  29249. for (charCode in builtInEncoding) {
  29250. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  29251. }
  29252. } else {
  29253. // For non-symbolic fonts that don't have a base encoding the standard
  29254. // encoding should be used.
  29255. baseEncoding = StandardEncoding;
  29256. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  29257. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  29258. if (glyphId >= 0) {
  29259. charCodeToGlyphId[charCode] = glyphId;
  29260. } else {
  29261. charCodeToGlyphId[charCode] = 0; // notdef
  29262. }
  29263. }
  29264. }
  29265. // Lastly, merge in the differences.
  29266. var differences = properties.differences, glyphsUnicodeMap;
  29267. if (differences) {
  29268. for (charCode in differences) {
  29269. var glyphName = differences[charCode];
  29270. glyphId = glyphNames.indexOf(glyphName);
  29271. if (glyphId === -1) {
  29272. if (!glyphsUnicodeMap) {
  29273. glyphsUnicodeMap = getGlyphsUnicode();
  29274. }
  29275. var standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  29276. if (standardGlyphName !== glyphName) {
  29277. glyphId = glyphNames.indexOf(standardGlyphName);
  29278. }
  29279. }
  29280. if (glyphId >= 0) {
  29281. charCodeToGlyphId[charCode] = glyphId;
  29282. } else {
  29283. charCodeToGlyphId[charCode] = 0; // notdef
  29284. }
  29285. }
  29286. }
  29287. return charCodeToGlyphId;
  29288. }
  29289. // Type1Font is also a CIDFontType0.
  29290. var Type1Font = (function Type1FontClosure() {
  29291. function findBlock(streamBytes, signature, startIndex) {
  29292. var streamBytesLength = streamBytes.length;
  29293. var signatureLength = signature.length;
  29294. var scanLength = streamBytesLength - signatureLength;
  29295. var i = startIndex, j, found = false;
  29296. while (i < scanLength) {
  29297. j = 0;
  29298. while (j < signatureLength && streamBytes[i + j] === signature[j]) {
  29299. j++;
  29300. }
  29301. if (j >= signatureLength) { // `signature` found, skip over whitespace.
  29302. i += j;
  29303. while (i < streamBytesLength && isSpace(streamBytes[i])) {
  29304. i++;
  29305. }
  29306. found = true;
  29307. break;
  29308. }
  29309. i++;
  29310. }
  29311. return {
  29312. found: found,
  29313. length: i,
  29314. };
  29315. }
  29316. function getHeaderBlock(stream, suggestedLength) {
  29317. var EEXEC_SIGNATURE = [0x65, 0x65, 0x78, 0x65, 0x63];
  29318. var streamStartPos = stream.pos; // Save the initial stream position.
  29319. var headerBytes, headerBytesLength, block;
  29320. try {
  29321. headerBytes = stream.getBytes(suggestedLength);
  29322. headerBytesLength = headerBytes.length;
  29323. } catch (ex) {
  29324. if (ex instanceof MissingDataException) {
  29325. throw ex;
  29326. }
  29327. // Ignore errors if the `suggestedLength` is huge enough that a Uint8Array
  29328. // cannot hold the result of `getBytes`, and fallback to simply checking
  29329. // the entire stream (fixes issue3928.pdf).
  29330. }
  29331. if (headerBytesLength === suggestedLength) {
  29332. // Most of the time `suggestedLength` is correct, so to speed things up we
  29333. // initially only check the last few bytes to see if the header was found.
  29334. // Otherwise we (potentially) check the entire stream to prevent errors in
  29335. // `Type1Parser` (fixes issue5686.pdf).
  29336. block = findBlock(headerBytes, EEXEC_SIGNATURE,
  29337. suggestedLength - 2 * EEXEC_SIGNATURE.length);
  29338. if (block.found && block.length === suggestedLength) {
  29339. return {
  29340. stream: new Stream(headerBytes),
  29341. length: suggestedLength,
  29342. };
  29343. }
  29344. }
  29345. warn('Invalid "Length1" property in Type1 font -- trying to recover.');
  29346. stream.pos = streamStartPos; // Reset the stream position.
  29347. var SCAN_BLOCK_LENGTH = 2048;
  29348. var actualLength;
  29349. while (true) {
  29350. var scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
  29351. block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
  29352. if (block.length === 0) {
  29353. break;
  29354. }
  29355. stream.pos += block.length; // Update the stream position.
  29356. if (block.found) {
  29357. actualLength = stream.pos - streamStartPos;
  29358. break;
  29359. }
  29360. }
  29361. stream.pos = streamStartPos; // Reset the stream position.
  29362. if (actualLength) {
  29363. return {
  29364. stream: new Stream(stream.getBytes(actualLength)),
  29365. length: actualLength,
  29366. };
  29367. }
  29368. warn('Unable to recover "Length1" property in Type1 font -- using as is.');
  29369. return {
  29370. stream: new Stream(stream.getBytes(suggestedLength)),
  29371. length: suggestedLength,
  29372. };
  29373. }
  29374. function getEexecBlock(stream, suggestedLength) {
  29375. // We should ideally parse the eexec block to ensure that `suggestedLength`
  29376. // is correct, so we don't truncate the block data if it's too small.
  29377. // However, this would also require checking if the fixed-content portion
  29378. // exists (using the 'Length3' property), and ensuring that it's valid.
  29379. //
  29380. // Given that `suggestedLength` almost always is correct, all the validation
  29381. // would require a great deal of unnecessary parsing for most fonts.
  29382. // To save time, we always fetch the entire stream instead, which also avoid
  29383. // issues if `suggestedLength` is huge (see comment in `getHeaderBlock`).
  29384. //
  29385. // NOTE: This means that the function can include the fixed-content portion
  29386. // in the returned eexec block. In practice this does *not* seem to matter,
  29387. // since `Type1Parser_extractFontProgram` will skip over any non-commands.
  29388. var eexecBytes = stream.getBytes();
  29389. return {
  29390. stream: new Stream(eexecBytes),
  29391. length: eexecBytes.length,
  29392. };
  29393. }
  29394. function Type1Font(name, file, properties) {
  29395. // Some bad generators embed pfb file as is, we have to strip 6-byte header.
  29396. // Also, length1 and length2 might be off by 6 bytes as well.
  29397. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  29398. var PFB_HEADER_SIZE = 6;
  29399. var headerBlockLength = properties.length1;
  29400. var eexecBlockLength = properties.length2;
  29401. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  29402. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  29403. if (pfbHeaderPresent) {
  29404. file.skip(PFB_HEADER_SIZE);
  29405. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  29406. (pfbHeader[3] << 8) | pfbHeader[2];
  29407. }
  29408. // Get the data block containing glyphs and subrs information
  29409. var headerBlock = getHeaderBlock(file, headerBlockLength);
  29410. headerBlockLength = headerBlock.length;
  29411. var headerBlockParser = new Type1Parser(headerBlock.stream, false,
  29412. SEAC_ANALYSIS_ENABLED);
  29413. headerBlockParser.extractFontHeader(properties);
  29414. if (pfbHeaderPresent) {
  29415. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  29416. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  29417. (pfbHeader[3] << 8) | pfbHeader[2];
  29418. }
  29419. // Decrypt the data blocks and retrieve it's content
  29420. var eexecBlock = getEexecBlock(file, eexecBlockLength);
  29421. eexecBlockLength = eexecBlock.length;
  29422. var eexecBlockParser = new Type1Parser(eexecBlock.stream, true,
  29423. SEAC_ANALYSIS_ENABLED);
  29424. var data = eexecBlockParser.extractFontProgram();
  29425. for (var info in data.properties) {
  29426. properties[info] = data.properties[info];
  29427. }
  29428. var charstrings = data.charstrings;
  29429. var type2Charstrings = this.getType2Charstrings(charstrings);
  29430. var subrs = this.getType2Subrs(data.subrs);
  29431. this.charstrings = charstrings;
  29432. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  29433. subrs, properties);
  29434. this.seacs = this.getSeacs(data.charstrings);
  29435. }
  29436. Type1Font.prototype = {
  29437. get numGlyphs() {
  29438. return this.charstrings.length + 1;
  29439. },
  29440. getCharset: function Type1Font_getCharset() {
  29441. var charset = ['.notdef'];
  29442. var charstrings = this.charstrings;
  29443. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  29444. charset.push(charstrings[glyphId].glyphName);
  29445. }
  29446. return charset;
  29447. },
  29448. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  29449. var charstrings = this.charstrings;
  29450. var glyphNames = ['.notdef'], glyphId;
  29451. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  29452. glyphNames.push(charstrings[glyphId].glyphName);
  29453. }
  29454. var encoding = properties.builtInEncoding;
  29455. if (encoding) {
  29456. var builtInEncoding = Object.create(null);
  29457. for (var charCode in encoding) {
  29458. glyphId = glyphNames.indexOf(encoding[charCode]);
  29459. if (glyphId >= 0) {
  29460. builtInEncoding[charCode] = glyphId;
  29461. }
  29462. }
  29463. }
  29464. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  29465. },
  29466. getSeacs: function Type1Font_getSeacs(charstrings) {
  29467. var i, ii;
  29468. var seacMap = [];
  29469. for (i = 0, ii = charstrings.length; i < ii; i++) {
  29470. var charstring = charstrings[i];
  29471. if (charstring.seac) {
  29472. // Offset by 1 for .notdef
  29473. seacMap[i + 1] = charstring.seac;
  29474. }
  29475. }
  29476. return seacMap;
  29477. },
  29478. getType2Charstrings: function Type1Font_getType2Charstrings(
  29479. type1Charstrings) {
  29480. var type2Charstrings = [];
  29481. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  29482. type2Charstrings.push(type1Charstrings[i].charstring);
  29483. }
  29484. return type2Charstrings;
  29485. },
  29486. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  29487. var bias = 0;
  29488. var count = type1Subrs.length;
  29489. if (count < 1133) {
  29490. bias = 107;
  29491. } else if (count < 33769) {
  29492. bias = 1131;
  29493. } else {
  29494. bias = 32768;
  29495. }
  29496. // Add a bunch of empty subrs to deal with the Type2 bias
  29497. var type2Subrs = [];
  29498. var i;
  29499. for (i = 0; i < bias; i++) {
  29500. type2Subrs.push([0x0B]);
  29501. }
  29502. for (i = 0; i < count; i++) {
  29503. type2Subrs.push(type1Subrs[i]);
  29504. }
  29505. return type2Subrs;
  29506. },
  29507. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs,
  29508. properties) {
  29509. var cff = new CFF();
  29510. cff.header = new CFFHeader(1, 0, 4, 4);
  29511. cff.names = [name];
  29512. var topDict = new CFFTopDict();
  29513. // CFF strings IDs 0...390 are predefined names, so refering
  29514. // to entries in our own String INDEX starts at SID 391.
  29515. topDict.setByName('version', 391);
  29516. topDict.setByName('Notice', 392);
  29517. topDict.setByName('FullName', 393);
  29518. topDict.setByName('FamilyName', 394);
  29519. topDict.setByName('Weight', 395);
  29520. topDict.setByName('Encoding', null); // placeholder
  29521. topDict.setByName('FontMatrix', properties.fontMatrix);
  29522. topDict.setByName('FontBBox', properties.bbox);
  29523. topDict.setByName('charset', null); // placeholder
  29524. topDict.setByName('CharStrings', null); // placeholder
  29525. topDict.setByName('Private', null); // placeholder
  29526. cff.topDict = topDict;
  29527. var strings = new CFFStrings();
  29528. strings.add('Version 0.11'); // Version
  29529. strings.add('See original notice'); // Notice
  29530. strings.add(name); // FullName
  29531. strings.add(name); // FamilyName
  29532. strings.add('Medium'); // Weight
  29533. cff.strings = strings;
  29534. cff.globalSubrIndex = new CFFIndex();
  29535. var count = glyphs.length;
  29536. var charsetArray = [0];
  29537. var i, ii;
  29538. for (i = 0; i < count; i++) {
  29539. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  29540. // TODO: Insert the string and correctly map it. Previously it was
  29541. // thought mapping names that aren't in the standard strings to .notdef
  29542. // was fine, however in issue818 when mapping them all to .notdef the
  29543. // adieresis glyph no longer worked.
  29544. if (index === -1) {
  29545. index = 0;
  29546. }
  29547. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  29548. }
  29549. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  29550. var charStringsIndex = new CFFIndex();
  29551. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  29552. for (i = 0; i < count; i++) {
  29553. var glyph = glyphs[i];
  29554. // If the CharString outline is empty, replace it with .notdef to
  29555. // prevent OTS from rejecting the font (fixes bug1252420.pdf).
  29556. if (glyph.length === 0) {
  29557. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  29558. continue;
  29559. }
  29560. charStringsIndex.add(glyph);
  29561. }
  29562. cff.charStrings = charStringsIndex;
  29563. var privateDict = new CFFPrivateDict();
  29564. privateDict.setByName('Subrs', null); // placeholder
  29565. var fields = [
  29566. 'BlueValues',
  29567. 'OtherBlues',
  29568. 'FamilyBlues',
  29569. 'FamilyOtherBlues',
  29570. 'StemSnapH',
  29571. 'StemSnapV',
  29572. 'BlueShift',
  29573. 'BlueFuzz',
  29574. 'BlueScale',
  29575. 'LanguageGroup',
  29576. 'ExpansionFactor',
  29577. 'ForceBold',
  29578. 'StdHW',
  29579. 'StdVW'
  29580. ];
  29581. for (i = 0, ii = fields.length; i < ii; i++) {
  29582. var field = fields[i];
  29583. if (!(field in properties.privateData)) {
  29584. continue;
  29585. }
  29586. var value = properties.privateData[field];
  29587. if (isArray(value)) {
  29588. // All of the private dictionary array data in CFF must be stored as
  29589. // "delta-encoded" numbers.
  29590. for (var j = value.length - 1; j > 0; j--) {
  29591. value[j] -= value[j - 1]; // ... difference from previous value
  29592. }
  29593. }
  29594. privateDict.setByName(field, value);
  29595. }
  29596. cff.topDict.privateDict = privateDict;
  29597. var subrIndex = new CFFIndex();
  29598. for (i = 0, ii = subrs.length; i < ii; i++) {
  29599. subrIndex.add(subrs[i]);
  29600. }
  29601. privateDict.subrsIndex = subrIndex;
  29602. var compiler = new CFFCompiler(cff);
  29603. return compiler.compile();
  29604. }
  29605. };
  29606. return Type1Font;
  29607. })();
  29608. var CFFFont = (function CFFFontClosure() {
  29609. function CFFFont(file, properties) {
  29610. this.properties = properties;
  29611. var parser = new CFFParser(file, properties, SEAC_ANALYSIS_ENABLED);
  29612. this.cff = parser.parse();
  29613. var compiler = new CFFCompiler(this.cff);
  29614. this.seacs = this.cff.seacs;
  29615. try {
  29616. this.data = compiler.compile();
  29617. } catch (e) {
  29618. warn('Failed to compile font ' + properties.loadedName);
  29619. // There may have just been an issue with the compiler, set the data
  29620. // anyway and hope the font loaded.
  29621. this.data = file;
  29622. }
  29623. }
  29624. CFFFont.prototype = {
  29625. get numGlyphs() {
  29626. return this.cff.charStrings.count;
  29627. },
  29628. getCharset: function CFFFont_getCharset() {
  29629. return this.cff.charset.charset;
  29630. },
  29631. getGlyphMapping: function CFFFont_getGlyphMapping() {
  29632. var cff = this.cff;
  29633. var properties = this.properties;
  29634. var charsets = cff.charset.charset;
  29635. var charCodeToGlyphId;
  29636. var glyphId;
  29637. if (properties.composite) {
  29638. charCodeToGlyphId = Object.create(null);
  29639. if (cff.isCIDFont) {
  29640. // If the font is actually a CID font then we should use the charset
  29641. // to map CIDs to GIDs.
  29642. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  29643. var cid = charsets[glyphId];
  29644. var charCode = properties.cMap.charCodeOf(cid);
  29645. charCodeToGlyphId[charCode] = glyphId;
  29646. }
  29647. } else {
  29648. // If it is NOT actually a CID font then CIDs should be mapped
  29649. // directly to GIDs.
  29650. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  29651. charCodeToGlyphId[glyphId] = glyphId;
  29652. }
  29653. }
  29654. return charCodeToGlyphId;
  29655. }
  29656. var encoding = cff.encoding ? cff.encoding.encoding : null;
  29657. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  29658. return charCodeToGlyphId;
  29659. }
  29660. };
  29661. return CFFFont;
  29662. })();
  29663. // Workaround for seac on Windows.
  29664. (function checkSeacSupport() {
  29665. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  29666. SEAC_ANALYSIS_ENABLED = true;
  29667. }
  29668. })();
  29669. // Workaround for Private Use Area characters in Chrome on Windows
  29670. // http://code.google.com/p/chromium/issues/detail?id=122465
  29671. // https://github.com/mozilla/pdf.js/issues/1689
  29672. (function checkChromeWindows() {
  29673. if (typeof navigator !== 'undefined' &&
  29674. /Windows.*Chrome/.test(navigator.userAgent)) {
  29675. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  29676. }
  29677. })();
  29678. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  29679. exports.ErrorFont = ErrorFont;
  29680. exports.Font = Font;
  29681. exports.FontFlags = FontFlags;
  29682. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  29683. exports.ToUnicodeMap = ToUnicodeMap;
  29684. exports.getFontType = getFontType;
  29685. }));
  29686. (function (root, factory) {
  29687. {
  29688. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  29689. root.pdfjsCoreParser);
  29690. }
  29691. }(this, function (exports, sharedUtil, coreParser) {
  29692. var error = sharedUtil.error;
  29693. var isSpace = sharedUtil.isSpace;
  29694. var EOF = coreParser.EOF;
  29695. var PostScriptParser = (function PostScriptParserClosure() {
  29696. function PostScriptParser(lexer) {
  29697. this.lexer = lexer;
  29698. this.operators = [];
  29699. this.token = null;
  29700. this.prev = null;
  29701. }
  29702. PostScriptParser.prototype = {
  29703. nextToken: function PostScriptParser_nextToken() {
  29704. this.prev = this.token;
  29705. this.token = this.lexer.getToken();
  29706. },
  29707. accept: function PostScriptParser_accept(type) {
  29708. if (this.token.type === type) {
  29709. this.nextToken();
  29710. return true;
  29711. }
  29712. return false;
  29713. },
  29714. expect: function PostScriptParser_expect(type) {
  29715. if (this.accept(type)) {
  29716. return true;
  29717. }
  29718. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  29719. type + '.');
  29720. },
  29721. parse: function PostScriptParser_parse() {
  29722. this.nextToken();
  29723. this.expect(PostScriptTokenTypes.LBRACE);
  29724. this.parseBlock();
  29725. this.expect(PostScriptTokenTypes.RBRACE);
  29726. return this.operators;
  29727. },
  29728. parseBlock: function PostScriptParser_parseBlock() {
  29729. while (true) {
  29730. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  29731. this.operators.push(this.prev.value);
  29732. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  29733. this.operators.push(this.prev.value);
  29734. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29735. this.parseCondition();
  29736. } else {
  29737. return;
  29738. }
  29739. }
  29740. },
  29741. parseCondition: function PostScriptParser_parseCondition() {
  29742. // Add two place holders that will be updated later
  29743. var conditionLocation = this.operators.length;
  29744. this.operators.push(null, null);
  29745. this.parseBlock();
  29746. this.expect(PostScriptTokenTypes.RBRACE);
  29747. if (this.accept(PostScriptTokenTypes.IF)) {
  29748. // The true block is right after the 'if' so it just falls through on
  29749. // true else it jumps and skips the true block.
  29750. this.operators[conditionLocation] = this.operators.length;
  29751. this.operators[conditionLocation + 1] = 'jz';
  29752. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29753. var jumpLocation = this.operators.length;
  29754. this.operators.push(null, null);
  29755. var endOfTrue = this.operators.length;
  29756. this.parseBlock();
  29757. this.expect(PostScriptTokenTypes.RBRACE);
  29758. this.expect(PostScriptTokenTypes.IFELSE);
  29759. // The jump is added at the end of the true block to skip the false
  29760. // block.
  29761. this.operators[jumpLocation] = this.operators.length;
  29762. this.operators[jumpLocation + 1] = 'j';
  29763. this.operators[conditionLocation] = endOfTrue;
  29764. this.operators[conditionLocation + 1] = 'jz';
  29765. } else {
  29766. error('PS Function: error parsing conditional.');
  29767. }
  29768. }
  29769. };
  29770. return PostScriptParser;
  29771. })();
  29772. var PostScriptTokenTypes = {
  29773. LBRACE: 0,
  29774. RBRACE: 1,
  29775. NUMBER: 2,
  29776. OPERATOR: 3,
  29777. IF: 4,
  29778. IFELSE: 5
  29779. };
  29780. var PostScriptToken = (function PostScriptTokenClosure() {
  29781. function PostScriptToken(type, value) {
  29782. this.type = type;
  29783. this.value = value;
  29784. }
  29785. var opCache = Object.create(null);
  29786. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  29787. var opValue = opCache[op];
  29788. if (opValue) {
  29789. return opValue;
  29790. }
  29791. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  29792. };
  29793. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  29794. '{');
  29795. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  29796. '}');
  29797. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  29798. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  29799. 'IFELSE');
  29800. return PostScriptToken;
  29801. })();
  29802. var PostScriptLexer = (function PostScriptLexerClosure() {
  29803. function PostScriptLexer(stream) {
  29804. this.stream = stream;
  29805. this.nextChar();
  29806. this.strBuf = [];
  29807. }
  29808. PostScriptLexer.prototype = {
  29809. nextChar: function PostScriptLexer_nextChar() {
  29810. return (this.currentChar = this.stream.getByte());
  29811. },
  29812. getToken: function PostScriptLexer_getToken() {
  29813. var comment = false;
  29814. var ch = this.currentChar;
  29815. // skip comments
  29816. while (true) {
  29817. if (ch < 0) {
  29818. return EOF;
  29819. }
  29820. if (comment) {
  29821. if (ch === 0x0A || ch === 0x0D) {
  29822. comment = false;
  29823. }
  29824. } else if (ch === 0x25) { // '%'
  29825. comment = true;
  29826. } else if (!isSpace(ch)) {
  29827. break;
  29828. }
  29829. ch = this.nextChar();
  29830. }
  29831. switch (ch | 0) {
  29832. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29833. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29834. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29835. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  29836. this.getNumber());
  29837. case 0x7B: // '{'
  29838. this.nextChar();
  29839. return PostScriptToken.LBRACE;
  29840. case 0x7D: // '}'
  29841. this.nextChar();
  29842. return PostScriptToken.RBRACE;
  29843. }
  29844. // operator
  29845. var strBuf = this.strBuf;
  29846. strBuf.length = 0;
  29847. strBuf[0] = String.fromCharCode(ch);
  29848. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  29849. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  29850. strBuf.push(String.fromCharCode(ch));
  29851. }
  29852. var str = strBuf.join('');
  29853. switch (str.toLowerCase()) {
  29854. case 'if':
  29855. return PostScriptToken.IF;
  29856. case 'ifelse':
  29857. return PostScriptToken.IFELSE;
  29858. default:
  29859. return PostScriptToken.getOperator(str);
  29860. }
  29861. },
  29862. getNumber: function PostScriptLexer_getNumber() {
  29863. var ch = this.currentChar;
  29864. var strBuf = this.strBuf;
  29865. strBuf.length = 0;
  29866. strBuf[0] = String.fromCharCode(ch);
  29867. while ((ch = this.nextChar()) >= 0) {
  29868. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  29869. ch === 0x2D || ch === 0x2E) { // '-', '.'
  29870. strBuf.push(String.fromCharCode(ch));
  29871. } else {
  29872. break;
  29873. }
  29874. }
  29875. var value = parseFloat(strBuf.join(''));
  29876. if (isNaN(value)) {
  29877. error('Invalid floating point number: ' + value);
  29878. }
  29879. return value;
  29880. }
  29881. };
  29882. return PostScriptLexer;
  29883. })();
  29884. exports.PostScriptLexer = PostScriptLexer;
  29885. exports.PostScriptParser = PostScriptParser;
  29886. }));
  29887. (function (root, factory) {
  29888. {
  29889. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  29890. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  29891. }
  29892. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  29893. var error = sharedUtil.error;
  29894. var info = sharedUtil.info;
  29895. var isArray = sharedUtil.isArray;
  29896. var isBool = sharedUtil.isBool;
  29897. var isDict = corePrimitives.isDict;
  29898. var isStream = corePrimitives.isStream;
  29899. var PostScriptLexer = corePsParser.PostScriptLexer;
  29900. var PostScriptParser = corePsParser.PostScriptParser;
  29901. var PDFFunction = (function PDFFunctionClosure() {
  29902. var CONSTRUCT_SAMPLED = 0;
  29903. var CONSTRUCT_INTERPOLATED = 2;
  29904. var CONSTRUCT_STICHED = 3;
  29905. var CONSTRUCT_POSTSCRIPT = 4;
  29906. return {
  29907. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  29908. str) {
  29909. var i, ii;
  29910. var length = 1;
  29911. for (i = 0, ii = size.length; i < ii; i++) {
  29912. length *= size[i];
  29913. }
  29914. length *= outputSize;
  29915. var array = new Array(length);
  29916. var codeSize = 0;
  29917. var codeBuf = 0;
  29918. // 32 is a valid bps so shifting won't work
  29919. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  29920. var strBytes = str.getBytes((length * bps + 7) / 8);
  29921. var strIdx = 0;
  29922. for (i = 0; i < length; i++) {
  29923. while (codeSize < bps) {
  29924. codeBuf <<= 8;
  29925. codeBuf |= strBytes[strIdx++];
  29926. codeSize += 8;
  29927. }
  29928. codeSize -= bps;
  29929. array[i] = (codeBuf >> codeSize) * sampleMul;
  29930. codeBuf &= (1 << codeSize) - 1;
  29931. }
  29932. return array;
  29933. },
  29934. getIR: function PDFFunction_getIR(xref, fn) {
  29935. var dict = fn.dict;
  29936. if (!dict) {
  29937. dict = fn;
  29938. }
  29939. var types = [this.constructSampled,
  29940. null,
  29941. this.constructInterpolated,
  29942. this.constructStiched,
  29943. this.constructPostScript];
  29944. var typeNum = dict.get('FunctionType');
  29945. var typeFn = types[typeNum];
  29946. if (!typeFn) {
  29947. error('Unknown type of function');
  29948. }
  29949. return typeFn.call(this, fn, dict, xref);
  29950. },
  29951. fromIR: function PDFFunction_fromIR(IR) {
  29952. var type = IR[0];
  29953. switch (type) {
  29954. case CONSTRUCT_SAMPLED:
  29955. return this.constructSampledFromIR(IR);
  29956. case CONSTRUCT_INTERPOLATED:
  29957. return this.constructInterpolatedFromIR(IR);
  29958. case CONSTRUCT_STICHED:
  29959. return this.constructStichedFromIR(IR);
  29960. //case CONSTRUCT_POSTSCRIPT:
  29961. default:
  29962. return this.constructPostScriptFromIR(IR);
  29963. }
  29964. },
  29965. parse: function PDFFunction_parse(xref, fn) {
  29966. var IR = this.getIR(xref, fn);
  29967. return this.fromIR(IR);
  29968. },
  29969. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  29970. if (!isArray(fnObj)) {
  29971. // not an array -- parsing as regular function
  29972. return this.parse(xref, fnObj);
  29973. }
  29974. var fnArray = [];
  29975. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  29976. var obj = xref.fetchIfRef(fnObj[j]);
  29977. fnArray.push(PDFFunction.parse(xref, obj));
  29978. }
  29979. return function (src, srcOffset, dest, destOffset) {
  29980. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  29981. fnArray[i](src, srcOffset, dest, destOffset + i);
  29982. }
  29983. };
  29984. },
  29985. constructSampled: function PDFFunction_constructSampled(str, dict) {
  29986. function toMultiArray(arr) {
  29987. var inputLength = arr.length;
  29988. var out = [];
  29989. var index = 0;
  29990. for (var i = 0; i < inputLength; i += 2) {
  29991. out[index] = [arr[i], arr[i + 1]];
  29992. ++index;
  29993. }
  29994. return out;
  29995. }
  29996. var domain = dict.getArray('Domain');
  29997. var range = dict.getArray('Range');
  29998. if (!domain || !range) {
  29999. error('No domain or range');
  30000. }
  30001. var inputSize = domain.length / 2;
  30002. var outputSize = range.length / 2;
  30003. domain = toMultiArray(domain);
  30004. range = toMultiArray(range);
  30005. var size = dict.get('Size');
  30006. var bps = dict.get('BitsPerSample');
  30007. var order = dict.get('Order') || 1;
  30008. if (order !== 1) {
  30009. // No description how cubic spline interpolation works in PDF32000:2008
  30010. // As in poppler, ignoring order, linear interpolation may work as good
  30011. info('No support for cubic spline interpolation: ' + order);
  30012. }
  30013. var encode = dict.getArray('Encode');
  30014. if (!encode) {
  30015. encode = [];
  30016. for (var i = 0; i < inputSize; ++i) {
  30017. encode.push(0);
  30018. encode.push(size[i] - 1);
  30019. }
  30020. }
  30021. encode = toMultiArray(encode);
  30022. var decode = dict.getArray('Decode');
  30023. if (!decode) {
  30024. decode = range;
  30025. } else {
  30026. decode = toMultiArray(decode);
  30027. }
  30028. var samples = this.getSampleArray(size, outputSize, bps, str);
  30029. return [
  30030. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  30031. outputSize, Math.pow(2, bps) - 1, range
  30032. ];
  30033. },
  30034. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  30035. // See chapter 3, page 109 of the PDF reference
  30036. function interpolate(x, xmin, xmax, ymin, ymax) {
  30037. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  30038. }
  30039. return function constructSampledFromIRResult(src, srcOffset,
  30040. dest, destOffset) {
  30041. // See chapter 3, page 110 of the PDF reference.
  30042. var m = IR[1];
  30043. var domain = IR[2];
  30044. var encode = IR[3];
  30045. var decode = IR[4];
  30046. var samples = IR[5];
  30047. var size = IR[6];
  30048. var n = IR[7];
  30049. //var mask = IR[8];
  30050. var range = IR[9];
  30051. // Building the cube vertices: its part and sample index
  30052. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  30053. var cubeVertices = 1 << m;
  30054. var cubeN = new Float64Array(cubeVertices);
  30055. var cubeVertex = new Uint32Array(cubeVertices);
  30056. var i, j;
  30057. for (j = 0; j < cubeVertices; j++) {
  30058. cubeN[j] = 1;
  30059. }
  30060. var k = n, pos = 1;
  30061. // Map x_i to y_j for 0 <= i < m using the sampled function.
  30062. for (i = 0; i < m; ++i) {
  30063. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  30064. var domain_2i = domain[i][0];
  30065. var domain_2i_1 = domain[i][1];
  30066. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  30067. domain_2i_1);
  30068. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  30069. // Encode_2i, Encode_2i+1)
  30070. var e = interpolate(xi, domain_2i, domain_2i_1,
  30071. encode[i][0], encode[i][1]);
  30072. // e_i' = min(max(e_i, 0), Size_i - 1)
  30073. var size_i = size[i];
  30074. e = Math.min(Math.max(e, 0), size_i - 1);
  30075. // Adjusting the cube: N and vertex sample index
  30076. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  30077. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  30078. var n1 = e - e0; // (e - e0) / (e1 - e0);
  30079. var offset0 = e0 * k;
  30080. var offset1 = offset0 + k; // e1 * k
  30081. for (j = 0; j < cubeVertices; j++) {
  30082. if (j & pos) {
  30083. cubeN[j] *= n1;
  30084. cubeVertex[j] += offset1;
  30085. } else {
  30086. cubeN[j] *= n0;
  30087. cubeVertex[j] += offset0;
  30088. }
  30089. }
  30090. k *= size_i;
  30091. pos <<= 1;
  30092. }
  30093. for (j = 0; j < n; ++j) {
  30094. // Sum all cube vertices' samples portions
  30095. var rj = 0;
  30096. for (i = 0; i < cubeVertices; i++) {
  30097. rj += samples[cubeVertex[i] + j] * cubeN[i];
  30098. }
  30099. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  30100. // Decode_2j, Decode_2j+1)
  30101. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  30102. // y_j = min(max(r_j, range_2j), range_2j+1)
  30103. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  30104. range[j][1]);
  30105. }
  30106. };
  30107. },
  30108. constructInterpolated: function PDFFunction_constructInterpolated(str,
  30109. dict) {
  30110. var c0 = dict.getArray('C0') || [0];
  30111. var c1 = dict.getArray('C1') || [1];
  30112. var n = dict.get('N');
  30113. if (!isArray(c0) || !isArray(c1)) {
  30114. error('Illegal dictionary for interpolated function');
  30115. }
  30116. var length = c0.length;
  30117. var diff = [];
  30118. for (var i = 0; i < length; ++i) {
  30119. diff.push(c1[i] - c0[i]);
  30120. }
  30121. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  30122. },
  30123. constructInterpolatedFromIR:
  30124. function PDFFunction_constructInterpolatedFromIR(IR) {
  30125. var c0 = IR[1];
  30126. var diff = IR[2];
  30127. var n = IR[3];
  30128. var length = diff.length;
  30129. return function constructInterpolatedFromIRResult(src, srcOffset,
  30130. dest, destOffset) {
  30131. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  30132. for (var j = 0; j < length; ++j) {
  30133. dest[destOffset + j] = c0[j] + (x * diff[j]);
  30134. }
  30135. };
  30136. },
  30137. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  30138. var domain = dict.getArray('Domain');
  30139. if (!domain) {
  30140. error('No domain');
  30141. }
  30142. var inputSize = domain.length / 2;
  30143. if (inputSize !== 1) {
  30144. error('Bad domain for stiched function');
  30145. }
  30146. var fnRefs = dict.get('Functions');
  30147. var fns = [];
  30148. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  30149. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  30150. }
  30151. var bounds = dict.getArray('Bounds');
  30152. var encode = dict.getArray('Encode');
  30153. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  30154. },
  30155. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  30156. var domain = IR[1];
  30157. var bounds = IR[2];
  30158. var encode = IR[3];
  30159. var fnsIR = IR[4];
  30160. var fns = [];
  30161. var tmpBuf = new Float32Array(1);
  30162. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  30163. fns.push(PDFFunction.fromIR(fnsIR[i]));
  30164. }
  30165. return function constructStichedFromIRResult(src, srcOffset,
  30166. dest, destOffset) {
  30167. var clip = function constructStichedFromIRClip(v, min, max) {
  30168. if (v > max) {
  30169. v = max;
  30170. } else if (v < min) {
  30171. v = min;
  30172. }
  30173. return v;
  30174. };
  30175. // clip to domain
  30176. var v = clip(src[srcOffset], domain[0], domain[1]);
  30177. // calculate which bound the value is in
  30178. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  30179. if (v < bounds[i]) {
  30180. break;
  30181. }
  30182. }
  30183. // encode value into domain of function
  30184. var dmin = domain[0];
  30185. if (i > 0) {
  30186. dmin = bounds[i - 1];
  30187. }
  30188. var dmax = domain[1];
  30189. if (i < bounds.length) {
  30190. dmax = bounds[i];
  30191. }
  30192. var rmin = encode[2 * i];
  30193. var rmax = encode[2 * i + 1];
  30194. // Prevent the value from becoming NaN as a result
  30195. // of division by zero (fixes issue6113.pdf).
  30196. tmpBuf[0] = dmin === dmax ? rmin :
  30197. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  30198. // call the appropriate function
  30199. fns[i](tmpBuf, 0, dest, destOffset);
  30200. };
  30201. },
  30202. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  30203. xref) {
  30204. var domain = dict.getArray('Domain');
  30205. var range = dict.getArray('Range');
  30206. if (!domain) {
  30207. error('No domain.');
  30208. }
  30209. if (!range) {
  30210. error('No range.');
  30211. }
  30212. var lexer = new PostScriptLexer(fn);
  30213. var parser = new PostScriptParser(lexer);
  30214. var code = parser.parse();
  30215. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  30216. },
  30217. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  30218. IR) {
  30219. var domain = IR[1];
  30220. var range = IR[2];
  30221. var code = IR[3];
  30222. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  30223. if (compiled) {
  30224. // Compiled function consists of simple expressions such as addition,
  30225. // subtraction, Math.max, and also contains 'var' and 'return'
  30226. // statements. See the generation in the PostScriptCompiler below.
  30227. /*jshint -W054 */
  30228. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  30229. }
  30230. info('Unable to compile PS function');
  30231. var numOutputs = range.length >> 1;
  30232. var numInputs = domain.length >> 1;
  30233. var evaluator = new PostScriptEvaluator(code);
  30234. // Cache the values for a big speed up, the cache size is limited though
  30235. // since the number of possible values can be huge from a PS function.
  30236. var cache = Object.create(null);
  30237. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  30238. // seen in our tests.
  30239. var MAX_CACHE_SIZE = 2048 * 4;
  30240. var cache_available = MAX_CACHE_SIZE;
  30241. var tmpBuf = new Float32Array(numInputs);
  30242. return function constructPostScriptFromIRResult(src, srcOffset,
  30243. dest, destOffset) {
  30244. var i, value;
  30245. var key = '';
  30246. var input = tmpBuf;
  30247. for (i = 0; i < numInputs; i++) {
  30248. value = src[srcOffset + i];
  30249. input[i] = value;
  30250. key += value + '_';
  30251. }
  30252. var cachedValue = cache[key];
  30253. if (cachedValue !== undefined) {
  30254. dest.set(cachedValue, destOffset);
  30255. return;
  30256. }
  30257. var output = new Float32Array(numOutputs);
  30258. var stack = evaluator.execute(input);
  30259. var stackIndex = stack.length - numOutputs;
  30260. for (i = 0; i < numOutputs; i++) {
  30261. value = stack[stackIndex + i];
  30262. var bound = range[i * 2];
  30263. if (value < bound) {
  30264. value = bound;
  30265. } else {
  30266. bound = range[i * 2 +1];
  30267. if (value > bound) {
  30268. value = bound;
  30269. }
  30270. }
  30271. output[i] = value;
  30272. }
  30273. if (cache_available > 0) {
  30274. cache_available--;
  30275. cache[key] = output;
  30276. }
  30277. dest.set(output, destOffset);
  30278. };
  30279. }
  30280. };
  30281. })();
  30282. function isPDFFunction(v) {
  30283. var fnDict;
  30284. if (typeof v !== 'object') {
  30285. return false;
  30286. } else if (isDict(v)) {
  30287. fnDict = v;
  30288. } else if (isStream(v)) {
  30289. fnDict = v.dict;
  30290. } else {
  30291. return false;
  30292. }
  30293. return fnDict.has('FunctionType');
  30294. }
  30295. var PostScriptStack = (function PostScriptStackClosure() {
  30296. var MAX_STACK_SIZE = 100;
  30297. function PostScriptStack(initialStack) {
  30298. this.stack = !initialStack ? [] :
  30299. Array.prototype.slice.call(initialStack, 0);
  30300. }
  30301. PostScriptStack.prototype = {
  30302. push: function PostScriptStack_push(value) {
  30303. if (this.stack.length >= MAX_STACK_SIZE) {
  30304. error('PostScript function stack overflow.');
  30305. }
  30306. this.stack.push(value);
  30307. },
  30308. pop: function PostScriptStack_pop() {
  30309. if (this.stack.length <= 0) {
  30310. error('PostScript function stack underflow.');
  30311. }
  30312. return this.stack.pop();
  30313. },
  30314. copy: function PostScriptStack_copy(n) {
  30315. if (this.stack.length + n >= MAX_STACK_SIZE) {
  30316. error('PostScript function stack overflow.');
  30317. }
  30318. var stack = this.stack;
  30319. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  30320. stack.push(stack[i]);
  30321. }
  30322. },
  30323. index: function PostScriptStack_index(n) {
  30324. this.push(this.stack[this.stack.length - n - 1]);
  30325. },
  30326. // rotate the last n stack elements p times
  30327. roll: function PostScriptStack_roll(n, p) {
  30328. var stack = this.stack;
  30329. var l = stack.length - n;
  30330. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  30331. for (i = l, j = r; i < j; i++, j--) {
  30332. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30333. }
  30334. for (i = l, j = c - 1; i < j; i++, j--) {
  30335. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30336. }
  30337. for (i = c, j = r; i < j; i++, j--) {
  30338. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30339. }
  30340. }
  30341. };
  30342. return PostScriptStack;
  30343. })();
  30344. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  30345. function PostScriptEvaluator(operators) {
  30346. this.operators = operators;
  30347. }
  30348. PostScriptEvaluator.prototype = {
  30349. execute: function PostScriptEvaluator_execute(initialStack) {
  30350. var stack = new PostScriptStack(initialStack);
  30351. var counter = 0;
  30352. var operators = this.operators;
  30353. var length = operators.length;
  30354. var operator, a, b;
  30355. while (counter < length) {
  30356. operator = operators[counter++];
  30357. if (typeof operator === 'number') {
  30358. // Operator is really an operand and should be pushed to the stack.
  30359. stack.push(operator);
  30360. continue;
  30361. }
  30362. switch (operator) {
  30363. // non standard ps operators
  30364. case 'jz': // jump if false
  30365. b = stack.pop();
  30366. a = stack.pop();
  30367. if (!a) {
  30368. counter = b;
  30369. }
  30370. break;
  30371. case 'j': // jump
  30372. a = stack.pop();
  30373. counter = a;
  30374. break;
  30375. // all ps operators in alphabetical order (excluding if/ifelse)
  30376. case 'abs':
  30377. a = stack.pop();
  30378. stack.push(Math.abs(a));
  30379. break;
  30380. case 'add':
  30381. b = stack.pop();
  30382. a = stack.pop();
  30383. stack.push(a + b);
  30384. break;
  30385. case 'and':
  30386. b = stack.pop();
  30387. a = stack.pop();
  30388. if (isBool(a) && isBool(b)) {
  30389. stack.push(a && b);
  30390. } else {
  30391. stack.push(a & b);
  30392. }
  30393. break;
  30394. case 'atan':
  30395. a = stack.pop();
  30396. stack.push(Math.atan(a));
  30397. break;
  30398. case 'bitshift':
  30399. b = stack.pop();
  30400. a = stack.pop();
  30401. if (a > 0) {
  30402. stack.push(a << b);
  30403. } else {
  30404. stack.push(a >> b);
  30405. }
  30406. break;
  30407. case 'ceiling':
  30408. a = stack.pop();
  30409. stack.push(Math.ceil(a));
  30410. break;
  30411. case 'copy':
  30412. a = stack.pop();
  30413. stack.copy(a);
  30414. break;
  30415. case 'cos':
  30416. a = stack.pop();
  30417. stack.push(Math.cos(a));
  30418. break;
  30419. case 'cvi':
  30420. a = stack.pop() | 0;
  30421. stack.push(a);
  30422. break;
  30423. case 'cvr':
  30424. // noop
  30425. break;
  30426. case 'div':
  30427. b = stack.pop();
  30428. a = stack.pop();
  30429. stack.push(a / b);
  30430. break;
  30431. case 'dup':
  30432. stack.copy(1);
  30433. break;
  30434. case 'eq':
  30435. b = stack.pop();
  30436. a = stack.pop();
  30437. stack.push(a === b);
  30438. break;
  30439. case 'exch':
  30440. stack.roll(2, 1);
  30441. break;
  30442. case 'exp':
  30443. b = stack.pop();
  30444. a = stack.pop();
  30445. stack.push(Math.pow(a, b));
  30446. break;
  30447. case 'false':
  30448. stack.push(false);
  30449. break;
  30450. case 'floor':
  30451. a = stack.pop();
  30452. stack.push(Math.floor(a));
  30453. break;
  30454. case 'ge':
  30455. b = stack.pop();
  30456. a = stack.pop();
  30457. stack.push(a >= b);
  30458. break;
  30459. case 'gt':
  30460. b = stack.pop();
  30461. a = stack.pop();
  30462. stack.push(a > b);
  30463. break;
  30464. case 'idiv':
  30465. b = stack.pop();
  30466. a = stack.pop();
  30467. stack.push((a / b) | 0);
  30468. break;
  30469. case 'index':
  30470. a = stack.pop();
  30471. stack.index(a);
  30472. break;
  30473. case 'le':
  30474. b = stack.pop();
  30475. a = stack.pop();
  30476. stack.push(a <= b);
  30477. break;
  30478. case 'ln':
  30479. a = stack.pop();
  30480. stack.push(Math.log(a));
  30481. break;
  30482. case 'log':
  30483. a = stack.pop();
  30484. stack.push(Math.log(a) / Math.LN10);
  30485. break;
  30486. case 'lt':
  30487. b = stack.pop();
  30488. a = stack.pop();
  30489. stack.push(a < b);
  30490. break;
  30491. case 'mod':
  30492. b = stack.pop();
  30493. a = stack.pop();
  30494. stack.push(a % b);
  30495. break;
  30496. case 'mul':
  30497. b = stack.pop();
  30498. a = stack.pop();
  30499. stack.push(a * b);
  30500. break;
  30501. case 'ne':
  30502. b = stack.pop();
  30503. a = stack.pop();
  30504. stack.push(a !== b);
  30505. break;
  30506. case 'neg':
  30507. a = stack.pop();
  30508. stack.push(-a);
  30509. break;
  30510. case 'not':
  30511. a = stack.pop();
  30512. if (isBool(a)) {
  30513. stack.push(!a);
  30514. } else {
  30515. stack.push(~a);
  30516. }
  30517. break;
  30518. case 'or':
  30519. b = stack.pop();
  30520. a = stack.pop();
  30521. if (isBool(a) && isBool(b)) {
  30522. stack.push(a || b);
  30523. } else {
  30524. stack.push(a | b);
  30525. }
  30526. break;
  30527. case 'pop':
  30528. stack.pop();
  30529. break;
  30530. case 'roll':
  30531. b = stack.pop();
  30532. a = stack.pop();
  30533. stack.roll(a, b);
  30534. break;
  30535. case 'round':
  30536. a = stack.pop();
  30537. stack.push(Math.round(a));
  30538. break;
  30539. case 'sin':
  30540. a = stack.pop();
  30541. stack.push(Math.sin(a));
  30542. break;
  30543. case 'sqrt':
  30544. a = stack.pop();
  30545. stack.push(Math.sqrt(a));
  30546. break;
  30547. case 'sub':
  30548. b = stack.pop();
  30549. a = stack.pop();
  30550. stack.push(a - b);
  30551. break;
  30552. case 'true':
  30553. stack.push(true);
  30554. break;
  30555. case 'truncate':
  30556. a = stack.pop();
  30557. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  30558. stack.push(a);
  30559. break;
  30560. case 'xor':
  30561. b = stack.pop();
  30562. a = stack.pop();
  30563. if (isBool(a) && isBool(b)) {
  30564. stack.push(a !== b);
  30565. } else {
  30566. stack.push(a ^ b);
  30567. }
  30568. break;
  30569. default:
  30570. error('Unknown operator ' + operator);
  30571. break;
  30572. }
  30573. }
  30574. return stack.stack;
  30575. }
  30576. };
  30577. return PostScriptEvaluator;
  30578. })();
  30579. // Most of the PDFs functions consist of simple operations such as:
  30580. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  30581. //
  30582. // We can compile most of such programs, and at the same moment, we can
  30583. // optimize some expressions using basic math properties. Keeping track of
  30584. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  30585. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  30586. function AstNode(type) {
  30587. this.type = type;
  30588. }
  30589. AstNode.prototype.visit = function (visitor) {
  30590. throw new Error('abstract method');
  30591. };
  30592. function AstArgument(index, min, max) {
  30593. AstNode.call(this, 'args');
  30594. this.index = index;
  30595. this.min = min;
  30596. this.max = max;
  30597. }
  30598. AstArgument.prototype = Object.create(AstNode.prototype);
  30599. AstArgument.prototype.visit = function (visitor) {
  30600. visitor.visitArgument(this);
  30601. };
  30602. function AstLiteral(number) {
  30603. AstNode.call(this, 'literal');
  30604. this.number = number;
  30605. this.min = number;
  30606. this.max = number;
  30607. }
  30608. AstLiteral.prototype = Object.create(AstNode.prototype);
  30609. AstLiteral.prototype.visit = function (visitor) {
  30610. visitor.visitLiteral(this);
  30611. };
  30612. function AstBinaryOperation(op, arg1, arg2, min, max) {
  30613. AstNode.call(this, 'binary');
  30614. this.op = op;
  30615. this.arg1 = arg1;
  30616. this.arg2 = arg2;
  30617. this.min = min;
  30618. this.max = max;
  30619. }
  30620. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  30621. AstBinaryOperation.prototype.visit = function (visitor) {
  30622. visitor.visitBinaryOperation(this);
  30623. };
  30624. function AstMin(arg, max) {
  30625. AstNode.call(this, 'max');
  30626. this.arg = arg;
  30627. this.min = arg.min;
  30628. this.max = max;
  30629. }
  30630. AstMin.prototype = Object.create(AstNode.prototype);
  30631. AstMin.prototype.visit = function (visitor) {
  30632. visitor.visitMin(this);
  30633. };
  30634. function AstVariable(index, min, max) {
  30635. AstNode.call(this, 'var');
  30636. this.index = index;
  30637. this.min = min;
  30638. this.max = max;
  30639. }
  30640. AstVariable.prototype = Object.create(AstNode.prototype);
  30641. AstVariable.prototype.visit = function (visitor) {
  30642. visitor.visitVariable(this);
  30643. };
  30644. function AstVariableDefinition(variable, arg) {
  30645. AstNode.call(this, 'definition');
  30646. this.variable = variable;
  30647. this.arg = arg;
  30648. }
  30649. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  30650. AstVariableDefinition.prototype.visit = function (visitor) {
  30651. visitor.visitVariableDefinition(this);
  30652. };
  30653. function ExpressionBuilderVisitor() {
  30654. this.parts = [];
  30655. }
  30656. ExpressionBuilderVisitor.prototype = {
  30657. visitArgument: function (arg) {
  30658. this.parts.push('Math.max(', arg.min, ', Math.min(',
  30659. arg.max, ', src[srcOffset + ', arg.index, ']))');
  30660. },
  30661. visitVariable: function (variable) {
  30662. this.parts.push('v', variable.index);
  30663. },
  30664. visitLiteral: function (literal) {
  30665. this.parts.push(literal.number);
  30666. },
  30667. visitBinaryOperation: function (operation) {
  30668. this.parts.push('(');
  30669. operation.arg1.visit(this);
  30670. this.parts.push(' ', operation.op, ' ');
  30671. operation.arg2.visit(this);
  30672. this.parts.push(')');
  30673. },
  30674. visitVariableDefinition: function (definition) {
  30675. this.parts.push('var ');
  30676. definition.variable.visit(this);
  30677. this.parts.push(' = ');
  30678. definition.arg.visit(this);
  30679. this.parts.push(';');
  30680. },
  30681. visitMin: function (max) {
  30682. this.parts.push('Math.min(');
  30683. max.arg.visit(this);
  30684. this.parts.push(', ', max.max, ')');
  30685. },
  30686. toString: function () {
  30687. return this.parts.join('');
  30688. }
  30689. };
  30690. function buildAddOperation(num1, num2) {
  30691. if (num2.type === 'literal' && num2.number === 0) {
  30692. // optimization: second operand is 0
  30693. return num1;
  30694. }
  30695. if (num1.type === 'literal' && num1.number === 0) {
  30696. // optimization: first operand is 0
  30697. return num2;
  30698. }
  30699. if (num2.type === 'literal' && num1.type === 'literal') {
  30700. // optimization: operands operand are literals
  30701. return new AstLiteral(num1.number + num2.number);
  30702. }
  30703. return new AstBinaryOperation('+', num1, num2,
  30704. num1.min + num2.min, num1.max + num2.max);
  30705. }
  30706. function buildMulOperation(num1, num2) {
  30707. if (num2.type === 'literal') {
  30708. // optimization: second operands is a literal...
  30709. if (num2.number === 0) {
  30710. return new AstLiteral(0); // and it's 0
  30711. } else if (num2.number === 1) {
  30712. return num1; // and it's 1
  30713. } else if (num1.type === 'literal') {
  30714. // ... and first operands is a literal too
  30715. return new AstLiteral(num1.number * num2.number);
  30716. }
  30717. }
  30718. if (num1.type === 'literal') {
  30719. // optimization: first operands is a literal...
  30720. if (num1.number === 0) {
  30721. return new AstLiteral(0); // and it's 0
  30722. } else if (num1.number === 1) {
  30723. return num2; // and it's 1
  30724. }
  30725. }
  30726. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  30727. num1.max * num2.min, num1.max * num2.max);
  30728. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  30729. num1.max * num2.min, num1.max * num2.max);
  30730. return new AstBinaryOperation('*', num1, num2, min, max);
  30731. }
  30732. function buildSubOperation(num1, num2) {
  30733. if (num2.type === 'literal') {
  30734. // optimization: second operands is a literal...
  30735. if (num2.number === 0) {
  30736. return num1; // ... and it's 0
  30737. } else if (num1.type === 'literal') {
  30738. // ... and first operands is a literal too
  30739. return new AstLiteral(num1.number - num2.number);
  30740. }
  30741. }
  30742. if (num2.type === 'binary' && num2.op === '-' &&
  30743. num1.type === 'literal' && num1.number === 1 &&
  30744. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  30745. // optimization for case: 1 - (1 - x)
  30746. return num2.arg2;
  30747. }
  30748. return new AstBinaryOperation('-', num1, num2,
  30749. num1.min - num2.max, num1.max - num2.min);
  30750. }
  30751. function buildMinOperation(num1, max) {
  30752. if (num1.min >= max) {
  30753. // optimization: num1 min value is not less than required max
  30754. return new AstLiteral(max); // just returning max
  30755. } else if (num1.max <= max) {
  30756. // optimization: num1 max value is not greater than required max
  30757. return num1; // just returning an argument
  30758. }
  30759. return new AstMin(num1, max);
  30760. }
  30761. function PostScriptCompiler() {}
  30762. PostScriptCompiler.prototype = {
  30763. compile: function PostScriptCompiler_compile(code, domain, range) {
  30764. var stack = [];
  30765. var i, ii;
  30766. var instructions = [];
  30767. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  30768. var lastRegister = 0;
  30769. var n, j;
  30770. var num1, num2, ast1, ast2, tmpVar, item;
  30771. for (i = 0; i < inputSize; i++) {
  30772. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  30773. }
  30774. for (i = 0, ii = code.length; i < ii; i++) {
  30775. item = code[i];
  30776. if (typeof item === 'number') {
  30777. stack.push(new AstLiteral(item));
  30778. continue;
  30779. }
  30780. switch (item) {
  30781. case 'add':
  30782. if (stack.length < 2) {
  30783. return null;
  30784. }
  30785. num2 = stack.pop();
  30786. num1 = stack.pop();
  30787. stack.push(buildAddOperation(num1, num2));
  30788. break;
  30789. case 'cvr':
  30790. if (stack.length < 1) {
  30791. return null;
  30792. }
  30793. break;
  30794. case 'mul':
  30795. if (stack.length < 2) {
  30796. return null;
  30797. }
  30798. num2 = stack.pop();
  30799. num1 = stack.pop();
  30800. stack.push(buildMulOperation(num1, num2));
  30801. break;
  30802. case 'sub':
  30803. if (stack.length < 2) {
  30804. return null;
  30805. }
  30806. num2 = stack.pop();
  30807. num1 = stack.pop();
  30808. stack.push(buildSubOperation(num1, num2));
  30809. break;
  30810. case 'exch':
  30811. if (stack.length < 2) {
  30812. return null;
  30813. }
  30814. ast1 = stack.pop(); ast2 = stack.pop();
  30815. stack.push(ast1, ast2);
  30816. break;
  30817. case 'pop':
  30818. if (stack.length < 1) {
  30819. return null;
  30820. }
  30821. stack.pop();
  30822. break;
  30823. case 'index':
  30824. if (stack.length < 1) {
  30825. return null;
  30826. }
  30827. num1 = stack.pop();
  30828. if (num1.type !== 'literal') {
  30829. return null;
  30830. }
  30831. n = num1.number;
  30832. if (n < 0 || (n|0) !== n || stack.length < n) {
  30833. return null;
  30834. }
  30835. ast1 = stack[stack.length - n - 1];
  30836. if (ast1.type === 'literal' || ast1.type === 'var') {
  30837. stack.push(ast1);
  30838. break;
  30839. }
  30840. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  30841. stack[stack.length - n - 1] = tmpVar;
  30842. stack.push(tmpVar);
  30843. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  30844. break;
  30845. case 'dup':
  30846. if (stack.length < 1) {
  30847. return null;
  30848. }
  30849. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  30850. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  30851. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  30852. // special case of the commands sequence for the min operation
  30853. num1 = stack.pop();
  30854. stack.push(buildMinOperation(num1, code[i + 1]));
  30855. i += 6;
  30856. break;
  30857. }
  30858. ast1 = stack[stack.length - 1];
  30859. if (ast1.type === 'literal' || ast1.type === 'var') {
  30860. // we don't have to save into intermediate variable a literal or
  30861. // variable.
  30862. stack.push(ast1);
  30863. break;
  30864. }
  30865. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  30866. stack[stack.length - 1] = tmpVar;
  30867. stack.push(tmpVar);
  30868. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  30869. break;
  30870. case 'roll':
  30871. if (stack.length < 2) {
  30872. return null;
  30873. }
  30874. num2 = stack.pop();
  30875. num1 = stack.pop();
  30876. if (num2.type !== 'literal' || num1.type !== 'literal') {
  30877. // both roll operands must be numbers
  30878. return null;
  30879. }
  30880. j = num2.number;
  30881. n = num1.number;
  30882. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  30883. // ... and integers
  30884. return null;
  30885. }
  30886. j = ((j % n) + n) % n;
  30887. if (j === 0) {
  30888. break; // just skipping -- there are nothing to rotate
  30889. }
  30890. Array.prototype.push.apply(stack,
  30891. stack.splice(stack.length - n, n - j));
  30892. break;
  30893. default:
  30894. return null; // unsupported operator
  30895. }
  30896. }
  30897. if (stack.length !== outputSize) {
  30898. return null;
  30899. }
  30900. var result = [];
  30901. instructions.forEach(function (instruction) {
  30902. var statementBuilder = new ExpressionBuilderVisitor();
  30903. instruction.visit(statementBuilder);
  30904. result.push(statementBuilder.toString());
  30905. });
  30906. stack.forEach(function (expr, i) {
  30907. var statementBuilder = new ExpressionBuilderVisitor();
  30908. expr.visit(statementBuilder);
  30909. var min = range[i * 2], max = range[i * 2 + 1];
  30910. var out = [statementBuilder.toString()];
  30911. if (min > expr.min) {
  30912. out.unshift('Math.max(', min, ', ');
  30913. out.push(')');
  30914. }
  30915. if (max < expr.max) {
  30916. out.unshift('Math.min(', max, ', ');
  30917. out.push(')');
  30918. }
  30919. out.unshift('dest[destOffset + ', i, '] = ');
  30920. out.push(';');
  30921. result.push(out.join(''));
  30922. });
  30923. return result.join('\n');
  30924. }
  30925. };
  30926. return PostScriptCompiler;
  30927. })();
  30928. exports.isPDFFunction = isPDFFunction;
  30929. exports.PDFFunction = PDFFunction;
  30930. exports.PostScriptEvaluator = PostScriptEvaluator;
  30931. exports.PostScriptCompiler = PostScriptCompiler;
  30932. }));
  30933. (function (root, factory) {
  30934. {
  30935. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  30936. root.pdfjsCorePrimitives, root.pdfjsCoreFunction);
  30937. }
  30938. }(this, function (exports, sharedUtil, corePrimitives, coreFunction) {
  30939. var error = sharedUtil.error;
  30940. var info = sharedUtil.info;
  30941. var isArray = sharedUtil.isArray;
  30942. var isString = sharedUtil.isString;
  30943. var shadow = sharedUtil.shadow;
  30944. var warn = sharedUtil.warn;
  30945. var isDict = corePrimitives.isDict;
  30946. var isName = corePrimitives.isName;
  30947. var isStream = corePrimitives.isStream;
  30948. var PDFFunction = coreFunction.PDFFunction;
  30949. var ColorSpace = (function ColorSpaceClosure() {
  30950. /**
  30951. * Resizes an RGB image with 3 components.
  30952. * @param {TypedArray} src - The source buffer.
  30953. * @param {Number} bpc - Number of bits per component.
  30954. * @param {Number} w1 - Original width.
  30955. * @param {Number} h1 - Original height.
  30956. * @param {Number} w2 - New width.
  30957. * @param {Number} h2 - New height.
  30958. * @param {Number} alpha01 - Size reserved for the alpha channel.
  30959. * @param {TypedArray} dest - The destination buffer.
  30960. */
  30961. function resizeRgbImage(src, bpc, w1, h1, w2, h2, alpha01, dest) {
  30962. var COMPONENTS = 3;
  30963. alpha01 = alpha01 !== 1 ? 0 : alpha01;
  30964. var xRatio = w1 / w2;
  30965. var yRatio = h1 / h2;
  30966. var i, j, py, newIndex = 0, oldIndex;
  30967. var xScaled = new Uint16Array(w2);
  30968. var w1Scanline = w1 * COMPONENTS;
  30969. for (i = 0; i < w2; i++) {
  30970. xScaled[i] = Math.floor(i * xRatio) * COMPONENTS;
  30971. }
  30972. for (i = 0; i < h2; i++) {
  30973. py = Math.floor(i * yRatio) * w1Scanline;
  30974. for (j = 0; j < w2; j++) {
  30975. oldIndex = py + xScaled[j];
  30976. dest[newIndex++] = src[oldIndex++];
  30977. dest[newIndex++] = src[oldIndex++];
  30978. dest[newIndex++] = src[oldIndex++];
  30979. newIndex += alpha01;
  30980. }
  30981. }
  30982. }
  30983. // Constructor should define this.numComps, this.defaultColor, this.name
  30984. function ColorSpace() {
  30985. error('should not call ColorSpace constructor');
  30986. }
  30987. ColorSpace.prototype = {
  30988. /**
  30989. * Converts the color value to the RGB color. The color components are
  30990. * located in the src array starting from the srcOffset. Returns the array
  30991. * of the rgb components, each value ranging from [0,255].
  30992. */
  30993. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  30994. var rgb = new Uint8Array(3);
  30995. this.getRgbItem(src, srcOffset, rgb, 0);
  30996. return rgb;
  30997. },
  30998. /**
  30999. * Converts the color value to the RGB color, similar to the getRgb method.
  31000. * The result placed into the dest array starting from the destOffset.
  31001. */
  31002. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  31003. dest, destOffset) {
  31004. error('Should not call ColorSpace.getRgbItem');
  31005. },
  31006. /**
  31007. * Converts the specified number of the color values to the RGB colors.
  31008. * The colors are located in the src array starting from the srcOffset.
  31009. * The result is placed into the dest array starting from the destOffset.
  31010. * The src array items shall be in [0,2^bits) range, the dest array items
  31011. * will be in [0,255] range. alpha01 indicates how many alpha components
  31012. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  31013. * array).
  31014. */
  31015. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  31016. dest, destOffset, bits,
  31017. alpha01) {
  31018. error('Should not call ColorSpace.getRgbBuffer');
  31019. },
  31020. /**
  31021. * Determines the number of bytes required to store the result of the
  31022. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  31023. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  31024. */
  31025. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  31026. alpha01) {
  31027. error('Should not call ColorSpace.getOutputLength');
  31028. },
  31029. /**
  31030. * Returns true if source data will be equal the result/output data.
  31031. */
  31032. isPassthrough: function ColorSpace_isPassthrough(bits) {
  31033. return false;
  31034. },
  31035. /**
  31036. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  31037. * how many alpha components there are in the dest array; it will be either
  31038. * 0 (RGB array) or 1 (RGBA array).
  31039. */
  31040. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  31041. originalHeight, width, height,
  31042. actualHeight, bpc, comps, alpha01) {
  31043. var count = originalWidth * originalHeight;
  31044. var rgbBuf = null;
  31045. var numComponentColors = 1 << bpc;
  31046. var needsResizing = originalHeight !== height || originalWidth !== width;
  31047. var i, ii;
  31048. if (this.isPassthrough(bpc)) {
  31049. rgbBuf = comps;
  31050. } else if (this.numComps === 1 && count > numComponentColors &&
  31051. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  31052. // Optimization: create a color map when there is just one component and
  31053. // we are converting more colors than the size of the color map. We
  31054. // don't build the map if the colorspace is gray or rgb since those
  31055. // methods are faster than building a map. This mainly offers big speed
  31056. // ups for indexed and alternate colorspaces.
  31057. //
  31058. // TODO it may be worth while to cache the color map. While running
  31059. // testing I never hit a cache so I will leave that out for now (perhaps
  31060. // we are reparsing colorspaces too much?).
  31061. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  31062. new Uint16Array(numComponentColors);
  31063. var key;
  31064. for (i = 0; i < numComponentColors; i++) {
  31065. allColors[i] = i;
  31066. }
  31067. var colorMap = new Uint8Array(numComponentColors * 3);
  31068. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  31069. /* alpha01 = */ 0);
  31070. var destPos, rgbPos;
  31071. if (!needsResizing) {
  31072. // Fill in the RGB values directly into |dest|.
  31073. destPos = 0;
  31074. for (i = 0; i < count; ++i) {
  31075. key = comps[i] * 3;
  31076. dest[destPos++] = colorMap[key];
  31077. dest[destPos++] = colorMap[key + 1];
  31078. dest[destPos++] = colorMap[key + 2];
  31079. destPos += alpha01;
  31080. }
  31081. } else {
  31082. rgbBuf = new Uint8Array(count * 3);
  31083. rgbPos = 0;
  31084. for (i = 0; i < count; ++i) {
  31085. key = comps[i] * 3;
  31086. rgbBuf[rgbPos++] = colorMap[key];
  31087. rgbBuf[rgbPos++] = colorMap[key + 1];
  31088. rgbBuf[rgbPos++] = colorMap[key + 2];
  31089. }
  31090. }
  31091. } else {
  31092. if (!needsResizing) {
  31093. // Fill in the RGB values directly into |dest|.
  31094. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  31095. alpha01);
  31096. } else {
  31097. rgbBuf = new Uint8Array(count * 3);
  31098. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  31099. /* alpha01 = */ 0);
  31100. }
  31101. }
  31102. if (rgbBuf) {
  31103. if (needsResizing) {
  31104. resizeRgbImage(rgbBuf, bpc, originalWidth, originalHeight,
  31105. width, height, alpha01, dest);
  31106. } else {
  31107. rgbPos = 0;
  31108. destPos = 0;
  31109. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  31110. dest[destPos++] = rgbBuf[rgbPos++];
  31111. dest[destPos++] = rgbBuf[rgbPos++];
  31112. dest[destPos++] = rgbBuf[rgbPos++];
  31113. destPos += alpha01;
  31114. }
  31115. }
  31116. }
  31117. },
  31118. /**
  31119. * True if the colorspace has components in the default range of [0, 1].
  31120. * This should be true for all colorspaces except for lab color spaces
  31121. * which are [0,100], [-128, 127], [-128, 127].
  31122. */
  31123. usesZeroToOneRange: true
  31124. };
  31125. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  31126. var IR = ColorSpace.parseToIR(cs, xref, res);
  31127. if (IR instanceof AlternateCS) {
  31128. return IR;
  31129. }
  31130. return ColorSpace.fromIR(IR);
  31131. };
  31132. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  31133. var name = isArray(IR) ? IR[0] : IR;
  31134. var whitePoint, blackPoint, gamma;
  31135. switch (name) {
  31136. case 'DeviceGrayCS':
  31137. return this.singletons.gray;
  31138. case 'DeviceRgbCS':
  31139. return this.singletons.rgb;
  31140. case 'DeviceCmykCS':
  31141. return this.singletons.cmyk;
  31142. case 'CalGrayCS':
  31143. whitePoint = IR[1];
  31144. blackPoint = IR[2];
  31145. gamma = IR[3];
  31146. return new CalGrayCS(whitePoint, blackPoint, gamma);
  31147. case 'CalRGBCS':
  31148. whitePoint = IR[1];
  31149. blackPoint = IR[2];
  31150. gamma = IR[3];
  31151. var matrix = IR[4];
  31152. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  31153. case 'PatternCS':
  31154. var basePatternCS = IR[1];
  31155. if (basePatternCS) {
  31156. basePatternCS = ColorSpace.fromIR(basePatternCS);
  31157. }
  31158. return new PatternCS(basePatternCS);
  31159. case 'IndexedCS':
  31160. var baseIndexedCS = IR[1];
  31161. var hiVal = IR[2];
  31162. var lookup = IR[3];
  31163. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  31164. case 'AlternateCS':
  31165. var numComps = IR[1];
  31166. var alt = IR[2];
  31167. var tintFnIR = IR[3];
  31168. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  31169. PDFFunction.fromIR(tintFnIR));
  31170. case 'LabCS':
  31171. whitePoint = IR[1];
  31172. blackPoint = IR[2];
  31173. var range = IR[3];
  31174. return new LabCS(whitePoint, blackPoint, range);
  31175. default:
  31176. error('Unknown name ' + name);
  31177. }
  31178. return null;
  31179. };
  31180. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  31181. if (isName(cs)) {
  31182. var colorSpaces = res.get('ColorSpace');
  31183. if (isDict(colorSpaces)) {
  31184. var refcs = colorSpaces.get(cs.name);
  31185. if (refcs) {
  31186. cs = refcs;
  31187. }
  31188. }
  31189. }
  31190. cs = xref.fetchIfRef(cs);
  31191. var mode;
  31192. if (isName(cs)) {
  31193. mode = cs.name;
  31194. this.mode = mode;
  31195. switch (mode) {
  31196. case 'DeviceGray':
  31197. case 'G':
  31198. return 'DeviceGrayCS';
  31199. case 'DeviceRGB':
  31200. case 'RGB':
  31201. return 'DeviceRgbCS';
  31202. case 'DeviceCMYK':
  31203. case 'CMYK':
  31204. return 'DeviceCmykCS';
  31205. case 'Pattern':
  31206. return ['PatternCS', null];
  31207. default:
  31208. error('unrecognized colorspace ' + mode);
  31209. }
  31210. } else if (isArray(cs)) {
  31211. mode = xref.fetchIfRef(cs[0]).name;
  31212. this.mode = mode;
  31213. var numComps, params, alt, whitePoint, blackPoint, gamma;
  31214. switch (mode) {
  31215. case 'DeviceGray':
  31216. case 'G':
  31217. return 'DeviceGrayCS';
  31218. case 'DeviceRGB':
  31219. case 'RGB':
  31220. return 'DeviceRgbCS';
  31221. case 'DeviceCMYK':
  31222. case 'CMYK':
  31223. return 'DeviceCmykCS';
  31224. case 'CalGray':
  31225. params = xref.fetchIfRef(cs[1]);
  31226. whitePoint = params.getArray('WhitePoint');
  31227. blackPoint = params.getArray('BlackPoint');
  31228. gamma = params.get('Gamma');
  31229. return ['CalGrayCS', whitePoint, blackPoint, gamma];
  31230. case 'CalRGB':
  31231. params = xref.fetchIfRef(cs[1]);
  31232. whitePoint = params.getArray('WhitePoint');
  31233. blackPoint = params.getArray('BlackPoint');
  31234. gamma = params.getArray('Gamma');
  31235. var matrix = params.getArray('Matrix');
  31236. return ['CalRGBCS', whitePoint, blackPoint, gamma, matrix];
  31237. case 'ICCBased':
  31238. var stream = xref.fetchIfRef(cs[1]);
  31239. var dict = stream.dict;
  31240. numComps = dict.get('N');
  31241. alt = dict.get('Alternate');
  31242. if (alt) {
  31243. var altIR = ColorSpace.parseToIR(alt, xref, res);
  31244. // Parse the /Alternate CS to ensure that the number of components
  31245. // are correct, and also (indirectly) that it is not a PatternCS.
  31246. var altCS = ColorSpace.fromIR(altIR);
  31247. if (altCS.numComps === numComps) {
  31248. return altIR;
  31249. }
  31250. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  31251. }
  31252. if (numComps === 1) {
  31253. return 'DeviceGrayCS';
  31254. } else if (numComps === 3) {
  31255. return 'DeviceRgbCS';
  31256. } else if (numComps === 4) {
  31257. return 'DeviceCmykCS';
  31258. }
  31259. break;
  31260. case 'Pattern':
  31261. var basePatternCS = cs[1] || null;
  31262. if (basePatternCS) {
  31263. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  31264. }
  31265. return ['PatternCS', basePatternCS];
  31266. case 'Indexed':
  31267. case 'I':
  31268. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  31269. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  31270. var lookup = xref.fetchIfRef(cs[3]);
  31271. if (isStream(lookup)) {
  31272. lookup = lookup.getBytes();
  31273. }
  31274. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  31275. case 'Separation':
  31276. case 'DeviceN':
  31277. var name = xref.fetchIfRef(cs[1]);
  31278. numComps = 1;
  31279. if (isName(name)) {
  31280. numComps = 1;
  31281. } else if (isArray(name)) {
  31282. numComps = name.length;
  31283. }
  31284. alt = ColorSpace.parseToIR(cs[2], xref, res);
  31285. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  31286. return ['AlternateCS', numComps, alt, tintFnIR];
  31287. case 'Lab':
  31288. params = xref.fetchIfRef(cs[1]);
  31289. whitePoint = params.getArray('WhitePoint');
  31290. blackPoint = params.getArray('BlackPoint');
  31291. var range = params.getArray('Range');
  31292. return ['LabCS', whitePoint, blackPoint, range];
  31293. default:
  31294. error('unimplemented color space object "' + mode + '"');
  31295. }
  31296. } else {
  31297. error('unrecognized color space object: "' + cs + '"');
  31298. }
  31299. return null;
  31300. };
  31301. /**
  31302. * Checks if a decode map matches the default decode map for a color space.
  31303. * This handles the general decode maps where there are two values per
  31304. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  31305. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  31306. * slightly different.
  31307. * @param {Array} decode Decode map (usually from an image).
  31308. * @param {Number} n Number of components the color space has.
  31309. */
  31310. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  31311. if (!isArray(decode)) {
  31312. return true;
  31313. }
  31314. if (n * 2 !== decode.length) {
  31315. warn('The decode map is not the correct length');
  31316. return true;
  31317. }
  31318. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  31319. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  31320. return false;
  31321. }
  31322. }
  31323. return true;
  31324. };
  31325. ColorSpace.singletons = {
  31326. get gray() {
  31327. return shadow(this, 'gray', new DeviceGrayCS());
  31328. },
  31329. get rgb() {
  31330. return shadow(this, 'rgb', new DeviceRgbCS());
  31331. },
  31332. get cmyk() {
  31333. return shadow(this, 'cmyk', new DeviceCmykCS());
  31334. }
  31335. };
  31336. return ColorSpace;
  31337. })();
  31338. /**
  31339. * Alternate color space handles both Separation and DeviceN color spaces. A
  31340. * Separation color space is actually just a DeviceN with one color component.
  31341. * Both color spaces use a tinting function to convert colors to a base color
  31342. * space.
  31343. */
  31344. var AlternateCS = (function AlternateCSClosure() {
  31345. function AlternateCS(numComps, base, tintFn) {
  31346. this.name = 'Alternate';
  31347. this.numComps = numComps;
  31348. this.defaultColor = new Float32Array(numComps);
  31349. for (var i = 0; i < numComps; ++i) {
  31350. this.defaultColor[i] = 1;
  31351. }
  31352. this.base = base;
  31353. this.tintFn = tintFn;
  31354. this.tmpBuf = new Float32Array(base.numComps);
  31355. }
  31356. AlternateCS.prototype = {
  31357. getRgb: ColorSpace.prototype.getRgb,
  31358. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  31359. dest, destOffset) {
  31360. var tmpBuf = this.tmpBuf;
  31361. this.tintFn(src, srcOffset, tmpBuf, 0);
  31362. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  31363. },
  31364. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  31365. dest, destOffset, bits,
  31366. alpha01) {
  31367. var tintFn = this.tintFn;
  31368. var base = this.base;
  31369. var scale = 1 / ((1 << bits) - 1);
  31370. var baseNumComps = base.numComps;
  31371. var usesZeroToOneRange = base.usesZeroToOneRange;
  31372. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  31373. alpha01 === 0;
  31374. var pos = isPassthrough ? destOffset : 0;
  31375. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  31376. var numComps = this.numComps;
  31377. var scaled = new Float32Array(numComps);
  31378. var tinted = new Float32Array(baseNumComps);
  31379. var i, j;
  31380. if (usesZeroToOneRange) {
  31381. for (i = 0; i < count; i++) {
  31382. for (j = 0; j < numComps; j++) {
  31383. scaled[j] = src[srcOffset++] * scale;
  31384. }
  31385. tintFn(scaled, 0, tinted, 0);
  31386. for (j = 0; j < baseNumComps; j++) {
  31387. baseBuf[pos++] = tinted[j] * 255;
  31388. }
  31389. }
  31390. } else {
  31391. for (i = 0; i < count; i++) {
  31392. for (j = 0; j < numComps; j++) {
  31393. scaled[j] = src[srcOffset++] * scale;
  31394. }
  31395. tintFn(scaled, 0, tinted, 0);
  31396. base.getRgbItem(tinted, 0, baseBuf, pos);
  31397. pos += baseNumComps;
  31398. }
  31399. }
  31400. if (!isPassthrough) {
  31401. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  31402. }
  31403. },
  31404. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  31405. alpha01) {
  31406. return this.base.getOutputLength(inputLength *
  31407. this.base.numComps / this.numComps,
  31408. alpha01);
  31409. },
  31410. isPassthrough: ColorSpace.prototype.isPassthrough,
  31411. fillRgb: ColorSpace.prototype.fillRgb,
  31412. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  31413. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31414. },
  31415. usesZeroToOneRange: true
  31416. };
  31417. return AlternateCS;
  31418. })();
  31419. var PatternCS = (function PatternCSClosure() {
  31420. function PatternCS(baseCS) {
  31421. this.name = 'Pattern';
  31422. this.base = baseCS;
  31423. }
  31424. PatternCS.prototype = {};
  31425. return PatternCS;
  31426. })();
  31427. var IndexedCS = (function IndexedCSClosure() {
  31428. function IndexedCS(base, highVal, lookup) {
  31429. this.name = 'Indexed';
  31430. this.numComps = 1;
  31431. this.defaultColor = new Uint8Array([0]);
  31432. this.base = base;
  31433. this.highVal = highVal;
  31434. var baseNumComps = base.numComps;
  31435. var length = baseNumComps * highVal;
  31436. var lookupArray;
  31437. if (isStream(lookup)) {
  31438. lookupArray = new Uint8Array(length);
  31439. var bytes = lookup.getBytes(length);
  31440. lookupArray.set(bytes);
  31441. } else if (isString(lookup)) {
  31442. lookupArray = new Uint8Array(length);
  31443. for (var i = 0; i < length; ++i) {
  31444. lookupArray[i] = lookup.charCodeAt(i);
  31445. }
  31446. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  31447. lookupArray = lookup;
  31448. } else {
  31449. error('Unrecognized lookup table: ' + lookup);
  31450. }
  31451. this.lookup = lookupArray;
  31452. }
  31453. IndexedCS.prototype = {
  31454. getRgb: ColorSpace.prototype.getRgb,
  31455. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  31456. dest, destOffset) {
  31457. var numComps = this.base.numComps;
  31458. var start = src[srcOffset] * numComps;
  31459. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  31460. },
  31461. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  31462. dest, destOffset, bits,
  31463. alpha01) {
  31464. var base = this.base;
  31465. var numComps = base.numComps;
  31466. var outputDelta = base.getOutputLength(numComps, alpha01);
  31467. var lookup = this.lookup;
  31468. for (var i = 0; i < count; ++i) {
  31469. var lookupPos = src[srcOffset++] * numComps;
  31470. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  31471. destOffset += outputDelta;
  31472. }
  31473. },
  31474. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  31475. return this.base.getOutputLength(inputLength * this.base.numComps,
  31476. alpha01);
  31477. },
  31478. isPassthrough: ColorSpace.prototype.isPassthrough,
  31479. fillRgb: ColorSpace.prototype.fillRgb,
  31480. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  31481. // indexed color maps shouldn't be changed
  31482. return true;
  31483. },
  31484. usesZeroToOneRange: true
  31485. };
  31486. return IndexedCS;
  31487. })();
  31488. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  31489. function DeviceGrayCS() {
  31490. this.name = 'DeviceGray';
  31491. this.numComps = 1;
  31492. this.defaultColor = new Float32Array([0]);
  31493. }
  31494. DeviceGrayCS.prototype = {
  31495. getRgb: ColorSpace.prototype.getRgb,
  31496. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  31497. dest, destOffset) {
  31498. var c = (src[srcOffset] * 255) | 0;
  31499. c = c < 0 ? 0 : c > 255 ? 255 : c;
  31500. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  31501. },
  31502. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  31503. dest, destOffset, bits,
  31504. alpha01) {
  31505. var scale = 255 / ((1 << bits) - 1);
  31506. var j = srcOffset, q = destOffset;
  31507. for (var i = 0; i < count; ++i) {
  31508. var c = (scale * src[j++]) | 0;
  31509. dest[q++] = c;
  31510. dest[q++] = c;
  31511. dest[q++] = c;
  31512. q += alpha01;
  31513. }
  31514. },
  31515. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  31516. alpha01) {
  31517. return inputLength * (3 + alpha01);
  31518. },
  31519. isPassthrough: ColorSpace.prototype.isPassthrough,
  31520. fillRgb: ColorSpace.prototype.fillRgb,
  31521. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  31522. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31523. },
  31524. usesZeroToOneRange: true
  31525. };
  31526. return DeviceGrayCS;
  31527. })();
  31528. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  31529. function DeviceRgbCS() {
  31530. this.name = 'DeviceRGB';
  31531. this.numComps = 3;
  31532. this.defaultColor = new Float32Array([0, 0, 0]);
  31533. }
  31534. DeviceRgbCS.prototype = {
  31535. getRgb: ColorSpace.prototype.getRgb,
  31536. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  31537. dest, destOffset) {
  31538. var r = (src[srcOffset] * 255) | 0;
  31539. var g = (src[srcOffset + 1] * 255) | 0;
  31540. var b = (src[srcOffset + 2] * 255) | 0;
  31541. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  31542. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  31543. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  31544. },
  31545. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  31546. dest, destOffset, bits,
  31547. alpha01) {
  31548. if (bits === 8 && alpha01 === 0) {
  31549. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  31550. return;
  31551. }
  31552. var scale = 255 / ((1 << bits) - 1);
  31553. var j = srcOffset, q = destOffset;
  31554. for (var i = 0; i < count; ++i) {
  31555. dest[q++] = (scale * src[j++]) | 0;
  31556. dest[q++] = (scale * src[j++]) | 0;
  31557. dest[q++] = (scale * src[j++]) | 0;
  31558. q += alpha01;
  31559. }
  31560. },
  31561. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  31562. alpha01) {
  31563. return (inputLength * (3 + alpha01) / 3) | 0;
  31564. },
  31565. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  31566. return bits === 8;
  31567. },
  31568. fillRgb: ColorSpace.prototype.fillRgb,
  31569. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  31570. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31571. },
  31572. usesZeroToOneRange: true
  31573. };
  31574. return DeviceRgbCS;
  31575. })();
  31576. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  31577. // The coefficients below was found using numerical analysis: the method of
  31578. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  31579. // where color_value is the tabular value from the table of sampled RGB colors
  31580. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  31581. // CMYK color conversion using the estimation below:
  31582. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  31583. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  31584. var c = src[srcOffset + 0] * srcScale;
  31585. var m = src[srcOffset + 1] * srcScale;
  31586. var y = src[srcOffset + 2] * srcScale;
  31587. var k = src[srcOffset + 3] * srcScale;
  31588. var r =
  31589. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  31590. 18.82290502165302 * y + 212.25662451639585 * k +
  31591. -285.2331026137004) +
  31592. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  31593. -17.873870861415444 * k - 5.497006427196366) +
  31594. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  31595. 17.5119270841813) +
  31596. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  31597. var g =
  31598. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  31599. 6.871425592049007 * y + 31.159100130055922 * k +
  31600. -79.2970844816548) +
  31601. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  31602. 131.35250912493976 * k - 190.9453302588951) +
  31603. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  31604. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  31605. var b =
  31606. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  31607. 30.89978309703729 * y - 0.23883238689178934 * k +
  31608. -14.183576799673286) +
  31609. m * (10.49593273432072 * m + 63.02378494754052 * y +
  31610. 50.606957656360734 * k - 112.23884253719248) +
  31611. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  31612. -193.58209356861505) +
  31613. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  31614. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  31615. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  31616. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  31617. }
  31618. function DeviceCmykCS() {
  31619. this.name = 'DeviceCMYK';
  31620. this.numComps = 4;
  31621. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  31622. }
  31623. DeviceCmykCS.prototype = {
  31624. getRgb: ColorSpace.prototype.getRgb,
  31625. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  31626. dest, destOffset) {
  31627. convertToRgb(src, srcOffset, 1, dest, destOffset);
  31628. },
  31629. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  31630. dest, destOffset, bits,
  31631. alpha01) {
  31632. var scale = 1 / ((1 << bits) - 1);
  31633. for (var i = 0; i < count; i++) {
  31634. convertToRgb(src, srcOffset, scale, dest, destOffset);
  31635. srcOffset += 4;
  31636. destOffset += 3 + alpha01;
  31637. }
  31638. },
  31639. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  31640. alpha01) {
  31641. return (inputLength / 4 * (3 + alpha01)) | 0;
  31642. },
  31643. isPassthrough: ColorSpace.prototype.isPassthrough,
  31644. fillRgb: ColorSpace.prototype.fillRgb,
  31645. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  31646. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31647. },
  31648. usesZeroToOneRange: true
  31649. };
  31650. return DeviceCmykCS;
  31651. })();
  31652. //
  31653. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  31654. //
  31655. var CalGrayCS = (function CalGrayCSClosure() {
  31656. function CalGrayCS(whitePoint, blackPoint, gamma) {
  31657. this.name = 'CalGray';
  31658. this.numComps = 1;
  31659. this.defaultColor = new Float32Array([0]);
  31660. if (!whitePoint) {
  31661. error('WhitePoint missing - required for color space CalGray');
  31662. }
  31663. blackPoint = blackPoint || [0, 0, 0];
  31664. gamma = gamma || 1;
  31665. // Translate arguments to spec variables.
  31666. this.XW = whitePoint[0];
  31667. this.YW = whitePoint[1];
  31668. this.ZW = whitePoint[2];
  31669. this.XB = blackPoint[0];
  31670. this.YB = blackPoint[1];
  31671. this.ZB = blackPoint[2];
  31672. this.G = gamma;
  31673. // Validate variables as per spec.
  31674. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  31675. error('Invalid WhitePoint components for ' + this.name +
  31676. ', no fallback available');
  31677. }
  31678. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  31679. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  31680. this.XB = this.YB = this.ZB = 0;
  31681. }
  31682. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  31683. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  31684. ', ZB: ' + this.ZB + ', only default values are supported.');
  31685. }
  31686. if (this.G < 1) {
  31687. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  31688. ', falling back to default');
  31689. this.G = 1;
  31690. }
  31691. }
  31692. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  31693. // A represents a gray component of a calibrated gray space.
  31694. // A <---> AG in the spec
  31695. var A = src[srcOffset] * scale;
  31696. var AG = Math.pow(A, cs.G);
  31697. // Computes L as per spec. ( = cs.YW * AG )
  31698. // Except if other than default BlackPoint values are used.
  31699. var L = cs.YW * AG;
  31700. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  31701. // Convert values to rgb range [0, 255].
  31702. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  31703. dest[destOffset] = val;
  31704. dest[destOffset + 1] = val;
  31705. dest[destOffset + 2] = val;
  31706. }
  31707. CalGrayCS.prototype = {
  31708. getRgb: ColorSpace.prototype.getRgb,
  31709. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  31710. dest, destOffset) {
  31711. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  31712. },
  31713. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  31714. dest, destOffset, bits,
  31715. alpha01) {
  31716. var scale = 1 / ((1 << bits) - 1);
  31717. for (var i = 0; i < count; ++i) {
  31718. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  31719. srcOffset += 1;
  31720. destOffset += 3 + alpha01;
  31721. }
  31722. },
  31723. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  31724. return inputLength * (3 + alpha01);
  31725. },
  31726. isPassthrough: ColorSpace.prototype.isPassthrough,
  31727. fillRgb: ColorSpace.prototype.fillRgb,
  31728. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  31729. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31730. },
  31731. usesZeroToOneRange: true
  31732. };
  31733. return CalGrayCS;
  31734. })();
  31735. //
  31736. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  31737. //
  31738. var CalRGBCS = (function CalRGBCSClosure() {
  31739. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  31740. // matrices.
  31741. var BRADFORD_SCALE_MATRIX = new Float32Array([
  31742. 0.8951, 0.2664, -0.1614,
  31743. -0.7502, 1.7135, 0.0367,
  31744. 0.0389, -0.0685, 1.0296]);
  31745. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  31746. 0.9869929, -0.1470543, 0.1599627,
  31747. 0.4323053, 0.5183603, 0.0492912,
  31748. -0.0085287, 0.0400428, 0.9684867]);
  31749. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  31750. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  31751. 3.2404542, -1.5371385, -0.4985314,
  31752. -0.9692660, 1.8760108, 0.0415560,
  31753. 0.0556434, -0.2040259, 1.0572252]);
  31754. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  31755. var tempNormalizeMatrix = new Float32Array(3);
  31756. var tempConvertMatrix1 = new Float32Array(3);
  31757. var tempConvertMatrix2 = new Float32Array(3);
  31758. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  31759. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  31760. this.name = 'CalRGB';
  31761. this.numComps = 3;
  31762. this.defaultColor = new Float32Array(3);
  31763. if (!whitePoint) {
  31764. error('WhitePoint missing - required for color space CalRGB');
  31765. }
  31766. blackPoint = blackPoint || new Float32Array(3);
  31767. gamma = gamma || new Float32Array([1, 1, 1]);
  31768. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  31769. // Translate arguments to spec variables.
  31770. var XW = whitePoint[0];
  31771. var YW = whitePoint[1];
  31772. var ZW = whitePoint[2];
  31773. this.whitePoint = whitePoint;
  31774. var XB = blackPoint[0];
  31775. var YB = blackPoint[1];
  31776. var ZB = blackPoint[2];
  31777. this.blackPoint = blackPoint;
  31778. this.GR = gamma[0];
  31779. this.GG = gamma[1];
  31780. this.GB = gamma[2];
  31781. this.MXA = matrix[0];
  31782. this.MYA = matrix[1];
  31783. this.MZA = matrix[2];
  31784. this.MXB = matrix[3];
  31785. this.MYB = matrix[4];
  31786. this.MZB = matrix[5];
  31787. this.MXC = matrix[6];
  31788. this.MYC = matrix[7];
  31789. this.MZC = matrix[8];
  31790. // Validate variables as per spec.
  31791. if (XW < 0 || ZW < 0 || YW !== 1) {
  31792. error('Invalid WhitePoint components for ' + this.name +
  31793. ', no fallback available');
  31794. }
  31795. if (XB < 0 || YB < 0 || ZB < 0) {
  31796. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  31797. ', ' + ZB + '], falling back to default');
  31798. this.blackPoint = new Float32Array(3);
  31799. }
  31800. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  31801. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  31802. '] for ' + this.name + ', falling back to default');
  31803. this.GR = this.GG = this.GB = 1;
  31804. }
  31805. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  31806. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  31807. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  31808. info('Invalid Matrix for ' + this.name + ' [' +
  31809. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  31810. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  31811. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  31812. '], falling back to default');
  31813. this.MXA = this.MYB = this.MZC = 1;
  31814. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  31815. }
  31816. }
  31817. function matrixProduct(a, b, result) {
  31818. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  31819. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  31820. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  31821. }
  31822. function convertToFlat(sourceWhitePoint, LMS, result) {
  31823. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  31824. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  31825. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  31826. }
  31827. function convertToD65(sourceWhitePoint, LMS, result) {
  31828. var D65X = 0.95047;
  31829. var D65Y = 1;
  31830. var D65Z = 1.08883;
  31831. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  31832. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  31833. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  31834. }
  31835. function sRGBTransferFunction(color) {
  31836. // See http://en.wikipedia.org/wiki/SRGB.
  31837. if (color <= 0.0031308){
  31838. return adjustToRange(0, 1, 12.92 * color);
  31839. }
  31840. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  31841. }
  31842. function adjustToRange(min, max, value) {
  31843. return Math.max(min, Math.min(max, value));
  31844. }
  31845. function decodeL(L) {
  31846. if (L < 0) {
  31847. return -decodeL(-L);
  31848. }
  31849. if (L > 8.0) {
  31850. return Math.pow(((L + 16) / 116), 3);
  31851. }
  31852. return L * DECODE_L_CONSTANT;
  31853. }
  31854. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  31855. // In case the blackPoint is already the default blackPoint then there is
  31856. // no need to do compensation.
  31857. if (sourceBlackPoint[0] === 0 &&
  31858. sourceBlackPoint[1] === 0 &&
  31859. sourceBlackPoint[2] === 0) {
  31860. result[0] = XYZ_Flat[0];
  31861. result[1] = XYZ_Flat[1];
  31862. result[2] = XYZ_Flat[2];
  31863. return;
  31864. }
  31865. // For the blackPoint calculation details, please see
  31866. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  31867. // AdobeBPC.pdf.
  31868. // The destination blackPoint is the default blackPoint [0, 0, 0].
  31869. var zeroDecodeL = decodeL(0);
  31870. var X_DST = zeroDecodeL;
  31871. var X_SRC = decodeL(sourceBlackPoint[0]);
  31872. var Y_DST = zeroDecodeL;
  31873. var Y_SRC = decodeL(sourceBlackPoint[1]);
  31874. var Z_DST = zeroDecodeL;
  31875. var Z_SRC = decodeL(sourceBlackPoint[2]);
  31876. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  31877. var X_Offset = 1 - X_Scale;
  31878. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  31879. var Y_Offset = 1 - Y_Scale;
  31880. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  31881. var Z_Offset = 1 - Z_Scale;
  31882. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  31883. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  31884. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  31885. }
  31886. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  31887. // In case the whitePoint is already flat then there is no need to do
  31888. // normalization.
  31889. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  31890. result[0] = XYZ_In[0];
  31891. result[1] = XYZ_In[1];
  31892. result[2] = XYZ_In[2];
  31893. return;
  31894. }
  31895. var LMS = result;
  31896. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  31897. var LMS_Flat = tempNormalizeMatrix;
  31898. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  31899. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  31900. }
  31901. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  31902. var LMS = result;
  31903. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  31904. var LMS_D65 = tempNormalizeMatrix;
  31905. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  31906. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  31907. }
  31908. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  31909. // A, B and C represent a red, green and blue components of a calibrated
  31910. // rgb space.
  31911. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  31912. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  31913. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  31914. // A <---> AGR in the spec
  31915. // B <---> BGG in the spec
  31916. // C <---> CGB in the spec
  31917. var AGR = Math.pow(A, cs.GR);
  31918. var BGG = Math.pow(B, cs.GG);
  31919. var CGB = Math.pow(C, cs.GB);
  31920. // Computes intermediate variables L, M, N as per spec.
  31921. // To decode X, Y, Z values map L, M, N directly to them.
  31922. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  31923. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  31924. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  31925. // The following calculations are based on this document:
  31926. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  31927. // AdobeBPC.pdf.
  31928. var XYZ = tempConvertMatrix1;
  31929. XYZ[0] = X;
  31930. XYZ[1] = Y;
  31931. XYZ[2] = Z;
  31932. var XYZ_Flat = tempConvertMatrix2;
  31933. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  31934. var XYZ_Black = tempConvertMatrix1;
  31935. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  31936. var XYZ_D65 = tempConvertMatrix2;
  31937. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  31938. var SRGB = tempConvertMatrix1;
  31939. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  31940. var sR = sRGBTransferFunction(SRGB[0]);
  31941. var sG = sRGBTransferFunction(SRGB[1]);
  31942. var sB = sRGBTransferFunction(SRGB[2]);
  31943. // Convert the values to rgb range [0, 255].
  31944. dest[destOffset] = Math.round(sR * 255);
  31945. dest[destOffset + 1] = Math.round(sG * 255);
  31946. dest[destOffset + 2] = Math.round(sB * 255);
  31947. }
  31948. CalRGBCS.prototype = {
  31949. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  31950. var rgb = new Uint8Array(3);
  31951. this.getRgbItem(src, srcOffset, rgb, 0);
  31952. return rgb;
  31953. },
  31954. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  31955. dest, destOffset) {
  31956. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  31957. },
  31958. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  31959. dest, destOffset, bits,
  31960. alpha01) {
  31961. var scale = 1 / ((1 << bits) - 1);
  31962. for (var i = 0; i < count; ++i) {
  31963. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  31964. srcOffset += 3;
  31965. destOffset += 3 + alpha01;
  31966. }
  31967. },
  31968. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  31969. return (inputLength * (3 + alpha01) / 3) | 0;
  31970. },
  31971. isPassthrough: ColorSpace.prototype.isPassthrough,
  31972. fillRgb: ColorSpace.prototype.fillRgb,
  31973. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  31974. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31975. },
  31976. usesZeroToOneRange: true
  31977. };
  31978. return CalRGBCS;
  31979. })();
  31980. //
  31981. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  31982. //
  31983. var LabCS = (function LabCSClosure() {
  31984. function LabCS(whitePoint, blackPoint, range) {
  31985. this.name = 'Lab';
  31986. this.numComps = 3;
  31987. this.defaultColor = new Float32Array([0, 0, 0]);
  31988. if (!whitePoint) {
  31989. error('WhitePoint missing - required for color space Lab');
  31990. }
  31991. blackPoint = blackPoint || [0, 0, 0];
  31992. range = range || [-100, 100, -100, 100];
  31993. // Translate args to spec variables
  31994. this.XW = whitePoint[0];
  31995. this.YW = whitePoint[1];
  31996. this.ZW = whitePoint[2];
  31997. this.amin = range[0];
  31998. this.amax = range[1];
  31999. this.bmin = range[2];
  32000. this.bmax = range[3];
  32001. // These are here just for completeness - the spec doesn't offer any
  32002. // formulas that use BlackPoint in Lab
  32003. this.XB = blackPoint[0];
  32004. this.YB = blackPoint[1];
  32005. this.ZB = blackPoint[2];
  32006. // Validate vars as per spec
  32007. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  32008. error('Invalid WhitePoint components, no fallback available');
  32009. }
  32010. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  32011. info('Invalid BlackPoint, falling back to default');
  32012. this.XB = this.YB = this.ZB = 0;
  32013. }
  32014. if (this.amin > this.amax || this.bmin > this.bmax) {
  32015. info('Invalid Range, falling back to defaults');
  32016. this.amin = -100;
  32017. this.amax = 100;
  32018. this.bmin = -100;
  32019. this.bmax = 100;
  32020. }
  32021. }
  32022. // Function g(x) from spec
  32023. function fn_g(x) {
  32024. if (x >= 6 / 29) {
  32025. return x * x * x;
  32026. } else {
  32027. return (108 / 841) * (x - 4 / 29);
  32028. }
  32029. }
  32030. function decode(value, high1, low2, high2) {
  32031. return low2 + (value) * (high2 - low2) / (high1);
  32032. }
  32033. // If decoding is needed maxVal should be 2^bits per component - 1.
  32034. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  32035. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  32036. // not the usual [0, 1]. If a command like setFillColor is used the src
  32037. // values will already be within the correct range. However, if we are
  32038. // converting an image we have to map the values to the correct range given
  32039. // above.
  32040. // Ls,as,bs <---> L*,a*,b* in the spec
  32041. var Ls = src[srcOffset];
  32042. var as = src[srcOffset + 1];
  32043. var bs = src[srcOffset + 2];
  32044. if (maxVal !== false) {
  32045. Ls = decode(Ls, maxVal, 0, 100);
  32046. as = decode(as, maxVal, cs.amin, cs.amax);
  32047. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  32048. }
  32049. // Adjust limits of 'as' and 'bs'
  32050. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  32051. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  32052. // Computes intermediate variables X,Y,Z as per spec
  32053. var M = (Ls + 16) / 116;
  32054. var L = M + (as / 500);
  32055. var N = M - (bs / 200);
  32056. var X = cs.XW * fn_g(L);
  32057. var Y = cs.YW * fn_g(M);
  32058. var Z = cs.ZW * fn_g(N);
  32059. var r, g, b;
  32060. // Using different conversions for D50 and D65 white points,
  32061. // per http://www.color.org/srgb.pdf
  32062. if (cs.ZW < 1) {
  32063. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  32064. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  32065. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  32066. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  32067. } else {
  32068. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  32069. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  32070. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  32071. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  32072. }
  32073. // clamp color values to [0,1] range then convert to [0,255] range.
  32074. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  32075. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  32076. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  32077. }
  32078. LabCS.prototype = {
  32079. getRgb: ColorSpace.prototype.getRgb,
  32080. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  32081. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  32082. },
  32083. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  32084. dest, destOffset, bits,
  32085. alpha01) {
  32086. var maxVal = (1 << bits) - 1;
  32087. for (var i = 0; i < count; i++) {
  32088. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  32089. srcOffset += 3;
  32090. destOffset += 3 + alpha01;
  32091. }
  32092. },
  32093. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  32094. return (inputLength * (3 + alpha01) / 3) | 0;
  32095. },
  32096. isPassthrough: ColorSpace.prototype.isPassthrough,
  32097. fillRgb: ColorSpace.prototype.fillRgb,
  32098. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  32099. // XXX: Decoding is handled with the lab conversion because of the strange
  32100. // ranges that are used.
  32101. return true;
  32102. },
  32103. usesZeroToOneRange: false
  32104. };
  32105. return LabCS;
  32106. })();
  32107. exports.ColorSpace = ColorSpace;
  32108. }));
  32109. (function (root, factory) {
  32110. {
  32111. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  32112. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  32113. root.pdfjsCoreJpx);
  32114. }
  32115. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  32116. coreStream, coreJpx) {
  32117. var ImageKind = sharedUtil.ImageKind;
  32118. var assert = sharedUtil.assert;
  32119. var error = sharedUtil.error;
  32120. var info = sharedUtil.info;
  32121. var isArray = sharedUtil.isArray;
  32122. var warn = sharedUtil.warn;
  32123. var Name = corePrimitives.Name;
  32124. var isStream = corePrimitives.isStream;
  32125. var ColorSpace = coreColorSpace.ColorSpace;
  32126. var DecodeStream = coreStream.DecodeStream;
  32127. var JpegStream = coreStream.JpegStream;
  32128. var JpxImage = coreJpx.JpxImage;
  32129. var PDFImage = (function PDFImageClosure() {
  32130. /**
  32131. * Decodes the image using native decoder if possible. Resolves the promise
  32132. * when the image data is ready.
  32133. */
  32134. function handleImageData(image, nativeDecoder) {
  32135. if (nativeDecoder && nativeDecoder.canDecode(image)) {
  32136. return nativeDecoder.decode(image);
  32137. } else {
  32138. return Promise.resolve(image);
  32139. }
  32140. }
  32141. /**
  32142. * Decode and clamp a value. The formula is different from the spec because we
  32143. * don't decode to float range [0,1], we decode it in the [0,max] range.
  32144. */
  32145. function decodeAndClamp(value, addend, coefficient, max) {
  32146. value = addend + value * coefficient;
  32147. // Clamp the value to the range
  32148. return (value < 0 ? 0 : (value > max ? max : value));
  32149. }
  32150. /**
  32151. * Resizes an image mask with 1 component.
  32152. * @param {TypedArray} src - The source buffer.
  32153. * @param {Number} bpc - Number of bits per component.
  32154. * @param {Number} w1 - Original width.
  32155. * @param {Number} h1 - Original height.
  32156. * @param {Number} w2 - New width.
  32157. * @param {Number} h2 - New height.
  32158. * @returns {TypedArray} The resized image mask buffer.
  32159. */
  32160. function resizeImageMask(src, bpc, w1, h1, w2, h2) {
  32161. var length = w2 * h2;
  32162. var dest = (bpc <= 8 ? new Uint8Array(length) :
  32163. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  32164. var xRatio = w1 / w2;
  32165. var yRatio = h1 / h2;
  32166. var i, j, py, newIndex = 0, oldIndex;
  32167. var xScaled = new Uint16Array(w2);
  32168. var w1Scanline = w1;
  32169. for (i = 0; i < w2; i++) {
  32170. xScaled[i] = Math.floor(i * xRatio);
  32171. }
  32172. for (i = 0; i < h2; i++) {
  32173. py = Math.floor(i * yRatio) * w1Scanline;
  32174. for (j = 0; j < w2; j++) {
  32175. oldIndex = py + xScaled[j];
  32176. dest[newIndex++] = src[oldIndex];
  32177. }
  32178. }
  32179. return dest;
  32180. }
  32181. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  32182. this.image = image;
  32183. var dict = image.dict;
  32184. if (dict.has('Filter')) {
  32185. var filter = dict.get('Filter').name;
  32186. if (filter === 'JPXDecode') {
  32187. var jpxImage = new JpxImage();
  32188. jpxImage.parseImageProperties(image.stream);
  32189. image.stream.reset();
  32190. image.bitsPerComponent = jpxImage.bitsPerComponent;
  32191. image.numComps = jpxImage.componentsCount;
  32192. } else if (filter === 'JBIG2Decode') {
  32193. image.bitsPerComponent = 1;
  32194. image.numComps = 1;
  32195. }
  32196. }
  32197. // TODO cache rendered images?
  32198. this.width = dict.get('Width', 'W');
  32199. this.height = dict.get('Height', 'H');
  32200. if (this.width < 1 || this.height < 1) {
  32201. error('Invalid image width: ' + this.width + ' or height: ' +
  32202. this.height);
  32203. }
  32204. this.interpolate = dict.get('Interpolate', 'I') || false;
  32205. this.imageMask = dict.get('ImageMask', 'IM') || false;
  32206. this.matte = dict.get('Matte') || false;
  32207. var bitsPerComponent = image.bitsPerComponent;
  32208. if (!bitsPerComponent) {
  32209. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  32210. if (!bitsPerComponent) {
  32211. if (this.imageMask) {
  32212. bitsPerComponent = 1;
  32213. } else {
  32214. error('Bits per component missing in image: ' + this.imageMask);
  32215. }
  32216. }
  32217. }
  32218. this.bpc = bitsPerComponent;
  32219. if (!this.imageMask) {
  32220. var colorSpace = dict.get('ColorSpace', 'CS');
  32221. if (!colorSpace) {
  32222. info('JPX images (which do not require color spaces)');
  32223. switch (image.numComps) {
  32224. case 1:
  32225. colorSpace = Name.get('DeviceGray');
  32226. break;
  32227. case 3:
  32228. colorSpace = Name.get('DeviceRGB');
  32229. break;
  32230. case 4:
  32231. colorSpace = Name.get('DeviceCMYK');
  32232. break;
  32233. default:
  32234. error('JPX images with ' + this.numComps +
  32235. ' color components not supported.');
  32236. }
  32237. }
  32238. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  32239. this.numComps = this.colorSpace.numComps;
  32240. }
  32241. this.decode = dict.getArray('Decode', 'D');
  32242. this.needsDecode = false;
  32243. if (this.decode &&
  32244. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  32245. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  32246. this.needsDecode = true;
  32247. // Do some preprocessing to avoid more math.
  32248. var max = (1 << bitsPerComponent) - 1;
  32249. this.decodeCoefficients = [];
  32250. this.decodeAddends = [];
  32251. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  32252. var dmin = this.decode[i];
  32253. var dmax = this.decode[i + 1];
  32254. this.decodeCoefficients[j] = dmax - dmin;
  32255. this.decodeAddends[j] = max * dmin;
  32256. }
  32257. }
  32258. if (smask) {
  32259. this.smask = new PDFImage(xref, res, smask, false);
  32260. } else if (mask) {
  32261. if (isStream(mask)) {
  32262. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  32263. if (!imageMask) {
  32264. warn('Ignoring /Mask in image without /ImageMask.');
  32265. } else {
  32266. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  32267. }
  32268. } else {
  32269. // Color key mask (just an array).
  32270. this.mask = mask;
  32271. }
  32272. }
  32273. }
  32274. /**
  32275. * Handles processing of image data and returns the Promise that is resolved
  32276. * with a PDFImage when the image is ready to be used.
  32277. */
  32278. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  32279. res, image, inline,
  32280. nativeDecoder) {
  32281. var imagePromise = handleImageData(image, nativeDecoder);
  32282. var smaskPromise;
  32283. var maskPromise;
  32284. var smask = image.dict.get('SMask');
  32285. var mask = image.dict.get('Mask');
  32286. if (smask) {
  32287. smaskPromise = handleImageData(smask, nativeDecoder);
  32288. maskPromise = Promise.resolve(null);
  32289. } else {
  32290. smaskPromise = Promise.resolve(null);
  32291. if (mask) {
  32292. if (isStream(mask)) {
  32293. maskPromise = handleImageData(mask, nativeDecoder);
  32294. } else if (isArray(mask)) {
  32295. maskPromise = Promise.resolve(mask);
  32296. } else {
  32297. warn('Unsupported mask format.');
  32298. maskPromise = Promise.resolve(null);
  32299. }
  32300. } else {
  32301. maskPromise = Promise.resolve(null);
  32302. }
  32303. }
  32304. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  32305. function(results) {
  32306. var imageData = results[0];
  32307. var smaskData = results[1];
  32308. var maskData = results[2];
  32309. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  32310. });
  32311. };
  32312. PDFImage.createMask =
  32313. function PDFImage_createMask(imgArray, width, height,
  32314. imageIsFromDecodeStream, inverseDecode) {
  32315. // |imgArray| might not contain full data for every pixel of the mask, so
  32316. // we need to distinguish between |computedLength| and |actualLength|.
  32317. // In particular, if inverseDecode is true, then the array we return must
  32318. // have a length of |computedLength|.
  32319. var computedLength = ((width + 7) >> 3) * height;
  32320. var actualLength = imgArray.byteLength;
  32321. var haveFullData = computedLength === actualLength;
  32322. var data, i;
  32323. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  32324. // imgArray came from a DecodeStream and its data is in an appropriate
  32325. // form, so we can just transfer it.
  32326. data = imgArray;
  32327. } else if (!inverseDecode) {
  32328. data = new Uint8Array(actualLength);
  32329. data.set(imgArray);
  32330. } else {
  32331. data = new Uint8Array(computedLength);
  32332. data.set(imgArray);
  32333. for (i = actualLength; i < computedLength; i++) {
  32334. data[i] = 0xff;
  32335. }
  32336. }
  32337. // If necessary, invert the original mask data (but not any extra we might
  32338. // have added above). It's safe to modify the array -- whether it's the
  32339. // original or a copy, we're about to transfer it anyway, so nothing else
  32340. // in this thread can be relying on its contents.
  32341. if (inverseDecode) {
  32342. for (i = 0; i < actualLength; i++) {
  32343. data[i] = ~data[i];
  32344. }
  32345. }
  32346. return {data: data, width: width, height: height};
  32347. };
  32348. PDFImage.prototype = {
  32349. get drawWidth() {
  32350. return Math.max(this.width,
  32351. this.smask && this.smask.width || 0,
  32352. this.mask && this.mask.width || 0);
  32353. },
  32354. get drawHeight() {
  32355. return Math.max(this.height,
  32356. this.smask && this.smask.height || 0,
  32357. this.mask && this.mask.height || 0);
  32358. },
  32359. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  32360. var bpc = this.bpc;
  32361. var numComps = this.numComps;
  32362. var decodeAddends = this.decodeAddends;
  32363. var decodeCoefficients = this.decodeCoefficients;
  32364. var max = (1 << bpc) - 1;
  32365. var i, ii;
  32366. if (bpc === 1) {
  32367. // If the buffer needed decode that means it just needs to be inverted.
  32368. for (i = 0, ii = buffer.length; i < ii; i++) {
  32369. buffer[i] = +!(buffer[i]);
  32370. }
  32371. return;
  32372. }
  32373. var index = 0;
  32374. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  32375. for (var j = 0; j < numComps; j++) {
  32376. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  32377. decodeCoefficients[j], max);
  32378. index++;
  32379. }
  32380. }
  32381. },
  32382. getComponents: function PDFImage_getComponents(buffer) {
  32383. var bpc = this.bpc;
  32384. // This image doesn't require any extra work.
  32385. if (bpc === 8) {
  32386. return buffer;
  32387. }
  32388. var width = this.width;
  32389. var height = this.height;
  32390. var numComps = this.numComps;
  32391. var length = width * height * numComps;
  32392. var bufferPos = 0;
  32393. var output = (bpc <= 8 ? new Uint8Array(length) :
  32394. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  32395. var rowComps = width * numComps;
  32396. var max = (1 << bpc) - 1;
  32397. var i = 0, ii, buf;
  32398. if (bpc === 1) {
  32399. // Optimization for reading 1 bpc images.
  32400. var mask, loop1End, loop2End;
  32401. for (var j = 0; j < height; j++) {
  32402. loop1End = i + (rowComps & ~7);
  32403. loop2End = i + rowComps;
  32404. // unroll loop for all full bytes
  32405. while (i < loop1End) {
  32406. buf = buffer[bufferPos++];
  32407. output[i] = (buf >> 7) & 1;
  32408. output[i + 1] = (buf >> 6) & 1;
  32409. output[i + 2] = (buf >> 5) & 1;
  32410. output[i + 3] = (buf >> 4) & 1;
  32411. output[i + 4] = (buf >> 3) & 1;
  32412. output[i + 5] = (buf >> 2) & 1;
  32413. output[i + 6] = (buf >> 1) & 1;
  32414. output[i + 7] = buf & 1;
  32415. i += 8;
  32416. }
  32417. // handle remaining bits
  32418. if (i < loop2End) {
  32419. buf = buffer[bufferPos++];
  32420. mask = 128;
  32421. while (i < loop2End) {
  32422. output[i++] = +!!(buf & mask);
  32423. mask >>= 1;
  32424. }
  32425. }
  32426. }
  32427. } else {
  32428. // The general case that handles all other bpc values.
  32429. var bits = 0;
  32430. buf = 0;
  32431. for (i = 0, ii = length; i < ii; ++i) {
  32432. if (i % rowComps === 0) {
  32433. buf = 0;
  32434. bits = 0;
  32435. }
  32436. while (bits < bpc) {
  32437. buf = (buf << 8) | buffer[bufferPos++];
  32438. bits += 8;
  32439. }
  32440. var remainingBits = bits - bpc;
  32441. var value = buf >> remainingBits;
  32442. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  32443. buf = buf & ((1 << remainingBits) - 1);
  32444. bits = remainingBits;
  32445. }
  32446. }
  32447. return output;
  32448. },
  32449. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  32450. actualHeight, image) {
  32451. var smask = this.smask;
  32452. var mask = this.mask;
  32453. var alphaBuf, sw, sh, i, ii, j;
  32454. if (smask) {
  32455. sw = smask.width;
  32456. sh = smask.height;
  32457. alphaBuf = new Uint8Array(sw * sh);
  32458. smask.fillGrayBuffer(alphaBuf);
  32459. if (sw !== width || sh !== height) {
  32460. alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh,
  32461. width, height);
  32462. }
  32463. } else if (mask) {
  32464. if (mask instanceof PDFImage) {
  32465. sw = mask.width;
  32466. sh = mask.height;
  32467. alphaBuf = new Uint8Array(sw * sh);
  32468. mask.numComps = 1;
  32469. mask.fillGrayBuffer(alphaBuf);
  32470. // Need to invert values in rgbaBuf
  32471. for (i = 0, ii = sw * sh; i < ii; ++i) {
  32472. alphaBuf[i] = 255 - alphaBuf[i];
  32473. }
  32474. if (sw !== width || sh !== height) {
  32475. alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh,
  32476. width, height);
  32477. }
  32478. } else if (isArray(mask)) {
  32479. // Color key mask: if any of the components are outside the range
  32480. // then they should be painted.
  32481. alphaBuf = new Uint8Array(width * height);
  32482. var numComps = this.numComps;
  32483. for (i = 0, ii = width * height; i < ii; ++i) {
  32484. var opacity = 0;
  32485. var imageOffset = i * numComps;
  32486. for (j = 0; j < numComps; ++j) {
  32487. var color = image[imageOffset + j];
  32488. var maskOffset = j * 2;
  32489. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  32490. opacity = 255;
  32491. break;
  32492. }
  32493. }
  32494. alphaBuf[i] = opacity;
  32495. }
  32496. } else {
  32497. error('Unknown mask format.');
  32498. }
  32499. }
  32500. if (alphaBuf) {
  32501. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  32502. rgbaBuf[j] = alphaBuf[i];
  32503. }
  32504. } else {
  32505. // No mask.
  32506. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  32507. rgbaBuf[j] = 255;
  32508. }
  32509. }
  32510. },
  32511. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  32512. var matte = this.smask && this.smask.matte;
  32513. if (!matte) {
  32514. return;
  32515. }
  32516. var matteRgb = this.colorSpace.getRgb(matte, 0);
  32517. var matteR = matteRgb[0];
  32518. var matteG = matteRgb[1];
  32519. var matteB = matteRgb[2];
  32520. var length = width * height * 4;
  32521. var r, g, b;
  32522. for (var i = 0; i < length; i += 4) {
  32523. var alpha = buffer[i + 3];
  32524. if (alpha === 0) {
  32525. // according formula we have to get Infinity in all components
  32526. // making it white (typical paper color) should be okay
  32527. buffer[i] = 255;
  32528. buffer[i + 1] = 255;
  32529. buffer[i + 2] = 255;
  32530. continue;
  32531. }
  32532. var k = 255 / alpha;
  32533. r = (buffer[i] - matteR) * k + matteR;
  32534. g = (buffer[i + 1] - matteG) * k + matteG;
  32535. b = (buffer[i + 2] - matteB) * k + matteB;
  32536. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  32537. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  32538. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  32539. }
  32540. },
  32541. createImageData: function PDFImage_createImageData(forceRGBA) {
  32542. var drawWidth = this.drawWidth;
  32543. var drawHeight = this.drawHeight;
  32544. var imgData = { // other fields are filled in below
  32545. width: drawWidth,
  32546. height: drawHeight
  32547. };
  32548. var numComps = this.numComps;
  32549. var originalWidth = this.width;
  32550. var originalHeight = this.height;
  32551. var bpc = this.bpc;
  32552. // Rows start at byte boundary.
  32553. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  32554. var imgArray;
  32555. if (!forceRGBA) {
  32556. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  32557. // without any complications, we pass a same-sized copy to the main
  32558. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  32559. // of memory for many scanned documents. It's also much faster.
  32560. //
  32561. // Similarly, if it is a 24-bit-per pixel RGB image without any
  32562. // complications, we avoid expanding by 1.333x to RGBA form.
  32563. var kind;
  32564. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  32565. kind = ImageKind.GRAYSCALE_1BPP;
  32566. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  32567. !this.needsDecode) {
  32568. kind = ImageKind.RGB_24BPP;
  32569. }
  32570. if (kind && !this.smask && !this.mask &&
  32571. drawWidth === originalWidth && drawHeight === originalHeight) {
  32572. imgData.kind = kind;
  32573. imgArray = this.getImageBytes(originalHeight * rowBytes);
  32574. // If imgArray came from a DecodeStream, we're safe to transfer it
  32575. // (and thus detach its underlying buffer) because it will constitute
  32576. // the entire DecodeStream's data. But if it came from a Stream, we
  32577. // need to copy it because it'll only be a portion of the Stream's
  32578. // data, and the rest will be read later on.
  32579. if (this.image instanceof DecodeStream) {
  32580. imgData.data = imgArray;
  32581. } else {
  32582. var newArray = new Uint8Array(imgArray.length);
  32583. newArray.set(imgArray);
  32584. imgData.data = newArray;
  32585. }
  32586. if (this.needsDecode) {
  32587. // Invert the buffer (which must be grayscale if we reached here).
  32588. assert(kind === ImageKind.GRAYSCALE_1BPP);
  32589. var buffer = imgData.data;
  32590. for (var i = 0, ii = buffer.length; i < ii; i++) {
  32591. buffer[i] ^= 0xff;
  32592. }
  32593. }
  32594. return imgData;
  32595. }
  32596. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  32597. (this.colorSpace.name === 'DeviceGray' ||
  32598. this.colorSpace.name === 'DeviceRGB' ||
  32599. this.colorSpace.name === 'DeviceCMYK')) {
  32600. imgData.kind = ImageKind.RGB_24BPP;
  32601. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  32602. drawWidth, drawHeight, true);
  32603. return imgData;
  32604. }
  32605. }
  32606. imgArray = this.getImageBytes(originalHeight * rowBytes);
  32607. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  32608. var actualHeight = 0 | (imgArray.length / rowBytes *
  32609. drawHeight / originalHeight);
  32610. var comps = this.getComponents(imgArray);
  32611. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  32612. // more compact RGB_24BPP form if allowable.
  32613. var alpha01, maybeUndoPreblend;
  32614. if (!forceRGBA && !this.smask && !this.mask) {
  32615. imgData.kind = ImageKind.RGB_24BPP;
  32616. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  32617. alpha01 = 0;
  32618. maybeUndoPreblend = false;
  32619. } else {
  32620. imgData.kind = ImageKind.RGBA_32BPP;
  32621. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  32622. alpha01 = 1;
  32623. maybeUndoPreblend = true;
  32624. // Color key masking (opacity) must be performed before decoding.
  32625. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  32626. comps);
  32627. }
  32628. if (this.needsDecode) {
  32629. this.decodeBuffer(comps);
  32630. }
  32631. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  32632. drawWidth, drawHeight, actualHeight, bpc, comps,
  32633. alpha01);
  32634. if (maybeUndoPreblend) {
  32635. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  32636. }
  32637. return imgData;
  32638. },
  32639. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  32640. var numComps = this.numComps;
  32641. if (numComps !== 1) {
  32642. error('Reading gray scale from a color image: ' + numComps);
  32643. }
  32644. var width = this.width;
  32645. var height = this.height;
  32646. var bpc = this.bpc;
  32647. // rows start at byte boundary
  32648. var rowBytes = (width * numComps * bpc + 7) >> 3;
  32649. var imgArray = this.getImageBytes(height * rowBytes);
  32650. var comps = this.getComponents(imgArray);
  32651. var i, length;
  32652. if (bpc === 1) {
  32653. // inline decoding (= inversion) for 1 bpc images
  32654. length = width * height;
  32655. if (this.needsDecode) {
  32656. // invert and scale to {0, 255}
  32657. for (i = 0; i < length; ++i) {
  32658. buffer[i] = (comps[i] - 1) & 255;
  32659. }
  32660. } else {
  32661. // scale to {0, 255}
  32662. for (i = 0; i < length; ++i) {
  32663. buffer[i] = (-comps[i]) & 255;
  32664. }
  32665. }
  32666. return;
  32667. }
  32668. if (this.needsDecode) {
  32669. this.decodeBuffer(comps);
  32670. }
  32671. length = width * height;
  32672. // we aren't using a colorspace so we need to scale the value
  32673. var scale = 255 / ((1 << bpc) - 1);
  32674. for (i = 0; i < length; ++i) {
  32675. buffer[i] = (scale * comps[i]) | 0;
  32676. }
  32677. },
  32678. getImageBytes: function PDFImage_getImageBytes(length,
  32679. drawWidth, drawHeight,
  32680. forceRGB) {
  32681. this.image.reset();
  32682. this.image.drawWidth = drawWidth || this.width;
  32683. this.image.drawHeight = drawHeight || this.height;
  32684. this.image.forceRGB = !!forceRGB;
  32685. return this.image.getBytes(length);
  32686. }
  32687. };
  32688. return PDFImage;
  32689. })();
  32690. exports.PDFImage = PDFImage;
  32691. }));
  32692. (function (root, factory) {
  32693. {
  32694. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  32695. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  32696. root.pdfjsCoreChunkedStream, root.pdfjsCoreColorSpace);
  32697. }
  32698. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  32699. coreChunkedStream, coreColorSpace) {
  32700. var InvalidPDFException = sharedUtil.InvalidPDFException;
  32701. var MissingDataException = sharedUtil.MissingDataException;
  32702. var XRefParseException = sharedUtil.XRefParseException;
  32703. var assert = sharedUtil.assert;
  32704. var bytesToString = sharedUtil.bytesToString;
  32705. var createPromiseCapability = sharedUtil.createPromiseCapability;
  32706. var error = sharedUtil.error;
  32707. var info = sharedUtil.info;
  32708. var isArray = sharedUtil.isArray;
  32709. var isInt = sharedUtil.isInt;
  32710. var isString = sharedUtil.isString;
  32711. var shadow = sharedUtil.shadow;
  32712. var stringToPDFString = sharedUtil.stringToPDFString;
  32713. var stringToUTF8String = sharedUtil.stringToUTF8String;
  32714. var warn = sharedUtil.warn;
  32715. var isValidUrl = sharedUtil.isValidUrl;
  32716. var Util = sharedUtil.Util;
  32717. var Ref = corePrimitives.Ref;
  32718. var RefSet = corePrimitives.RefSet;
  32719. var RefSetCache = corePrimitives.RefSetCache;
  32720. var isName = corePrimitives.isName;
  32721. var isCmd = corePrimitives.isCmd;
  32722. var isDict = corePrimitives.isDict;
  32723. var isRef = corePrimitives.isRef;
  32724. var isRefsEqual = corePrimitives.isRefsEqual;
  32725. var isStream = corePrimitives.isStream;
  32726. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  32727. var Lexer = coreParser.Lexer;
  32728. var Parser = coreParser.Parser;
  32729. var ChunkedStream = coreChunkedStream.ChunkedStream;
  32730. var ColorSpace = coreColorSpace.ColorSpace;
  32731. var Catalog = (function CatalogClosure() {
  32732. function Catalog(pdfManager, xref, pageFactory) {
  32733. this.pdfManager = pdfManager;
  32734. this.xref = xref;
  32735. this.catDict = xref.getCatalogObj();
  32736. this.fontCache = new RefSetCache();
  32737. assert(isDict(this.catDict),
  32738. 'catalog object is not a dictionary');
  32739. // TODO refactor to move getPage() to the PDFDocument.
  32740. this.pageFactory = pageFactory;
  32741. this.pagePromises = [];
  32742. }
  32743. Catalog.prototype = {
  32744. get metadata() {
  32745. var streamRef = this.catDict.getRaw('Metadata');
  32746. if (!isRef(streamRef)) {
  32747. return shadow(this, 'metadata', null);
  32748. }
  32749. var encryptMetadata = (!this.xref.encrypt ? false :
  32750. this.xref.encrypt.encryptMetadata);
  32751. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  32752. var metadata;
  32753. if (stream && isDict(stream.dict)) {
  32754. var type = stream.dict.get('Type');
  32755. var subtype = stream.dict.get('Subtype');
  32756. if (isName(type, 'Metadata') && isName(subtype, 'XML')) {
  32757. // XXX: This should examine the charset the XML document defines,
  32758. // however since there are currently no real means to decode
  32759. // arbitrary charsets, let's just hope that the author of the PDF
  32760. // was reasonable enough to stick with the XML default charset,
  32761. // which is UTF-8.
  32762. try {
  32763. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  32764. } catch (e) {
  32765. info('Skipping invalid metadata.');
  32766. }
  32767. }
  32768. }
  32769. return shadow(this, 'metadata', metadata);
  32770. },
  32771. get toplevelPagesDict() {
  32772. var pagesObj = this.catDict.get('Pages');
  32773. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  32774. // shadow the prototype getter
  32775. return shadow(this, 'toplevelPagesDict', pagesObj);
  32776. },
  32777. get documentOutline() {
  32778. var obj = null;
  32779. try {
  32780. obj = this.readDocumentOutline();
  32781. } catch (ex) {
  32782. if (ex instanceof MissingDataException) {
  32783. throw ex;
  32784. }
  32785. warn('Unable to read document outline');
  32786. }
  32787. return shadow(this, 'documentOutline', obj);
  32788. },
  32789. readDocumentOutline: function Catalog_readDocumentOutline() {
  32790. var obj = this.catDict.get('Outlines');
  32791. if (!isDict(obj)) {
  32792. return null;
  32793. }
  32794. obj = obj.getRaw('First');
  32795. if (!isRef(obj)) {
  32796. return null;
  32797. }
  32798. var root = { items: [] };
  32799. var queue = [{obj: obj, parent: root}];
  32800. // To avoid recursion, keep track of the already processed items.
  32801. var processed = new RefSet();
  32802. processed.put(obj);
  32803. var xref = this.xref, blackColor = new Uint8Array(3);
  32804. while (queue.length > 0) {
  32805. var i = queue.shift();
  32806. var outlineDict = xref.fetchIfRef(i.obj);
  32807. if (outlineDict === null) {
  32808. continue;
  32809. }
  32810. assert(outlineDict.has('Title'), 'Invalid outline item');
  32811. var actionDict = outlineDict.get('A'), dest = null, url = null;
  32812. if (actionDict) {
  32813. var destEntry = actionDict.get('D');
  32814. if (destEntry) {
  32815. dest = destEntry;
  32816. } else {
  32817. var uriEntry = actionDict.get('URI');
  32818. if (isString(uriEntry) && isValidUrl(uriEntry, false)) {
  32819. url = uriEntry;
  32820. }
  32821. }
  32822. } else if (outlineDict.has('Dest')) {
  32823. dest = outlineDict.getRaw('Dest');
  32824. if (isName(dest)) {
  32825. dest = dest.name;
  32826. }
  32827. }
  32828. var title = outlineDict.get('Title');
  32829. var flags = outlineDict.get('F') || 0;
  32830. var color = outlineDict.getArray('C'), rgbColor = blackColor;
  32831. // We only need to parse the color when it's valid, and non-default.
  32832. if (isArray(color) && color.length === 3 &&
  32833. (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
  32834. rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
  32835. }
  32836. var outlineItem = {
  32837. dest: dest,
  32838. url: url,
  32839. title: stringToPDFString(title),
  32840. color: rgbColor,
  32841. count: outlineDict.get('Count'),
  32842. bold: !!(flags & 2),
  32843. italic: !!(flags & 1),
  32844. items: []
  32845. };
  32846. i.parent.items.push(outlineItem);
  32847. obj = outlineDict.getRaw('First');
  32848. if (isRef(obj) && !processed.has(obj)) {
  32849. queue.push({obj: obj, parent: outlineItem});
  32850. processed.put(obj);
  32851. }
  32852. obj = outlineDict.getRaw('Next');
  32853. if (isRef(obj) && !processed.has(obj)) {
  32854. queue.push({obj: obj, parent: i.parent});
  32855. processed.put(obj);
  32856. }
  32857. }
  32858. return (root.items.length > 0 ? root.items : null);
  32859. },
  32860. get numPages() {
  32861. var obj = this.toplevelPagesDict.get('Count');
  32862. assert(
  32863. isInt(obj),
  32864. 'page count in top level pages object is not an integer'
  32865. );
  32866. // shadow the prototype getter
  32867. return shadow(this, 'num', obj);
  32868. },
  32869. get destinations() {
  32870. function fetchDestination(dest) {
  32871. return isDict(dest) ? dest.get('D') : dest;
  32872. }
  32873. var xref = this.xref;
  32874. var dests = {}, nameTreeRef, nameDictionaryRef;
  32875. var obj = this.catDict.get('Names');
  32876. if (obj && obj.has('Dests')) {
  32877. nameTreeRef = obj.getRaw('Dests');
  32878. } else if (this.catDict.has('Dests')) {
  32879. nameDictionaryRef = this.catDict.get('Dests');
  32880. }
  32881. if (nameDictionaryRef) {
  32882. // reading simple destination dictionary
  32883. obj = nameDictionaryRef;
  32884. obj.forEach(function catalogForEach(key, value) {
  32885. if (!value) {
  32886. return;
  32887. }
  32888. dests[key] = fetchDestination(value);
  32889. });
  32890. }
  32891. if (nameTreeRef) {
  32892. var nameTree = new NameTree(nameTreeRef, xref);
  32893. var names = nameTree.getAll();
  32894. for (var name in names) {
  32895. dests[name] = fetchDestination(names[name]);
  32896. }
  32897. }
  32898. return shadow(this, 'destinations', dests);
  32899. },
  32900. getDestination: function Catalog_getDestination(destinationId) {
  32901. function fetchDestination(dest) {
  32902. return isDict(dest) ? dest.get('D') : dest;
  32903. }
  32904. var xref = this.xref;
  32905. var dest = null, nameTreeRef, nameDictionaryRef;
  32906. var obj = this.catDict.get('Names');
  32907. if (obj && obj.has('Dests')) {
  32908. nameTreeRef = obj.getRaw('Dests');
  32909. } else if (this.catDict.has('Dests')) {
  32910. nameDictionaryRef = this.catDict.get('Dests');
  32911. }
  32912. if (nameDictionaryRef) { // Simple destination dictionary.
  32913. var value = nameDictionaryRef.get(destinationId);
  32914. if (value) {
  32915. dest = fetchDestination(value);
  32916. }
  32917. }
  32918. if (nameTreeRef) {
  32919. var nameTree = new NameTree(nameTreeRef, xref);
  32920. dest = fetchDestination(nameTree.get(destinationId));
  32921. }
  32922. return dest;
  32923. },
  32924. get pageLabels() {
  32925. var obj = null;
  32926. try {
  32927. obj = this.readPageLabels();
  32928. } catch (ex) {
  32929. if (ex instanceof MissingDataException) {
  32930. throw ex;
  32931. }
  32932. warn('Unable to read page labels.');
  32933. }
  32934. return shadow(this, 'pageLabels', obj);
  32935. },
  32936. readPageLabels: function Catalog_readPageLabels() {
  32937. var obj = this.catDict.getRaw('PageLabels');
  32938. if (!obj) {
  32939. return null;
  32940. }
  32941. var pageLabels = new Array(this.numPages);
  32942. var style = null;
  32943. var prefix = '';
  32944. var start = 1;
  32945. var numberTree = new NumberTree(obj, this.xref);
  32946. var nums = numberTree.getAll();
  32947. var currentLabel = '', currentIndex = 1;
  32948. for (var i = 0, ii = this.numPages; i < ii; i++) {
  32949. if (i in nums) {
  32950. var labelDict = nums[i];
  32951. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  32952. var type = labelDict.get('Type');
  32953. assert(!type || isName(type, 'PageLabel'),
  32954. 'Invalid type in PageLabel dictionary.');
  32955. var s = labelDict.get('S');
  32956. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  32957. style = (s ? s.name : null);
  32958. prefix = labelDict.get('P') || '';
  32959. assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
  32960. start = labelDict.get('St') || 1;
  32961. assert(isInt(start), 'Invalid start in PageLabel dictionary.');
  32962. currentIndex = start;
  32963. }
  32964. switch (style) {
  32965. case 'D':
  32966. currentLabel = currentIndex;
  32967. break;
  32968. case 'R':
  32969. case 'r':
  32970. currentLabel = Util.toRoman(currentIndex, style === 'r');
  32971. break;
  32972. case 'A':
  32973. case 'a':
  32974. var LIMIT = 26; // Use only the characters A--Z, or a--z.
  32975. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  32976. var baseCharCode = (style === 'a' ? A_LOWER_CASE : A_UPPER_CASE);
  32977. var letterIndex = currentIndex - 1;
  32978. var character = String.fromCharCode(baseCharCode +
  32979. (letterIndex % LIMIT));
  32980. var charBuf = [];
  32981. for (var j = 0, jj = (letterIndex / LIMIT) | 0; j <= jj; j++) {
  32982. charBuf.push(character);
  32983. }
  32984. currentLabel = charBuf.join('');
  32985. break;
  32986. default:
  32987. assert(!style,
  32988. 'Invalid style "' + style + '" in PageLabel dictionary.');
  32989. }
  32990. pageLabels[i] = prefix + currentLabel;
  32991. currentLabel = '';
  32992. currentIndex++;
  32993. }
  32994. return pageLabels;
  32995. },
  32996. get attachments() {
  32997. var xref = this.xref;
  32998. var attachments = null, nameTreeRef;
  32999. var obj = this.catDict.get('Names');
  33000. if (obj) {
  33001. nameTreeRef = obj.getRaw('EmbeddedFiles');
  33002. }
  33003. if (nameTreeRef) {
  33004. var nameTree = new NameTree(nameTreeRef, xref);
  33005. var names = nameTree.getAll();
  33006. for (var name in names) {
  33007. var fs = new FileSpec(names[name], xref);
  33008. if (!attachments) {
  33009. attachments = Object.create(null);
  33010. }
  33011. attachments[stringToPDFString(name)] = fs.serializable;
  33012. }
  33013. }
  33014. return shadow(this, 'attachments', attachments);
  33015. },
  33016. get javaScript() {
  33017. var xref = this.xref;
  33018. var obj = this.catDict.get('Names');
  33019. var javaScript = [];
  33020. function appendIfJavaScriptDict(jsDict) {
  33021. var type = jsDict.get('S');
  33022. if (!isName(type, 'JavaScript')) {
  33023. return;
  33024. }
  33025. var js = jsDict.get('JS');
  33026. if (isStream(js)) {
  33027. js = bytesToString(js.getBytes());
  33028. } else if (!isString(js)) {
  33029. return;
  33030. }
  33031. javaScript.push(stringToPDFString(js));
  33032. }
  33033. if (obj && obj.has('JavaScript')) {
  33034. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  33035. var names = nameTree.getAll();
  33036. for (var name in names) {
  33037. // We don't really use the JavaScript right now. This code is
  33038. // defensive so we don't cause errors on document load.
  33039. var jsDict = names[name];
  33040. if (isDict(jsDict)) {
  33041. appendIfJavaScriptDict(jsDict);
  33042. }
  33043. }
  33044. }
  33045. // Append OpenAction actions to javaScript array
  33046. var openactionDict = this.catDict.get('OpenAction');
  33047. if (isDict(openactionDict, 'Action')) {
  33048. var actionType = openactionDict.get('S');
  33049. if (isName(actionType, 'Named')) {
  33050. // The named Print action is not a part of the PDF 1.7 specification,
  33051. // but is supported by many PDF readers/writers (including Adobe's).
  33052. var action = openactionDict.get('N');
  33053. if (isName(action, 'Print')) {
  33054. javaScript.push('print({});');
  33055. }
  33056. } else {
  33057. appendIfJavaScriptDict(openactionDict);
  33058. }
  33059. }
  33060. return shadow(this, 'javaScript', javaScript);
  33061. },
  33062. cleanup: function Catalog_cleanup() {
  33063. var promises = [];
  33064. this.fontCache.forEach(function (promise) {
  33065. promises.push(promise);
  33066. });
  33067. return Promise.all(promises).then(function (translatedFonts) {
  33068. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  33069. var font = translatedFonts[i].dict;
  33070. delete font.translated;
  33071. }
  33072. this.fontCache.clear();
  33073. }.bind(this));
  33074. },
  33075. getPage: function Catalog_getPage(pageIndex) {
  33076. if (!(pageIndex in this.pagePromises)) {
  33077. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  33078. function (a) {
  33079. var dict = a[0];
  33080. var ref = a[1];
  33081. return this.pageFactory.createPage(pageIndex, dict, ref,
  33082. this.fontCache);
  33083. }.bind(this)
  33084. );
  33085. }
  33086. return this.pagePromises[pageIndex];
  33087. },
  33088. getPageDict: function Catalog_getPageDict(pageIndex) {
  33089. var capability = createPromiseCapability();
  33090. var nodesToVisit = [this.catDict.getRaw('Pages')];
  33091. var currentPageIndex = 0;
  33092. var xref = this.xref;
  33093. var checkAllKids = false;
  33094. function next() {
  33095. while (nodesToVisit.length) {
  33096. var currentNode = nodesToVisit.pop();
  33097. if (isRef(currentNode)) {
  33098. xref.fetchAsync(currentNode).then(function (obj) {
  33099. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  33100. if (pageIndex === currentPageIndex) {
  33101. capability.resolve([obj, currentNode]);
  33102. } else {
  33103. currentPageIndex++;
  33104. next();
  33105. }
  33106. return;
  33107. }
  33108. nodesToVisit.push(obj);
  33109. next();
  33110. }, capability.reject);
  33111. return;
  33112. }
  33113. // Must be a child page dictionary.
  33114. assert(
  33115. isDict(currentNode),
  33116. 'page dictionary kid reference points to wrong type of object'
  33117. );
  33118. var count = currentNode.get('Count');
  33119. // If the current node doesn't have any children, avoid getting stuck
  33120. // in an empty node further down in the tree (see issue5644.pdf).
  33121. if (count === 0) {
  33122. checkAllKids = true;
  33123. }
  33124. // Skip nodes where the page can't be.
  33125. if (currentPageIndex + count <= pageIndex) {
  33126. currentPageIndex += count;
  33127. continue;
  33128. }
  33129. var kids = currentNode.get('Kids');
  33130. assert(isArray(kids), 'page dictionary kids object is not an array');
  33131. if (!checkAllKids && count === kids.length) {
  33132. // Nodes that don't have the page have been skipped and this is the
  33133. // bottom of the tree which means the page requested must be a
  33134. // descendant of this pages node. Ideally we would just resolve the
  33135. // promise with the page ref here, but there is the case where more
  33136. // pages nodes could link to single a page (see issue 3666 pdf). To
  33137. // handle this push it back on the queue so if it is a pages node it
  33138. // will be descended into.
  33139. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  33140. currentPageIndex = pageIndex;
  33141. continue;
  33142. } else {
  33143. for (var last = kids.length - 1; last >= 0; last--) {
  33144. nodesToVisit.push(kids[last]);
  33145. }
  33146. }
  33147. }
  33148. capability.reject('Page index ' + pageIndex + ' not found.');
  33149. }
  33150. next();
  33151. return capability.promise;
  33152. },
  33153. getPageIndex: function Catalog_getPageIndex(pageRef) {
  33154. // The page tree nodes have the count of all the leaves below them. To get
  33155. // how many pages are before we just have to walk up the tree and keep
  33156. // adding the count of siblings to the left of the node.
  33157. var xref = this.xref;
  33158. function pagesBeforeRef(kidRef) {
  33159. var total = 0;
  33160. var parentRef;
  33161. return xref.fetchAsync(kidRef).then(function (node) {
  33162. if (isRefsEqual(kidRef, pageRef) && !isDict(node, 'Page') &&
  33163. !(isDict(node) && !node.has('Type') && node.has('Contents'))) {
  33164. throw new Error('The reference does not point to a /Page Dict.');
  33165. }
  33166. if (!node) {
  33167. return null;
  33168. }
  33169. assert(isDict(node), 'node must be a Dict.');
  33170. parentRef = node.getRaw('Parent');
  33171. return node.getAsync('Parent');
  33172. }).then(function (parent) {
  33173. if (!parent) {
  33174. return null;
  33175. }
  33176. assert(isDict(parent), 'parent must be a Dict.');
  33177. return parent.getAsync('Kids');
  33178. }).then(function (kids) {
  33179. if (!kids) {
  33180. return null;
  33181. }
  33182. var kidPromises = [];
  33183. var found = false;
  33184. for (var i = 0; i < kids.length; i++) {
  33185. var kid = kids[i];
  33186. assert(isRef(kid), 'kid must be a Ref.');
  33187. if (kid.num === kidRef.num) {
  33188. found = true;
  33189. break;
  33190. }
  33191. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  33192. if (kid.has('Count')) {
  33193. var count = kid.get('Count');
  33194. total += count;
  33195. } else { // page leaf node
  33196. total++;
  33197. }
  33198. }));
  33199. }
  33200. if (!found) {
  33201. error('kid ref not found in parents kids');
  33202. }
  33203. return Promise.all(kidPromises).then(function () {
  33204. return [total, parentRef];
  33205. });
  33206. });
  33207. }
  33208. var total = 0;
  33209. function next(ref) {
  33210. return pagesBeforeRef(ref).then(function (args) {
  33211. if (!args) {
  33212. return total;
  33213. }
  33214. var count = args[0];
  33215. var parentRef = args[1];
  33216. total += count;
  33217. return next(parentRef);
  33218. });
  33219. }
  33220. return next(pageRef);
  33221. }
  33222. };
  33223. return Catalog;
  33224. })();
  33225. var XRef = (function XRefClosure() {
  33226. function XRef(stream, password) {
  33227. this.stream = stream;
  33228. this.entries = [];
  33229. this.xrefstms = Object.create(null);
  33230. // prepare the XRef cache
  33231. this.cache = [];
  33232. this.password = password;
  33233. this.stats = {
  33234. streamTypes: [],
  33235. fontTypes: []
  33236. };
  33237. }
  33238. XRef.prototype = {
  33239. setStartXRef: function XRef_setStartXRef(startXRef) {
  33240. // Store the starting positions of xref tables as we process them
  33241. // so we can recover from missing data errors
  33242. this.startXRefQueue = [startXRef];
  33243. },
  33244. parse: function XRef_parse(recoveryMode) {
  33245. var trailerDict;
  33246. if (!recoveryMode) {
  33247. trailerDict = this.readXRef();
  33248. } else {
  33249. warn('Indexing all PDF objects');
  33250. trailerDict = this.indexObjects();
  33251. }
  33252. trailerDict.assignXref(this);
  33253. this.trailer = trailerDict;
  33254. var encrypt = trailerDict.get('Encrypt');
  33255. if (encrypt) {
  33256. var ids = trailerDict.get('ID');
  33257. var fileId = (ids && ids.length) ? ids[0] : '';
  33258. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  33259. this.password);
  33260. }
  33261. // get the root dictionary (catalog) object
  33262. if (!(this.root = trailerDict.get('Root'))) {
  33263. error('Invalid root reference');
  33264. }
  33265. },
  33266. processXRefTable: function XRef_processXRefTable(parser) {
  33267. if (!('tableState' in this)) {
  33268. // Stores state of the table as we process it so we can resume
  33269. // from middle of table in case of missing data error
  33270. this.tableState = {
  33271. entryNum: 0,
  33272. streamPos: parser.lexer.stream.pos,
  33273. parserBuf1: parser.buf1,
  33274. parserBuf2: parser.buf2
  33275. };
  33276. }
  33277. var obj = this.readXRefTable(parser);
  33278. // Sanity check
  33279. if (!isCmd(obj, 'trailer')) {
  33280. error('Invalid XRef table: could not find trailer dictionary');
  33281. }
  33282. // Read trailer dictionary, e.g.
  33283. // trailer
  33284. // << /Size 22
  33285. // /Root 20R
  33286. // /Info 10R
  33287. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  33288. // >>
  33289. // The parser goes through the entire stream << ... >> and provides
  33290. // a getter interface for the key-value table
  33291. var dict = parser.getObj();
  33292. // The pdflib PDF generator can generate a nested trailer dictionary
  33293. if (!isDict(dict) && dict.dict) {
  33294. dict = dict.dict;
  33295. }
  33296. if (!isDict(dict)) {
  33297. error('Invalid XRef table: could not parse trailer dictionary');
  33298. }
  33299. delete this.tableState;
  33300. return dict;
  33301. },
  33302. readXRefTable: function XRef_readXRefTable(parser) {
  33303. // Example of cross-reference table:
  33304. // xref
  33305. // 0 1 <-- subsection header (first obj #, obj count)
  33306. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  33307. // 23 2 <-- subsection header ... and so on ...
  33308. // 0000025518 00002 n
  33309. // 0000025635 00000 n
  33310. // trailer
  33311. // ...
  33312. var stream = parser.lexer.stream;
  33313. var tableState = this.tableState;
  33314. stream.pos = tableState.streamPos;
  33315. parser.buf1 = tableState.parserBuf1;
  33316. parser.buf2 = tableState.parserBuf2;
  33317. // Outer loop is over subsection headers
  33318. var obj;
  33319. while (true) {
  33320. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  33321. if (isCmd(obj = parser.getObj(), 'trailer')) {
  33322. break;
  33323. }
  33324. tableState.firstEntryNum = obj;
  33325. tableState.entryCount = parser.getObj();
  33326. }
  33327. var first = tableState.firstEntryNum;
  33328. var count = tableState.entryCount;
  33329. if (!isInt(first) || !isInt(count)) {
  33330. error('Invalid XRef table: wrong types in subsection header');
  33331. }
  33332. // Inner loop is over objects themselves
  33333. for (var i = tableState.entryNum; i < count; i++) {
  33334. tableState.streamPos = stream.pos;
  33335. tableState.entryNum = i;
  33336. tableState.parserBuf1 = parser.buf1;
  33337. tableState.parserBuf2 = parser.buf2;
  33338. var entry = {};
  33339. entry.offset = parser.getObj();
  33340. entry.gen = parser.getObj();
  33341. var type = parser.getObj();
  33342. if (isCmd(type, 'f')) {
  33343. entry.free = true;
  33344. } else if (isCmd(type, 'n')) {
  33345. entry.uncompressed = true;
  33346. }
  33347. // Validate entry obj
  33348. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  33349. !(entry.free || entry.uncompressed)) {
  33350. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  33351. }
  33352. // The first xref table entry, i.e. obj 0, should be free. Attempting
  33353. // to adjust an incorrect first obj # (fixes issue 3248 and 7229).
  33354. if (i === 0 && entry.free && first === 1) {
  33355. first = 0;
  33356. }
  33357. if (!this.entries[i + first]) {
  33358. this.entries[i + first] = entry;
  33359. }
  33360. }
  33361. tableState.entryNum = 0;
  33362. tableState.streamPos = stream.pos;
  33363. tableState.parserBuf1 = parser.buf1;
  33364. tableState.parserBuf2 = parser.buf2;
  33365. delete tableState.firstEntryNum;
  33366. delete tableState.entryCount;
  33367. }
  33368. // Sanity check: as per spec, first object must be free
  33369. if (this.entries[0] && !this.entries[0].free) {
  33370. error('Invalid XRef table: unexpected first object');
  33371. }
  33372. return obj;
  33373. },
  33374. processXRefStream: function XRef_processXRefStream(stream) {
  33375. if (!('streamState' in this)) {
  33376. // Stores state of the stream as we process it so we can resume
  33377. // from middle of stream in case of missing data error
  33378. var streamParameters = stream.dict;
  33379. var byteWidths = streamParameters.get('W');
  33380. var range = streamParameters.get('Index');
  33381. if (!range) {
  33382. range = [0, streamParameters.get('Size')];
  33383. }
  33384. this.streamState = {
  33385. entryRanges: range,
  33386. byteWidths: byteWidths,
  33387. entryNum: 0,
  33388. streamPos: stream.pos
  33389. };
  33390. }
  33391. this.readXRefStream(stream);
  33392. delete this.streamState;
  33393. return stream.dict;
  33394. },
  33395. readXRefStream: function XRef_readXRefStream(stream) {
  33396. var i, j;
  33397. var streamState = this.streamState;
  33398. stream.pos = streamState.streamPos;
  33399. var byteWidths = streamState.byteWidths;
  33400. var typeFieldWidth = byteWidths[0];
  33401. var offsetFieldWidth = byteWidths[1];
  33402. var generationFieldWidth = byteWidths[2];
  33403. var entryRanges = streamState.entryRanges;
  33404. while (entryRanges.length > 0) {
  33405. var first = entryRanges[0];
  33406. var n = entryRanges[1];
  33407. if (!isInt(first) || !isInt(n)) {
  33408. error('Invalid XRef range fields: ' + first + ', ' + n);
  33409. }
  33410. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  33411. !isInt(generationFieldWidth)) {
  33412. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  33413. }
  33414. for (i = streamState.entryNum; i < n; ++i) {
  33415. streamState.entryNum = i;
  33416. streamState.streamPos = stream.pos;
  33417. var type = 0, offset = 0, generation = 0;
  33418. for (j = 0; j < typeFieldWidth; ++j) {
  33419. type = (type << 8) | stream.getByte();
  33420. }
  33421. // if type field is absent, its default value is 1
  33422. if (typeFieldWidth === 0) {
  33423. type = 1;
  33424. }
  33425. for (j = 0; j < offsetFieldWidth; ++j) {
  33426. offset = (offset << 8) | stream.getByte();
  33427. }
  33428. for (j = 0; j < generationFieldWidth; ++j) {
  33429. generation = (generation << 8) | stream.getByte();
  33430. }
  33431. var entry = {};
  33432. entry.offset = offset;
  33433. entry.gen = generation;
  33434. switch (type) {
  33435. case 0:
  33436. entry.free = true;
  33437. break;
  33438. case 1:
  33439. entry.uncompressed = true;
  33440. break;
  33441. case 2:
  33442. break;
  33443. default:
  33444. error('Invalid XRef entry type: ' + type);
  33445. }
  33446. if (!this.entries[first + i]) {
  33447. this.entries[first + i] = entry;
  33448. }
  33449. }
  33450. streamState.entryNum = 0;
  33451. streamState.streamPos = stream.pos;
  33452. entryRanges.splice(0, 2);
  33453. }
  33454. },
  33455. indexObjects: function XRef_indexObjects() {
  33456. // Simple scan through the PDF content to find objects,
  33457. // trailers and XRef streams.
  33458. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  33459. var PERCENT = 0x25, LT = 0x3C;
  33460. function readToken(data, offset) {
  33461. var token = '', ch = data[offset];
  33462. while (ch !== LF && ch !== CR && ch !== LT) {
  33463. if (++offset >= data.length) {
  33464. break;
  33465. }
  33466. token += String.fromCharCode(ch);
  33467. ch = data[offset];
  33468. }
  33469. return token;
  33470. }
  33471. function skipUntil(data, offset, what) {
  33472. var length = what.length, dataLength = data.length;
  33473. var skipped = 0;
  33474. // finding byte sequence
  33475. while (offset < dataLength) {
  33476. var i = 0;
  33477. while (i < length && data[offset + i] === what[i]) {
  33478. ++i;
  33479. }
  33480. if (i >= length) {
  33481. break; // sequence found
  33482. }
  33483. offset++;
  33484. skipped++;
  33485. }
  33486. return skipped;
  33487. }
  33488. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  33489. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  33490. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  33491. 101, 102]);
  33492. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  33493. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  33494. // Clear out any existing entries, since they may be bogus.
  33495. this.entries.length = 0;
  33496. var stream = this.stream;
  33497. stream.pos = 0;
  33498. var buffer = stream.getBytes();
  33499. var position = stream.start, length = buffer.length;
  33500. var trailers = [], xrefStms = [];
  33501. while (position < length) {
  33502. var ch = buffer[position];
  33503. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  33504. ++position;
  33505. continue;
  33506. }
  33507. if (ch === PERCENT) { // %-comment
  33508. do {
  33509. ++position;
  33510. if (position >= length) {
  33511. break;
  33512. }
  33513. ch = buffer[position];
  33514. } while (ch !== LF && ch !== CR);
  33515. continue;
  33516. }
  33517. var token = readToken(buffer, position);
  33518. var m;
  33519. if (token.indexOf('xref') === 0 &&
  33520. (token.length === 4 || /\s/.test(token[4]))) {
  33521. position += skipUntil(buffer, position, trailerBytes);
  33522. trailers.push(position);
  33523. position += skipUntil(buffer, position, startxrefBytes);
  33524. } else if ((m = objRegExp.exec(token))) {
  33525. if (typeof this.entries[m[1]] === 'undefined') {
  33526. this.entries[m[1]] = {
  33527. offset: position - stream.start,
  33528. gen: m[2] | 0,
  33529. uncompressed: true
  33530. };
  33531. }
  33532. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  33533. var content = buffer.subarray(position, position + contentLength);
  33534. // checking XRef stream suspect
  33535. // (it shall have '/XRef' and next char is not a letter)
  33536. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  33537. if (xrefTagOffset < contentLength &&
  33538. content[xrefTagOffset + 5] < 64) {
  33539. xrefStms.push(position - stream.start);
  33540. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  33541. }
  33542. position += contentLength;
  33543. } else if (token.indexOf('trailer') === 0 &&
  33544. (token.length === 7 || /\s/.test(token[7]))) {
  33545. trailers.push(position);
  33546. position += skipUntil(buffer, position, startxrefBytes);
  33547. } else {
  33548. position += token.length + 1;
  33549. }
  33550. }
  33551. // reading XRef streams
  33552. var i, ii;
  33553. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  33554. this.startXRefQueue.push(xrefStms[i]);
  33555. this.readXRef(/* recoveryMode */ true);
  33556. }
  33557. // finding main trailer
  33558. var dict;
  33559. for (i = 0, ii = trailers.length; i < ii; ++i) {
  33560. stream.pos = trailers[i];
  33561. var parser = new Parser(new Lexer(stream), /* allowStreams = */ true,
  33562. /* xref = */ this, /* recoveryMode = */ true);
  33563. var obj = parser.getObj();
  33564. if (!isCmd(obj, 'trailer')) {
  33565. continue;
  33566. }
  33567. // read the trailer dictionary
  33568. dict = parser.getObj();
  33569. if (!isDict(dict)) {
  33570. continue;
  33571. }
  33572. // taking the first one with 'ID'
  33573. if (dict.has('ID')) {
  33574. return dict;
  33575. }
  33576. }
  33577. // no tailer with 'ID', taking last one (if exists)
  33578. if (dict) {
  33579. return dict;
  33580. }
  33581. // nothing helps
  33582. // calling error() would reject worker with an UnknownErrorException.
  33583. throw new InvalidPDFException('Invalid PDF structure');
  33584. },
  33585. readXRef: function XRef_readXRef(recoveryMode) {
  33586. var stream = this.stream;
  33587. try {
  33588. while (this.startXRefQueue.length) {
  33589. var startXRef = this.startXRefQueue[0];
  33590. stream.pos = startXRef + stream.start;
  33591. var parser = new Parser(new Lexer(stream), true, this);
  33592. var obj = parser.getObj();
  33593. var dict;
  33594. // Get dictionary
  33595. if (isCmd(obj, 'xref')) {
  33596. // Parse end-of-file XRef
  33597. dict = this.processXRefTable(parser);
  33598. if (!this.topDict) {
  33599. this.topDict = dict;
  33600. }
  33601. // Recursively get other XRefs 'XRefStm', if any
  33602. obj = dict.get('XRefStm');
  33603. if (isInt(obj)) {
  33604. var pos = obj;
  33605. // ignore previously loaded xref streams
  33606. // (possible infinite recursion)
  33607. if (!(pos in this.xrefstms)) {
  33608. this.xrefstms[pos] = 1;
  33609. this.startXRefQueue.push(pos);
  33610. }
  33611. }
  33612. } else if (isInt(obj)) {
  33613. // Parse in-stream XRef
  33614. if (!isInt(parser.getObj()) ||
  33615. !isCmd(parser.getObj(), 'obj') ||
  33616. !isStream(obj = parser.getObj())) {
  33617. error('Invalid XRef stream');
  33618. }
  33619. dict = this.processXRefStream(obj);
  33620. if (!this.topDict) {
  33621. this.topDict = dict;
  33622. }
  33623. if (!dict) {
  33624. error('Failed to read XRef stream');
  33625. }
  33626. } else {
  33627. error('Invalid XRef stream header');
  33628. }
  33629. // Recursively get previous dictionary, if any
  33630. obj = dict.get('Prev');
  33631. if (isInt(obj)) {
  33632. this.startXRefQueue.push(obj);
  33633. } else if (isRef(obj)) {
  33634. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  33635. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  33636. this.startXRefQueue.push(obj.num);
  33637. }
  33638. this.startXRefQueue.shift();
  33639. }
  33640. return this.topDict;
  33641. } catch (e) {
  33642. if (e instanceof MissingDataException) {
  33643. throw e;
  33644. }
  33645. info('(while reading XRef): ' + e);
  33646. }
  33647. if (recoveryMode) {
  33648. return;
  33649. }
  33650. throw new XRefParseException();
  33651. },
  33652. getEntry: function XRef_getEntry(i) {
  33653. var xrefEntry = this.entries[i];
  33654. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  33655. return xrefEntry;
  33656. }
  33657. return null;
  33658. },
  33659. fetchIfRef: function XRef_fetchIfRef(obj) {
  33660. if (!isRef(obj)) {
  33661. return obj;
  33662. }
  33663. return this.fetch(obj);
  33664. },
  33665. fetch: function XRef_fetch(ref, suppressEncryption) {
  33666. assert(isRef(ref), 'ref object is not a reference');
  33667. var num = ref.num;
  33668. if (num in this.cache) {
  33669. var cacheEntry = this.cache[num];
  33670. return cacheEntry;
  33671. }
  33672. var xrefEntry = this.getEntry(num);
  33673. // the referenced entry can be free
  33674. if (xrefEntry === null) {
  33675. return (this.cache[num] = null);
  33676. }
  33677. if (xrefEntry.uncompressed) {
  33678. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  33679. } else {
  33680. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  33681. }
  33682. if (isDict(xrefEntry)){
  33683. xrefEntry.objId = ref.toString();
  33684. } else if (isStream(xrefEntry)) {
  33685. xrefEntry.dict.objId = ref.toString();
  33686. }
  33687. return xrefEntry;
  33688. },
  33689. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  33690. suppressEncryption) {
  33691. var gen = ref.gen;
  33692. var num = ref.num;
  33693. if (xrefEntry.gen !== gen) {
  33694. error('inconsistent generation in XRef');
  33695. }
  33696. var stream = this.stream.makeSubStream(xrefEntry.offset +
  33697. this.stream.start);
  33698. var parser = new Parser(new Lexer(stream), true, this);
  33699. var obj1 = parser.getObj();
  33700. var obj2 = parser.getObj();
  33701. var obj3 = parser.getObj();
  33702. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  33703. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  33704. !isCmd(obj3)) {
  33705. error('bad XRef entry');
  33706. }
  33707. if (!isCmd(obj3, 'obj')) {
  33708. // some bad PDFs use "obj1234" and really mean 1234
  33709. if (obj3.cmd.indexOf('obj') === 0) {
  33710. num = parseInt(obj3.cmd.substring(3), 10);
  33711. if (!isNaN(num)) {
  33712. return num;
  33713. }
  33714. }
  33715. error('bad XRef entry');
  33716. }
  33717. if (this.encrypt && !suppressEncryption) {
  33718. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  33719. } else {
  33720. xrefEntry = parser.getObj();
  33721. }
  33722. if (!isStream(xrefEntry)) {
  33723. this.cache[num] = xrefEntry;
  33724. }
  33725. return xrefEntry;
  33726. },
  33727. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  33728. suppressEncryption) {
  33729. var tableOffset = xrefEntry.offset;
  33730. var stream = this.fetch(new Ref(tableOffset, 0));
  33731. if (!isStream(stream)) {
  33732. error('bad ObjStm stream');
  33733. }
  33734. var first = stream.dict.get('First');
  33735. var n = stream.dict.get('N');
  33736. if (!isInt(first) || !isInt(n)) {
  33737. error('invalid first and n parameters for ObjStm stream');
  33738. }
  33739. var parser = new Parser(new Lexer(stream), false, this);
  33740. parser.allowStreams = true;
  33741. var i, entries = [], num, nums = [];
  33742. // read the object numbers to populate cache
  33743. for (i = 0; i < n; ++i) {
  33744. num = parser.getObj();
  33745. if (!isInt(num)) {
  33746. error('invalid object number in the ObjStm stream: ' + num);
  33747. }
  33748. nums.push(num);
  33749. var offset = parser.getObj();
  33750. if (!isInt(offset)) {
  33751. error('invalid object offset in the ObjStm stream: ' + offset);
  33752. }
  33753. }
  33754. // read stream objects for cache
  33755. for (i = 0; i < n; ++i) {
  33756. entries.push(parser.getObj());
  33757. // The ObjStm should not contain 'endobj'. If it's present, skip over it
  33758. // to support corrupt PDFs (fixes issue 5241, bug 898610, bug 1037816).
  33759. if (isCmd(parser.buf1, 'endobj')) {
  33760. parser.shift();
  33761. }
  33762. num = nums[i];
  33763. var entry = this.entries[num];
  33764. if (entry && entry.offset === tableOffset && entry.gen === i) {
  33765. this.cache[num] = entries[i];
  33766. }
  33767. }
  33768. xrefEntry = entries[xrefEntry.gen];
  33769. if (xrefEntry === undefined) {
  33770. error('bad XRef entry for compressed object');
  33771. }
  33772. return xrefEntry;
  33773. },
  33774. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  33775. if (!isRef(obj)) {
  33776. return Promise.resolve(obj);
  33777. }
  33778. return this.fetchAsync(obj);
  33779. },
  33780. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  33781. var streamManager = this.stream.manager;
  33782. var xref = this;
  33783. return new Promise(function tryFetch(resolve, reject) {
  33784. try {
  33785. resolve(xref.fetch(ref, suppressEncryption));
  33786. } catch (e) {
  33787. if (e instanceof MissingDataException) {
  33788. streamManager.requestRange(e.begin, e.end).then(function () {
  33789. tryFetch(resolve, reject);
  33790. }, reject);
  33791. return;
  33792. }
  33793. reject(e);
  33794. }
  33795. });
  33796. },
  33797. getCatalogObj: function XRef_getCatalogObj() {
  33798. return this.root;
  33799. }
  33800. };
  33801. return XRef;
  33802. })();
  33803. /**
  33804. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  33805. * see the specification (7.9.6 and 7.9.7) for additional details.
  33806. * TODO: implement all the Dict functions and make this more efficient.
  33807. */
  33808. var NameOrNumberTree = (function NameOrNumberTreeClosure() {
  33809. function NameOrNumberTree(root, xref) {
  33810. throw new Error('Cannot initialize NameOrNumberTree.');
  33811. }
  33812. NameOrNumberTree.prototype = {
  33813. getAll: function NameOrNumberTree_getAll() {
  33814. var dict = Object.create(null);
  33815. if (!this.root) {
  33816. return dict;
  33817. }
  33818. var xref = this.xref;
  33819. // Reading Name/Number tree.
  33820. var processed = new RefSet();
  33821. processed.put(this.root);
  33822. var queue = [this.root];
  33823. while (queue.length > 0) {
  33824. var i, n;
  33825. var obj = xref.fetchIfRef(queue.shift());
  33826. if (!isDict(obj)) {
  33827. continue;
  33828. }
  33829. if (obj.has('Kids')) {
  33830. var kids = obj.get('Kids');
  33831. for (i = 0, n = kids.length; i < n; i++) {
  33832. var kid = kids[i];
  33833. assert(!processed.has(kid),
  33834. 'Duplicate entry in "' + this._type + '" tree.');
  33835. queue.push(kid);
  33836. processed.put(kid);
  33837. }
  33838. continue;
  33839. }
  33840. var entries = obj.get(this._type);
  33841. if (isArray(entries)) {
  33842. for (i = 0, n = entries.length; i < n; i += 2) {
  33843. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  33844. }
  33845. }
  33846. }
  33847. return dict;
  33848. },
  33849. get: function NameOrNumberTree_get(key) {
  33850. if (!this.root) {
  33851. return null;
  33852. }
  33853. var xref = this.xref;
  33854. var kidsOrEntries = xref.fetchIfRef(this.root);
  33855. var loopCount = 0;
  33856. var MAX_LEVELS = 10;
  33857. var l, r, m;
  33858. // Perform a binary search to quickly find the entry that
  33859. // contains the key we are looking for.
  33860. while (kidsOrEntries.has('Kids')) {
  33861. if (++loopCount > MAX_LEVELS) {
  33862. warn('Search depth limit reached for "' + this._type + '" tree.');
  33863. return null;
  33864. }
  33865. var kids = kidsOrEntries.get('Kids');
  33866. if (!isArray(kids)) {
  33867. return null;
  33868. }
  33869. l = 0;
  33870. r = kids.length - 1;
  33871. while (l <= r) {
  33872. m = (l + r) >> 1;
  33873. var kid = xref.fetchIfRef(kids[m]);
  33874. var limits = kid.get('Limits');
  33875. if (key < xref.fetchIfRef(limits[0])) {
  33876. r = m - 1;
  33877. } else if (key > xref.fetchIfRef(limits[1])) {
  33878. l = m + 1;
  33879. } else {
  33880. kidsOrEntries = xref.fetchIfRef(kids[m]);
  33881. break;
  33882. }
  33883. }
  33884. if (l > r) {
  33885. return null;
  33886. }
  33887. }
  33888. // If we get here, then we have found the right entry. Now go through the
  33889. // entries in the dictionary until we find the key we're looking for.
  33890. var entries = kidsOrEntries.get(this._type);
  33891. if (isArray(entries)) {
  33892. // Perform a binary search to reduce the lookup time.
  33893. l = 0;
  33894. r = entries.length - 2;
  33895. while (l <= r) {
  33896. // Check only even indices (0, 2, 4, ...) because the
  33897. // odd indices contain the actual data.
  33898. m = (l + r) & ~1;
  33899. var currentKey = xref.fetchIfRef(entries[m]);
  33900. if (key < currentKey) {
  33901. r = m - 2;
  33902. } else if (key > currentKey) {
  33903. l = m + 2;
  33904. } else {
  33905. return xref.fetchIfRef(entries[m + 1]);
  33906. }
  33907. }
  33908. }
  33909. return null;
  33910. }
  33911. };
  33912. return NameOrNumberTree;
  33913. })();
  33914. var NameTree = (function NameTreeClosure() {
  33915. function NameTree(root, xref) {
  33916. this.root = root;
  33917. this.xref = xref;
  33918. this._type = 'Names';
  33919. }
  33920. Util.inherit(NameTree, NameOrNumberTree, {});
  33921. return NameTree;
  33922. })();
  33923. var NumberTree = (function NumberTreeClosure() {
  33924. function NumberTree(root, xref) {
  33925. this.root = root;
  33926. this.xref = xref;
  33927. this._type = 'Nums';
  33928. }
  33929. Util.inherit(NumberTree, NameOrNumberTree, {});
  33930. return NumberTree;
  33931. })();
  33932. /**
  33933. * "A PDF file can refer to the contents of another file by using a File
  33934. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  33935. * NOTE: Only embedded files are supported (as part of the attachments support)
  33936. * TODO: support the 'URL' file system (with caching if !/V), portable
  33937. * collections attributes and related files (/RF)
  33938. */
  33939. var FileSpec = (function FileSpecClosure() {
  33940. function FileSpec(root, xref) {
  33941. if (!root || !isDict(root)) {
  33942. return;
  33943. }
  33944. this.xref = xref;
  33945. this.root = root;
  33946. if (root.has('FS')) {
  33947. this.fs = root.get('FS');
  33948. }
  33949. this.description = root.has('Desc') ?
  33950. stringToPDFString(root.get('Desc')) :
  33951. '';
  33952. if (root.has('RF')) {
  33953. warn('Related file specifications are not supported');
  33954. }
  33955. this.contentAvailable = true;
  33956. if (!root.has('EF')) {
  33957. this.contentAvailable = false;
  33958. warn('Non-embedded file specifications are not supported');
  33959. }
  33960. }
  33961. function pickPlatformItem(dict) {
  33962. // Look for the filename in this order:
  33963. // UF, F, Unix, Mac, DOS
  33964. if (dict.has('UF')) {
  33965. return dict.get('UF');
  33966. } else if (dict.has('F')) {
  33967. return dict.get('F');
  33968. } else if (dict.has('Unix')) {
  33969. return dict.get('Unix');
  33970. } else if (dict.has('Mac')) {
  33971. return dict.get('Mac');
  33972. } else if (dict.has('DOS')) {
  33973. return dict.get('DOS');
  33974. } else {
  33975. return null;
  33976. }
  33977. }
  33978. FileSpec.prototype = {
  33979. get filename() {
  33980. if (!this._filename && this.root) {
  33981. var filename = pickPlatformItem(this.root) || 'unnamed';
  33982. this._filename = stringToPDFString(filename).
  33983. replace(/\\\\/g, '\\').
  33984. replace(/\\\//g, '/').
  33985. replace(/\\/g, '/');
  33986. }
  33987. return this._filename;
  33988. },
  33989. get content() {
  33990. if (!this.contentAvailable) {
  33991. return null;
  33992. }
  33993. if (!this.contentRef && this.root) {
  33994. this.contentRef = pickPlatformItem(this.root.get('EF'));
  33995. }
  33996. var content = null;
  33997. if (this.contentRef) {
  33998. var xref = this.xref;
  33999. var fileObj = xref.fetchIfRef(this.contentRef);
  34000. if (fileObj && isStream(fileObj)) {
  34001. content = fileObj.getBytes();
  34002. } else {
  34003. warn('Embedded file specification points to non-existing/invalid ' +
  34004. 'content');
  34005. }
  34006. } else {
  34007. warn('Embedded file specification does not have a content');
  34008. }
  34009. return content;
  34010. },
  34011. get serializable() {
  34012. return {
  34013. filename: this.filename,
  34014. content: this.content
  34015. };
  34016. }
  34017. };
  34018. return FileSpec;
  34019. })();
  34020. /**
  34021. * A helper for loading missing data in object graphs. It traverses the graph
  34022. * depth first and queues up any objects that have missing data. Once it has
  34023. * has traversed as many objects that are available it attempts to bundle the
  34024. * missing data requests and then resume from the nodes that weren't ready.
  34025. *
  34026. * NOTE: It provides protection from circular references by keeping track of
  34027. * of loaded references. However, you must be careful not to load any graphs
  34028. * that have references to the catalog or other pages since that will cause the
  34029. * entire PDF document object graph to be traversed.
  34030. */
  34031. var ObjectLoader = (function() {
  34032. function mayHaveChildren(value) {
  34033. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  34034. }
  34035. function addChildren(node, nodesToVisit) {
  34036. var value;
  34037. if (isDict(node) || isStream(node)) {
  34038. var map;
  34039. if (isDict(node)) {
  34040. map = node.map;
  34041. } else {
  34042. map = node.dict.map;
  34043. }
  34044. for (var key in map) {
  34045. value = map[key];
  34046. if (mayHaveChildren(value)) {
  34047. nodesToVisit.push(value);
  34048. }
  34049. }
  34050. } else if (isArray(node)) {
  34051. for (var i = 0, ii = node.length; i < ii; i++) {
  34052. value = node[i];
  34053. if (mayHaveChildren(value)) {
  34054. nodesToVisit.push(value);
  34055. }
  34056. }
  34057. }
  34058. }
  34059. function ObjectLoader(obj, keys, xref) {
  34060. this.obj = obj;
  34061. this.keys = keys;
  34062. this.xref = xref;
  34063. this.refSet = null;
  34064. this.capability = null;
  34065. }
  34066. ObjectLoader.prototype = {
  34067. load: function ObjectLoader_load() {
  34068. var keys = this.keys;
  34069. this.capability = createPromiseCapability();
  34070. // Don't walk the graph if all the data is already loaded.
  34071. if (!(this.xref.stream instanceof ChunkedStream) ||
  34072. this.xref.stream.getMissingChunks().length === 0) {
  34073. this.capability.resolve();
  34074. return this.capability.promise;
  34075. }
  34076. this.refSet = new RefSet();
  34077. // Setup the initial nodes to visit.
  34078. var nodesToVisit = [];
  34079. for (var i = 0; i < keys.length; i++) {
  34080. nodesToVisit.push(this.obj[keys[i]]);
  34081. }
  34082. this._walk(nodesToVisit);
  34083. return this.capability.promise;
  34084. },
  34085. _walk: function ObjectLoader_walk(nodesToVisit) {
  34086. var nodesToRevisit = [];
  34087. var pendingRequests = [];
  34088. // DFS walk of the object graph.
  34089. while (nodesToVisit.length) {
  34090. var currentNode = nodesToVisit.pop();
  34091. // Only references or chunked streams can cause missing data exceptions.
  34092. if (isRef(currentNode)) {
  34093. // Skip nodes that have already been visited.
  34094. if (this.refSet.has(currentNode)) {
  34095. continue;
  34096. }
  34097. try {
  34098. var ref = currentNode;
  34099. this.refSet.put(ref);
  34100. currentNode = this.xref.fetch(currentNode);
  34101. } catch (e) {
  34102. if (!(e instanceof MissingDataException)) {
  34103. throw e;
  34104. }
  34105. nodesToRevisit.push(currentNode);
  34106. pendingRequests.push({ begin: e.begin, end: e.end });
  34107. }
  34108. }
  34109. if (currentNode && currentNode.getBaseStreams) {
  34110. var baseStreams = currentNode.getBaseStreams();
  34111. var foundMissingData = false;
  34112. for (var i = 0; i < baseStreams.length; i++) {
  34113. var stream = baseStreams[i];
  34114. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  34115. foundMissingData = true;
  34116. pendingRequests.push({
  34117. begin: stream.start,
  34118. end: stream.end
  34119. });
  34120. }
  34121. }
  34122. if (foundMissingData) {
  34123. nodesToRevisit.push(currentNode);
  34124. }
  34125. }
  34126. addChildren(currentNode, nodesToVisit);
  34127. }
  34128. if (pendingRequests.length) {
  34129. this.xref.stream.manager.requestRanges(pendingRequests).then(
  34130. function pendingRequestCallback() {
  34131. nodesToVisit = nodesToRevisit;
  34132. for (var i = 0; i < nodesToRevisit.length; i++) {
  34133. var node = nodesToRevisit[i];
  34134. // Remove any reference nodes from the currrent refset so they
  34135. // aren't skipped when we revist them.
  34136. if (isRef(node)) {
  34137. this.refSet.remove(node);
  34138. }
  34139. }
  34140. this._walk(nodesToVisit);
  34141. }.bind(this), this.capability.reject);
  34142. return;
  34143. }
  34144. // Everything is loaded.
  34145. this.refSet = null;
  34146. this.capability.resolve();
  34147. }
  34148. };
  34149. return ObjectLoader;
  34150. })();
  34151. exports.Catalog = Catalog;
  34152. exports.ObjectLoader = ObjectLoader;
  34153. exports.XRef = XRef;
  34154. exports.FileSpec = FileSpec;
  34155. }));
  34156. (function (root, factory) {
  34157. {
  34158. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  34159. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  34160. root.pdfjsCoreColorSpace);
  34161. }
  34162. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  34163. coreColorSpace) {
  34164. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  34165. var MissingDataException = sharedUtil.MissingDataException;
  34166. var Util = sharedUtil.Util;
  34167. var assert = sharedUtil.assert;
  34168. var error = sharedUtil.error;
  34169. var info = sharedUtil.info;
  34170. var warn = sharedUtil.warn;
  34171. var isStream = corePrimitives.isStream;
  34172. var PDFFunction = coreFunction.PDFFunction;
  34173. var ColorSpace = coreColorSpace.ColorSpace;
  34174. var ShadingType = {
  34175. FUNCTION_BASED: 1,
  34176. AXIAL: 2,
  34177. RADIAL: 3,
  34178. FREE_FORM_MESH: 4,
  34179. LATTICE_FORM_MESH: 5,
  34180. COONS_PATCH_MESH: 6,
  34181. TENSOR_PATCH_MESH: 7
  34182. };
  34183. var Pattern = (function PatternClosure() {
  34184. // Constructor should define this.getPattern
  34185. function Pattern() {
  34186. error('should not call Pattern constructor');
  34187. }
  34188. Pattern.prototype = {
  34189. // Input: current Canvas context
  34190. // Output: the appropriate fillStyle or strokeStyle
  34191. getPattern: function Pattern_getPattern(ctx) {
  34192. error('Should not call Pattern.getStyle: ' + ctx);
  34193. }
  34194. };
  34195. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  34196. res, handler) {
  34197. var dict = isStream(shading) ? shading.dict : shading;
  34198. var type = dict.get('ShadingType');
  34199. try {
  34200. switch (type) {
  34201. case ShadingType.AXIAL:
  34202. case ShadingType.RADIAL:
  34203. // Both radial and axial shadings are handled by RadialAxial shading.
  34204. return new Shadings.RadialAxial(dict, matrix, xref, res);
  34205. case ShadingType.FREE_FORM_MESH:
  34206. case ShadingType.LATTICE_FORM_MESH:
  34207. case ShadingType.COONS_PATCH_MESH:
  34208. case ShadingType.TENSOR_PATCH_MESH:
  34209. return new Shadings.Mesh(shading, matrix, xref, res);
  34210. default:
  34211. throw new Error('Unsupported ShadingType: ' + type);
  34212. }
  34213. } catch (ex) {
  34214. if (ex instanceof MissingDataException) {
  34215. throw ex;
  34216. }
  34217. handler.send('UnsupportedFeature',
  34218. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  34219. warn(ex);
  34220. return new Shadings.Dummy();
  34221. }
  34222. };
  34223. return Pattern;
  34224. })();
  34225. var Shadings = {};
  34226. // A small number to offset the first/last color stops so we can insert ones to
  34227. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  34228. Shadings.SMALL_NUMBER = 1e-6;
  34229. // Radial and axial shading have very similar implementations
  34230. // If needed, the implementations can be broken into two classes
  34231. Shadings.RadialAxial = (function RadialAxialClosure() {
  34232. function RadialAxial(dict, matrix, xref, res) {
  34233. this.matrix = matrix;
  34234. this.coordsArr = dict.getArray('Coords');
  34235. this.shadingType = dict.get('ShadingType');
  34236. this.type = 'Pattern';
  34237. var cs = dict.get('ColorSpace', 'CS');
  34238. cs = ColorSpace.parse(cs, xref, res);
  34239. this.cs = cs;
  34240. var t0 = 0.0, t1 = 1.0;
  34241. if (dict.has('Domain')) {
  34242. var domainArr = dict.getArray('Domain');
  34243. t0 = domainArr[0];
  34244. t1 = domainArr[1];
  34245. }
  34246. var extendStart = false, extendEnd = false;
  34247. if (dict.has('Extend')) {
  34248. var extendArr = dict.getArray('Extend');
  34249. extendStart = extendArr[0];
  34250. extendEnd = extendArr[1];
  34251. }
  34252. if (this.shadingType === ShadingType.RADIAL &&
  34253. (!extendStart || !extendEnd)) {
  34254. // Radial gradient only currently works if either circle is fully within
  34255. // the other circle.
  34256. var x1 = this.coordsArr[0];
  34257. var y1 = this.coordsArr[1];
  34258. var r1 = this.coordsArr[2];
  34259. var x2 = this.coordsArr[3];
  34260. var y2 = this.coordsArr[4];
  34261. var r2 = this.coordsArr[5];
  34262. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  34263. if (r1 <= r2 + distance &&
  34264. r2 <= r1 + distance) {
  34265. warn('Unsupported radial gradient.');
  34266. }
  34267. }
  34268. this.extendStart = extendStart;
  34269. this.extendEnd = extendEnd;
  34270. var fnObj = dict.get('Function');
  34271. var fn = PDFFunction.parseArray(xref, fnObj);
  34272. // 10 samples seems good enough for now, but probably won't work
  34273. // if there are sharp color changes. Ideally, we would implement
  34274. // the spec faithfully and add lossless optimizations.
  34275. var diff = t1 - t0;
  34276. var step = diff / 10;
  34277. var colorStops = this.colorStops = [];
  34278. // Protect against bad domains so we don't end up in an infinte loop below.
  34279. if (t0 >= t1 || step <= 0) {
  34280. // Acrobat doesn't seem to handle these cases so we'll ignore for
  34281. // now.
  34282. info('Bad shading domain.');
  34283. return;
  34284. }
  34285. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  34286. var rgbColor;
  34287. for (var i = t0; i <= t1; i += step) {
  34288. ratio[0] = i;
  34289. fn(ratio, 0, color, 0);
  34290. rgbColor = cs.getRgb(color, 0);
  34291. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  34292. colorStops.push([(i - t0) / diff, cssColor]);
  34293. }
  34294. var background = 'transparent';
  34295. if (dict.has('Background')) {
  34296. rgbColor = cs.getRgb(dict.get('Background'), 0);
  34297. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  34298. }
  34299. if (!extendStart) {
  34300. // Insert a color stop at the front and offset the first real color stop
  34301. // so it doesn't conflict with the one we insert.
  34302. colorStops.unshift([0, background]);
  34303. colorStops[1][0] += Shadings.SMALL_NUMBER;
  34304. }
  34305. if (!extendEnd) {
  34306. // Same idea as above in extendStart but for the end.
  34307. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  34308. colorStops.push([1, background]);
  34309. }
  34310. this.colorStops = colorStops;
  34311. }
  34312. RadialAxial.prototype = {
  34313. getIR: function RadialAxial_getIR() {
  34314. var coordsArr = this.coordsArr;
  34315. var shadingType = this.shadingType;
  34316. var type, p0, p1, r0, r1;
  34317. if (shadingType === ShadingType.AXIAL) {
  34318. p0 = [coordsArr[0], coordsArr[1]];
  34319. p1 = [coordsArr[2], coordsArr[3]];
  34320. r0 = null;
  34321. r1 = null;
  34322. type = 'axial';
  34323. } else if (shadingType === ShadingType.RADIAL) {
  34324. p0 = [coordsArr[0], coordsArr[1]];
  34325. p1 = [coordsArr[3], coordsArr[4]];
  34326. r0 = coordsArr[2];
  34327. r1 = coordsArr[5];
  34328. type = 'radial';
  34329. } else {
  34330. error('getPattern type unknown: ' + shadingType);
  34331. }
  34332. var matrix = this.matrix;
  34333. if (matrix) {
  34334. p0 = Util.applyTransform(p0, matrix);
  34335. p1 = Util.applyTransform(p1, matrix);
  34336. if (shadingType === ShadingType.RADIAL) {
  34337. var scale = Util.singularValueDecompose2dScale(matrix);
  34338. r0 *= scale[0];
  34339. r1 *= scale[1];
  34340. }
  34341. }
  34342. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  34343. }
  34344. };
  34345. return RadialAxial;
  34346. })();
  34347. // All mesh shading. For now, they will be presented as set of the triangles
  34348. // to be drawn on the canvas and rgb color for each vertex.
  34349. Shadings.Mesh = (function MeshClosure() {
  34350. function MeshStreamReader(stream, context) {
  34351. this.stream = stream;
  34352. this.context = context;
  34353. this.buffer = 0;
  34354. this.bufferLength = 0;
  34355. var numComps = context.numComps;
  34356. this.tmpCompsBuf = new Float32Array(numComps);
  34357. var csNumComps = context.colorSpace.numComps;
  34358. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  34359. this.tmpCompsBuf;
  34360. }
  34361. MeshStreamReader.prototype = {
  34362. get hasData() {
  34363. if (this.stream.end) {
  34364. return this.stream.pos < this.stream.end;
  34365. }
  34366. if (this.bufferLength > 0) {
  34367. return true;
  34368. }
  34369. var nextByte = this.stream.getByte();
  34370. if (nextByte < 0) {
  34371. return false;
  34372. }
  34373. this.buffer = nextByte;
  34374. this.bufferLength = 8;
  34375. return true;
  34376. },
  34377. readBits: function MeshStreamReader_readBits(n) {
  34378. var buffer = this.buffer;
  34379. var bufferLength = this.bufferLength;
  34380. if (n === 32) {
  34381. if (bufferLength === 0) {
  34382. return ((this.stream.getByte() << 24) |
  34383. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  34384. this.stream.getByte()) >>> 0;
  34385. }
  34386. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  34387. (this.stream.getByte() << 8) | this.stream.getByte();
  34388. var nextByte = this.stream.getByte();
  34389. this.buffer = nextByte & ((1 << bufferLength) - 1);
  34390. return ((buffer << (8 - bufferLength)) |
  34391. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  34392. }
  34393. if (n === 8 && bufferLength === 0) {
  34394. return this.stream.getByte();
  34395. }
  34396. while (bufferLength < n) {
  34397. buffer = (buffer << 8) | this.stream.getByte();
  34398. bufferLength += 8;
  34399. }
  34400. bufferLength -= n;
  34401. this.bufferLength = bufferLength;
  34402. this.buffer = buffer & ((1 << bufferLength) - 1);
  34403. return buffer >> bufferLength;
  34404. },
  34405. align: function MeshStreamReader_align() {
  34406. this.buffer = 0;
  34407. this.bufferLength = 0;
  34408. },
  34409. readFlag: function MeshStreamReader_readFlag() {
  34410. return this.readBits(this.context.bitsPerFlag);
  34411. },
  34412. readCoordinate: function MeshStreamReader_readCoordinate() {
  34413. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  34414. var xi = this.readBits(bitsPerCoordinate);
  34415. var yi = this.readBits(bitsPerCoordinate);
  34416. var decode = this.context.decode;
  34417. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  34418. 2.3283064365386963e-10; // 2 ^ -32
  34419. return [
  34420. xi * scale * (decode[1] - decode[0]) + decode[0],
  34421. yi * scale * (decode[3] - decode[2]) + decode[2]
  34422. ];
  34423. },
  34424. readComponents: function MeshStreamReader_readComponents() {
  34425. var numComps = this.context.numComps;
  34426. var bitsPerComponent = this.context.bitsPerComponent;
  34427. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  34428. 2.3283064365386963e-10; // 2 ^ -32
  34429. var decode = this.context.decode;
  34430. var components = this.tmpCompsBuf;
  34431. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  34432. var ci = this.readBits(bitsPerComponent);
  34433. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  34434. }
  34435. var color = this.tmpCsCompsBuf;
  34436. if (this.context.colorFn) {
  34437. this.context.colorFn(components, 0, color, 0);
  34438. }
  34439. return this.context.colorSpace.getRgb(color, 0);
  34440. }
  34441. };
  34442. function decodeType4Shading(mesh, reader) {
  34443. var coords = mesh.coords;
  34444. var colors = mesh.colors;
  34445. var operators = [];
  34446. var ps = []; // not maintaining cs since that will match ps
  34447. var verticesLeft = 0; // assuming we have all data to start a new triangle
  34448. while (reader.hasData) {
  34449. var f = reader.readFlag();
  34450. var coord = reader.readCoordinate();
  34451. var color = reader.readComponents();
  34452. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  34453. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  34454. switch (f) {
  34455. case 0:
  34456. verticesLeft = 3;
  34457. break;
  34458. case 1:
  34459. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  34460. verticesLeft = 1;
  34461. break;
  34462. case 2:
  34463. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  34464. verticesLeft = 1;
  34465. break;
  34466. }
  34467. operators.push(f);
  34468. }
  34469. ps.push(coords.length);
  34470. coords.push(coord);
  34471. colors.push(color);
  34472. verticesLeft--;
  34473. reader.align();
  34474. }
  34475. mesh.figures.push({
  34476. type: 'triangles',
  34477. coords: new Int32Array(ps),
  34478. colors: new Int32Array(ps),
  34479. });
  34480. }
  34481. function decodeType5Shading(mesh, reader, verticesPerRow) {
  34482. var coords = mesh.coords;
  34483. var colors = mesh.colors;
  34484. var ps = []; // not maintaining cs since that will match ps
  34485. while (reader.hasData) {
  34486. var coord = reader.readCoordinate();
  34487. var color = reader.readComponents();
  34488. ps.push(coords.length);
  34489. coords.push(coord);
  34490. colors.push(color);
  34491. }
  34492. mesh.figures.push({
  34493. type: 'lattice',
  34494. coords: new Int32Array(ps),
  34495. colors: new Int32Array(ps),
  34496. verticesPerRow: verticesPerRow
  34497. });
  34498. }
  34499. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  34500. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  34501. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  34502. var getB = (function getBClosure() {
  34503. function buildB(count) {
  34504. var lut = [];
  34505. for (var i = 0; i <= count; i++) {
  34506. var t = i / count, t_ = 1 - t;
  34507. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  34508. 3 * t * t * t_, t * t * t]));
  34509. }
  34510. return lut;
  34511. }
  34512. var cache = [];
  34513. return function getB(count) {
  34514. if (!cache[count]) {
  34515. cache[count] = buildB(count);
  34516. }
  34517. return cache[count];
  34518. };
  34519. })();
  34520. function buildFigureFromPatch(mesh, index) {
  34521. var figure = mesh.figures[index];
  34522. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  34523. var coords = mesh.coords, colors = mesh.colors;
  34524. var pi = figure.coords;
  34525. var ci = figure.colors;
  34526. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  34527. coords[pi[12]][0], coords[pi[15]][0]);
  34528. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  34529. coords[pi[12]][1], coords[pi[15]][1]);
  34530. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  34531. coords[pi[12]][0], coords[pi[15]][0]);
  34532. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  34533. coords[pi[12]][1], coords[pi[15]][1]);
  34534. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  34535. (mesh.bounds[2] - mesh.bounds[0]));
  34536. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  34537. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  34538. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  34539. (mesh.bounds[3] - mesh.bounds[1]));
  34540. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  34541. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  34542. var verticesPerRow = splitXBy + 1;
  34543. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  34544. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  34545. var k = 0;
  34546. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  34547. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  34548. c2 = colors[ci[2]], c3 = colors[ci[3]];
  34549. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  34550. for (var row = 0; row <= splitYBy; row++) {
  34551. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  34552. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  34553. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  34554. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  34555. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  34556. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  34557. for (var col = 0; col <= splitXBy; col++, k++) {
  34558. if ((row === 0 || row === splitYBy) &&
  34559. (col === 0 || col === splitXBy)) {
  34560. continue;
  34561. }
  34562. var x = 0, y = 0;
  34563. var q = 0;
  34564. for (var i = 0; i <= 3; i++) {
  34565. for (var j = 0; j <= 3; j++, q++) {
  34566. var m = bRow[row][i] * bCol[col][j];
  34567. x += coords[pi[q]][0] * m;
  34568. y += coords[pi[q]][1] * m;
  34569. }
  34570. }
  34571. figureCoords[k] = coords.length;
  34572. coords.push([x, y]);
  34573. figureColors[k] = colors.length;
  34574. var newColor = new Uint8Array(3);
  34575. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  34576. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  34577. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  34578. colors.push(newColor);
  34579. }
  34580. }
  34581. figureCoords[0] = pi[0];
  34582. figureColors[0] = ci[0];
  34583. figureCoords[splitXBy] = pi[3];
  34584. figureColors[splitXBy] = ci[1];
  34585. figureCoords[verticesPerRow * splitYBy] = pi[12];
  34586. figureColors[verticesPerRow * splitYBy] = ci[2];
  34587. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  34588. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  34589. mesh.figures[index] = {
  34590. type: 'lattice',
  34591. coords: figureCoords,
  34592. colors: figureColors,
  34593. verticesPerRow: verticesPerRow
  34594. };
  34595. }
  34596. function decodeType6Shading(mesh, reader) {
  34597. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  34598. var coords = mesh.coords;
  34599. var colors = mesh.colors;
  34600. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  34601. var cs = new Int32Array(4); // c00, c30, c03, c33
  34602. while (reader.hasData) {
  34603. var f = reader.readFlag();
  34604. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  34605. var i, ii;
  34606. var pi = coords.length;
  34607. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  34608. coords.push(reader.readCoordinate());
  34609. }
  34610. var ci = colors.length;
  34611. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  34612. colors.push(reader.readComponents());
  34613. }
  34614. var tmp1, tmp2, tmp3, tmp4;
  34615. switch (f) {
  34616. case 0:
  34617. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  34618. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  34619. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  34620. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  34621. cs[2] = ci + 1; cs[3] = ci + 2;
  34622. cs[0] = ci; cs[1] = ci + 3;
  34623. break;
  34624. case 1:
  34625. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  34626. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34627. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  34628. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  34629. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34630. tmp1 = cs[2]; tmp2 = cs[3];
  34631. cs[2] = tmp2; cs[3] = ci;
  34632. cs[0] = tmp1; cs[1] = ci + 1;
  34633. break;
  34634. case 2:
  34635. tmp1 = ps[15];
  34636. tmp2 = ps[11];
  34637. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34638. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  34639. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  34640. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34641. tmp1 = cs[3];
  34642. cs[2] = cs[1]; cs[3] = ci;
  34643. cs[0] = tmp1; cs[1] = ci + 1;
  34644. break;
  34645. case 3:
  34646. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34647. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  34648. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  34649. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34650. cs[2] = cs[0]; cs[3] = ci;
  34651. cs[0] = cs[1]; cs[1] = ci + 1;
  34652. break;
  34653. }
  34654. // set p11, p12, p21, p22
  34655. ps[5] = coords.length;
  34656. coords.push([
  34657. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  34658. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  34659. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  34660. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  34661. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  34662. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  34663. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  34664. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  34665. ]);
  34666. ps[6] = coords.length;
  34667. coords.push([
  34668. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  34669. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  34670. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  34671. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  34672. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  34673. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  34674. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  34675. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  34676. ]);
  34677. ps[9] = coords.length;
  34678. coords.push([
  34679. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  34680. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  34681. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  34682. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  34683. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  34684. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  34685. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  34686. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  34687. ]);
  34688. ps[10] = coords.length;
  34689. coords.push([
  34690. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  34691. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  34692. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  34693. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  34694. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  34695. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  34696. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  34697. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  34698. ]);
  34699. mesh.figures.push({
  34700. type: 'patch',
  34701. coords: new Int32Array(ps), // making copies of ps and cs
  34702. colors: new Int32Array(cs)
  34703. });
  34704. }
  34705. }
  34706. function decodeType7Shading(mesh, reader) {
  34707. var coords = mesh.coords;
  34708. var colors = mesh.colors;
  34709. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  34710. var cs = new Int32Array(4); // c00, c30, c03, c33
  34711. while (reader.hasData) {
  34712. var f = reader.readFlag();
  34713. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  34714. var i, ii;
  34715. var pi = coords.length;
  34716. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  34717. coords.push(reader.readCoordinate());
  34718. }
  34719. var ci = colors.length;
  34720. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  34721. colors.push(reader.readComponents());
  34722. }
  34723. var tmp1, tmp2, tmp3, tmp4;
  34724. switch (f) {
  34725. case 0:
  34726. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  34727. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  34728. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  34729. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  34730. cs[2] = ci + 1; cs[3] = ci + 2;
  34731. cs[0] = ci; cs[1] = ci + 3;
  34732. break;
  34733. case 1:
  34734. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  34735. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34736. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  34737. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  34738. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34739. tmp1 = cs[2]; tmp2 = cs[3];
  34740. cs[2] = tmp2; cs[3] = ci;
  34741. cs[0] = tmp1; cs[1] = ci + 1;
  34742. break;
  34743. case 2:
  34744. tmp1 = ps[15];
  34745. tmp2 = ps[11];
  34746. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34747. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  34748. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  34749. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34750. tmp1 = cs[3];
  34751. cs[2] = cs[1]; cs[3] = ci;
  34752. cs[0] = tmp1; cs[1] = ci + 1;
  34753. break;
  34754. case 3:
  34755. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34756. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  34757. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  34758. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34759. cs[2] = cs[0]; cs[3] = ci;
  34760. cs[0] = cs[1]; cs[1] = ci + 1;
  34761. break;
  34762. }
  34763. mesh.figures.push({
  34764. type: 'patch',
  34765. coords: new Int32Array(ps), // making copies of ps and cs
  34766. colors: new Int32Array(cs)
  34767. });
  34768. }
  34769. }
  34770. function updateBounds(mesh) {
  34771. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  34772. maxX = minX, maxY = minY;
  34773. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  34774. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  34775. minX = minX > x ? x : minX;
  34776. minY = minY > y ? y : minY;
  34777. maxX = maxX < x ? x : maxX;
  34778. maxY = maxY < y ? y : maxY;
  34779. }
  34780. mesh.bounds = [minX, minY, maxX, maxY];
  34781. }
  34782. function packData(mesh) {
  34783. var i, ii, j, jj;
  34784. var coords = mesh.coords;
  34785. var coordsPacked = new Float32Array(coords.length * 2);
  34786. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  34787. var xy = coords[i];
  34788. coordsPacked[j++] = xy[0];
  34789. coordsPacked[j++] = xy[1];
  34790. }
  34791. mesh.coords = coordsPacked;
  34792. var colors = mesh.colors;
  34793. var colorsPacked = new Uint8Array(colors.length * 3);
  34794. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  34795. var c = colors[i];
  34796. colorsPacked[j++] = c[0];
  34797. colorsPacked[j++] = c[1];
  34798. colorsPacked[j++] = c[2];
  34799. }
  34800. mesh.colors = colorsPacked;
  34801. var figures = mesh.figures;
  34802. for (i = 0, ii = figures.length; i < ii; i++) {
  34803. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  34804. for (j = 0, jj = ps.length; j < jj; j++) {
  34805. ps[j] *= 2;
  34806. cs[j] *= 3;
  34807. }
  34808. }
  34809. }
  34810. function Mesh(stream, matrix, xref, res) {
  34811. assert(isStream(stream), 'Mesh data is not a stream');
  34812. var dict = stream.dict;
  34813. this.matrix = matrix;
  34814. this.shadingType = dict.get('ShadingType');
  34815. this.type = 'Pattern';
  34816. this.bbox = dict.getArray('BBox');
  34817. var cs = dict.get('ColorSpace', 'CS');
  34818. cs = ColorSpace.parse(cs, xref, res);
  34819. this.cs = cs;
  34820. this.background = dict.has('Background') ?
  34821. cs.getRgb(dict.get('Background'), 0) : null;
  34822. var fnObj = dict.get('Function');
  34823. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  34824. this.coords = [];
  34825. this.colors = [];
  34826. this.figures = [];
  34827. var decodeContext = {
  34828. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  34829. bitsPerComponent: dict.get('BitsPerComponent'),
  34830. bitsPerFlag: dict.get('BitsPerFlag'),
  34831. decode: dict.getArray('Decode'),
  34832. colorFn: fn,
  34833. colorSpace: cs,
  34834. numComps: fn ? 1 : cs.numComps
  34835. };
  34836. var reader = new MeshStreamReader(stream, decodeContext);
  34837. var patchMesh = false;
  34838. switch (this.shadingType) {
  34839. case ShadingType.FREE_FORM_MESH:
  34840. decodeType4Shading(this, reader);
  34841. break;
  34842. case ShadingType.LATTICE_FORM_MESH:
  34843. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  34844. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  34845. decodeType5Shading(this, reader, verticesPerRow);
  34846. break;
  34847. case ShadingType.COONS_PATCH_MESH:
  34848. decodeType6Shading(this, reader);
  34849. patchMesh = true;
  34850. break;
  34851. case ShadingType.TENSOR_PATCH_MESH:
  34852. decodeType7Shading(this, reader);
  34853. patchMesh = true;
  34854. break;
  34855. default:
  34856. error('Unsupported mesh type.');
  34857. break;
  34858. }
  34859. if (patchMesh) {
  34860. // dirty bounds calculation for determining, how dense shall be triangles
  34861. updateBounds(this);
  34862. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  34863. buildFigureFromPatch(this, i);
  34864. }
  34865. }
  34866. // calculate bounds
  34867. updateBounds(this);
  34868. packData(this);
  34869. }
  34870. Mesh.prototype = {
  34871. getIR: function Mesh_getIR() {
  34872. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  34873. this.bounds, this.matrix, this.bbox, this.background];
  34874. }
  34875. };
  34876. return Mesh;
  34877. })();
  34878. Shadings.Dummy = (function DummyClosure() {
  34879. function Dummy() {
  34880. this.type = 'Pattern';
  34881. }
  34882. Dummy.prototype = {
  34883. getIR: function Dummy_getIR() {
  34884. return ['Dummy'];
  34885. }
  34886. };
  34887. return Dummy;
  34888. })();
  34889. function getTilingPatternIR(operatorList, dict, args) {
  34890. var matrix = dict.getArray('Matrix');
  34891. var bbox = dict.getArray('BBox');
  34892. var xstep = dict.get('XStep');
  34893. var ystep = dict.get('YStep');
  34894. var paintType = dict.get('PaintType');
  34895. var tilingType = dict.get('TilingType');
  34896. return [
  34897. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  34898. paintType, tilingType
  34899. ];
  34900. }
  34901. exports.Pattern = Pattern;
  34902. exports.getTilingPatternIR = getTilingPatternIR;
  34903. }));
  34904. (function (root, factory) {
  34905. {
  34906. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  34907. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  34908. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  34909. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  34910. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi,
  34911. root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts,
  34912. root.pdfjsCoreUnicode, root.pdfjsCoreGlyphList);
  34913. }
  34914. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  34915. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  34916. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi,
  34917. coreEncodings, coreStandardFonts, coreUnicode,
  34918. coreGlyphList) {
  34919. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  34920. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  34921. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  34922. var ImageKind = sharedUtil.ImageKind;
  34923. var OPS = sharedUtil.OPS;
  34924. var TextRenderingMode = sharedUtil.TextRenderingMode;
  34925. var Util = sharedUtil.Util;
  34926. var assert = sharedUtil.assert;
  34927. var createPromiseCapability = sharedUtil.createPromiseCapability;
  34928. var error = sharedUtil.error;
  34929. var info = sharedUtil.info;
  34930. var isArray = sharedUtil.isArray;
  34931. var isNum = sharedUtil.isNum;
  34932. var isString = sharedUtil.isString;
  34933. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  34934. var warn = sharedUtil.warn;
  34935. var Dict = corePrimitives.Dict;
  34936. var Name = corePrimitives.Name;
  34937. var isCmd = corePrimitives.isCmd;
  34938. var isDict = corePrimitives.isDict;
  34939. var isName = corePrimitives.isName;
  34940. var isRef = corePrimitives.isRef;
  34941. var isStream = corePrimitives.isStream;
  34942. var DecodeStream = coreStream.DecodeStream;
  34943. var JpegStream = coreStream.JpegStream;
  34944. var Stream = coreStream.Stream;
  34945. var Lexer = coreParser.Lexer;
  34946. var Parser = coreParser.Parser;
  34947. var isEOF = coreParser.isEOF;
  34948. var PDFImage = coreImage.PDFImage;
  34949. var ColorSpace = coreColorSpace.ColorSpace;
  34950. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  34951. var ErrorFont = coreFonts.ErrorFont;
  34952. var FontFlags = coreFonts.FontFlags;
  34953. var Font = coreFonts.Font;
  34954. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  34955. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  34956. var getFontType = coreFonts.getFontType;
  34957. var isPDFFunction = coreFunction.isPDFFunction;
  34958. var PDFFunction = coreFunction.PDFFunction;
  34959. var Pattern = corePattern.Pattern;
  34960. var getTilingPatternIR = corePattern.getTilingPatternIR;
  34961. var CMapFactory = coreCMap.CMapFactory;
  34962. var IdentityCMap = coreCMap.IdentityCMap;
  34963. var getMetrics = coreMetrics.getMetrics;
  34964. var bidi = coreBidi.bidi;
  34965. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  34966. var StandardEncoding = coreEncodings.StandardEncoding;
  34967. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  34968. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  34969. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  34970. var getEncoding = coreEncodings.getEncoding;
  34971. var getStdFontMap = coreStandardFonts.getStdFontMap;
  34972. var getSerifFonts = coreStandardFonts.getSerifFonts;
  34973. var getSymbolsFonts = coreStandardFonts.getSymbolsFonts;
  34974. var getNormalizedUnicodes = coreUnicode.getNormalizedUnicodes;
  34975. var reverseIfRtl = coreUnicode.reverseIfRtl;
  34976. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  34977. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  34978. var PartialEvaluator = (function PartialEvaluatorClosure() {
  34979. var DefaultPartialEvaluatorOptions = {
  34980. forceDataSchema: false,
  34981. maxImageSize: -1,
  34982. disableFontFace: false,
  34983. cMapOptions: { url: null, packed: false }
  34984. };
  34985. function NativeImageDecoder(xref, resources, handler, forceDataSchema) {
  34986. this.xref = xref;
  34987. this.resources = resources;
  34988. this.handler = handler;
  34989. this.forceDataSchema = forceDataSchema;
  34990. }
  34991. NativeImageDecoder.prototype = {
  34992. canDecode: function (image) {
  34993. return image instanceof JpegStream &&
  34994. NativeImageDecoder.isDecodable(image, this.xref, this.resources);
  34995. },
  34996. decode: function (image) {
  34997. // For natively supported JPEGs send them to the main thread for decoding.
  34998. var dict = image.dict;
  34999. var colorSpace = dict.get('ColorSpace', 'CS');
  35000. colorSpace = ColorSpace.parse(colorSpace, this.xref, this.resources);
  35001. var numComps = colorSpace.numComps;
  35002. var decodePromise = this.handler.sendWithPromise('JpegDecode',
  35003. [image.getIR(this.forceDataSchema), numComps]);
  35004. return decodePromise.then(function (message) {
  35005. var data = message.data;
  35006. return new Stream(data, 0, data.length, image.dict);
  35007. });
  35008. }
  35009. };
  35010. /**
  35011. * Checks if the image can be decoded and displayed by the browser without any
  35012. * further processing such as color space conversions.
  35013. */
  35014. NativeImageDecoder.isSupported =
  35015. function NativeImageDecoder_isSupported(image, xref, res) {
  35016. var dict = image.dict;
  35017. if (dict.has('DecodeParms') || dict.has('DP')) {
  35018. return false;
  35019. }
  35020. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  35021. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  35022. cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  35023. };
  35024. /**
  35025. * Checks if the image can be decoded by the browser.
  35026. */
  35027. NativeImageDecoder.isDecodable =
  35028. function NativeImageDecoder_isDecodable(image, xref, res) {
  35029. var dict = image.dict;
  35030. if (dict.has('DecodeParms') || dict.has('DP')) {
  35031. return false;
  35032. }
  35033. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  35034. return (cs.numComps === 1 || cs.numComps === 3) &&
  35035. cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  35036. };
  35037. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  35038. uniquePrefix, idCounters, fontCache, options) {
  35039. this.pdfManager = pdfManager;
  35040. this.xref = xref;
  35041. this.handler = handler;
  35042. this.pageIndex = pageIndex;
  35043. this.uniquePrefix = uniquePrefix;
  35044. this.idCounters = idCounters;
  35045. this.fontCache = fontCache;
  35046. this.options = options || DefaultPartialEvaluatorOptions;
  35047. }
  35048. // Trying to minimize Date.now() usage and check every 100 time
  35049. var TIME_SLOT_DURATION_MS = 20;
  35050. var CHECK_TIME_EVERY = 100;
  35051. function TimeSlotManager() {
  35052. this.reset();
  35053. }
  35054. TimeSlotManager.prototype = {
  35055. check: function TimeSlotManager_check() {
  35056. if (++this.checked < CHECK_TIME_EVERY) {
  35057. return false;
  35058. }
  35059. this.checked = 0;
  35060. return this.endTime <= Date.now();
  35061. },
  35062. reset: function TimeSlotManager_reset() {
  35063. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  35064. this.checked = 0;
  35065. }
  35066. };
  35067. var deferred = Promise.resolve();
  35068. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  35069. PartialEvaluator.prototype = {
  35070. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  35071. if (!isDict(resources)) {
  35072. return false;
  35073. }
  35074. var processed = Object.create(null);
  35075. if (resources.objId) {
  35076. processed[resources.objId] = true;
  35077. }
  35078. var nodes = [resources], xref = this.xref;
  35079. while (nodes.length) {
  35080. var key, i, ii;
  35081. var node = nodes.shift();
  35082. // First check the current resources for blend modes.
  35083. var graphicStates = node.get('ExtGState');
  35084. if (isDict(graphicStates)) {
  35085. var graphicStatesKeys = graphicStates.getKeys();
  35086. for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
  35087. key = graphicStatesKeys[i];
  35088. var graphicState = graphicStates.get(key);
  35089. var bm = graphicState.get('BM');
  35090. if (isName(bm) && bm.name !== 'Normal') {
  35091. return true;
  35092. }
  35093. }
  35094. }
  35095. // Descend into the XObjects to look for more resources and blend modes.
  35096. var xObjects = node.get('XObject');
  35097. if (!isDict(xObjects)) {
  35098. continue;
  35099. }
  35100. var xObjectsKeys = xObjects.getKeys();
  35101. for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
  35102. key = xObjectsKeys[i];
  35103. var xObject = xObjects.getRaw(key);
  35104. if (isRef(xObject)) {
  35105. if (processed[xObject.toString()]) {
  35106. // The XObject has already been processed, and by avoiding a
  35107. // redundant `xref.fetch` we can *significantly* reduce the load
  35108. // time for badly generated PDF files (fixes issue6961.pdf).
  35109. continue;
  35110. }
  35111. xObject = xref.fetch(xObject);
  35112. }
  35113. if (!isStream(xObject)) {
  35114. continue;
  35115. }
  35116. if (xObject.dict.objId) {
  35117. if (processed[xObject.dict.objId]) {
  35118. // stream has objId and is processed already
  35119. continue;
  35120. }
  35121. processed[xObject.dict.objId] = true;
  35122. }
  35123. var xResources = xObject.dict.get('Resources');
  35124. // Checking objId to detect an infinite loop.
  35125. if (isDict(xResources) &&
  35126. (!xResources.objId || !processed[xResources.objId])) {
  35127. nodes.push(xResources);
  35128. if (xResources.objId) {
  35129. processed[xResources.objId] = true;
  35130. }
  35131. }
  35132. }
  35133. }
  35134. return false;
  35135. },
  35136. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  35137. xobj, smask,
  35138. operatorList,
  35139. task,
  35140. initialState) {
  35141. var matrix = xobj.dict.getArray('Matrix');
  35142. var bbox = xobj.dict.getArray('BBox');
  35143. var group = xobj.dict.get('Group');
  35144. if (group) {
  35145. var groupOptions = {
  35146. matrix: matrix,
  35147. bbox: bbox,
  35148. smask: smask,
  35149. isolated: false,
  35150. knockout: false
  35151. };
  35152. var groupSubtype = group.get('S');
  35153. var colorSpace;
  35154. if (isName(groupSubtype, 'Transparency')) {
  35155. groupOptions.isolated = (group.get('I') || false);
  35156. groupOptions.knockout = (group.get('K') || false);
  35157. colorSpace = (group.has('CS') ?
  35158. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  35159. }
  35160. if (smask && smask.backdrop) {
  35161. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  35162. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  35163. }
  35164. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  35165. }
  35166. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  35167. return this.getOperatorList(xobj, task,
  35168. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  35169. then(function () {
  35170. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  35171. if (group) {
  35172. operatorList.addOp(OPS.endGroup, [groupOptions]);
  35173. }
  35174. });
  35175. },
  35176. buildPaintImageXObject:
  35177. function PartialEvaluator_buildPaintImageXObject(resources, image,
  35178. inline, operatorList,
  35179. cacheKey, imageCache) {
  35180. var self = this;
  35181. var dict = image.dict;
  35182. var w = dict.get('Width', 'W');
  35183. var h = dict.get('Height', 'H');
  35184. if (!(w && isNum(w)) || !(h && isNum(h))) {
  35185. warn('Image dimensions are missing, or not numbers.');
  35186. return;
  35187. }
  35188. var maxImageSize = this.options.maxImageSize;
  35189. if (maxImageSize !== -1 && w * h > maxImageSize) {
  35190. warn('Image exceeded maximum allowed size and was removed.');
  35191. return;
  35192. }
  35193. var imageMask = (dict.get('ImageMask', 'IM') || false);
  35194. var imgData, args;
  35195. if (imageMask) {
  35196. // This depends on a tmpCanvas being filled with the
  35197. // current fillStyle, such that processing the pixel
  35198. // data can't be done here. Instead of creating a
  35199. // complete PDFImage, only read the information needed
  35200. // for later.
  35201. var width = dict.get('Width', 'W');
  35202. var height = dict.get('Height', 'H');
  35203. var bitStrideLength = (width + 7) >> 3;
  35204. var imgArray = image.getBytes(bitStrideLength * height);
  35205. var decode = dict.getArray('Decode', 'D');
  35206. var inverseDecode = (!!decode && decode[0] > 0);
  35207. imgData = PDFImage.createMask(imgArray, width, height,
  35208. image instanceof DecodeStream,
  35209. inverseDecode);
  35210. imgData.cached = true;
  35211. args = [imgData];
  35212. operatorList.addOp(OPS.paintImageMaskXObject, args);
  35213. if (cacheKey) {
  35214. imageCache[cacheKey] = {
  35215. fn: OPS.paintImageMaskXObject,
  35216. args: args
  35217. };
  35218. }
  35219. return;
  35220. }
  35221. var softMask = (dict.get('SMask', 'SM') || false);
  35222. var mask = (dict.get('Mask') || false);
  35223. var SMALL_IMAGE_DIMENSIONS = 200;
  35224. // Inlining small images into the queue as RGB data
  35225. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  35226. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  35227. var imageObj = new PDFImage(this.xref, resources, image,
  35228. inline, null, null);
  35229. // We force the use of RGBA_32BPP images here, because we can't handle
  35230. // any other kind.
  35231. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  35232. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  35233. return;
  35234. }
  35235. // If there is no imageMask, create the PDFImage and a lot
  35236. // of image processing can be done here.
  35237. var uniquePrefix = (this.uniquePrefix || '');
  35238. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  35239. operatorList.addDependency(objId);
  35240. args = [objId, w, h];
  35241. if (!softMask && !mask && image instanceof JpegStream &&
  35242. NativeImageDecoder.isSupported(image, this.xref, resources)) {
  35243. // These JPEGs don't need any more processing so we can just send it.
  35244. operatorList.addOp(OPS.paintJpegXObject, args);
  35245. this.handler.send('obj',
  35246. [objId, this.pageIndex, 'JpegStream',
  35247. image.getIR(this.options.forceDataSchema)]);
  35248. return;
  35249. }
  35250. // Creates native image decoder only if a JPEG image or mask is present.
  35251. var nativeImageDecoder = null;
  35252. if (image instanceof JpegStream || mask instanceof JpegStream ||
  35253. softMask instanceof JpegStream) {
  35254. nativeImageDecoder = new NativeImageDecoder(self.xref, resources,
  35255. self.handler, self.options.forceDataSchema);
  35256. }
  35257. PDFImage.buildImage(self.handler, self.xref, resources, image, inline,
  35258. nativeImageDecoder).
  35259. then(function(imageObj) {
  35260. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  35261. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  35262. [imgData.data.buffer]);
  35263. }).then(undefined, function (reason) {
  35264. warn('Unable to decode image: ' + reason);
  35265. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  35266. });
  35267. operatorList.addOp(OPS.paintImageXObject, args);
  35268. if (cacheKey) {
  35269. imageCache[cacheKey] = {
  35270. fn: OPS.paintImageXObject,
  35271. args: args
  35272. };
  35273. }
  35274. },
  35275. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  35276. operatorList, task,
  35277. stateManager) {
  35278. var smaskContent = smask.get('G');
  35279. var smaskOptions = {
  35280. subtype: smask.get('S').name,
  35281. backdrop: smask.get('BC')
  35282. };
  35283. // The SMask might have a alpha/luminosity value transfer function --
  35284. // we will build a map of integer values in range 0..255 to be fast.
  35285. var transferObj = smask.get('TR');
  35286. if (isPDFFunction(transferObj)) {
  35287. var transferFn = PDFFunction.parse(this.xref, transferObj);
  35288. var transferMap = new Uint8Array(256);
  35289. var tmp = new Float32Array(1);
  35290. for (var i = 0; i < 256; i++) {
  35291. tmp[0] = i / 255;
  35292. transferFn(tmp, 0, tmp, 0);
  35293. transferMap[i] = (tmp[0] * 255) | 0;
  35294. }
  35295. smaskOptions.transferMap = transferMap;
  35296. }
  35297. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  35298. operatorList, task, stateManager.state.clone());
  35299. },
  35300. handleTilingType:
  35301. function PartialEvaluator_handleTilingType(fn, args, resources,
  35302. pattern, patternDict,
  35303. operatorList, task) {
  35304. // Create an IR of the pattern code.
  35305. var tilingOpList = new OperatorList();
  35306. // Merge the available resources, to prevent issues when the patternDict
  35307. // is missing some /Resources entries (fixes issue6541.pdf).
  35308. var resourcesArray = [patternDict.get('Resources'), resources];
  35309. var patternResources = Dict.merge(this.xref, resourcesArray);
  35310. return this.getOperatorList(pattern, task, patternResources,
  35311. tilingOpList).then(function () {
  35312. // Add the dependencies to the parent operator list so they are
  35313. // resolved before sub operator list is executed synchronously.
  35314. operatorList.addDependencies(tilingOpList.dependencies);
  35315. operatorList.addOp(fn, getTilingPatternIR({
  35316. fnArray: tilingOpList.fnArray,
  35317. argsArray: tilingOpList.argsArray
  35318. }, patternDict, args));
  35319. });
  35320. },
  35321. handleSetFont:
  35322. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  35323. operatorList, task, state) {
  35324. // TODO(mack): Not needed?
  35325. var fontName;
  35326. if (fontArgs) {
  35327. fontArgs = fontArgs.slice();
  35328. fontName = fontArgs[0].name;
  35329. }
  35330. var self = this;
  35331. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  35332. function (translated) {
  35333. if (!translated.font.isType3Font) {
  35334. return translated;
  35335. }
  35336. return translated.loadType3Data(self, resources, operatorList, task).
  35337. then(function () {
  35338. return translated;
  35339. }, function (reason) {
  35340. // Error in the font data -- sending unsupported feature notification.
  35341. self.handler.send('UnsupportedFeature',
  35342. {featureId: UNSUPPORTED_FEATURES.font});
  35343. return new TranslatedFont('g_font_error',
  35344. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  35345. });
  35346. }).then(function (translated) {
  35347. state.font = translated.font;
  35348. translated.send(self.handler);
  35349. return translated.loadedName;
  35350. });
  35351. },
  35352. handleText: function PartialEvaluator_handleText(chars, state) {
  35353. var font = state.font;
  35354. var glyphs = font.charsToGlyphs(chars);
  35355. var isAddToPathSet = !!(state.textRenderingMode &
  35356. TextRenderingMode.ADD_TO_PATH_FLAG);
  35357. if (font.data && (isAddToPathSet || this.options.disableFontFace)) {
  35358. var buildPath = function (fontChar) {
  35359. if (!font.renderer.hasBuiltPath(fontChar)) {
  35360. var path = font.renderer.getPathJs(fontChar);
  35361. this.handler.send('commonobj', [
  35362. font.loadedName + '_path_' + fontChar,
  35363. 'FontPath',
  35364. path
  35365. ]);
  35366. }
  35367. }.bind(this);
  35368. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  35369. var glyph = glyphs[i];
  35370. buildPath(glyph.fontChar);
  35371. // If the glyph has an accent we need to build a path for its
  35372. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  35373. var accent = glyph.accent;
  35374. if (accent && accent.fontChar) {
  35375. buildPath(accent.fontChar);
  35376. }
  35377. }
  35378. }
  35379. return glyphs;
  35380. },
  35381. setGState: function PartialEvaluator_setGState(resources, gState,
  35382. operatorList, task,
  35383. xref, stateManager) {
  35384. // This array holds the converted/processed state data.
  35385. var gStateObj = [];
  35386. var gStateKeys = gState.getKeys();
  35387. var self = this;
  35388. var promise = Promise.resolve();
  35389. for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
  35390. var key = gStateKeys[i];
  35391. var value = gState.get(key);
  35392. switch (key) {
  35393. case 'Type':
  35394. break;
  35395. case 'LW':
  35396. case 'LC':
  35397. case 'LJ':
  35398. case 'ML':
  35399. case 'D':
  35400. case 'RI':
  35401. case 'FL':
  35402. case 'CA':
  35403. case 'ca':
  35404. gStateObj.push([key, value]);
  35405. break;
  35406. case 'Font':
  35407. promise = promise.then(function () {
  35408. return self.handleSetFont(resources, null, value[0], operatorList,
  35409. task, stateManager.state).
  35410. then(function (loadedName) {
  35411. operatorList.addDependency(loadedName);
  35412. gStateObj.push([key, [loadedName, value[1]]]);
  35413. });
  35414. });
  35415. break;
  35416. case 'BM':
  35417. gStateObj.push([key, value]);
  35418. break;
  35419. case 'SMask':
  35420. if (isName(value, 'None')) {
  35421. gStateObj.push([key, false]);
  35422. break;
  35423. }
  35424. if (isDict(value)) {
  35425. promise = promise.then(function (dict) {
  35426. return self.handleSMask(dict, resources, operatorList,
  35427. task, stateManager);
  35428. }.bind(this, value));
  35429. gStateObj.push([key, true]);
  35430. } else {
  35431. warn('Unsupported SMask type');
  35432. }
  35433. break;
  35434. // Only generate info log messages for the following since
  35435. // they are unlikely to have a big impact on the rendering.
  35436. case 'OP':
  35437. case 'op':
  35438. case 'OPM':
  35439. case 'BG':
  35440. case 'BG2':
  35441. case 'UCR':
  35442. case 'UCR2':
  35443. case 'TR':
  35444. case 'TR2':
  35445. case 'HT':
  35446. case 'SM':
  35447. case 'SA':
  35448. case 'AIS':
  35449. case 'TK':
  35450. // TODO implement these operators.
  35451. info('graphic state operator ' + key);
  35452. break;
  35453. default:
  35454. info('Unknown graphic state operator ' + key);
  35455. break;
  35456. }
  35457. }
  35458. return promise.then(function () {
  35459. if (gStateObj.length > 0) {
  35460. operatorList.addOp(OPS.setGState, [gStateObj]);
  35461. }
  35462. });
  35463. },
  35464. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  35465. resources) {
  35466. function errorFont() {
  35467. return Promise.resolve(new TranslatedFont('g_font_error',
  35468. new ErrorFont('Font ' + fontName + ' is not available'), font));
  35469. }
  35470. var fontRef;
  35471. if (font) { // Loading by ref.
  35472. assert(isRef(font));
  35473. fontRef = font;
  35474. } else { // Loading by name.
  35475. var fontRes = resources.get('Font');
  35476. if (fontRes) {
  35477. fontRef = fontRes.getRaw(fontName);
  35478. } else {
  35479. warn('fontRes not available');
  35480. return errorFont();
  35481. }
  35482. }
  35483. if (!fontRef) {
  35484. warn('fontRef not available');
  35485. return errorFont();
  35486. }
  35487. if (this.fontCache.has(fontRef)) {
  35488. return this.fontCache.get(fontRef);
  35489. }
  35490. font = xref.fetchIfRef(fontRef);
  35491. if (!isDict(font)) {
  35492. return errorFont();
  35493. }
  35494. // We are holding `font.translated` references just for `fontRef`s that
  35495. // are not actually `Ref`s, but rather `Dict`s. See explanation below.
  35496. if (font.translated) {
  35497. return font.translated;
  35498. }
  35499. var fontCapability = createPromiseCapability();
  35500. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  35501. var descriptor = preEvaluatedFont.descriptor;
  35502. var fontRefIsRef = isRef(fontRef), fontID;
  35503. if (fontRefIsRef) {
  35504. fontID = fontRef.toString();
  35505. }
  35506. if (isDict(descriptor)) {
  35507. if (!descriptor.fontAliases) {
  35508. descriptor.fontAliases = Object.create(null);
  35509. }
  35510. var fontAliases = descriptor.fontAliases;
  35511. var hash = preEvaluatedFont.hash;
  35512. if (fontAliases[hash]) {
  35513. var aliasFontRef = fontAliases[hash].aliasRef;
  35514. if (fontRefIsRef && aliasFontRef &&
  35515. this.fontCache.has(aliasFontRef)) {
  35516. this.fontCache.putAlias(fontRef, aliasFontRef);
  35517. return this.fontCache.get(fontRef);
  35518. }
  35519. } else {
  35520. fontAliases[hash] = {
  35521. fontID: Font.getFontID()
  35522. };
  35523. }
  35524. if (fontRefIsRef) {
  35525. fontAliases[hash].aliasRef = fontRef;
  35526. }
  35527. fontID = fontAliases[hash].fontID;
  35528. }
  35529. // Workaround for bad PDF generators that reference fonts incorrectly,
  35530. // where `fontRef` is a `Dict` rather than a `Ref` (fixes bug946506.pdf).
  35531. // In this case we should not put the font into `this.fontCache` (which is
  35532. // a `RefSetCache`), since it's not meaningful to use a `Dict` as a key.
  35533. //
  35534. // However, if we don't cache the font it's not possible to remove it
  35535. // when `cleanup` is triggered from the API, which causes issues on
  35536. // subsequent rendering operations (see issue7403.pdf).
  35537. // A simple workaround would be to just not hold `font.translated`
  35538. // references in this case, but this would force us to unnecessarily load
  35539. // the same fonts over and over.
  35540. //
  35541. // Instead, we cheat a bit by attempting to use a modified `fontID` as a
  35542. // key in `this.fontCache`, to allow the font to be cached.
  35543. // NOTE: This works because `RefSetCache` calls `toString()` on provided
  35544. // keys. Also, since `fontRef` is used when getting cached fonts,
  35545. // we'll not accidentally match fonts cached with the `fontID`.
  35546. if (fontRefIsRef) {
  35547. this.fontCache.put(fontRef, fontCapability.promise);
  35548. } else {
  35549. if (!fontID) {
  35550. fontID = (this.uniquePrefix || 'F_') + (++this.idCounters.obj);
  35551. }
  35552. this.fontCache.put('id_' + fontID, fontCapability.promise);
  35553. }
  35554. assert(fontID, 'The "fontID" must be defined.');
  35555. // Keep track of each font we translated so the caller can
  35556. // load them asynchronously before calling display on a page.
  35557. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + fontID;
  35558. font.translated = fontCapability.promise;
  35559. // TODO move promises into translate font
  35560. var translatedPromise;
  35561. try {
  35562. translatedPromise = this.translateFont(preEvaluatedFont, xref);
  35563. } catch (e) {
  35564. translatedPromise = Promise.reject(e);
  35565. }
  35566. var self = this;
  35567. translatedPromise.then(function (translatedFont) {
  35568. if (translatedFont.fontType !== undefined) {
  35569. var xrefFontStats = xref.stats.fontTypes;
  35570. xrefFontStats[translatedFont.fontType] = true;
  35571. }
  35572. fontCapability.resolve(new TranslatedFont(font.loadedName,
  35573. translatedFont, font));
  35574. }, function (reason) {
  35575. // TODO fontCapability.reject?
  35576. // Error in the font data -- sending unsupported feature notification.
  35577. self.handler.send('UnsupportedFeature',
  35578. {featureId: UNSUPPORTED_FEATURES.font});
  35579. try {
  35580. // error, but it's still nice to have font type reported
  35581. var descriptor = preEvaluatedFont.descriptor;
  35582. var fontFile3 = descriptor && descriptor.get('FontFile3');
  35583. var subtype = fontFile3 && fontFile3.get('Subtype');
  35584. var fontType = getFontType(preEvaluatedFont.type,
  35585. subtype && subtype.name);
  35586. var xrefFontStats = xref.stats.fontTypes;
  35587. xrefFontStats[fontType] = true;
  35588. } catch (ex) { }
  35589. fontCapability.resolve(new TranslatedFont(font.loadedName,
  35590. new ErrorFont(reason instanceof Error ? reason.message : reason),
  35591. font));
  35592. });
  35593. return fontCapability.promise;
  35594. },
  35595. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  35596. var lastIndex = operatorList.length - 1;
  35597. if (!args) {
  35598. args = [];
  35599. }
  35600. if (lastIndex < 0 ||
  35601. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  35602. operatorList.addOp(OPS.constructPath, [[fn], args]);
  35603. } else {
  35604. var opArgs = operatorList.argsArray[lastIndex];
  35605. opArgs[0].push(fn);
  35606. Array.prototype.push.apply(opArgs[1], args);
  35607. }
  35608. },
  35609. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  35610. cs, patterns, resources, task, xref) {
  35611. // compile tiling patterns
  35612. var patternName = args[args.length - 1];
  35613. // SCN/scn applies patterns along with normal colors
  35614. var pattern;
  35615. if (isName(patternName) &&
  35616. (pattern = patterns.get(patternName.name))) {
  35617. var dict = (isStream(pattern) ? pattern.dict : pattern);
  35618. var typeNum = dict.get('PatternType');
  35619. if (typeNum === TILING_PATTERN) {
  35620. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  35621. return this.handleTilingType(fn, color, resources, pattern,
  35622. dict, operatorList, task);
  35623. } else if (typeNum === SHADING_PATTERN) {
  35624. var shading = dict.get('Shading');
  35625. var matrix = dict.getArray('Matrix');
  35626. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  35627. this.handler);
  35628. operatorList.addOp(fn, pattern.getIR());
  35629. return Promise.resolve();
  35630. } else {
  35631. return Promise.reject('Unknown PatternType: ' + typeNum);
  35632. }
  35633. }
  35634. // TODO shall we fail here?
  35635. operatorList.addOp(fn, args);
  35636. return Promise.resolve();
  35637. },
  35638. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  35639. task,
  35640. resources,
  35641. operatorList,
  35642. initialState) {
  35643. var self = this;
  35644. var xref = this.xref;
  35645. var imageCache = Object.create(null);
  35646. assert(operatorList);
  35647. resources = (resources || Dict.empty);
  35648. var xobjs = (resources.get('XObject') || Dict.empty);
  35649. var patterns = (resources.get('Pattern') || Dict.empty);
  35650. var stateManager = new StateManager(initialState || new EvalState());
  35651. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  35652. var timeSlotManager = new TimeSlotManager();
  35653. return new Promise(function promiseBody(resolve, reject) {
  35654. var next = function (promise) {
  35655. promise.then(function () {
  35656. try {
  35657. promiseBody(resolve, reject);
  35658. } catch (ex) {
  35659. reject(ex);
  35660. }
  35661. }, reject);
  35662. };
  35663. task.ensureNotTerminated();
  35664. timeSlotManager.reset();
  35665. var stop, operation = {}, i, ii, cs;
  35666. while (!(stop = timeSlotManager.check())) {
  35667. // The arguments parsed by read() are used beyond this loop, so we
  35668. // cannot reuse the same array on each iteration. Therefore we pass
  35669. // in |null| as the initial value (see the comment on
  35670. // EvaluatorPreprocessor_read() for why).
  35671. operation.args = null;
  35672. if (!(preprocessor.read(operation))) {
  35673. break;
  35674. }
  35675. var args = operation.args;
  35676. var fn = operation.fn;
  35677. switch (fn | 0) {
  35678. case OPS.paintXObject:
  35679. if (args[0].code) {
  35680. break;
  35681. }
  35682. // eagerly compile XForm objects
  35683. var name = args[0].name;
  35684. if (!name) {
  35685. warn('XObject must be referred to by name.');
  35686. continue;
  35687. }
  35688. if (imageCache[name] !== undefined) {
  35689. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  35690. args = null;
  35691. continue;
  35692. }
  35693. var xobj = xobjs.get(name);
  35694. if (xobj) {
  35695. assert(isStream(xobj), 'XObject should be a stream');
  35696. var type = xobj.dict.get('Subtype');
  35697. assert(isName(type), 'XObject should have a Name subtype');
  35698. if (type.name === 'Form') {
  35699. stateManager.save();
  35700. next(self.buildFormXObject(resources, xobj, null,
  35701. operatorList, task,
  35702. stateManager.state.clone()).
  35703. then(function () {
  35704. stateManager.restore();
  35705. }));
  35706. return;
  35707. } else if (type.name === 'Image') {
  35708. self.buildPaintImageXObject(resources, xobj, false,
  35709. operatorList, name, imageCache);
  35710. args = null;
  35711. continue;
  35712. } else if (type.name === 'PS') {
  35713. // PostScript XObjects are unused when viewing documents.
  35714. // See section 4.7.1 of Adobe's PDF reference.
  35715. info('Ignored XObject subtype PS');
  35716. continue;
  35717. } else {
  35718. error('Unhandled XObject subtype ' + type.name);
  35719. }
  35720. }
  35721. break;
  35722. case OPS.setFont:
  35723. var fontSize = args[1];
  35724. // eagerly collect all fonts
  35725. next(self.handleSetFont(resources, args, null, operatorList,
  35726. task, stateManager.state).
  35727. then(function (loadedName) {
  35728. operatorList.addDependency(loadedName);
  35729. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  35730. }));
  35731. return;
  35732. case OPS.endInlineImage:
  35733. var cacheKey = args[0].cacheKey;
  35734. if (cacheKey) {
  35735. var cacheEntry = imageCache[cacheKey];
  35736. if (cacheEntry !== undefined) {
  35737. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  35738. args = null;
  35739. continue;
  35740. }
  35741. }
  35742. self.buildPaintImageXObject(resources, args[0], true,
  35743. operatorList, cacheKey, imageCache);
  35744. args = null;
  35745. continue;
  35746. case OPS.showText:
  35747. args[0] = self.handleText(args[0], stateManager.state);
  35748. break;
  35749. case OPS.showSpacedText:
  35750. var arr = args[0];
  35751. var combinedGlyphs = [];
  35752. var arrLength = arr.length;
  35753. var state = stateManager.state;
  35754. for (i = 0; i < arrLength; ++i) {
  35755. var arrItem = arr[i];
  35756. if (isString(arrItem)) {
  35757. Array.prototype.push.apply(combinedGlyphs,
  35758. self.handleText(arrItem, state));
  35759. } else if (isNum(arrItem)) {
  35760. combinedGlyphs.push(arrItem);
  35761. }
  35762. }
  35763. args[0] = combinedGlyphs;
  35764. fn = OPS.showText;
  35765. break;
  35766. case OPS.nextLineShowText:
  35767. operatorList.addOp(OPS.nextLine);
  35768. args[0] = self.handleText(args[0], stateManager.state);
  35769. fn = OPS.showText;
  35770. break;
  35771. case OPS.nextLineSetSpacingShowText:
  35772. operatorList.addOp(OPS.nextLine);
  35773. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  35774. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  35775. args[0] = self.handleText(args[0], stateManager.state);
  35776. fn = OPS.showText;
  35777. break;
  35778. case OPS.setTextRenderingMode:
  35779. stateManager.state.textRenderingMode = args[0];
  35780. break;
  35781. case OPS.setFillColorSpace:
  35782. stateManager.state.fillColorSpace =
  35783. ColorSpace.parse(args[0], xref, resources);
  35784. continue;
  35785. case OPS.setStrokeColorSpace:
  35786. stateManager.state.strokeColorSpace =
  35787. ColorSpace.parse(args[0], xref, resources);
  35788. continue;
  35789. case OPS.setFillColor:
  35790. cs = stateManager.state.fillColorSpace;
  35791. args = cs.getRgb(args, 0);
  35792. fn = OPS.setFillRGBColor;
  35793. break;
  35794. case OPS.setStrokeColor:
  35795. cs = stateManager.state.strokeColorSpace;
  35796. args = cs.getRgb(args, 0);
  35797. fn = OPS.setStrokeRGBColor;
  35798. break;
  35799. case OPS.setFillGray:
  35800. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  35801. args = ColorSpace.singletons.gray.getRgb(args, 0);
  35802. fn = OPS.setFillRGBColor;
  35803. break;
  35804. case OPS.setStrokeGray:
  35805. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  35806. args = ColorSpace.singletons.gray.getRgb(args, 0);
  35807. fn = OPS.setStrokeRGBColor;
  35808. break;
  35809. case OPS.setFillCMYKColor:
  35810. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  35811. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  35812. fn = OPS.setFillRGBColor;
  35813. break;
  35814. case OPS.setStrokeCMYKColor:
  35815. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  35816. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  35817. fn = OPS.setStrokeRGBColor;
  35818. break;
  35819. case OPS.setFillRGBColor:
  35820. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  35821. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  35822. break;
  35823. case OPS.setStrokeRGBColor:
  35824. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  35825. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  35826. break;
  35827. case OPS.setFillColorN:
  35828. cs = stateManager.state.fillColorSpace;
  35829. if (cs.name === 'Pattern') {
  35830. next(self.handleColorN(operatorList, OPS.setFillColorN, args,
  35831. cs, patterns, resources, task, xref));
  35832. return;
  35833. }
  35834. args = cs.getRgb(args, 0);
  35835. fn = OPS.setFillRGBColor;
  35836. break;
  35837. case OPS.setStrokeColorN:
  35838. cs = stateManager.state.strokeColorSpace;
  35839. if (cs.name === 'Pattern') {
  35840. next(self.handleColorN(operatorList, OPS.setStrokeColorN, args,
  35841. cs, patterns, resources, task, xref));
  35842. return;
  35843. }
  35844. args = cs.getRgb(args, 0);
  35845. fn = OPS.setStrokeRGBColor;
  35846. break;
  35847. case OPS.shadingFill:
  35848. var shadingRes = resources.get('Shading');
  35849. if (!shadingRes) {
  35850. error('No shading resource found');
  35851. }
  35852. var shading = shadingRes.get(args[0].name);
  35853. if (!shading) {
  35854. error('No shading object found');
  35855. }
  35856. var shadingFill = Pattern.parseShading(shading, null, xref,
  35857. resources, self.handler);
  35858. var patternIR = shadingFill.getIR();
  35859. args = [patternIR];
  35860. fn = OPS.shadingFill;
  35861. break;
  35862. case OPS.setGState:
  35863. var dictName = args[0];
  35864. var extGState = resources.get('ExtGState');
  35865. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  35866. break;
  35867. }
  35868. var gState = extGState.get(dictName.name);
  35869. next(self.setGState(resources, gState, operatorList, task, xref,
  35870. stateManager));
  35871. return;
  35872. case OPS.moveTo:
  35873. case OPS.lineTo:
  35874. case OPS.curveTo:
  35875. case OPS.curveTo2:
  35876. case OPS.curveTo3:
  35877. case OPS.closePath:
  35878. self.buildPath(operatorList, fn, args);
  35879. continue;
  35880. case OPS.rectangle:
  35881. self.buildPath(operatorList, fn, args);
  35882. continue;
  35883. case OPS.markPoint:
  35884. case OPS.markPointProps:
  35885. case OPS.beginMarkedContent:
  35886. case OPS.beginMarkedContentProps:
  35887. case OPS.endMarkedContent:
  35888. case OPS.beginCompat:
  35889. case OPS.endCompat:
  35890. // Ignore operators where the corresponding handlers are known to
  35891. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  35892. // serialization errors and is also a bit more efficient.
  35893. // We could also try to serialize all objects in a general way,
  35894. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  35895. // but doing so is meaningless without knowing the semantics.
  35896. continue;
  35897. default:
  35898. // Note: Ignore the operator if it has `Dict` arguments, since
  35899. // those are non-serializable, otherwise postMessage will throw
  35900. // "An object could not be cloned.".
  35901. if (args !== null) {
  35902. for (i = 0, ii = args.length; i < ii; i++) {
  35903. if (args[i] instanceof Dict) {
  35904. break;
  35905. }
  35906. }
  35907. if (i < ii) {
  35908. warn('getOperatorList - ignoring operator: ' + fn);
  35909. continue;
  35910. }
  35911. }
  35912. }
  35913. operatorList.addOp(fn, args);
  35914. }
  35915. if (stop) {
  35916. next(deferred);
  35917. return;
  35918. }
  35919. // Some PDFs don't close all restores inside object/form.
  35920. // Closing those for them.
  35921. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  35922. operatorList.addOp(OPS.restore, []);
  35923. }
  35924. resolve();
  35925. });
  35926. },
  35927. getTextContent:
  35928. function PartialEvaluator_getTextContent(stream, task, resources,
  35929. stateManager,
  35930. normalizeWhitespace,
  35931. combineTextItems) {
  35932. stateManager = (stateManager || new StateManager(new TextState()));
  35933. var WhitespaceRegexp = /\s/g;
  35934. var textContent = {
  35935. items: [],
  35936. styles: Object.create(null)
  35937. };
  35938. var textContentItem = {
  35939. initialized: false,
  35940. str: [],
  35941. width: 0,
  35942. height: 0,
  35943. vertical: false,
  35944. lastAdvanceWidth: 0,
  35945. lastAdvanceHeight: 0,
  35946. textAdvanceScale: 0,
  35947. spaceWidth: 0,
  35948. fakeSpaceMin: Infinity,
  35949. fakeMultiSpaceMin: Infinity,
  35950. fakeMultiSpaceMax: -0,
  35951. textRunBreakAllowed: false,
  35952. transform: null,
  35953. fontName: null
  35954. };
  35955. var SPACE_FACTOR = 0.3;
  35956. var MULTI_SPACE_FACTOR = 1.5;
  35957. var MULTI_SPACE_FACTOR_MAX = 4;
  35958. var self = this;
  35959. var xref = this.xref;
  35960. resources = (xref.fetchIfRef(resources) || Dict.empty);
  35961. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  35962. var xobjs = null;
  35963. var xobjsCache = Object.create(null);
  35964. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  35965. var textState;
  35966. function ensureTextContentItem() {
  35967. if (textContentItem.initialized) {
  35968. return textContentItem;
  35969. }
  35970. var font = textState.font;
  35971. if (!(font.loadedName in textContent.styles)) {
  35972. textContent.styles[font.loadedName] = {
  35973. fontFamily: font.fallbackName,
  35974. ascent: font.ascent,
  35975. descent: font.descent,
  35976. vertical: font.vertical
  35977. };
  35978. }
  35979. textContentItem.fontName = font.loadedName;
  35980. // 9.4.4 Text Space Details
  35981. var tsm = [textState.fontSize * textState.textHScale, 0,
  35982. 0, textState.fontSize,
  35983. 0, textState.textRise];
  35984. if (font.isType3Font &&
  35985. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  35986. textState.fontSize === 1) {
  35987. var glyphHeight = font.bbox[3] - font.bbox[1];
  35988. if (glyphHeight > 0) {
  35989. glyphHeight = glyphHeight * textState.fontMatrix[3];
  35990. tsm[3] *= glyphHeight;
  35991. }
  35992. }
  35993. var trm = Util.transform(textState.ctm,
  35994. Util.transform(textState.textMatrix, tsm));
  35995. textContentItem.transform = trm;
  35996. if (!font.vertical) {
  35997. textContentItem.width = 0;
  35998. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  35999. textContentItem.vertical = false;
  36000. } else {
  36001. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  36002. textContentItem.height = 0;
  36003. textContentItem.vertical = true;
  36004. }
  36005. var a = textState.textLineMatrix[0];
  36006. var b = textState.textLineMatrix[1];
  36007. var scaleLineX = Math.sqrt(a * a + b * b);
  36008. a = textState.ctm[0];
  36009. b = textState.ctm[1];
  36010. var scaleCtmX = Math.sqrt(a * a + b * b);
  36011. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  36012. textContentItem.lastAdvanceWidth = 0;
  36013. textContentItem.lastAdvanceHeight = 0;
  36014. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  36015. if (spaceWidth) {
  36016. textContentItem.spaceWidth = spaceWidth;
  36017. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  36018. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  36019. textContentItem.fakeMultiSpaceMax =
  36020. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  36021. // It's okay for monospace fonts to fake as much space as needed.
  36022. textContentItem.textRunBreakAllowed = !font.isMonospace;
  36023. } else {
  36024. textContentItem.spaceWidth = 0;
  36025. textContentItem.fakeSpaceMin = Infinity;
  36026. textContentItem.fakeMultiSpaceMin = Infinity;
  36027. textContentItem.fakeMultiSpaceMax = 0;
  36028. textContentItem.textRunBreakAllowed = false;
  36029. }
  36030. textContentItem.initialized = true;
  36031. return textContentItem;
  36032. }
  36033. function replaceWhitespace(str) {
  36034. // Replaces all whitespaces with standard spaces (0x20), to avoid
  36035. // alignment issues between the textLayer and the canvas if the text
  36036. // contains e.g. tabs (fixes issue6612.pdf).
  36037. var i = 0, ii = str.length, code;
  36038. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  36039. i++;
  36040. }
  36041. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  36042. }
  36043. function runBidiTransform(textChunk) {
  36044. var str = textChunk.str.join('');
  36045. var bidiResult = bidi(str, -1, textChunk.vertical);
  36046. return {
  36047. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  36048. bidiResult.str),
  36049. dir: bidiResult.dir,
  36050. width: textChunk.width,
  36051. height: textChunk.height,
  36052. transform: textChunk.transform,
  36053. fontName: textChunk.fontName
  36054. };
  36055. }
  36056. function handleSetFont(fontName, fontRef) {
  36057. return self.loadFont(fontName, fontRef, xref, resources).
  36058. then(function (translated) {
  36059. textState.font = translated.font;
  36060. textState.fontMatrix = translated.font.fontMatrix ||
  36061. FONT_IDENTITY_MATRIX;
  36062. });
  36063. }
  36064. function buildTextContentItem(chars) {
  36065. var font = textState.font;
  36066. var textChunk = ensureTextContentItem();
  36067. var width = 0;
  36068. var height = 0;
  36069. var glyphs = font.charsToGlyphs(chars);
  36070. var defaultVMetrics = font.defaultVMetrics;
  36071. for (var i = 0; i < glyphs.length; i++) {
  36072. var glyph = glyphs[i];
  36073. var vMetricX = null;
  36074. var vMetricY = null;
  36075. var glyphWidth = null;
  36076. if (font.vertical) {
  36077. if (glyph.vmetric) {
  36078. glyphWidth = glyph.vmetric[0];
  36079. vMetricX = glyph.vmetric[1];
  36080. vMetricY = glyph.vmetric[2];
  36081. } else {
  36082. glyphWidth = glyph.width;
  36083. vMetricX = glyph.width * 0.5;
  36084. vMetricY = defaultVMetrics[2];
  36085. }
  36086. } else {
  36087. glyphWidth = glyph.width;
  36088. }
  36089. var glyphUnicode = glyph.unicode;
  36090. var NormalizedUnicodes = getNormalizedUnicodes();
  36091. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  36092. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  36093. }
  36094. glyphUnicode = reverseIfRtl(glyphUnicode);
  36095. // The following will calculate the x and y of the individual glyphs.
  36096. // if (font.vertical) {
  36097. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  36098. // textState.fontMatrix[0];
  36099. // tsm[5] -= vMetricY * textState.fontSize *
  36100. // textState.fontMatrix[0];
  36101. // }
  36102. // var trm = Util.transform(textState.textMatrix, tsm);
  36103. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  36104. // var x = pt[0];
  36105. // var y = pt[1];
  36106. var charSpacing = textState.charSpacing;
  36107. if (glyph.isSpace) {
  36108. var wordSpacing = textState.wordSpacing;
  36109. charSpacing += wordSpacing;
  36110. if (wordSpacing > 0) {
  36111. addFakeSpaces(wordSpacing, textChunk.str);
  36112. }
  36113. }
  36114. var tx = 0;
  36115. var ty = 0;
  36116. if (!font.vertical) {
  36117. var w0 = glyphWidth * textState.fontMatrix[0];
  36118. tx = (w0 * textState.fontSize + charSpacing) *
  36119. textState.textHScale;
  36120. width += tx;
  36121. } else {
  36122. var w1 = glyphWidth * textState.fontMatrix[0];
  36123. ty = w1 * textState.fontSize + charSpacing;
  36124. height += ty;
  36125. }
  36126. textState.translateTextMatrix(tx, ty);
  36127. textChunk.str.push(glyphUnicode);
  36128. }
  36129. if (!font.vertical) {
  36130. textChunk.lastAdvanceWidth = width;
  36131. textChunk.width += width * textChunk.textAdvanceScale;
  36132. } else {
  36133. textChunk.lastAdvanceHeight = height;
  36134. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  36135. }
  36136. return textChunk;
  36137. }
  36138. function addFakeSpaces(width, strBuf) {
  36139. if (width < textContentItem.fakeSpaceMin) {
  36140. return;
  36141. }
  36142. if (width < textContentItem.fakeMultiSpaceMin) {
  36143. strBuf.push(' ');
  36144. return;
  36145. }
  36146. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  36147. while (fakeSpaces-- > 0) {
  36148. strBuf.push(' ');
  36149. }
  36150. }
  36151. function flushTextContentItem() {
  36152. if (!textContentItem.initialized) {
  36153. return;
  36154. }
  36155. textContent.items.push(runBidiTransform(textContentItem));
  36156. textContentItem.initialized = false;
  36157. textContentItem.str.length = 0;
  36158. }
  36159. var timeSlotManager = new TimeSlotManager();
  36160. return new Promise(function promiseBody(resolve, reject) {
  36161. var next = function (promise) {
  36162. promise.then(function () {
  36163. try {
  36164. promiseBody(resolve, reject);
  36165. } catch (ex) {
  36166. reject(ex);
  36167. }
  36168. }, reject);
  36169. };
  36170. task.ensureNotTerminated();
  36171. timeSlotManager.reset();
  36172. var stop, operation = {}, args = [];
  36173. while (!(stop = timeSlotManager.check())) {
  36174. // The arguments parsed by read() are not used beyond this loop, so
  36175. // we can reuse the same array on every iteration, thus avoiding
  36176. // unnecessary allocations.
  36177. args.length = 0;
  36178. operation.args = args;
  36179. if (!(preprocessor.read(operation))) {
  36180. break;
  36181. }
  36182. textState = stateManager.state;
  36183. var fn = operation.fn;
  36184. args = operation.args;
  36185. var advance, diff;
  36186. switch (fn | 0) {
  36187. case OPS.setFont:
  36188. // Optimization to ignore multiple identical Tf commands.
  36189. var fontNameArg = args[0].name, fontSizeArg = args[1];
  36190. if (textState.font && fontNameArg === textState.fontName &&
  36191. fontSizeArg === textState.fontSize) {
  36192. break;
  36193. }
  36194. flushTextContentItem();
  36195. textState.fontName = fontNameArg;
  36196. textState.fontSize = fontSizeArg;
  36197. next(handleSetFont(fontNameArg, null));
  36198. return;
  36199. case OPS.setTextRise:
  36200. flushTextContentItem();
  36201. textState.textRise = args[0];
  36202. break;
  36203. case OPS.setHScale:
  36204. flushTextContentItem();
  36205. textState.textHScale = args[0] / 100;
  36206. break;
  36207. case OPS.setLeading:
  36208. flushTextContentItem();
  36209. textState.leading = args[0];
  36210. break;
  36211. case OPS.moveText:
  36212. // Optimization to treat same line movement as advance
  36213. var isSameTextLine = !textState.font ? false :
  36214. ((textState.font.vertical ? args[0] : args[1]) === 0);
  36215. advance = args[0] - args[1];
  36216. if (combineTextItems &&
  36217. isSameTextLine && textContentItem.initialized &&
  36218. advance > 0 &&
  36219. advance <= textContentItem.fakeMultiSpaceMax) {
  36220. textState.translateTextLineMatrix(args[0], args[1]);
  36221. textContentItem.width +=
  36222. (args[0] - textContentItem.lastAdvanceWidth);
  36223. textContentItem.height +=
  36224. (args[1] - textContentItem.lastAdvanceHeight);
  36225. diff = (args[0] - textContentItem.lastAdvanceWidth) -
  36226. (args[1] - textContentItem.lastAdvanceHeight);
  36227. addFakeSpaces(diff, textContentItem.str);
  36228. break;
  36229. }
  36230. flushTextContentItem();
  36231. textState.translateTextLineMatrix(args[0], args[1]);
  36232. textState.textMatrix = textState.textLineMatrix.slice();
  36233. break;
  36234. case OPS.setLeadingMoveText:
  36235. flushTextContentItem();
  36236. textState.leading = -args[1];
  36237. textState.translateTextLineMatrix(args[0], args[1]);
  36238. textState.textMatrix = textState.textLineMatrix.slice();
  36239. break;
  36240. case OPS.nextLine:
  36241. flushTextContentItem();
  36242. textState.carriageReturn();
  36243. break;
  36244. case OPS.setTextMatrix:
  36245. // Optimization to treat same line movement as advance.
  36246. advance = textState.calcTextLineMatrixAdvance(
  36247. args[0], args[1], args[2], args[3], args[4], args[5]);
  36248. if (combineTextItems &&
  36249. advance !== null && textContentItem.initialized &&
  36250. advance.value > 0 &&
  36251. advance.value <= textContentItem.fakeMultiSpaceMax) {
  36252. textState.translateTextLineMatrix(advance.width,
  36253. advance.height);
  36254. textContentItem.width +=
  36255. (advance.width - textContentItem.lastAdvanceWidth);
  36256. textContentItem.height +=
  36257. (advance.height - textContentItem.lastAdvanceHeight);
  36258. diff = (advance.width - textContentItem.lastAdvanceWidth) -
  36259. (advance.height - textContentItem.lastAdvanceHeight);
  36260. addFakeSpaces(diff, textContentItem.str);
  36261. break;
  36262. }
  36263. flushTextContentItem();
  36264. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  36265. args[4], args[5]);
  36266. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  36267. args[4], args[5]);
  36268. break;
  36269. case OPS.setCharSpacing:
  36270. textState.charSpacing = args[0];
  36271. break;
  36272. case OPS.setWordSpacing:
  36273. textState.wordSpacing = args[0];
  36274. break;
  36275. case OPS.beginText:
  36276. flushTextContentItem();
  36277. textState.textMatrix = IDENTITY_MATRIX.slice();
  36278. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  36279. break;
  36280. case OPS.showSpacedText:
  36281. var items = args[0];
  36282. var offset;
  36283. for (var j = 0, jj = items.length; j < jj; j++) {
  36284. if (typeof items[j] === 'string') {
  36285. buildTextContentItem(items[j]);
  36286. } else {
  36287. ensureTextContentItem();
  36288. // PDF Specification 5.3.2 states:
  36289. // The number is expressed in thousandths of a unit of text
  36290. // space.
  36291. // This amount is subtracted from the current horizontal or
  36292. // vertical coordinate, depending on the writing mode.
  36293. // In the default coordinate system, a positive adjustment
  36294. // has the effect of moving the next glyph painted either to
  36295. // the left or down by the given amount.
  36296. advance = items[j] * textState.fontSize / 1000;
  36297. var breakTextRun = false;
  36298. if (textState.font.vertical) {
  36299. offset = advance *
  36300. (textState.textHScale * textState.textMatrix[2] +
  36301. textState.textMatrix[3]);
  36302. textState.translateTextMatrix(0, advance);
  36303. breakTextRun = textContentItem.textRunBreakAllowed &&
  36304. advance > textContentItem.fakeMultiSpaceMax;
  36305. if (!breakTextRun) {
  36306. // Value needs to be added to height to paint down.
  36307. textContentItem.height += offset;
  36308. }
  36309. } else {
  36310. advance = -advance;
  36311. offset = advance * (
  36312. textState.textHScale * textState.textMatrix[0] +
  36313. textState.textMatrix[1]);
  36314. textState.translateTextMatrix(advance, 0);
  36315. breakTextRun = textContentItem.textRunBreakAllowed &&
  36316. advance > textContentItem.fakeMultiSpaceMax;
  36317. if (!breakTextRun) {
  36318. // Value needs to be subtracted from width to paint left.
  36319. textContentItem.width += offset;
  36320. }
  36321. }
  36322. if (breakTextRun) {
  36323. flushTextContentItem();
  36324. } else if (advance > 0) {
  36325. addFakeSpaces(advance, textContentItem.str);
  36326. }
  36327. }
  36328. }
  36329. break;
  36330. case OPS.showText:
  36331. buildTextContentItem(args[0]);
  36332. break;
  36333. case OPS.nextLineShowText:
  36334. flushTextContentItem();
  36335. textState.carriageReturn();
  36336. buildTextContentItem(args[0]);
  36337. break;
  36338. case OPS.nextLineSetSpacingShowText:
  36339. flushTextContentItem();
  36340. textState.wordSpacing = args[0];
  36341. textState.charSpacing = args[1];
  36342. textState.carriageReturn();
  36343. buildTextContentItem(args[2]);
  36344. break;
  36345. case OPS.paintXObject:
  36346. flushTextContentItem();
  36347. if (args[0].code) {
  36348. break;
  36349. }
  36350. if (!xobjs) {
  36351. xobjs = (resources.get('XObject') || Dict.empty);
  36352. }
  36353. var name = args[0].name;
  36354. if (xobjsCache.key === name) {
  36355. if (xobjsCache.texts) {
  36356. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  36357. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  36358. }
  36359. break;
  36360. }
  36361. var xobj = xobjs.get(name);
  36362. if (!xobj) {
  36363. break;
  36364. }
  36365. assert(isStream(xobj), 'XObject should be a stream');
  36366. var type = xobj.dict.get('Subtype');
  36367. assert(isName(type), 'XObject should have a Name subtype');
  36368. if ('Form' !== type.name) {
  36369. xobjsCache.key = name;
  36370. xobjsCache.texts = null;
  36371. break;
  36372. }
  36373. stateManager.save();
  36374. var matrix = xobj.dict.getArray('Matrix');
  36375. if (isArray(matrix) && matrix.length === 6) {
  36376. stateManager.transform(matrix);
  36377. }
  36378. next(self.getTextContent(xobj, task,
  36379. xobj.dict.get('Resources') || resources, stateManager,
  36380. normalizeWhitespace, combineTextItems).then(
  36381. function (formTextContent) {
  36382. Util.appendToArray(textContent.items, formTextContent.items);
  36383. Util.extendObj(textContent.styles, formTextContent.styles);
  36384. stateManager.restore();
  36385. xobjsCache.key = name;
  36386. xobjsCache.texts = formTextContent;
  36387. }));
  36388. return;
  36389. case OPS.setGState:
  36390. flushTextContentItem();
  36391. var dictName = args[0];
  36392. var extGState = resources.get('ExtGState');
  36393. if (!isDict(extGState) || !isName(dictName)) {
  36394. break;
  36395. }
  36396. var gState = extGState.get(dictName.name);
  36397. if (!isDict(gState)) {
  36398. break;
  36399. }
  36400. var gStateFont = gState.get('Font');
  36401. if (gStateFont) {
  36402. textState.fontName = null;
  36403. textState.fontSize = gStateFont[1];
  36404. next(handleSetFont(null, gStateFont[0]));
  36405. return;
  36406. }
  36407. break;
  36408. } // switch
  36409. } // while
  36410. if (stop) {
  36411. next(deferred);
  36412. return;
  36413. }
  36414. flushTextContentItem();
  36415. resolve(textContent);
  36416. });
  36417. },
  36418. extractDataStructures:
  36419. function PartialEvaluator_extractDataStructures(dict, baseDict,
  36420. xref, properties) {
  36421. // 9.10.2
  36422. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  36423. var toUnicodePromise = toUnicode ?
  36424. this.readToUnicode(toUnicode) : Promise.resolve(undefined);
  36425. if (properties.composite) {
  36426. // CIDSystemInfo helps to match CID to glyphs
  36427. var cidSystemInfo = dict.get('CIDSystemInfo');
  36428. if (isDict(cidSystemInfo)) {
  36429. properties.cidSystemInfo = {
  36430. registry: cidSystemInfo.get('Registry'),
  36431. ordering: cidSystemInfo.get('Ordering'),
  36432. supplement: cidSystemInfo.get('Supplement')
  36433. };
  36434. }
  36435. var cidToGidMap = dict.get('CIDToGIDMap');
  36436. if (isStream(cidToGidMap)) {
  36437. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  36438. }
  36439. }
  36440. // Based on 9.6.6 of the spec the encoding can come from multiple places
  36441. // and depends on the font type. The base encoding and differences are
  36442. // read here, but the encoding that is actually used is chosen during
  36443. // glyph mapping in the font.
  36444. // TODO: Loading the built in encoding in the font would allow the
  36445. // differences to be merged in here not require us to hold on to it.
  36446. var differences = [];
  36447. var baseEncodingName = null;
  36448. var encoding;
  36449. if (dict.has('Encoding')) {
  36450. encoding = dict.get('Encoding');
  36451. if (isDict(encoding)) {
  36452. baseEncodingName = encoding.get('BaseEncoding');
  36453. baseEncodingName = (isName(baseEncodingName) ?
  36454. baseEncodingName.name : null);
  36455. // Load the differences between the base and original
  36456. if (encoding.has('Differences')) {
  36457. var diffEncoding = encoding.get('Differences');
  36458. var index = 0;
  36459. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  36460. var data = xref.fetchIfRef(diffEncoding[j]);
  36461. if (isNum(data)) {
  36462. index = data;
  36463. } else if (isName(data)) {
  36464. differences[index++] = data.name;
  36465. } else {
  36466. error('Invalid entry in \'Differences\' array: ' + data);
  36467. }
  36468. }
  36469. }
  36470. } else if (isName(encoding)) {
  36471. baseEncodingName = encoding.name;
  36472. } else {
  36473. error('Encoding is not a Name nor a Dict');
  36474. }
  36475. // According to table 114 if the encoding is a named encoding it must be
  36476. // one of these predefined encodings.
  36477. if ((baseEncodingName !== 'MacRomanEncoding' &&
  36478. baseEncodingName !== 'MacExpertEncoding' &&
  36479. baseEncodingName !== 'WinAnsiEncoding')) {
  36480. baseEncodingName = null;
  36481. }
  36482. }
  36483. if (baseEncodingName) {
  36484. properties.defaultEncoding = getEncoding(baseEncodingName).slice();
  36485. } else {
  36486. encoding = (properties.type === 'TrueType' ?
  36487. WinAnsiEncoding : StandardEncoding);
  36488. // The Symbolic attribute can be misused for regular fonts
  36489. // Heuristic: we have to check if the font is a standard one also
  36490. if (!!(properties.flags & FontFlags.Symbolic)) {
  36491. encoding = MacRomanEncoding;
  36492. if (!properties.file) {
  36493. if (/Symbol/i.test(properties.name)) {
  36494. encoding = SymbolSetEncoding;
  36495. } else if (/Dingbats/i.test(properties.name)) {
  36496. encoding = ZapfDingbatsEncoding;
  36497. }
  36498. }
  36499. }
  36500. properties.defaultEncoding = encoding;
  36501. }
  36502. properties.differences = differences;
  36503. properties.baseEncodingName = baseEncodingName;
  36504. properties.hasEncoding = !!baseEncodingName || differences.length > 0;
  36505. properties.dict = dict;
  36506. return toUnicodePromise.then(function(toUnicode) {
  36507. properties.toUnicode = toUnicode;
  36508. return this.buildToUnicode(properties);
  36509. }.bind(this)).then(function (toUnicode) {
  36510. properties.toUnicode = toUnicode;
  36511. return properties;
  36512. });
  36513. },
  36514. /**
  36515. * Builds a char code to unicode map based on section 9.10 of the spec.
  36516. * @param {Object} properties Font properties object.
  36517. * @return {Promise} A Promise that is resolved with a
  36518. * {ToUnicodeMap|IdentityToUnicodeMap} object.
  36519. */
  36520. buildToUnicode: function PartialEvaluator_buildToUnicode(properties) {
  36521. properties.hasIncludedToUnicodeMap =
  36522. !!properties.toUnicode && properties.toUnicode.length > 0;
  36523. // Section 9.10.2 Mapping Character Codes to Unicode Values
  36524. if (properties.hasIncludedToUnicodeMap) {
  36525. return Promise.resolve(properties.toUnicode);
  36526. }
  36527. // According to the spec if the font is a simple font we should only map
  36528. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  36529. // the differences array only contains adobe standard or symbol set names,
  36530. // in pratice it seems better to always try to create a toUnicode
  36531. // map based of the default encoding.
  36532. var toUnicode, charcode, glyphName;
  36533. if (!properties.composite /* is simple font */) {
  36534. toUnicode = [];
  36535. var encoding = properties.defaultEncoding.slice();
  36536. var baseEncodingName = properties.baseEncodingName;
  36537. // Merge in the differences array.
  36538. var differences = properties.differences;
  36539. for (charcode in differences) {
  36540. glyphName = differences[charcode];
  36541. if (glyphName === '.notdef') {
  36542. // Skip .notdef to prevent rendering errors, e.g. boxes appearing
  36543. // where there should be spaces (fixes issue5256.pdf).
  36544. continue;
  36545. }
  36546. encoding[charcode] = glyphName;
  36547. }
  36548. var glyphsUnicodeMap = getGlyphsUnicode();
  36549. for (charcode in encoding) {
  36550. // a) Map the character code to a character name.
  36551. glyphName = encoding[charcode];
  36552. // b) Look up the character name in the Adobe Glyph List (see the
  36553. // Bibliography) to obtain the corresponding Unicode value.
  36554. if (glyphName === '') {
  36555. continue;
  36556. } else if (glyphsUnicodeMap[glyphName] === undefined) {
  36557. // (undocumented) c) Few heuristics to recognize unknown glyphs
  36558. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  36559. var code = 0;
  36560. switch (glyphName[0]) {
  36561. case 'G': // Gxx glyph
  36562. if (glyphName.length === 3) {
  36563. code = parseInt(glyphName.substr(1), 16);
  36564. }
  36565. break;
  36566. case 'g': // g00xx glyph
  36567. if (glyphName.length === 5) {
  36568. code = parseInt(glyphName.substr(1), 16);
  36569. }
  36570. break;
  36571. case 'C': // Cddd glyph
  36572. case 'c': // cddd glyph
  36573. if (glyphName.length >= 3) {
  36574. code = +glyphName.substr(1);
  36575. }
  36576. break;
  36577. default:
  36578. // 'uniXXXX'/'uXXXX{XX}' glyphs
  36579. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  36580. if (unicode !== -1) {
  36581. code = unicode;
  36582. }
  36583. }
  36584. if (code) {
  36585. // If |baseEncodingName| is one the predefined encodings,
  36586. // and |code| equals |charcode|, using the glyph defined in the
  36587. // baseEncoding seems to yield a better |toUnicode| mapping
  36588. // (fixes issue 5070).
  36589. if (baseEncodingName && code === +charcode) {
  36590. var baseEncoding = getEncoding(baseEncodingName);
  36591. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  36592. toUnicode[charcode] =
  36593. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  36594. continue;
  36595. }
  36596. }
  36597. toUnicode[charcode] = String.fromCharCode(code);
  36598. }
  36599. continue;
  36600. }
  36601. toUnicode[charcode] =
  36602. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  36603. }
  36604. return Promise.resolve(new ToUnicodeMap(toUnicode));
  36605. }
  36606. // If the font is a composite font that uses one of the predefined CMaps
  36607. // listed in Table 118 (except Identity–H and Identity–V) or whose
  36608. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  36609. // Adobe-Korea1 character collection:
  36610. if (properties.composite && (
  36611. (properties.cMap.builtInCMap &&
  36612. !(properties.cMap instanceof IdentityCMap)) ||
  36613. (properties.cidSystemInfo.registry === 'Adobe' &&
  36614. (properties.cidSystemInfo.ordering === 'GB1' ||
  36615. properties.cidSystemInfo.ordering === 'CNS1' ||
  36616. properties.cidSystemInfo.ordering === 'Japan1' ||
  36617. properties.cidSystemInfo.ordering === 'Korea1')))) {
  36618. // Then:
  36619. // a) Map the character code to a character identifier (CID) according
  36620. // to the font’s CMap.
  36621. // b) Obtain the registry and ordering of the character collection used
  36622. // by the font’s CMap (for example, Adobe and Japan1) from its
  36623. // CIDSystemInfo dictionary.
  36624. var registry = properties.cidSystemInfo.registry;
  36625. var ordering = properties.cidSystemInfo.ordering;
  36626. // c) Construct a second CMap name by concatenating the registry and
  36627. // ordering obtained in step (b) in the format registry–ordering–UCS2
  36628. // (for example, Adobe–Japan1–UCS2).
  36629. var ucs2CMapName = Name.get(registry + '-' + ordering + '-UCS2');
  36630. // d) Obtain the CMap with the name constructed in step (c) (available
  36631. // from the ASN Web site; see the Bibliography).
  36632. return CMapFactory.create(ucs2CMapName, this.options.cMapOptions,
  36633. null).then(
  36634. function (ucs2CMap) {
  36635. var cMap = properties.cMap;
  36636. toUnicode = [];
  36637. cMap.forEach(function(charcode, cid) {
  36638. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  36639. // e) Map the CID obtained in step (a) according to the CMap
  36640. // obtained in step (d), producing a Unicode value.
  36641. var ucs2 = ucs2CMap.lookup(cid);
  36642. if (ucs2) {
  36643. toUnicode[charcode] =
  36644. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  36645. ucs2.charCodeAt(1));
  36646. }
  36647. });
  36648. return new ToUnicodeMap(toUnicode);
  36649. });
  36650. }
  36651. // The viewer's choice, just use an identity map.
  36652. return Promise.resolve(new IdentityToUnicodeMap(properties.firstChar,
  36653. properties.lastChar));
  36654. },
  36655. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  36656. var cmapObj = toUnicode;
  36657. if (isName(cmapObj)) {
  36658. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
  36659. function (cmap) {
  36660. if (cmap instanceof IdentityCMap) {
  36661. return new IdentityToUnicodeMap(0, 0xFFFF);
  36662. }
  36663. return new ToUnicodeMap(cmap.getMap());
  36664. });
  36665. } else if (isStream(cmapObj)) {
  36666. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
  36667. function (cmap) {
  36668. if (cmap instanceof IdentityCMap) {
  36669. return new IdentityToUnicodeMap(0, 0xFFFF);
  36670. }
  36671. var map = new Array(cmap.length);
  36672. // Convert UTF-16BE
  36673. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  36674. // to iterate over all keys.
  36675. cmap.forEach(function(charCode, token) {
  36676. var str = [];
  36677. for (var k = 0; k < token.length; k += 2) {
  36678. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  36679. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  36680. str.push(w1);
  36681. continue;
  36682. }
  36683. k += 2;
  36684. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  36685. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  36686. }
  36687. map[charCode] = String.fromCharCode.apply(String, str);
  36688. });
  36689. return new ToUnicodeMap(map);
  36690. });
  36691. }
  36692. return Promise.resolve(null);
  36693. },
  36694. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  36695. // Extract the encoding from the CIDToGIDMap
  36696. var glyphsData = cidToGidStream.getBytes();
  36697. // Set encoding 0 to later verify the font has an encoding
  36698. var result = [];
  36699. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  36700. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  36701. if (glyphID === 0) {
  36702. continue;
  36703. }
  36704. var code = j >> 1;
  36705. result[code] = glyphID;
  36706. }
  36707. return result;
  36708. },
  36709. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  36710. descriptor,
  36711. properties) {
  36712. var glyphsWidths = [];
  36713. var defaultWidth = 0;
  36714. var glyphsVMetrics = [];
  36715. var defaultVMetrics;
  36716. var i, ii, j, jj, start, code, widths;
  36717. if (properties.composite) {
  36718. defaultWidth = dict.get('DW') || 1000;
  36719. widths = dict.get('W');
  36720. if (widths) {
  36721. for (i = 0, ii = widths.length; i < ii; i++) {
  36722. start = widths[i++];
  36723. code = xref.fetchIfRef(widths[i]);
  36724. if (isArray(code)) {
  36725. for (j = 0, jj = code.length; j < jj; j++) {
  36726. glyphsWidths[start++] = code[j];
  36727. }
  36728. } else {
  36729. var width = widths[++i];
  36730. for (j = start; j <= code; j++) {
  36731. glyphsWidths[j] = width;
  36732. }
  36733. }
  36734. }
  36735. }
  36736. if (properties.vertical) {
  36737. var vmetrics = (dict.get('DW2') || [880, -1000]);
  36738. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  36739. vmetrics = dict.get('W2');
  36740. if (vmetrics) {
  36741. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  36742. start = vmetrics[i++];
  36743. code = xref.fetchIfRef(vmetrics[i]);
  36744. if (isArray(code)) {
  36745. for (j = 0, jj = code.length; j < jj; j++) {
  36746. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  36747. }
  36748. } else {
  36749. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  36750. for (j = start; j <= code; j++) {
  36751. glyphsVMetrics[j] = vmetric;
  36752. }
  36753. }
  36754. }
  36755. }
  36756. }
  36757. } else {
  36758. var firstChar = properties.firstChar;
  36759. widths = dict.get('Widths');
  36760. if (widths) {
  36761. j = firstChar;
  36762. for (i = 0, ii = widths.length; i < ii; i++) {
  36763. glyphsWidths[j++] = widths[i];
  36764. }
  36765. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  36766. } else {
  36767. // Trying get the BaseFont metrics (see comment above).
  36768. var baseFontName = dict.get('BaseFont');
  36769. if (isName(baseFontName)) {
  36770. var metrics = this.getBaseFontMetrics(baseFontName.name);
  36771. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  36772. properties);
  36773. defaultWidth = metrics.defaultWidth;
  36774. }
  36775. }
  36776. }
  36777. // Heuristic: detection of monospace font by checking all non-zero widths
  36778. var isMonospace = true;
  36779. var firstWidth = defaultWidth;
  36780. for (var glyph in glyphsWidths) {
  36781. var glyphWidth = glyphsWidths[glyph];
  36782. if (!glyphWidth) {
  36783. continue;
  36784. }
  36785. if (!firstWidth) {
  36786. firstWidth = glyphWidth;
  36787. continue;
  36788. }
  36789. if (firstWidth !== glyphWidth) {
  36790. isMonospace = false;
  36791. break;
  36792. }
  36793. }
  36794. if (isMonospace) {
  36795. properties.flags |= FontFlags.FixedPitch;
  36796. }
  36797. properties.defaultWidth = defaultWidth;
  36798. properties.widths = glyphsWidths;
  36799. properties.defaultVMetrics = defaultVMetrics;
  36800. properties.vmetrics = glyphsVMetrics;
  36801. },
  36802. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  36803. // Simulating descriptor flags attribute
  36804. var fontNameWoStyle = baseFontName.split('-')[0];
  36805. return (fontNameWoStyle in getSerifFonts()) ||
  36806. (fontNameWoStyle.search(/serif/gi) !== -1);
  36807. },
  36808. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  36809. var defaultWidth = 0;
  36810. var widths = [];
  36811. var monospace = false;
  36812. var stdFontMap = getStdFontMap();
  36813. var lookupName = (stdFontMap[name] || name);
  36814. var Metrics = getMetrics();
  36815. if (!(lookupName in Metrics)) {
  36816. // Use default fonts for looking up font metrics if the passed
  36817. // font is not a base font
  36818. if (this.isSerifFont(name)) {
  36819. lookupName = 'Times-Roman';
  36820. } else {
  36821. lookupName = 'Helvetica';
  36822. }
  36823. }
  36824. var glyphWidths = Metrics[lookupName];
  36825. if (isNum(glyphWidths)) {
  36826. defaultWidth = glyphWidths;
  36827. monospace = true;
  36828. } else {
  36829. widths = glyphWidths(); // expand lazy widths array
  36830. }
  36831. return {
  36832. defaultWidth: defaultWidth,
  36833. monospace: monospace,
  36834. widths: widths
  36835. };
  36836. },
  36837. buildCharCodeToWidth:
  36838. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  36839. properties) {
  36840. var widths = Object.create(null);
  36841. var differences = properties.differences;
  36842. var encoding = properties.defaultEncoding;
  36843. for (var charCode = 0; charCode < 256; charCode++) {
  36844. if (charCode in differences &&
  36845. widthsByGlyphName[differences[charCode]]) {
  36846. widths[charCode] = widthsByGlyphName[differences[charCode]];
  36847. continue;
  36848. }
  36849. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  36850. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  36851. continue;
  36852. }
  36853. }
  36854. return widths;
  36855. },
  36856. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  36857. var baseDict = dict;
  36858. var type = dict.get('Subtype');
  36859. assert(isName(type), 'invalid font Subtype');
  36860. var composite = false;
  36861. var uint8array;
  36862. if (type.name === 'Type0') {
  36863. // If font is a composite
  36864. // - get the descendant font
  36865. // - set the type according to the descendant font
  36866. // - get the FontDescriptor from the descendant font
  36867. var df = dict.get('DescendantFonts');
  36868. if (!df) {
  36869. error('Descendant fonts are not specified');
  36870. }
  36871. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  36872. type = dict.get('Subtype');
  36873. assert(isName(type), 'invalid font Subtype');
  36874. composite = true;
  36875. }
  36876. var descriptor = dict.get('FontDescriptor');
  36877. if (descriptor) {
  36878. var hash = new MurmurHash3_64();
  36879. var encoding = baseDict.getRaw('Encoding');
  36880. if (isName(encoding)) {
  36881. hash.update(encoding.name);
  36882. } else if (isRef(encoding)) {
  36883. hash.update(encoding.toString());
  36884. } else if (isDict(encoding)) {
  36885. var keys = encoding.getKeys();
  36886. for (var i = 0, ii = keys.length; i < ii; i++) {
  36887. var entry = encoding.getRaw(keys[i]);
  36888. if (isName(entry)) {
  36889. hash.update(entry.name);
  36890. } else if (isRef(entry)) {
  36891. hash.update(entry.toString());
  36892. } else if (isArray(entry)) { // 'Differences' entry.
  36893. // Ideally we should check the contents of the array, but to avoid
  36894. // parsing it here and then again in |extractDataStructures|,
  36895. // we only use the array length for now (fixes bug1157493.pdf).
  36896. hash.update(entry.length.toString());
  36897. }
  36898. }
  36899. }
  36900. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  36901. if (isStream(toUnicode)) {
  36902. var stream = toUnicode.str || toUnicode;
  36903. uint8array = stream.buffer ?
  36904. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  36905. new Uint8Array(stream.bytes.buffer,
  36906. stream.start, stream.end - stream.start);
  36907. hash.update(uint8array);
  36908. } else if (isName(toUnicode)) {
  36909. hash.update(toUnicode.name);
  36910. }
  36911. var widths = dict.get('Widths') || baseDict.get('Widths');
  36912. if (widths) {
  36913. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  36914. hash.update(uint8array);
  36915. }
  36916. }
  36917. return {
  36918. descriptor: descriptor,
  36919. dict: dict,
  36920. baseDict: baseDict,
  36921. composite: composite,
  36922. type: type.name,
  36923. hash: hash ? hash.hexdigest() : ''
  36924. };
  36925. },
  36926. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  36927. xref) {
  36928. var baseDict = preEvaluatedFont.baseDict;
  36929. var dict = preEvaluatedFont.dict;
  36930. var composite = preEvaluatedFont.composite;
  36931. var descriptor = preEvaluatedFont.descriptor;
  36932. var type = preEvaluatedFont.type;
  36933. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  36934. var cMapOptions = this.options.cMapOptions;
  36935. var properties;
  36936. if (!descriptor) {
  36937. if (type === 'Type3') {
  36938. // FontDescriptor is only required for Type3 fonts when the document
  36939. // is a tagged pdf. Create a barbebones one to get by.
  36940. descriptor = new Dict(null);
  36941. descriptor.set('FontName', Name.get(type));
  36942. descriptor.set('FontBBox', dict.getArray('FontBBox'));
  36943. } else {
  36944. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  36945. // FontDescriptor was not required.
  36946. // This case is here for compatibility.
  36947. var baseFontName = dict.get('BaseFont');
  36948. if (!isName(baseFontName)) {
  36949. error('Base font is not specified');
  36950. }
  36951. // Using base font name as a font name.
  36952. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  36953. var metrics = this.getBaseFontMetrics(baseFontName);
  36954. // Simulating descriptor flags attribute
  36955. var fontNameWoStyle = baseFontName.split('-')[0];
  36956. var flags =
  36957. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  36958. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  36959. (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic :
  36960. FontFlags.Nonsymbolic);
  36961. properties = {
  36962. type: type,
  36963. name: baseFontName,
  36964. widths: metrics.widths,
  36965. defaultWidth: metrics.defaultWidth,
  36966. flags: flags,
  36967. firstChar: 0,
  36968. lastChar: maxCharIndex
  36969. };
  36970. return this.extractDataStructures(dict, dict, xref, properties).then(
  36971. function (properties) {
  36972. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  36973. properties);
  36974. return new Font(baseFontName, null, properties);
  36975. }.bind(this));
  36976. }
  36977. }
  36978. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  36979. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  36980. // to ignore this rule when a variant of a standard font is used.
  36981. // TODO Fill the width array depending on which of the base font this is
  36982. // a variant.
  36983. var firstChar = (dict.get('FirstChar') || 0);
  36984. var lastChar = (dict.get('LastChar') || maxCharIndex);
  36985. var fontName = descriptor.get('FontName');
  36986. var baseFont = dict.get('BaseFont');
  36987. // Some bad PDFs have a string as the font name.
  36988. if (isString(fontName)) {
  36989. fontName = Name.get(fontName);
  36990. }
  36991. if (isString(baseFont)) {
  36992. baseFont = Name.get(baseFont);
  36993. }
  36994. if (type !== 'Type3') {
  36995. var fontNameStr = fontName && fontName.name;
  36996. var baseFontStr = baseFont && baseFont.name;
  36997. if (fontNameStr !== baseFontStr) {
  36998. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  36999. '" but should be the same as the Font\'s BaseFont "' +
  37000. baseFontStr + '"');
  37001. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  37002. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  37003. if (fontNameStr && baseFontStr &&
  37004. baseFontStr.indexOf(fontNameStr) === 0) {
  37005. fontName = baseFont;
  37006. }
  37007. }
  37008. }
  37009. fontName = (fontName || baseFont);
  37010. assert(isName(fontName), 'invalid font name');
  37011. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  37012. if (fontFile) {
  37013. if (fontFile.dict) {
  37014. var subtype = fontFile.dict.get('Subtype');
  37015. if (subtype) {
  37016. subtype = subtype.name;
  37017. }
  37018. var length1 = fontFile.dict.get('Length1');
  37019. var length2 = fontFile.dict.get('Length2');
  37020. var length3 = fontFile.dict.get('Length3');
  37021. }
  37022. }
  37023. properties = {
  37024. type: type,
  37025. name: fontName.name,
  37026. subtype: subtype,
  37027. file: fontFile,
  37028. length1: length1,
  37029. length2: length2,
  37030. length3: length3,
  37031. loadedName: baseDict.loadedName,
  37032. composite: composite,
  37033. wideChars: composite,
  37034. fixedPitch: false,
  37035. fontMatrix: (dict.getArray('FontMatrix') || FONT_IDENTITY_MATRIX),
  37036. firstChar: firstChar || 0,
  37037. lastChar: (lastChar || maxCharIndex),
  37038. bbox: descriptor.getArray('FontBBox'),
  37039. ascent: descriptor.get('Ascent'),
  37040. descent: descriptor.get('Descent'),
  37041. xHeight: descriptor.get('XHeight'),
  37042. capHeight: descriptor.get('CapHeight'),
  37043. flags: descriptor.get('Flags'),
  37044. italicAngle: descriptor.get('ItalicAngle'),
  37045. coded: false
  37046. };
  37047. var cMapPromise;
  37048. if (composite) {
  37049. var cidEncoding = baseDict.get('Encoding');
  37050. if (isName(cidEncoding)) {
  37051. properties.cidEncoding = cidEncoding.name;
  37052. }
  37053. cMapPromise = CMapFactory.create(cidEncoding, cMapOptions, null).then(
  37054. function (cMap) {
  37055. properties.cMap = cMap;
  37056. properties.vertical = properties.cMap.vertical;
  37057. });
  37058. } else {
  37059. cMapPromise = Promise.resolve(undefined);
  37060. }
  37061. return cMapPromise.then(function () {
  37062. return this.extractDataStructures(dict, baseDict, xref, properties);
  37063. }.bind(this)).then(function (properties) {
  37064. this.extractWidths(dict, xref, descriptor, properties);
  37065. if (type === 'Type3') {
  37066. properties.isType3Font = true;
  37067. }
  37068. return new Font(fontName.name, fontFile, properties);
  37069. }.bind(this));
  37070. }
  37071. };
  37072. return PartialEvaluator;
  37073. })();
  37074. var TranslatedFont = (function TranslatedFontClosure() {
  37075. function TranslatedFont(loadedName, font, dict) {
  37076. this.loadedName = loadedName;
  37077. this.font = font;
  37078. this.dict = dict;
  37079. this.type3Loaded = null;
  37080. this.sent = false;
  37081. }
  37082. TranslatedFont.prototype = {
  37083. send: function (handler) {
  37084. if (this.sent) {
  37085. return;
  37086. }
  37087. var fontData = this.font.exportData();
  37088. handler.send('commonobj', [
  37089. this.loadedName,
  37090. 'Font',
  37091. fontData
  37092. ]);
  37093. this.sent = true;
  37094. },
  37095. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  37096. assert(this.font.isType3Font);
  37097. if (this.type3Loaded) {
  37098. return this.type3Loaded;
  37099. }
  37100. var translatedFont = this.font;
  37101. var loadCharProcsPromise = Promise.resolve();
  37102. var charProcs = this.dict.get('CharProcs');
  37103. var fontResources = this.dict.get('Resources') || resources;
  37104. var charProcKeys = charProcs.getKeys();
  37105. var charProcOperatorList = Object.create(null);
  37106. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  37107. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  37108. var glyphStream = charProcs.get(key);
  37109. var operatorList = new OperatorList();
  37110. return evaluator.getOperatorList(glyphStream, task, fontResources,
  37111. operatorList).then(function () {
  37112. charProcOperatorList[key] = operatorList.getIR();
  37113. // Add the dependencies to the parent operator list so they are
  37114. // resolved before sub operator list is executed synchronously.
  37115. parentOperatorList.addDependencies(operatorList.dependencies);
  37116. }, function (reason) {
  37117. warn('Type3 font resource \"' + key + '\" is not available');
  37118. var operatorList = new OperatorList();
  37119. charProcOperatorList[key] = operatorList.getIR();
  37120. });
  37121. }.bind(this, charProcKeys[i]));
  37122. }
  37123. this.type3Loaded = loadCharProcsPromise.then(function () {
  37124. translatedFont.charProcOperatorList = charProcOperatorList;
  37125. });
  37126. return this.type3Loaded;
  37127. }
  37128. };
  37129. return TranslatedFont;
  37130. })();
  37131. var OperatorList = (function OperatorListClosure() {
  37132. var CHUNK_SIZE = 1000;
  37133. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  37134. function getTransfers(queue) {
  37135. var transfers = [];
  37136. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  37137. for (var i = 0, ii = queue.length; i < ii; i++) {
  37138. switch (fnArray[i]) {
  37139. case OPS.paintInlineImageXObject:
  37140. case OPS.paintInlineImageXObjectGroup:
  37141. case OPS.paintImageMaskXObject:
  37142. var arg = argsArray[i][0]; // first param in imgData
  37143. if (!arg.cached) {
  37144. transfers.push(arg.data.buffer);
  37145. }
  37146. break;
  37147. }
  37148. }
  37149. return transfers;
  37150. }
  37151. function OperatorList(intent, messageHandler, pageIndex) {
  37152. this.messageHandler = messageHandler;
  37153. this.fnArray = [];
  37154. this.argsArray = [];
  37155. this.dependencies = Object.create(null);
  37156. this._totalLength = 0;
  37157. this.pageIndex = pageIndex;
  37158. this.intent = intent;
  37159. }
  37160. OperatorList.prototype = {
  37161. get length() {
  37162. return this.argsArray.length;
  37163. },
  37164. /**
  37165. * @returns {number} The total length of the entire operator list,
  37166. * since `this.length === 0` after flushing.
  37167. */
  37168. get totalLength() {
  37169. return (this._totalLength + this.length);
  37170. },
  37171. addOp: function(fn, args) {
  37172. this.fnArray.push(fn);
  37173. this.argsArray.push(args);
  37174. if (this.messageHandler) {
  37175. if (this.fnArray.length >= CHUNK_SIZE) {
  37176. this.flush();
  37177. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  37178. (fn === OPS.restore || fn === OPS.endText)) {
  37179. // heuristic to flush on boundary of restore or endText
  37180. this.flush();
  37181. }
  37182. }
  37183. },
  37184. addDependency: function(dependency) {
  37185. if (dependency in this.dependencies) {
  37186. return;
  37187. }
  37188. this.dependencies[dependency] = true;
  37189. this.addOp(OPS.dependency, [dependency]);
  37190. },
  37191. addDependencies: function(dependencies) {
  37192. for (var key in dependencies) {
  37193. this.addDependency(key);
  37194. }
  37195. },
  37196. addOpList: function(opList) {
  37197. Util.extendObj(this.dependencies, opList.dependencies);
  37198. for (var i = 0, ii = opList.length; i < ii; i++) {
  37199. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  37200. }
  37201. },
  37202. getIR: function() {
  37203. return {
  37204. fnArray: this.fnArray,
  37205. argsArray: this.argsArray,
  37206. length: this.length
  37207. };
  37208. },
  37209. flush: function(lastChunk) {
  37210. if (this.intent !== 'oplist') {
  37211. new QueueOptimizer().optimize(this);
  37212. }
  37213. var transfers = getTransfers(this);
  37214. var length = this.length;
  37215. this._totalLength += length;
  37216. this.messageHandler.send('RenderPageChunk', {
  37217. operatorList: {
  37218. fnArray: this.fnArray,
  37219. argsArray: this.argsArray,
  37220. lastChunk: lastChunk,
  37221. length: length
  37222. },
  37223. pageIndex: this.pageIndex,
  37224. intent: this.intent
  37225. }, transfers);
  37226. this.dependencies = Object.create(null);
  37227. this.fnArray.length = 0;
  37228. this.argsArray.length = 0;
  37229. }
  37230. };
  37231. return OperatorList;
  37232. })();
  37233. var StateManager = (function StateManagerClosure() {
  37234. function StateManager(initialState) {
  37235. this.state = initialState;
  37236. this.stateStack = [];
  37237. }
  37238. StateManager.prototype = {
  37239. save: function () {
  37240. var old = this.state;
  37241. this.stateStack.push(this.state);
  37242. this.state = old.clone();
  37243. },
  37244. restore: function () {
  37245. var prev = this.stateStack.pop();
  37246. if (prev) {
  37247. this.state = prev;
  37248. }
  37249. },
  37250. transform: function (args) {
  37251. this.state.ctm = Util.transform(this.state.ctm, args);
  37252. }
  37253. };
  37254. return StateManager;
  37255. })();
  37256. var TextState = (function TextStateClosure() {
  37257. function TextState() {
  37258. this.ctm = new Float32Array(IDENTITY_MATRIX);
  37259. this.fontName = null;
  37260. this.fontSize = 0;
  37261. this.font = null;
  37262. this.fontMatrix = FONT_IDENTITY_MATRIX;
  37263. this.textMatrix = IDENTITY_MATRIX.slice();
  37264. this.textLineMatrix = IDENTITY_MATRIX.slice();
  37265. this.charSpacing = 0;
  37266. this.wordSpacing = 0;
  37267. this.leading = 0;
  37268. this.textHScale = 1;
  37269. this.textRise = 0;
  37270. }
  37271. TextState.prototype = {
  37272. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  37273. var m = this.textMatrix;
  37274. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  37275. },
  37276. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  37277. var m = this.textLineMatrix;
  37278. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  37279. },
  37280. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  37281. var m = this.textMatrix;
  37282. m[4] = m[0] * x + m[2] * y + m[4];
  37283. m[5] = m[1] * x + m[3] * y + m[5];
  37284. },
  37285. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  37286. var m = this.textLineMatrix;
  37287. m[4] = m[0] * x + m[2] * y + m[4];
  37288. m[5] = m[1] * x + m[3] * y + m[5];
  37289. },
  37290. calcTextLineMatrixAdvance:
  37291. function TextState_calcTextLineMatrixAdvance(a, b, c, d, e, f) {
  37292. var font = this.font;
  37293. if (!font) {
  37294. return null;
  37295. }
  37296. var m = this.textLineMatrix;
  37297. if (!(a === m[0] && b === m[1] && c === m[2] && d === m[3])) {
  37298. return null;
  37299. }
  37300. var txDiff = e - m[4], tyDiff = f - m[5];
  37301. if ((font.vertical && txDiff !== 0) || (!font.vertical && tyDiff !== 0)) {
  37302. return null;
  37303. }
  37304. var tx, ty, denominator = a * d - b * c;
  37305. if (font.vertical) {
  37306. tx = -tyDiff * c / denominator;
  37307. ty = tyDiff * a / denominator;
  37308. } else {
  37309. tx = txDiff * d / denominator;
  37310. ty = -txDiff * b / denominator;
  37311. }
  37312. return { width: tx, height: ty, value: (font.vertical ? ty : tx), };
  37313. },
  37314. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  37315. // 9.4.4 Text Space Details
  37316. var tsm = [this.fontSize * this.textHScale, 0,
  37317. 0, this.fontSize,
  37318. 0, this.textRise];
  37319. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  37320. },
  37321. carriageReturn: function TextState_carriageReturn() {
  37322. this.translateTextLineMatrix(0, -this.leading);
  37323. this.textMatrix = this.textLineMatrix.slice();
  37324. },
  37325. clone: function TextState_clone() {
  37326. var clone = Object.create(this);
  37327. clone.textMatrix = this.textMatrix.slice();
  37328. clone.textLineMatrix = this.textLineMatrix.slice();
  37329. clone.fontMatrix = this.fontMatrix.slice();
  37330. return clone;
  37331. }
  37332. };
  37333. return TextState;
  37334. })();
  37335. var EvalState = (function EvalStateClosure() {
  37336. function EvalState() {
  37337. this.ctm = new Float32Array(IDENTITY_MATRIX);
  37338. this.font = null;
  37339. this.textRenderingMode = TextRenderingMode.FILL;
  37340. this.fillColorSpace = ColorSpace.singletons.gray;
  37341. this.strokeColorSpace = ColorSpace.singletons.gray;
  37342. }
  37343. EvalState.prototype = {
  37344. clone: function CanvasExtraState_clone() {
  37345. return Object.create(this);
  37346. },
  37347. };
  37348. return EvalState;
  37349. })();
  37350. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  37351. // Specifies properties for each command
  37352. //
  37353. // If variableArgs === true: [0, `numArgs`] expected
  37354. // If variableArgs === false: exactly `numArgs` expected
  37355. var getOPMap = getLookupTableFactory(function (t) {
  37356. // Graphic state
  37357. t['w'] = { id: OPS.setLineWidth, numArgs: 1, variableArgs: false };
  37358. t['J'] = { id: OPS.setLineCap, numArgs: 1, variableArgs: false };
  37359. t['j'] = { id: OPS.setLineJoin, numArgs: 1, variableArgs: false };
  37360. t['M'] = { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false };
  37361. t['d'] = { id: OPS.setDash, numArgs: 2, variableArgs: false };
  37362. t['ri'] = { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false };
  37363. t['i'] = { id: OPS.setFlatness, numArgs: 1, variableArgs: false };
  37364. t['gs'] = { id: OPS.setGState, numArgs: 1, variableArgs: false };
  37365. t['q'] = { id: OPS.save, numArgs: 0, variableArgs: false };
  37366. t['Q'] = { id: OPS.restore, numArgs: 0, variableArgs: false };
  37367. t['cm'] = { id: OPS.transform, numArgs: 6, variableArgs: false };
  37368. // Path
  37369. t['m'] = { id: OPS.moveTo, numArgs: 2, variableArgs: false };
  37370. t['l'] = { id: OPS.lineTo, numArgs: 2, variableArgs: false };
  37371. t['c'] = { id: OPS.curveTo, numArgs: 6, variableArgs: false };
  37372. t['v'] = { id: OPS.curveTo2, numArgs: 4, variableArgs: false };
  37373. t['y'] = { id: OPS.curveTo3, numArgs: 4, variableArgs: false };
  37374. t['h'] = { id: OPS.closePath, numArgs: 0, variableArgs: false };
  37375. t['re'] = { id: OPS.rectangle, numArgs: 4, variableArgs: false };
  37376. t['S'] = { id: OPS.stroke, numArgs: 0, variableArgs: false };
  37377. t['s'] = { id: OPS.closeStroke, numArgs: 0, variableArgs: false };
  37378. t['f'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  37379. t['F'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  37380. t['f*'] = { id: OPS.eoFill, numArgs: 0, variableArgs: false };
  37381. t['B'] = { id: OPS.fillStroke, numArgs: 0, variableArgs: false };
  37382. t['B*'] = { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false };
  37383. t['b'] = { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false };
  37384. t['b*'] = { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false };
  37385. t['n'] = { id: OPS.endPath, numArgs: 0, variableArgs: false };
  37386. // Clipping
  37387. t['W'] = { id: OPS.clip, numArgs: 0, variableArgs: false };
  37388. t['W*'] = { id: OPS.eoClip, numArgs: 0, variableArgs: false };
  37389. // Text
  37390. t['BT'] = { id: OPS.beginText, numArgs: 0, variableArgs: false };
  37391. t['ET'] = { id: OPS.endText, numArgs: 0, variableArgs: false };
  37392. t['Tc'] = { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false };
  37393. t['Tw'] = { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false };
  37394. t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false };
  37395. t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false };
  37396. t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false };
  37397. t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false };
  37398. t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false };
  37399. t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false };
  37400. t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false };
  37401. t['Tm'] = { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false };
  37402. t['T*'] = { id: OPS.nextLine, numArgs: 0, variableArgs: false };
  37403. t['Tj'] = { id: OPS.showText, numArgs: 1, variableArgs: false };
  37404. t['TJ'] = { id: OPS.showSpacedText, numArgs: 1, variableArgs: false };
  37405. t['\''] = { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false };
  37406. t['"'] = { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  37407. variableArgs: false };
  37408. // Type3 fonts
  37409. t['d0'] = { id: OPS.setCharWidth, numArgs: 2, variableArgs: false };
  37410. t['d1'] = { id: OPS.setCharWidthAndBounds, numArgs: 6,
  37411. variableArgs: false };
  37412. // Color
  37413. t['CS'] = { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false };
  37414. t['cs'] = { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false };
  37415. t['SC'] = { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true };
  37416. t['SCN'] = { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true };
  37417. t['sc'] = { id: OPS.setFillColor, numArgs: 4, variableArgs: true };
  37418. t['scn'] = { id: OPS.setFillColorN, numArgs: 33, variableArgs: true };
  37419. t['G'] = { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false };
  37420. t['g'] = { id: OPS.setFillGray, numArgs: 1, variableArgs: false };
  37421. t['RG'] = { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false };
  37422. t['rg'] = { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false };
  37423. t['K'] = { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false };
  37424. t['k'] = { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false };
  37425. // Shading
  37426. t['sh'] = { id: OPS.shadingFill, numArgs: 1, variableArgs: false };
  37427. // Images
  37428. t['BI'] = { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false };
  37429. t['ID'] = { id: OPS.beginImageData, numArgs: 0, variableArgs: false };
  37430. t['EI'] = { id: OPS.endInlineImage, numArgs: 1, variableArgs: false };
  37431. // XObjects
  37432. t['Do'] = { id: OPS.paintXObject, numArgs: 1, variableArgs: false };
  37433. t['MP'] = { id: OPS.markPoint, numArgs: 1, variableArgs: false };
  37434. t['DP'] = { id: OPS.markPointProps, numArgs: 2, variableArgs: false };
  37435. t['BMC'] = { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false };
  37436. t['BDC'] = { id: OPS.beginMarkedContentProps, numArgs: 2,
  37437. variableArgs: false };
  37438. t['EMC'] = { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false };
  37439. // Compatibility
  37440. t['BX'] = { id: OPS.beginCompat, numArgs: 0, variableArgs: false };
  37441. t['EX'] = { id: OPS.endCompat, numArgs: 0, variableArgs: false };
  37442. // (reserved partial commands for the lexer)
  37443. t['BM'] = null;
  37444. t['BD'] = null;
  37445. t['true'] = null;
  37446. t['fa'] = null;
  37447. t['fal'] = null;
  37448. t['fals'] = null;
  37449. t['false'] = null;
  37450. t['nu'] = null;
  37451. t['nul'] = null;
  37452. t['null'] = null;
  37453. });
  37454. function EvaluatorPreprocessor(stream, xref, stateManager) {
  37455. this.opMap = getOPMap();
  37456. // TODO(mduan): pass array of knownCommands rather than this.opMap
  37457. // dictionary
  37458. this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
  37459. this.stateManager = stateManager;
  37460. this.nonProcessedArgs = [];
  37461. }
  37462. EvaluatorPreprocessor.prototype = {
  37463. get savedStatesDepth() {
  37464. return this.stateManager.stateStack.length;
  37465. },
  37466. // |operation| is an object with two fields:
  37467. //
  37468. // - |fn| is an out param.
  37469. //
  37470. // - |args| is an inout param. On entry, it should have one of two values.
  37471. //
  37472. // - An empty array. This indicates that the caller is providing the
  37473. // array in which the args will be stored in. The caller should use
  37474. // this value if it can reuse a single array for each call to read().
  37475. //
  37476. // - |null|. This indicates that the caller needs this function to create
  37477. // the array in which any args are stored in. If there are zero args,
  37478. // this function will leave |operation.args| as |null| (thus avoiding
  37479. // allocations that would occur if we used an empty array to represent
  37480. // zero arguments). Otherwise, it will replace |null| with a new array
  37481. // containing the arguments. The caller should use this value if it
  37482. // cannot reuse an array for each call to read().
  37483. //
  37484. // These two modes are present because this function is very hot and so
  37485. // avoiding allocations where possible is worthwhile.
  37486. //
  37487. read: function EvaluatorPreprocessor_read(operation) {
  37488. var args = operation.args;
  37489. while (true) {
  37490. var obj = this.parser.getObj();
  37491. if (isCmd(obj)) {
  37492. var cmd = obj.cmd;
  37493. // Check that the command is valid
  37494. var opSpec = this.opMap[cmd];
  37495. if (!opSpec) {
  37496. warn('Unknown command "' + cmd + '"');
  37497. continue;
  37498. }
  37499. var fn = opSpec.id;
  37500. var numArgs = opSpec.numArgs;
  37501. var argsLength = args !== null ? args.length : 0;
  37502. if (!opSpec.variableArgs) {
  37503. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  37504. if (argsLength !== numArgs) {
  37505. var nonProcessedArgs = this.nonProcessedArgs;
  37506. while (argsLength > numArgs) {
  37507. nonProcessedArgs.push(args.shift());
  37508. argsLength--;
  37509. }
  37510. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  37511. if (!args) {
  37512. args = [];
  37513. }
  37514. args.unshift(nonProcessedArgs.pop());
  37515. argsLength++;
  37516. }
  37517. }
  37518. if (argsLength < numArgs) {
  37519. // If we receive too few args, it's not possible to possible
  37520. // to execute the command, so skip the command
  37521. info('Command ' + fn + ': because expected ' +
  37522. numArgs + ' args, but received ' + argsLength +
  37523. ' args; skipping');
  37524. args = null;
  37525. continue;
  37526. }
  37527. } else if (argsLength > numArgs) {
  37528. info('Command ' + fn + ': expected [0,' + numArgs +
  37529. '] args, but received ' + argsLength + ' args');
  37530. }
  37531. // TODO figure out how to type-check vararg functions
  37532. this.preprocessCommand(fn, args);
  37533. operation.fn = fn;
  37534. operation.args = args;
  37535. return true;
  37536. } else {
  37537. if (isEOF(obj)) {
  37538. return false; // no more commands
  37539. }
  37540. // argument
  37541. if (obj !== null) {
  37542. if (!args) {
  37543. args = [];
  37544. }
  37545. args.push(obj);
  37546. assert(args.length <= 33, 'Too many arguments');
  37547. }
  37548. }
  37549. }
  37550. },
  37551. preprocessCommand:
  37552. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  37553. switch (fn | 0) {
  37554. case OPS.save:
  37555. this.stateManager.save();
  37556. break;
  37557. case OPS.restore:
  37558. this.stateManager.restore();
  37559. break;
  37560. case OPS.transform:
  37561. this.stateManager.transform(args);
  37562. break;
  37563. }
  37564. }
  37565. };
  37566. return EvaluatorPreprocessor;
  37567. })();
  37568. var QueueOptimizer = (function QueueOptimizerClosure() {
  37569. function addState(parentState, pattern, fn) {
  37570. var state = parentState;
  37571. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  37572. var item = pattern[i];
  37573. state = (state[item] || (state[item] = []));
  37574. }
  37575. state[pattern[pattern.length - 1]] = fn;
  37576. }
  37577. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  37578. argsArray) {
  37579. // Handles special case of mainly LaTeX documents which use image masks to
  37580. // draw lines with the current fill style.
  37581. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  37582. // have been found at iFirstSave.
  37583. var iFirstPIMXO = iFirstSave + 2;
  37584. for (var i = 0; i < count; i++) {
  37585. var arg = argsArray[iFirstPIMXO + 4 * i];
  37586. var imageMask = arg.length === 1 && arg[0];
  37587. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  37588. (!imageMask.data.length ||
  37589. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  37590. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  37591. continue;
  37592. }
  37593. break;
  37594. }
  37595. return count - i;
  37596. }
  37597. var InitialState = [];
  37598. // This replaces (save, transform, paintInlineImageXObject, restore)+
  37599. // sequences with one |paintInlineImageXObjectGroup| operation.
  37600. addState(InitialState,
  37601. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  37602. function foundInlineImageGroup(context) {
  37603. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  37604. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  37605. var MAX_WIDTH = 1000;
  37606. var IMAGE_PADDING = 1;
  37607. var fnArray = context.fnArray, argsArray = context.argsArray;
  37608. var curr = context.iCurr;
  37609. var iFirstSave = curr - 3;
  37610. var iFirstTransform = curr - 2;
  37611. var iFirstPIIXO = curr - 1;
  37612. // Look for the quartets.
  37613. var i = iFirstSave + 4;
  37614. var ii = fnArray.length;
  37615. while (i + 3 < ii) {
  37616. if (fnArray[i] !== OPS.save ||
  37617. fnArray[i + 1] !== OPS.transform ||
  37618. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  37619. fnArray[i + 3] !== OPS.restore) {
  37620. break; // ops don't match
  37621. }
  37622. i += 4;
  37623. }
  37624. // At this point, i is the index of the first op past the last valid
  37625. // quartet.
  37626. var count = Math.min((i - iFirstSave) / 4,
  37627. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  37628. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  37629. return i;
  37630. }
  37631. // assuming that heights of those image is too small (~1 pixel)
  37632. // packing as much as possible by lines
  37633. var maxX = 0;
  37634. var map = [], maxLineHeight = 0;
  37635. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  37636. var q;
  37637. for (q = 0; q < count; q++) {
  37638. var transform = argsArray[iFirstTransform + (q << 2)];
  37639. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  37640. if (currentX + img.width > MAX_WIDTH) {
  37641. // starting new line
  37642. maxX = Math.max(maxX, currentX);
  37643. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  37644. currentX = 0;
  37645. maxLineHeight = 0;
  37646. }
  37647. map.push({
  37648. transform: transform,
  37649. x: currentX, y: currentY,
  37650. w: img.width, h: img.height
  37651. });
  37652. currentX += img.width + 2 * IMAGE_PADDING;
  37653. maxLineHeight = Math.max(maxLineHeight, img.height);
  37654. }
  37655. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  37656. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  37657. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  37658. var imgRowSize = imgWidth << 2;
  37659. for (q = 0; q < count; q++) {
  37660. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  37661. // Copy image by lines and extends pixels into padding.
  37662. var rowSize = map[q].w << 2;
  37663. var dataOffset = 0;
  37664. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  37665. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  37666. for (var k = 0, kk = map[q].h; k < kk; k++) {
  37667. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  37668. dataOffset += rowSize;
  37669. offset += imgRowSize;
  37670. }
  37671. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  37672. while (offset >= 0) {
  37673. data[offset - 4] = data[offset];
  37674. data[offset - 3] = data[offset + 1];
  37675. data[offset - 2] = data[offset + 2];
  37676. data[offset - 1] = data[offset + 3];
  37677. data[offset + rowSize] = data[offset + rowSize - 4];
  37678. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  37679. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  37680. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  37681. offset -= imgRowSize;
  37682. }
  37683. }
  37684. // Replace queue items.
  37685. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  37686. argsArray.splice(iFirstSave, count * 4,
  37687. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  37688. data: imgData }, map]);
  37689. return iFirstSave + 1;
  37690. });
  37691. // This replaces (save, transform, paintImageMaskXObject, restore)+
  37692. // sequences with one |paintImageMaskXObjectGroup| or one
  37693. // |paintImageMaskXObjectRepeat| operation.
  37694. addState(InitialState,
  37695. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  37696. function foundImageMaskGroup(context) {
  37697. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  37698. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  37699. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  37700. var fnArray = context.fnArray, argsArray = context.argsArray;
  37701. var curr = context.iCurr;
  37702. var iFirstSave = curr - 3;
  37703. var iFirstTransform = curr - 2;
  37704. var iFirstPIMXO = curr - 1;
  37705. // Look for the quartets.
  37706. var i = iFirstSave + 4;
  37707. var ii = fnArray.length;
  37708. while (i + 3 < ii) {
  37709. if (fnArray[i] !== OPS.save ||
  37710. fnArray[i + 1] !== OPS.transform ||
  37711. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  37712. fnArray[i + 3] !== OPS.restore) {
  37713. break; // ops don't match
  37714. }
  37715. i += 4;
  37716. }
  37717. // At this point, i is the index of the first op past the last valid
  37718. // quartet.
  37719. var count = (i - iFirstSave) / 4;
  37720. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  37721. argsArray);
  37722. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  37723. return i;
  37724. }
  37725. var q;
  37726. var isSameImage = false;
  37727. var iTransform, transformArgs;
  37728. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  37729. if (argsArray[iFirstTransform][1] === 0 &&
  37730. argsArray[iFirstTransform][2] === 0) {
  37731. isSameImage = true;
  37732. var firstTransformArg0 = argsArray[iFirstTransform][0];
  37733. var firstTransformArg3 = argsArray[iFirstTransform][3];
  37734. iTransform = iFirstTransform + 4;
  37735. var iPIMXO = iFirstPIMXO + 4;
  37736. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  37737. transformArgs = argsArray[iTransform];
  37738. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  37739. transformArgs[0] !== firstTransformArg0 ||
  37740. transformArgs[1] !== 0 ||
  37741. transformArgs[2] !== 0 ||
  37742. transformArgs[3] !== firstTransformArg3) {
  37743. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  37744. isSameImage = false;
  37745. } else {
  37746. count = q;
  37747. }
  37748. break; // different image or transform
  37749. }
  37750. }
  37751. }
  37752. if (isSameImage) {
  37753. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  37754. var positions = new Float32Array(count * 2);
  37755. iTransform = iFirstTransform;
  37756. for (q = 0; q < count; q++, iTransform += 4) {
  37757. transformArgs = argsArray[iTransform];
  37758. positions[(q << 1)] = transformArgs[4];
  37759. positions[(q << 1) + 1] = transformArgs[5];
  37760. }
  37761. // Replace queue items.
  37762. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  37763. argsArray.splice(iFirstSave, count * 4,
  37764. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  37765. } else {
  37766. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  37767. var images = [];
  37768. for (q = 0; q < count; q++) {
  37769. transformArgs = argsArray[iFirstTransform + (q << 2)];
  37770. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  37771. images.push({ data: maskParams.data, width: maskParams.width,
  37772. height: maskParams.height,
  37773. transform: transformArgs });
  37774. }
  37775. // Replace queue items.
  37776. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  37777. argsArray.splice(iFirstSave, count * 4, [images]);
  37778. }
  37779. return iFirstSave + 1;
  37780. });
  37781. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  37782. // with one paintImageXObjectRepeat operation, if the |transform| and
  37783. // |paintImageXObjectRepeat| ops are appropriate.
  37784. addState(InitialState,
  37785. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  37786. function (context) {
  37787. var MIN_IMAGES_IN_BLOCK = 3;
  37788. var MAX_IMAGES_IN_BLOCK = 1000;
  37789. var fnArray = context.fnArray, argsArray = context.argsArray;
  37790. var curr = context.iCurr;
  37791. var iFirstSave = curr - 3;
  37792. var iFirstTransform = curr - 2;
  37793. var iFirstPIXO = curr - 1;
  37794. var iFirstRestore = curr;
  37795. if (argsArray[iFirstTransform][1] !== 0 ||
  37796. argsArray[iFirstTransform][2] !== 0) {
  37797. return iFirstRestore + 1; // transform has the wrong form
  37798. }
  37799. // Look for the quartets.
  37800. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  37801. var firstTransformArg0 = argsArray[iFirstTransform][0];
  37802. var firstTransformArg3 = argsArray[iFirstTransform][3];
  37803. var i = iFirstSave + 4;
  37804. var ii = fnArray.length;
  37805. while (i + 3 < ii) {
  37806. if (fnArray[i] !== OPS.save ||
  37807. fnArray[i + 1] !== OPS.transform ||
  37808. fnArray[i + 2] !== OPS.paintImageXObject ||
  37809. fnArray[i + 3] !== OPS.restore) {
  37810. break; // ops don't match
  37811. }
  37812. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  37813. argsArray[i + 1][1] !== 0 ||
  37814. argsArray[i + 1][2] !== 0 ||
  37815. argsArray[i + 1][3] !== firstTransformArg3) {
  37816. break; // transforms don't match
  37817. }
  37818. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  37819. break; // images don't match
  37820. }
  37821. i += 4;
  37822. }
  37823. // At this point, i is the index of the first op past the last valid
  37824. // quartet.
  37825. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  37826. if (count < MIN_IMAGES_IN_BLOCK) {
  37827. return i;
  37828. }
  37829. // Extract the (x,y) positions from all of the matching transforms.
  37830. var positions = new Float32Array(count * 2);
  37831. var iTransform = iFirstTransform;
  37832. for (var q = 0; q < count; q++, iTransform += 4) {
  37833. var transformArgs = argsArray[iTransform];
  37834. positions[(q << 1)] = transformArgs[4];
  37835. positions[(q << 1) + 1] = transformArgs[5];
  37836. }
  37837. // Replace queue items.
  37838. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  37839. positions];
  37840. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  37841. argsArray.splice(iFirstSave, count * 4, args);
  37842. return iFirstSave + 1;
  37843. });
  37844. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  37845. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  37846. // sequences, if the font for each one is the same.
  37847. addState(InitialState,
  37848. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  37849. function (context) {
  37850. var MIN_CHARS_IN_BLOCK = 3;
  37851. var MAX_CHARS_IN_BLOCK = 1000;
  37852. var fnArray = context.fnArray, argsArray = context.argsArray;
  37853. var curr = context.iCurr;
  37854. var iFirstBeginText = curr - 4;
  37855. var iFirstSetFont = curr - 3;
  37856. var iFirstSetTextMatrix = curr - 2;
  37857. var iFirstShowText = curr - 1;
  37858. var iFirstEndText = curr;
  37859. // Look for the quintets.
  37860. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  37861. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  37862. var i = iFirstBeginText + 5;
  37863. var ii = fnArray.length;
  37864. while (i + 4 < ii) {
  37865. if (fnArray[i] !== OPS.beginText ||
  37866. fnArray[i + 1] !== OPS.setFont ||
  37867. fnArray[i + 2] !== OPS.setTextMatrix ||
  37868. fnArray[i + 3] !== OPS.showText ||
  37869. fnArray[i + 4] !== OPS.endText) {
  37870. break; // ops don't match
  37871. }
  37872. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  37873. argsArray[i + 1][1] !== firstSetFontArg1) {
  37874. break; // fonts don't match
  37875. }
  37876. i += 5;
  37877. }
  37878. // At this point, i is the index of the first op past the last valid
  37879. // quintet.
  37880. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  37881. if (count < MIN_CHARS_IN_BLOCK) {
  37882. return i;
  37883. }
  37884. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  37885. // showText, endText), include that as well. (E.g. <something> might be
  37886. // |dependency|.)
  37887. var iFirst = iFirstBeginText;
  37888. if (iFirstBeginText >= 4 &&
  37889. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  37890. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  37891. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  37892. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  37893. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  37894. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  37895. count++;
  37896. iFirst -= 5;
  37897. }
  37898. // Remove (endText, beginText, setFont) trios.
  37899. var iEndText = iFirst + 4;
  37900. for (var q = 1; q < count; q++) {
  37901. fnArray.splice(iEndText, 3);
  37902. argsArray.splice(iEndText, 3);
  37903. iEndText += 2;
  37904. }
  37905. return iEndText + 1;
  37906. });
  37907. function QueueOptimizer() {}
  37908. QueueOptimizer.prototype = {
  37909. optimize: function QueueOptimizer_optimize(queue) {
  37910. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  37911. var context = {
  37912. iCurr: 0,
  37913. fnArray: fnArray,
  37914. argsArray: argsArray
  37915. };
  37916. var state;
  37917. var i = 0, ii = fnArray.length;
  37918. while (i < ii) {
  37919. state = (state || InitialState)[fnArray[i]];
  37920. if (typeof state === 'function') { // we found some handler
  37921. context.iCurr = i;
  37922. // state() returns the index of the first non-matching op (if we
  37923. // didn't match) or the first op past the modified ops (if we did
  37924. // match and replace).
  37925. i = state(context);
  37926. state = undefined; // reset the state machine
  37927. ii = context.fnArray.length;
  37928. } else {
  37929. i++;
  37930. }
  37931. }
  37932. }
  37933. };
  37934. return QueueOptimizer;
  37935. })();
  37936. exports.OperatorList = OperatorList;
  37937. exports.PartialEvaluator = PartialEvaluator;
  37938. }));
  37939. (function (root, factory) {
  37940. {
  37941. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  37942. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  37943. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  37944. }
  37945. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  37946. coreColorSpace, coreObj, coreEvaluator) {
  37947. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  37948. var AnnotationFieldFlag = sharedUtil.AnnotationFieldFlag;
  37949. var AnnotationFlag = sharedUtil.AnnotationFlag;
  37950. var AnnotationType = sharedUtil.AnnotationType;
  37951. var OPS = sharedUtil.OPS;
  37952. var Util = sharedUtil.Util;
  37953. var isBool = sharedUtil.isBool;
  37954. var isString = sharedUtil.isString;
  37955. var isArray = sharedUtil.isArray;
  37956. var isInt = sharedUtil.isInt;
  37957. var isValidUrl = sharedUtil.isValidUrl;
  37958. var stringToBytes = sharedUtil.stringToBytes;
  37959. var stringToPDFString = sharedUtil.stringToPDFString;
  37960. var stringToUTF8String = sharedUtil.stringToUTF8String;
  37961. var warn = sharedUtil.warn;
  37962. var Dict = corePrimitives.Dict;
  37963. var isDict = corePrimitives.isDict;
  37964. var isName = corePrimitives.isName;
  37965. var isRef = corePrimitives.isRef;
  37966. var Stream = coreStream.Stream;
  37967. var ColorSpace = coreColorSpace.ColorSpace;
  37968. var ObjectLoader = coreObj.ObjectLoader;
  37969. var FileSpec = coreObj.FileSpec;
  37970. var OperatorList = coreEvaluator.OperatorList;
  37971. /**
  37972. * @class
  37973. * @alias AnnotationFactory
  37974. */
  37975. function AnnotationFactory() {}
  37976. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  37977. /**
  37978. * @param {XRef} xref
  37979. * @param {Object} ref
  37980. * @param {string} uniquePrefix
  37981. * @param {Object} idCounters
  37982. * @returns {Annotation}
  37983. */
  37984. create: function AnnotationFactory_create(xref, ref,
  37985. uniquePrefix, idCounters) {
  37986. var dict = xref.fetchIfRef(ref);
  37987. if (!isDict(dict)) {
  37988. return;
  37989. }
  37990. var id = isRef(ref) ? ref.toString() :
  37991. 'annot_' + (uniquePrefix || '') + (++idCounters.obj);
  37992. // Determine the annotation's subtype.
  37993. var subtype = dict.get('Subtype');
  37994. subtype = isName(subtype) ? subtype.name : null;
  37995. // Return the right annotation object based on the subtype and field type.
  37996. var parameters = {
  37997. xref: xref,
  37998. dict: dict,
  37999. ref: isRef(ref) ? ref : null,
  38000. subtype: subtype,
  38001. id: id,
  38002. };
  38003. switch (subtype) {
  38004. case 'Link':
  38005. return new LinkAnnotation(parameters);
  38006. case 'Text':
  38007. return new TextAnnotation(parameters);
  38008. case 'Widget':
  38009. var fieldType = Util.getInheritableProperty(dict, 'FT');
  38010. fieldType = isName(fieldType) ? fieldType.name : null;
  38011. switch (fieldType) {
  38012. case 'Tx':
  38013. return new TextWidgetAnnotation(parameters);
  38014. }
  38015. warn('Unimplemented widget field type "' + fieldType + '", ' +
  38016. 'falling back to base field type.');
  38017. return new WidgetAnnotation(parameters);
  38018. case 'Popup':
  38019. return new PopupAnnotation(parameters);
  38020. case 'Highlight':
  38021. return new HighlightAnnotation(parameters);
  38022. case 'Underline':
  38023. return new UnderlineAnnotation(parameters);
  38024. case 'Squiggly':
  38025. return new SquigglyAnnotation(parameters);
  38026. case 'StrikeOut':
  38027. return new StrikeOutAnnotation(parameters);
  38028. case 'FileAttachment':
  38029. return new FileAttachmentAnnotation(parameters);
  38030. default:
  38031. if (!subtype) {
  38032. warn('Annotation is missing the required /Subtype.');
  38033. } else {
  38034. warn('Unimplemented annotation type "' + subtype + '", ' +
  38035. 'falling back to base annotation.');
  38036. }
  38037. return new Annotation(parameters);
  38038. }
  38039. }
  38040. };
  38041. var Annotation = (function AnnotationClosure() {
  38042. // 12.5.5: Algorithm: Appearance streams
  38043. function getTransformMatrix(rect, bbox, matrix) {
  38044. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  38045. var minX = bounds[0];
  38046. var minY = bounds[1];
  38047. var maxX = bounds[2];
  38048. var maxY = bounds[3];
  38049. if (minX === maxX || minY === maxY) {
  38050. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  38051. // just apply the transform for rect
  38052. return [1, 0, 0, 1, rect[0], rect[1]];
  38053. }
  38054. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  38055. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  38056. return [
  38057. xRatio,
  38058. 0,
  38059. 0,
  38060. yRatio,
  38061. rect[0] - minX * xRatio,
  38062. rect[1] - minY * yRatio
  38063. ];
  38064. }
  38065. function getDefaultAppearance(dict) {
  38066. var appearanceState = dict.get('AP');
  38067. if (!isDict(appearanceState)) {
  38068. return;
  38069. }
  38070. var appearance;
  38071. var appearances = appearanceState.get('N');
  38072. if (isDict(appearances)) {
  38073. var as = dict.get('AS');
  38074. if (as && appearances.has(as.name)) {
  38075. appearance = appearances.get(as.name);
  38076. }
  38077. } else {
  38078. appearance = appearances;
  38079. }
  38080. return appearance;
  38081. }
  38082. function Annotation(params) {
  38083. var dict = params.dict;
  38084. this.setFlags(dict.get('F'));
  38085. this.setRectangle(dict.getArray('Rect'));
  38086. this.setColor(dict.getArray('C'));
  38087. this.setBorderStyle(dict);
  38088. this.appearance = getDefaultAppearance(dict);
  38089. // Expose public properties using a data object.
  38090. this.data = {};
  38091. this.data.id = params.id;
  38092. this.data.subtype = params.subtype;
  38093. this.data.annotationFlags = this.flags;
  38094. this.data.rect = this.rectangle;
  38095. this.data.color = this.color;
  38096. this.data.borderStyle = this.borderStyle;
  38097. this.data.hasAppearance = !!this.appearance;
  38098. }
  38099. Annotation.prototype = {
  38100. /**
  38101. * @private
  38102. */
  38103. _hasFlag: function Annotation_hasFlag(flags, flag) {
  38104. return !!(flags & flag);
  38105. },
  38106. /**
  38107. * @private
  38108. */
  38109. _isViewable: function Annotation_isViewable(flags) {
  38110. return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
  38111. !this._hasFlag(flags, AnnotationFlag.HIDDEN) &&
  38112. !this._hasFlag(flags, AnnotationFlag.NOVIEW);
  38113. },
  38114. /**
  38115. * @private
  38116. */
  38117. _isPrintable: function AnnotationFlag_isPrintable(flags) {
  38118. return this._hasFlag(flags, AnnotationFlag.PRINT) &&
  38119. !this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
  38120. !this._hasFlag(flags, AnnotationFlag.HIDDEN);
  38121. },
  38122. /**
  38123. * @return {boolean}
  38124. */
  38125. get viewable() {
  38126. if (this.flags === 0) {
  38127. return true;
  38128. }
  38129. return this._isViewable(this.flags);
  38130. },
  38131. /**
  38132. * @return {boolean}
  38133. */
  38134. get printable() {
  38135. if (this.flags === 0) {
  38136. return false;
  38137. }
  38138. return this._isPrintable(this.flags);
  38139. },
  38140. /**
  38141. * Set the flags.
  38142. *
  38143. * @public
  38144. * @memberof Annotation
  38145. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  38146. * characteristics
  38147. * @see {@link shared/util.js}
  38148. */
  38149. setFlags: function Annotation_setFlags(flags) {
  38150. this.flags = (isInt(flags) && flags > 0) ? flags : 0;
  38151. },
  38152. /**
  38153. * Check if a provided flag is set.
  38154. *
  38155. * @public
  38156. * @memberof Annotation
  38157. * @param {number} flag - Hexadecimal representation for an annotation
  38158. * characteristic
  38159. * @return {boolean}
  38160. * @see {@link shared/util.js}
  38161. */
  38162. hasFlag: function Annotation_hasFlag(flag) {
  38163. return this._hasFlag(this.flags, flag);
  38164. },
  38165. /**
  38166. * Set the rectangle.
  38167. *
  38168. * @public
  38169. * @memberof Annotation
  38170. * @param {Array} rectangle - The rectangle array with exactly four entries
  38171. */
  38172. setRectangle: function Annotation_setRectangle(rectangle) {
  38173. if (isArray(rectangle) && rectangle.length === 4) {
  38174. this.rectangle = Util.normalizeRect(rectangle);
  38175. } else {
  38176. this.rectangle = [0, 0, 0, 0];
  38177. }
  38178. },
  38179. /**
  38180. * Set the color and take care of color space conversion.
  38181. *
  38182. * @public
  38183. * @memberof Annotation
  38184. * @param {Array} color - The color array containing either 0
  38185. * (transparent), 1 (grayscale), 3 (RGB) or
  38186. * 4 (CMYK) elements
  38187. */
  38188. setColor: function Annotation_setColor(color) {
  38189. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  38190. if (!isArray(color)) {
  38191. this.color = rgbColor;
  38192. return;
  38193. }
  38194. switch (color.length) {
  38195. case 0: // Transparent, which we indicate with a null value
  38196. this.color = null;
  38197. break;
  38198. case 1: // Convert grayscale to RGB
  38199. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  38200. this.color = rgbColor;
  38201. break;
  38202. case 3: // Convert RGB percentages to RGB
  38203. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  38204. this.color = rgbColor;
  38205. break;
  38206. case 4: // Convert CMYK to RGB
  38207. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  38208. this.color = rgbColor;
  38209. break;
  38210. default:
  38211. this.color = rgbColor;
  38212. break;
  38213. }
  38214. },
  38215. /**
  38216. * Set the border style (as AnnotationBorderStyle object).
  38217. *
  38218. * @public
  38219. * @memberof Annotation
  38220. * @param {Dict} borderStyle - The border style dictionary
  38221. */
  38222. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  38223. this.borderStyle = new AnnotationBorderStyle();
  38224. if (!isDict(borderStyle)) {
  38225. return;
  38226. }
  38227. if (borderStyle.has('BS')) {
  38228. var dict = borderStyle.get('BS');
  38229. var dictType = dict.get('Type');
  38230. if (!dictType || isName(dictType, 'Border')) {
  38231. this.borderStyle.setWidth(dict.get('W'));
  38232. this.borderStyle.setStyle(dict.get('S'));
  38233. this.borderStyle.setDashArray(dict.getArray('D'));
  38234. }
  38235. } else if (borderStyle.has('Border')) {
  38236. var array = borderStyle.getArray('Border');
  38237. if (isArray(array) && array.length >= 3) {
  38238. this.borderStyle.setHorizontalCornerRadius(array[0]);
  38239. this.borderStyle.setVerticalCornerRadius(array[1]);
  38240. this.borderStyle.setWidth(array[2]);
  38241. if (array.length === 4) { // Dash array available
  38242. this.borderStyle.setDashArray(array[3]);
  38243. }
  38244. }
  38245. } else {
  38246. // There are no border entries in the dictionary. According to the
  38247. // specification, we should draw a solid border of width 1 in that
  38248. // case, but Adobe Reader did not implement that part of the
  38249. // specification and instead draws no border at all, so we do the same.
  38250. // See also https://github.com/mozilla/pdf.js/issues/6179.
  38251. this.borderStyle.setWidth(0);
  38252. }
  38253. },
  38254. /**
  38255. * Prepare the annotation for working with a popup in the display layer.
  38256. *
  38257. * @private
  38258. * @memberof Annotation
  38259. * @param {Dict} dict - The annotation's data dictionary
  38260. */
  38261. _preparePopup: function Annotation_preparePopup(dict) {
  38262. if (!dict.has('C')) {
  38263. // Fall back to the default background color.
  38264. this.data.color = null;
  38265. }
  38266. this.data.hasPopup = dict.has('Popup');
  38267. this.data.title = stringToPDFString(dict.get('T') || '');
  38268. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  38269. },
  38270. loadResources: function Annotation_loadResources(keys) {
  38271. return new Promise(function (resolve, reject) {
  38272. this.appearance.dict.getAsync('Resources').then(function (resources) {
  38273. if (!resources) {
  38274. resolve();
  38275. return;
  38276. }
  38277. var objectLoader = new ObjectLoader(resources.map,
  38278. keys,
  38279. resources.xref);
  38280. objectLoader.load().then(function() {
  38281. resolve(resources);
  38282. }, reject);
  38283. }, reject);
  38284. }.bind(this));
  38285. },
  38286. getOperatorList: function Annotation_getOperatorList(evaluator, task,
  38287. renderForms) {
  38288. if (!this.appearance) {
  38289. return Promise.resolve(new OperatorList());
  38290. }
  38291. var data = this.data;
  38292. var appearanceDict = this.appearance.dict;
  38293. var resourcesPromise = this.loadResources([
  38294. 'ExtGState',
  38295. 'ColorSpace',
  38296. 'Pattern',
  38297. 'Shading',
  38298. 'XObject',
  38299. 'Font'
  38300. // ProcSet
  38301. // Properties
  38302. ]);
  38303. var bbox = appearanceDict.getArray('BBox') || [0, 0, 1, 1];
  38304. var matrix = appearanceDict.getArray('Matrix') || [1, 0, 0, 1, 0 ,0];
  38305. var transform = getTransformMatrix(data.rect, bbox, matrix);
  38306. var self = this;
  38307. return resourcesPromise.then(function(resources) {
  38308. var opList = new OperatorList();
  38309. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  38310. return evaluator.getOperatorList(self.appearance, task,
  38311. resources, opList).
  38312. then(function () {
  38313. opList.addOp(OPS.endAnnotation, []);
  38314. self.appearance.reset();
  38315. return opList;
  38316. });
  38317. });
  38318. }
  38319. };
  38320. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  38321. annotations, opList, partialEvaluator, task, intent, renderForms) {
  38322. var annotationPromises = [];
  38323. for (var i = 0, n = annotations.length; i < n; ++i) {
  38324. if ((intent === 'display' && annotations[i].viewable) ||
  38325. (intent === 'print' && annotations[i].printable)) {
  38326. annotationPromises.push(
  38327. annotations[i].getOperatorList(partialEvaluator, task, renderForms));
  38328. }
  38329. }
  38330. return Promise.all(annotationPromises).then(function(operatorLists) {
  38331. opList.addOp(OPS.beginAnnotations, []);
  38332. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  38333. opList.addOpList(operatorLists[i]);
  38334. }
  38335. opList.addOp(OPS.endAnnotations, []);
  38336. });
  38337. };
  38338. return Annotation;
  38339. })();
  38340. /**
  38341. * Contains all data regarding an annotation's border style.
  38342. *
  38343. * @class
  38344. */
  38345. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  38346. /**
  38347. * @constructor
  38348. * @private
  38349. */
  38350. function AnnotationBorderStyle() {
  38351. this.width = 1;
  38352. this.style = AnnotationBorderStyleType.SOLID;
  38353. this.dashArray = [3];
  38354. this.horizontalCornerRadius = 0;
  38355. this.verticalCornerRadius = 0;
  38356. }
  38357. AnnotationBorderStyle.prototype = {
  38358. /**
  38359. * Set the width.
  38360. *
  38361. * @public
  38362. * @memberof AnnotationBorderStyle
  38363. * @param {integer} width - The width
  38364. */
  38365. setWidth: function AnnotationBorderStyle_setWidth(width) {
  38366. if (width === (width | 0)) {
  38367. this.width = width;
  38368. }
  38369. },
  38370. /**
  38371. * Set the style.
  38372. *
  38373. * @public
  38374. * @memberof AnnotationBorderStyle
  38375. * @param {Object} style - The style object
  38376. * @see {@link shared/util.js}
  38377. */
  38378. setStyle: function AnnotationBorderStyle_setStyle(style) {
  38379. if (!style) {
  38380. return;
  38381. }
  38382. switch (style.name) {
  38383. case 'S':
  38384. this.style = AnnotationBorderStyleType.SOLID;
  38385. break;
  38386. case 'D':
  38387. this.style = AnnotationBorderStyleType.DASHED;
  38388. break;
  38389. case 'B':
  38390. this.style = AnnotationBorderStyleType.BEVELED;
  38391. break;
  38392. case 'I':
  38393. this.style = AnnotationBorderStyleType.INSET;
  38394. break;
  38395. case 'U':
  38396. this.style = AnnotationBorderStyleType.UNDERLINE;
  38397. break;
  38398. default:
  38399. break;
  38400. }
  38401. },
  38402. /**
  38403. * Set the dash array.
  38404. *
  38405. * @public
  38406. * @memberof AnnotationBorderStyle
  38407. * @param {Array} dashArray - The dash array with at least one element
  38408. */
  38409. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  38410. // We validate the dash array, but we do not use it because CSS does not
  38411. // allow us to change spacing of dashes. For more information, visit
  38412. // http://www.w3.org/TR/css3-background/#the-border-style.
  38413. if (isArray(dashArray) && dashArray.length > 0) {
  38414. // According to the PDF specification: the elements in a dashArray
  38415. // shall be numbers that are nonnegative and not all equal to zero.
  38416. var isValid = true;
  38417. var allZeros = true;
  38418. for (var i = 0, len = dashArray.length; i < len; i++) {
  38419. var element = dashArray[i];
  38420. var validNumber = (+element >= 0);
  38421. if (!validNumber) {
  38422. isValid = false;
  38423. break;
  38424. } else if (element > 0) {
  38425. allZeros = false;
  38426. }
  38427. }
  38428. if (isValid && !allZeros) {
  38429. this.dashArray = dashArray;
  38430. } else {
  38431. this.width = 0; // Adobe behavior when the array is invalid.
  38432. }
  38433. } else if (dashArray) {
  38434. this.width = 0; // Adobe behavior when the array is invalid.
  38435. }
  38436. },
  38437. /**
  38438. * Set the horizontal corner radius (from a Border dictionary).
  38439. *
  38440. * @public
  38441. * @memberof AnnotationBorderStyle
  38442. * @param {integer} radius - The horizontal corner radius
  38443. */
  38444. setHorizontalCornerRadius:
  38445. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  38446. if (radius === (radius | 0)) {
  38447. this.horizontalCornerRadius = radius;
  38448. }
  38449. },
  38450. /**
  38451. * Set the vertical corner radius (from a Border dictionary).
  38452. *
  38453. * @public
  38454. * @memberof AnnotationBorderStyle
  38455. * @param {integer} radius - The vertical corner radius
  38456. */
  38457. setVerticalCornerRadius:
  38458. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  38459. if (radius === (radius | 0)) {
  38460. this.verticalCornerRadius = radius;
  38461. }
  38462. }
  38463. };
  38464. return AnnotationBorderStyle;
  38465. })();
  38466. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  38467. function WidgetAnnotation(params) {
  38468. Annotation.call(this, params);
  38469. var dict = params.dict;
  38470. var data = this.data;
  38471. data.annotationType = AnnotationType.WIDGET;
  38472. data.fieldValue = stringToPDFString(
  38473. Util.getInheritableProperty(dict, 'V') || '');
  38474. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  38475. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  38476. var fieldType = Util.getInheritableProperty(dict, 'FT');
  38477. data.fieldType = isName(fieldType) ? fieldType.name : null;
  38478. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  38479. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff');
  38480. if (!isInt(data.fieldFlags) || data.fieldFlags < 0) {
  38481. data.fieldFlags = 0;
  38482. }
  38483. // Hide signatures because we cannot validate them.
  38484. if (data.fieldType === 'Sig') {
  38485. this.setFlags(AnnotationFlag.HIDDEN);
  38486. }
  38487. // Building the full field name by collecting the field and
  38488. // its ancestors 'T' data and joining them using '.'.
  38489. var fieldName = [];
  38490. var namedItem = dict;
  38491. var ref = params.ref;
  38492. while (namedItem) {
  38493. var parent = namedItem.get('Parent');
  38494. var parentRef = namedItem.getRaw('Parent');
  38495. var name = namedItem.get('T');
  38496. if (name) {
  38497. fieldName.unshift(stringToPDFString(name));
  38498. } else if (parent && ref) {
  38499. // The field name is absent, that means more than one field
  38500. // with the same name may exist. Replacing the empty name
  38501. // with the '`' plus index in the parent's 'Kids' array.
  38502. // This is not in the PDF spec but necessary to id the
  38503. // the input controls.
  38504. var kids = parent.get('Kids');
  38505. var j, jj;
  38506. for (j = 0, jj = kids.length; j < jj; j++) {
  38507. var kidRef = kids[j];
  38508. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  38509. break;
  38510. }
  38511. }
  38512. fieldName.unshift('`' + j);
  38513. }
  38514. namedItem = parent;
  38515. ref = parentRef;
  38516. }
  38517. data.fullName = fieldName.join('.');
  38518. }
  38519. Util.inherit(WidgetAnnotation, Annotation, {
  38520. /**
  38521. * Check if a provided field flag is set.
  38522. *
  38523. * @public
  38524. * @memberof WidgetAnnotation
  38525. * @param {number} flag - Hexadecimal representation for an annotation
  38526. * field characteristic
  38527. * @return {boolean}
  38528. * @see {@link shared/util.js}
  38529. */
  38530. hasFieldFlag: function WidgetAnnotation_hasFieldFlag(flag) {
  38531. return !!(this.data.fieldFlags & flag);
  38532. },
  38533. });
  38534. return WidgetAnnotation;
  38535. })();
  38536. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  38537. function TextWidgetAnnotation(params) {
  38538. WidgetAnnotation.call(this, params);
  38539. // Determine the alignment of text in the field.
  38540. var alignment = Util.getInheritableProperty(params.dict, 'Q');
  38541. if (!isInt(alignment) || alignment < 0 || alignment > 2) {
  38542. alignment = null;
  38543. }
  38544. this.data.textAlignment = alignment;
  38545. // Determine the maximum length of text in the field.
  38546. var maximumLength = Util.getInheritableProperty(params.dict, 'MaxLen');
  38547. if (!isInt(maximumLength) || maximumLength < 0) {
  38548. maximumLength = null;
  38549. }
  38550. this.data.maxLen = maximumLength;
  38551. // Process field flags for the display layer.
  38552. this.data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
  38553. this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
  38554. this.data.comb = this.hasFieldFlag(AnnotationFieldFlag.COMB) &&
  38555. !this.hasFieldFlag(AnnotationFieldFlag.MULTILINE) &&
  38556. !this.hasFieldFlag(AnnotationFieldFlag.PASSWORD) &&
  38557. !this.hasFieldFlag(AnnotationFieldFlag.FILESELECT) &&
  38558. this.data.maxLen !== null;
  38559. }
  38560. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  38561. getOperatorList:
  38562. function TextWidgetAnnotation_getOperatorList(evaluator, task,
  38563. renderForms) {
  38564. var operatorList = new OperatorList();
  38565. // Do not render form elements on the canvas when interactive forms are
  38566. // enabled. The display layer is responsible for rendering them instead.
  38567. if (renderForms) {
  38568. return Promise.resolve(operatorList);
  38569. }
  38570. if (this.appearance) {
  38571. return Annotation.prototype.getOperatorList.call(this, evaluator, task,
  38572. renderForms);
  38573. }
  38574. // Even if there is an appearance stream, ignore it. This is the
  38575. // behaviour used by Adobe Reader.
  38576. if (!this.data.defaultAppearance) {
  38577. return Promise.resolve(operatorList);
  38578. }
  38579. var stream = new Stream(stringToBytes(this.data.defaultAppearance));
  38580. return evaluator.getOperatorList(stream, task, this.fieldResources,
  38581. operatorList).
  38582. then(function () {
  38583. return operatorList;
  38584. });
  38585. }
  38586. });
  38587. return TextWidgetAnnotation;
  38588. })();
  38589. var TextAnnotation = (function TextAnnotationClosure() {
  38590. var DEFAULT_ICON_SIZE = 22; // px
  38591. function TextAnnotation(parameters) {
  38592. Annotation.call(this, parameters);
  38593. this.data.annotationType = AnnotationType.TEXT;
  38594. if (this.data.hasAppearance) {
  38595. this.data.name = 'NoIcon';
  38596. } else {
  38597. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  38598. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  38599. this.data.name = parameters.dict.has('Name') ?
  38600. parameters.dict.get('Name').name : 'Note';
  38601. }
  38602. this._preparePopup(parameters.dict);
  38603. }
  38604. Util.inherit(TextAnnotation, Annotation, {});
  38605. return TextAnnotation;
  38606. })();
  38607. var LinkAnnotation = (function LinkAnnotationClosure() {
  38608. function LinkAnnotation(params) {
  38609. Annotation.call(this, params);
  38610. var dict = params.dict;
  38611. var data = this.data;
  38612. data.annotationType = AnnotationType.LINK;
  38613. var action = dict.get('A'), url, dest;
  38614. if (action && isDict(action)) {
  38615. var linkType = action.get('S').name;
  38616. switch (linkType) {
  38617. case 'URI':
  38618. url = action.get('URI');
  38619. if (isName(url)) {
  38620. // Some bad PDFs do not put parentheses around relative URLs.
  38621. url = '/' + url.name;
  38622. } else if (url) {
  38623. url = addDefaultProtocolToUrl(url);
  38624. }
  38625. // TODO: pdf spec mentions urls can be relative to a Base
  38626. // entry in the dictionary.
  38627. break;
  38628. case 'GoTo':
  38629. dest = action.get('D');
  38630. break;
  38631. case 'GoToR':
  38632. var urlDict = action.get('F');
  38633. if (isDict(urlDict)) {
  38634. // We assume that we found a FileSpec dictionary
  38635. // and fetch the URL without checking any further.
  38636. url = urlDict.get('F') || null;
  38637. } else if (isString(urlDict)) {
  38638. url = urlDict;
  38639. }
  38640. // NOTE: the destination is relative to the *remote* document.
  38641. var remoteDest = action.get('D');
  38642. if (remoteDest) {
  38643. if (isName(remoteDest)) {
  38644. remoteDest = remoteDest.name;
  38645. }
  38646. if (isString(url)) {
  38647. var baseUrl = url.split('#')[0];
  38648. if (isString(remoteDest)) {
  38649. // In practice, a named destination may contain only a number.
  38650. // If that happens, use the '#nameddest=' form to avoid the link
  38651. // redirecting to a page, instead of the correct destination.
  38652. url = baseUrl + '#' +
  38653. (/^\d+$/.test(remoteDest) ? 'nameddest=' : '') + remoteDest;
  38654. } else if (isArray(remoteDest)) {
  38655. url = baseUrl + '#' + JSON.stringify(remoteDest);
  38656. }
  38657. }
  38658. }
  38659. // The 'NewWindow' property, equal to `LinkTarget.BLANK`.
  38660. var newWindow = action.get('NewWindow');
  38661. if (isBool(newWindow)) {
  38662. data.newWindow = newWindow;
  38663. }
  38664. break;
  38665. case 'Named':
  38666. data.action = action.get('N').name;
  38667. break;
  38668. default:
  38669. warn('unrecognized link type: ' + linkType);
  38670. }
  38671. } else if (dict.has('Dest')) { // Simple destination link.
  38672. dest = dict.get('Dest');
  38673. }
  38674. if (url) {
  38675. if (isValidUrl(url, /* allowRelative = */ false)) {
  38676. data.url = tryConvertUrlEncoding(url);
  38677. }
  38678. }
  38679. if (dest) {
  38680. data.dest = isName(dest) ? dest.name : dest;
  38681. }
  38682. }
  38683. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  38684. function addDefaultProtocolToUrl(url) {
  38685. if (isString(url) && url.indexOf('www.') === 0) {
  38686. return ('http://' + url);
  38687. }
  38688. return url;
  38689. }
  38690. function tryConvertUrlEncoding(url) {
  38691. // According to ISO 32000-1:2008, section 12.6.4.7, URIs should be encoded
  38692. // in 7-bit ASCII. Some bad PDFs use UTF-8 encoding, see Bugzilla 1122280.
  38693. try {
  38694. return stringToUTF8String(url);
  38695. } catch (e) {
  38696. return url;
  38697. }
  38698. }
  38699. Util.inherit(LinkAnnotation, Annotation, {});
  38700. return LinkAnnotation;
  38701. })();
  38702. var PopupAnnotation = (function PopupAnnotationClosure() {
  38703. function PopupAnnotation(parameters) {
  38704. Annotation.call(this, parameters);
  38705. this.data.annotationType = AnnotationType.POPUP;
  38706. var dict = parameters.dict;
  38707. var parentItem = dict.get('Parent');
  38708. if (!parentItem) {
  38709. warn('Popup annotation has a missing or invalid parent annotation.');
  38710. return;
  38711. }
  38712. this.data.parentId = dict.getRaw('Parent').toString();
  38713. this.data.title = stringToPDFString(parentItem.get('T') || '');
  38714. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  38715. if (!parentItem.has('C')) {
  38716. // Fall back to the default background color.
  38717. this.data.color = null;
  38718. } else {
  38719. this.setColor(parentItem.getArray('C'));
  38720. this.data.color = this.color;
  38721. }
  38722. // If the Popup annotation is not viewable, but the parent annotation is,
  38723. // that is most likely a bug. Fallback to inherit the flags from the parent
  38724. // annotation (this is consistent with the behaviour in Adobe Reader).
  38725. if (!this.viewable) {
  38726. var parentFlags = parentItem.get('F');
  38727. if (this._isViewable(parentFlags)) {
  38728. this.setFlags(parentFlags);
  38729. }
  38730. }
  38731. }
  38732. Util.inherit(PopupAnnotation, Annotation, {});
  38733. return PopupAnnotation;
  38734. })();
  38735. var HighlightAnnotation = (function HighlightAnnotationClosure() {
  38736. function HighlightAnnotation(parameters) {
  38737. Annotation.call(this, parameters);
  38738. this.data.annotationType = AnnotationType.HIGHLIGHT;
  38739. this._preparePopup(parameters.dict);
  38740. // PDF viewers completely ignore any border styles.
  38741. this.data.borderStyle.setWidth(0);
  38742. }
  38743. Util.inherit(HighlightAnnotation, Annotation, {});
  38744. return HighlightAnnotation;
  38745. })();
  38746. var UnderlineAnnotation = (function UnderlineAnnotationClosure() {
  38747. function UnderlineAnnotation(parameters) {
  38748. Annotation.call(this, parameters);
  38749. this.data.annotationType = AnnotationType.UNDERLINE;
  38750. this._preparePopup(parameters.dict);
  38751. // PDF viewers completely ignore any border styles.
  38752. this.data.borderStyle.setWidth(0);
  38753. }
  38754. Util.inherit(UnderlineAnnotation, Annotation, {});
  38755. return UnderlineAnnotation;
  38756. })();
  38757. var SquigglyAnnotation = (function SquigglyAnnotationClosure() {
  38758. function SquigglyAnnotation(parameters) {
  38759. Annotation.call(this, parameters);
  38760. this.data.annotationType = AnnotationType.SQUIGGLY;
  38761. this._preparePopup(parameters.dict);
  38762. // PDF viewers completely ignore any border styles.
  38763. this.data.borderStyle.setWidth(0);
  38764. }
  38765. Util.inherit(SquigglyAnnotation, Annotation, {});
  38766. return SquigglyAnnotation;
  38767. })();
  38768. var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() {
  38769. function StrikeOutAnnotation(parameters) {
  38770. Annotation.call(this, parameters);
  38771. this.data.annotationType = AnnotationType.STRIKEOUT;
  38772. this._preparePopup(parameters.dict);
  38773. // PDF viewers completely ignore any border styles.
  38774. this.data.borderStyle.setWidth(0);
  38775. }
  38776. Util.inherit(StrikeOutAnnotation, Annotation, {});
  38777. return StrikeOutAnnotation;
  38778. })();
  38779. var FileAttachmentAnnotation = (function FileAttachmentAnnotationClosure() {
  38780. function FileAttachmentAnnotation(parameters) {
  38781. Annotation.call(this, parameters);
  38782. var file = new FileSpec(parameters.dict.get('FS'), parameters.xref);
  38783. this.data.annotationType = AnnotationType.FILEATTACHMENT;
  38784. this.data.file = file.serializable;
  38785. this._preparePopup(parameters.dict);
  38786. }
  38787. Util.inherit(FileAttachmentAnnotation, Annotation, {});
  38788. return FileAttachmentAnnotation;
  38789. })();
  38790. exports.Annotation = Annotation;
  38791. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  38792. exports.AnnotationFactory = AnnotationFactory;
  38793. }));
  38794. (function (root, factory) {
  38795. {
  38796. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  38797. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  38798. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  38799. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  38800. }
  38801. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  38802. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  38803. var MissingDataException = sharedUtil.MissingDataException;
  38804. var Util = sharedUtil.Util;
  38805. var assert = sharedUtil.assert;
  38806. var error = sharedUtil.error;
  38807. var info = sharedUtil.info;
  38808. var isArray = sharedUtil.isArray;
  38809. var isArrayBuffer = sharedUtil.isArrayBuffer;
  38810. var isString = sharedUtil.isString;
  38811. var shadow = sharedUtil.shadow;
  38812. var stringToBytes = sharedUtil.stringToBytes;
  38813. var stringToPDFString = sharedUtil.stringToPDFString;
  38814. var warn = sharedUtil.warn;
  38815. var isSpace = sharedUtil.isSpace;
  38816. var Dict = corePrimitives.Dict;
  38817. var isDict = corePrimitives.isDict;
  38818. var isName = corePrimitives.isName;
  38819. var isStream = corePrimitives.isStream;
  38820. var NullStream = coreStream.NullStream;
  38821. var Stream = coreStream.Stream;
  38822. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  38823. var Catalog = coreObj.Catalog;
  38824. var ObjectLoader = coreObj.ObjectLoader;
  38825. var XRef = coreObj.XRef;
  38826. var Linearization = coreParser.Linearization;
  38827. var calculateMD5 = coreCrypto.calculateMD5;
  38828. var OperatorList = coreEvaluator.OperatorList;
  38829. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  38830. var Annotation = coreAnnotation.Annotation;
  38831. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  38832. var Page = (function PageClosure() {
  38833. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  38834. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  38835. this.pdfManager = pdfManager;
  38836. this.pageIndex = pageIndex;
  38837. this.pageDict = pageDict;
  38838. this.xref = xref;
  38839. this.ref = ref;
  38840. this.fontCache = fontCache;
  38841. this.uniquePrefix = 'p' + this.pageIndex + '_';
  38842. this.idCounters = {
  38843. obj: 0
  38844. };
  38845. this.evaluatorOptions = pdfManager.evaluatorOptions;
  38846. this.resourcesPromise = null;
  38847. }
  38848. Page.prototype = {
  38849. getPageProp: function Page_getPageProp(key) {
  38850. return this.pageDict.get(key);
  38851. },
  38852. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  38853. var dict = this.pageDict, valueArray = null, loopCount = 0;
  38854. var MAX_LOOP_COUNT = 100;
  38855. // Always walk up the entire parent chain, to be able to find
  38856. // e.g. \Resources placed on multiple levels of the tree.
  38857. while (dict) {
  38858. var value = dict.get(key);
  38859. if (value) {
  38860. if (!valueArray) {
  38861. valueArray = [];
  38862. }
  38863. valueArray.push(value);
  38864. }
  38865. if (++loopCount > MAX_LOOP_COUNT) {
  38866. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  38867. break;
  38868. }
  38869. dict = dict.get('Parent');
  38870. }
  38871. if (!valueArray) {
  38872. return Dict.empty;
  38873. }
  38874. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  38875. loopCount > MAX_LOOP_COUNT) {
  38876. return valueArray[0];
  38877. }
  38878. return Dict.merge(this.xref, valueArray);
  38879. },
  38880. get content() {
  38881. return this.getPageProp('Contents');
  38882. },
  38883. get resources() {
  38884. // For robustness: The spec states that a \Resources entry has to be
  38885. // present, but can be empty. Some document omit it still, in this case
  38886. // we return an empty dictionary.
  38887. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  38888. },
  38889. get mediaBox() {
  38890. var obj = this.getInheritedPageProp('MediaBox');
  38891. // Reset invalid media box to letter size.
  38892. if (!isArray(obj) || obj.length !== 4) {
  38893. obj = LETTER_SIZE_MEDIABOX;
  38894. }
  38895. return shadow(this, 'mediaBox', obj);
  38896. },
  38897. get view() {
  38898. var mediaBox = this.mediaBox;
  38899. var cropBox = this.getInheritedPageProp('CropBox');
  38900. if (!isArray(cropBox) || cropBox.length !== 4) {
  38901. return shadow(this, 'view', mediaBox);
  38902. }
  38903. // From the spec, 6th ed., p.963:
  38904. // "The crop, bleed, trim, and art boxes should not ordinarily
  38905. // extend beyond the boundaries of the media box. If they do, they are
  38906. // effectively reduced to their intersection with the media box."
  38907. cropBox = Util.intersect(cropBox, mediaBox);
  38908. if (!cropBox) {
  38909. return shadow(this, 'view', mediaBox);
  38910. }
  38911. return shadow(this, 'view', cropBox);
  38912. },
  38913. get rotate() {
  38914. var rotate = this.getInheritedPageProp('Rotate') || 0;
  38915. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  38916. if (rotate % 90 !== 0) {
  38917. rotate = 0;
  38918. } else if (rotate >= 360) {
  38919. rotate = rotate % 360;
  38920. } else if (rotate < 0) {
  38921. // The spec doesn't cover negatives, assume its counterclockwise
  38922. // rotation. The following is the other implementation of modulo.
  38923. rotate = ((rotate % 360) + 360) % 360;
  38924. }
  38925. return shadow(this, 'rotate', rotate);
  38926. },
  38927. getContentStream: function Page_getContentStream() {
  38928. var content = this.content;
  38929. var stream;
  38930. if (isArray(content)) {
  38931. // fetching items
  38932. var xref = this.xref;
  38933. var i, n = content.length;
  38934. var streams = [];
  38935. for (i = 0; i < n; ++i) {
  38936. streams.push(xref.fetchIfRef(content[i]));
  38937. }
  38938. stream = new StreamsSequenceStream(streams);
  38939. } else if (isStream(content)) {
  38940. stream = content;
  38941. } else {
  38942. // replacing non-existent page content with empty one
  38943. stream = new NullStream();
  38944. }
  38945. return stream;
  38946. },
  38947. loadResources: function Page_loadResources(keys) {
  38948. if (!this.resourcesPromise) {
  38949. // TODO: add async getInheritedPageProp and remove this.
  38950. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  38951. }
  38952. return this.resourcesPromise.then(function resourceSuccess() {
  38953. var objectLoader = new ObjectLoader(this.resources.map,
  38954. keys,
  38955. this.xref);
  38956. return objectLoader.load();
  38957. }.bind(this));
  38958. },
  38959. getOperatorList: function Page_getOperatorList(handler, task, intent,
  38960. renderInteractiveForms) {
  38961. var self = this;
  38962. var pdfManager = this.pdfManager;
  38963. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  38964. []);
  38965. var resourcesPromise = this.loadResources([
  38966. 'ExtGState',
  38967. 'ColorSpace',
  38968. 'Pattern',
  38969. 'Shading',
  38970. 'XObject',
  38971. 'Font'
  38972. // ProcSet
  38973. // Properties
  38974. ]);
  38975. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  38976. handler, this.pageIndex,
  38977. this.uniquePrefix,
  38978. this.idCounters,
  38979. this.fontCache,
  38980. this.evaluatorOptions);
  38981. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  38982. var pageListPromise = dataPromises.then(function(data) {
  38983. var contentStream = data[0];
  38984. var opList = new OperatorList(intent, handler, self.pageIndex);
  38985. handler.send('StartRenderPage', {
  38986. transparency: partialEvaluator.hasBlendModes(self.resources),
  38987. pageIndex: self.pageIndex,
  38988. intent: intent
  38989. });
  38990. return partialEvaluator.getOperatorList(contentStream, task,
  38991. self.resources, opList).then(function () {
  38992. return opList;
  38993. });
  38994. });
  38995. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  38996. return Promise.all([pageListPromise, annotationsPromise]).then(
  38997. function(datas) {
  38998. var pageOpList = datas[0];
  38999. var annotations = datas[1];
  39000. if (annotations.length === 0) {
  39001. pageOpList.flush(true);
  39002. return pageOpList;
  39003. }
  39004. var annotationsReadyPromise = Annotation.appendToOperatorList(
  39005. annotations, pageOpList, partialEvaluator, task, intent,
  39006. renderInteractiveForms);
  39007. return annotationsReadyPromise.then(function () {
  39008. pageOpList.flush(true);
  39009. return pageOpList;
  39010. });
  39011. });
  39012. },
  39013. extractTextContent: function Page_extractTextContent(task,
  39014. normalizeWhitespace,
  39015. combineTextItems) {
  39016. var handler = {
  39017. on: function nullHandlerOn() {},
  39018. send: function nullHandlerSend() {}
  39019. };
  39020. var self = this;
  39021. var pdfManager = this.pdfManager;
  39022. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  39023. []);
  39024. var resourcesPromise = this.loadResources([
  39025. 'ExtGState',
  39026. 'XObject',
  39027. 'Font'
  39028. ]);
  39029. var dataPromises = Promise.all([contentStreamPromise,
  39030. resourcesPromise]);
  39031. return dataPromises.then(function(data) {
  39032. var contentStream = data[0];
  39033. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  39034. handler, self.pageIndex,
  39035. self.uniquePrefix,
  39036. self.idCounters,
  39037. self.fontCache,
  39038. self.evaluatorOptions);
  39039. return partialEvaluator.getTextContent(contentStream,
  39040. task,
  39041. self.resources,
  39042. /* stateManager = */ null,
  39043. normalizeWhitespace,
  39044. combineTextItems);
  39045. });
  39046. },
  39047. getAnnotationsData: function Page_getAnnotationsData(intent) {
  39048. var annotations = this.annotations;
  39049. var annotationsData = [];
  39050. for (var i = 0, n = annotations.length; i < n; ++i) {
  39051. if (intent) {
  39052. if (!(intent === 'display' && annotations[i].viewable) &&
  39053. !(intent === 'print' && annotations[i].printable)) {
  39054. continue;
  39055. }
  39056. }
  39057. annotationsData.push(annotations[i].data);
  39058. }
  39059. return annotationsData;
  39060. },
  39061. get annotations() {
  39062. var annotations = [];
  39063. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  39064. var annotationFactory = new AnnotationFactory();
  39065. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  39066. var annotationRef = annotationRefs[i];
  39067. var annotation = annotationFactory.create(this.xref, annotationRef,
  39068. this.uniquePrefix,
  39069. this.idCounters);
  39070. if (annotation) {
  39071. annotations.push(annotation);
  39072. }
  39073. }
  39074. return shadow(this, 'annotations', annotations);
  39075. }
  39076. };
  39077. return Page;
  39078. })();
  39079. /**
  39080. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  39081. * `PDFDoc`, this one doesn't have any job management code.
  39082. * Right now there exists one PDFDocument on the main thread + one object
  39083. * for each worker. If there is no worker support enabled, there are two
  39084. * `PDFDocument` objects on the main thread created.
  39085. */
  39086. var PDFDocument = (function PDFDocumentClosure() {
  39087. var FINGERPRINT_FIRST_BYTES = 1024;
  39088. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  39089. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  39090. function PDFDocument(pdfManager, arg, password) {
  39091. if (isStream(arg)) {
  39092. init.call(this, pdfManager, arg, password);
  39093. } else if (isArrayBuffer(arg)) {
  39094. init.call(this, pdfManager, new Stream(arg), password);
  39095. } else {
  39096. error('PDFDocument: Unknown argument type');
  39097. }
  39098. }
  39099. function init(pdfManager, stream, password) {
  39100. assert(stream.length > 0, 'stream must have data');
  39101. this.pdfManager = pdfManager;
  39102. this.stream = stream;
  39103. var xref = new XRef(this.stream, password, pdfManager);
  39104. this.xref = xref;
  39105. }
  39106. function find(stream, needle, limit, backwards) {
  39107. var pos = stream.pos;
  39108. var end = stream.end;
  39109. var strBuf = [];
  39110. if (pos + limit > end) {
  39111. limit = end - pos;
  39112. }
  39113. for (var n = 0; n < limit; ++n) {
  39114. strBuf.push(String.fromCharCode(stream.getByte()));
  39115. }
  39116. var str = strBuf.join('');
  39117. stream.pos = pos;
  39118. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  39119. if (index === -1) {
  39120. return false; /* not found */
  39121. }
  39122. stream.pos += index;
  39123. return true; /* found */
  39124. }
  39125. var DocumentInfoValidators = {
  39126. get entries() {
  39127. // Lazily build this since all the validation functions below are not
  39128. // defined until after this file loads.
  39129. return shadow(this, 'entries', {
  39130. Title: isString,
  39131. Author: isString,
  39132. Subject: isString,
  39133. Keywords: isString,
  39134. Creator: isString,
  39135. Producer: isString,
  39136. CreationDate: isString,
  39137. ModDate: isString,
  39138. Trapped: isName
  39139. });
  39140. }
  39141. };
  39142. PDFDocument.prototype = {
  39143. parse: function PDFDocument_parse(recoveryMode) {
  39144. this.setup(recoveryMode);
  39145. var version = this.catalog.catDict.get('Version');
  39146. if (isName(version)) {
  39147. this.pdfFormatVersion = version.name;
  39148. }
  39149. try {
  39150. // checking if AcroForm is present
  39151. this.acroForm = this.catalog.catDict.get('AcroForm');
  39152. if (this.acroForm) {
  39153. this.xfa = this.acroForm.get('XFA');
  39154. var fields = this.acroForm.get('Fields');
  39155. if ((!fields || !isArray(fields) || fields.length === 0) &&
  39156. !this.xfa) {
  39157. // no fields and no XFA -- not a form (?)
  39158. this.acroForm = null;
  39159. }
  39160. }
  39161. } catch (ex) {
  39162. info('Something wrong with AcroForm entry');
  39163. this.acroForm = null;
  39164. }
  39165. },
  39166. get linearization() {
  39167. var linearization = null;
  39168. if (this.stream.length) {
  39169. try {
  39170. linearization = Linearization.create(this.stream);
  39171. } catch (err) {
  39172. if (err instanceof MissingDataException) {
  39173. throw err;
  39174. }
  39175. info(err);
  39176. }
  39177. }
  39178. // shadow the prototype getter with a data property
  39179. return shadow(this, 'linearization', linearization);
  39180. },
  39181. get startXRef() {
  39182. var stream = this.stream;
  39183. var startXRef = 0;
  39184. var linearization = this.linearization;
  39185. if (linearization) {
  39186. // Find end of first obj.
  39187. stream.reset();
  39188. if (find(stream, 'endobj', 1024)) {
  39189. startXRef = stream.pos + 6;
  39190. }
  39191. } else {
  39192. // Find startxref by jumping backward from the end of the file.
  39193. var step = 1024;
  39194. var found = false, pos = stream.end;
  39195. while (!found && pos > 0) {
  39196. pos -= step - 'startxref'.length;
  39197. if (pos < 0) {
  39198. pos = 0;
  39199. }
  39200. stream.pos = pos;
  39201. found = find(stream, 'startxref', step, true);
  39202. }
  39203. if (found) {
  39204. stream.skip(9);
  39205. var ch;
  39206. do {
  39207. ch = stream.getByte();
  39208. } while (isSpace(ch));
  39209. var str = '';
  39210. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  39211. str += String.fromCharCode(ch);
  39212. ch = stream.getByte();
  39213. }
  39214. startXRef = parseInt(str, 10);
  39215. if (isNaN(startXRef)) {
  39216. startXRef = 0;
  39217. }
  39218. }
  39219. }
  39220. // shadow the prototype getter with a data property
  39221. return shadow(this, 'startXRef', startXRef);
  39222. },
  39223. get mainXRefEntriesOffset() {
  39224. var mainXRefEntriesOffset = 0;
  39225. var linearization = this.linearization;
  39226. if (linearization) {
  39227. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  39228. }
  39229. // shadow the prototype getter with a data property
  39230. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  39231. },
  39232. // Find the header, remove leading garbage and setup the stream
  39233. // starting from the header.
  39234. checkHeader: function PDFDocument_checkHeader() {
  39235. var stream = this.stream;
  39236. stream.reset();
  39237. if (find(stream, '%PDF-', 1024)) {
  39238. // Found the header, trim off any garbage before it.
  39239. stream.moveStart();
  39240. // Reading file format version
  39241. var MAX_VERSION_LENGTH = 12;
  39242. var version = '', ch;
  39243. while ((ch = stream.getByte()) > 0x20) { // SPACE
  39244. if (version.length >= MAX_VERSION_LENGTH) {
  39245. break;
  39246. }
  39247. version += String.fromCharCode(ch);
  39248. }
  39249. if (!this.pdfFormatVersion) {
  39250. // removing "%PDF-"-prefix
  39251. this.pdfFormatVersion = version.substring(5);
  39252. }
  39253. return;
  39254. }
  39255. // May not be a PDF file, continue anyway.
  39256. },
  39257. parseStartXRef: function PDFDocument_parseStartXRef() {
  39258. var startXRef = this.startXRef;
  39259. this.xref.setStartXRef(startXRef);
  39260. },
  39261. setup: function PDFDocument_setup(recoveryMode) {
  39262. this.xref.parse(recoveryMode);
  39263. var self = this;
  39264. var pageFactory = {
  39265. createPage: function (pageIndex, dict, ref, fontCache) {
  39266. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  39267. fontCache);
  39268. }
  39269. };
  39270. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  39271. },
  39272. get numPages() {
  39273. var linearization = this.linearization;
  39274. var num = linearization ? linearization.numPages : this.catalog.numPages;
  39275. // shadow the prototype getter
  39276. return shadow(this, 'numPages', num);
  39277. },
  39278. get documentInfo() {
  39279. var docInfo = {
  39280. PDFFormatVersion: this.pdfFormatVersion,
  39281. IsAcroFormPresent: !!this.acroForm,
  39282. IsXFAPresent: !!this.xfa
  39283. };
  39284. var infoDict;
  39285. try {
  39286. infoDict = this.xref.trailer.get('Info');
  39287. } catch (err) {
  39288. info('The document information dictionary is invalid.');
  39289. }
  39290. if (infoDict) {
  39291. var validEntries = DocumentInfoValidators.entries;
  39292. // Only fill the document info with valid entries from the spec.
  39293. for (var key in validEntries) {
  39294. if (infoDict.has(key)) {
  39295. var value = infoDict.get(key);
  39296. // Make sure the value conforms to the spec.
  39297. if (validEntries[key](value)) {
  39298. docInfo[key] = (typeof value !== 'string' ?
  39299. value : stringToPDFString(value));
  39300. } else {
  39301. info('Bad value in document info for "' + key + '"');
  39302. }
  39303. }
  39304. }
  39305. }
  39306. return shadow(this, 'documentInfo', docInfo);
  39307. },
  39308. get fingerprint() {
  39309. var xref = this.xref, hash, fileID = '';
  39310. var idArray = xref.trailer.get('ID');
  39311. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  39312. idArray[0] !== EMPTY_FINGERPRINT) {
  39313. hash = stringToBytes(idArray[0]);
  39314. } else {
  39315. if (this.stream.ensureRange) {
  39316. this.stream.ensureRange(0,
  39317. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  39318. }
  39319. hash = calculateMD5(this.stream.bytes.subarray(0,
  39320. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  39321. }
  39322. for (var i = 0, n = hash.length; i < n; i++) {
  39323. var hex = hash[i].toString(16);
  39324. fileID += hex.length === 1 ? '0' + hex : hex;
  39325. }
  39326. return shadow(this, 'fingerprint', fileID);
  39327. },
  39328. getPage: function PDFDocument_getPage(pageIndex) {
  39329. return this.catalog.getPage(pageIndex);
  39330. },
  39331. cleanup: function PDFDocument_cleanup() {
  39332. return this.catalog.cleanup();
  39333. }
  39334. };
  39335. return PDFDocument;
  39336. })();
  39337. exports.Page = Page;
  39338. exports.PDFDocument = PDFDocument;
  39339. }));
  39340. (function (root, factory) {
  39341. {
  39342. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  39343. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  39344. root.pdfjsCoreDocument);
  39345. }
  39346. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  39347. coreDocument) {
  39348. var NotImplementedException = sharedUtil.NotImplementedException;
  39349. var MissingDataException = sharedUtil.MissingDataException;
  39350. var createPromiseCapability = sharedUtil.createPromiseCapability;
  39351. var Util = sharedUtil.Util;
  39352. var Stream = coreStream.Stream;
  39353. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  39354. var PDFDocument = coreDocument.PDFDocument;
  39355. var BasePdfManager = (function BasePdfManagerClosure() {
  39356. function BasePdfManager() {
  39357. throw new Error('Cannot initialize BaseManagerManager');
  39358. }
  39359. BasePdfManager.prototype = {
  39360. get docId() {
  39361. return this._docId;
  39362. },
  39363. onLoadedStream: function BasePdfManager_onLoadedStream() {
  39364. throw new NotImplementedException();
  39365. },
  39366. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  39367. return this.ensure(this.pdfDocument, prop, args);
  39368. },
  39369. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  39370. return this.ensure(this.pdfDocument.xref, prop, args);
  39371. },
  39372. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  39373. return this.ensure(this.pdfDocument.catalog, prop, args);
  39374. },
  39375. getPage: function BasePdfManager_getPage(pageIndex) {
  39376. return this.pdfDocument.getPage(pageIndex);
  39377. },
  39378. cleanup: function BasePdfManager_cleanup() {
  39379. return this.pdfDocument.cleanup();
  39380. },
  39381. ensure: function BasePdfManager_ensure(obj, prop, args) {
  39382. return new NotImplementedException();
  39383. },
  39384. requestRange: function BasePdfManager_requestRange(begin, end) {
  39385. return new NotImplementedException();
  39386. },
  39387. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  39388. return new NotImplementedException();
  39389. },
  39390. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  39391. return new NotImplementedException();
  39392. },
  39393. updatePassword: function BasePdfManager_updatePassword(password) {
  39394. this.pdfDocument.xref.password = this.password = password;
  39395. if (this._passwordChangedCapability) {
  39396. this._passwordChangedCapability.resolve();
  39397. }
  39398. },
  39399. passwordChanged: function BasePdfManager_passwordChanged() {
  39400. this._passwordChangedCapability = createPromiseCapability();
  39401. return this._passwordChangedCapability.promise;
  39402. },
  39403. terminate: function BasePdfManager_terminate() {
  39404. return new NotImplementedException();
  39405. }
  39406. };
  39407. return BasePdfManager;
  39408. })();
  39409. var LocalPdfManager = (function LocalPdfManagerClosure() {
  39410. function LocalPdfManager(docId, data, password, evaluatorOptions) {
  39411. this._docId = docId;
  39412. this.evaluatorOptions = evaluatorOptions;
  39413. var stream = new Stream(data);
  39414. this.pdfDocument = new PDFDocument(this, stream, password);
  39415. this._loadedStreamCapability = createPromiseCapability();
  39416. this._loadedStreamCapability.resolve(stream);
  39417. }
  39418. Util.inherit(LocalPdfManager, BasePdfManager, {
  39419. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  39420. return new Promise(function (resolve, reject) {
  39421. try {
  39422. var value = obj[prop];
  39423. var result;
  39424. if (typeof value === 'function') {
  39425. result = value.apply(obj, args);
  39426. } else {
  39427. result = value;
  39428. }
  39429. resolve(result);
  39430. } catch (e) {
  39431. reject(e);
  39432. }
  39433. });
  39434. },
  39435. requestRange: function LocalPdfManager_requestRange(begin, end) {
  39436. return Promise.resolve();
  39437. },
  39438. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  39439. return;
  39440. },
  39441. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  39442. return this._loadedStreamCapability.promise;
  39443. },
  39444. terminate: function LocalPdfManager_terminate() {
  39445. return;
  39446. }
  39447. });
  39448. return LocalPdfManager;
  39449. })();
  39450. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  39451. function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions) {
  39452. this._docId = docId;
  39453. this.msgHandler = args.msgHandler;
  39454. this.evaluatorOptions = evaluatorOptions;
  39455. var params = {
  39456. msgHandler: args.msgHandler,
  39457. url: args.url,
  39458. length: args.length,
  39459. disableAutoFetch: args.disableAutoFetch,
  39460. rangeChunkSize: args.rangeChunkSize
  39461. };
  39462. this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
  39463. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  39464. args.password);
  39465. }
  39466. Util.inherit(NetworkPdfManager, BasePdfManager, {
  39467. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  39468. var pdfManager = this;
  39469. return new Promise(function (resolve, reject) {
  39470. function ensureHelper() {
  39471. try {
  39472. var result;
  39473. var value = obj[prop];
  39474. if (typeof value === 'function') {
  39475. result = value.apply(obj, args);
  39476. } else {
  39477. result = value;
  39478. }
  39479. resolve(result);
  39480. } catch(e) {
  39481. if (!(e instanceof MissingDataException)) {
  39482. reject(e);
  39483. return;
  39484. }
  39485. pdfManager.streamManager.requestRange(e.begin, e.end).
  39486. then(ensureHelper, reject);
  39487. }
  39488. }
  39489. ensureHelper();
  39490. });
  39491. },
  39492. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  39493. return this.streamManager.requestRange(begin, end);
  39494. },
  39495. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  39496. this.streamManager.requestAllChunks();
  39497. },
  39498. sendProgressiveData:
  39499. function NetworkPdfManager_sendProgressiveData(chunk) {
  39500. this.streamManager.onReceiveData({ chunk: chunk });
  39501. },
  39502. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  39503. return this.streamManager.onLoadedStream();
  39504. },
  39505. terminate: function NetworkPdfManager_terminate() {
  39506. this.streamManager.abort();
  39507. }
  39508. });
  39509. return NetworkPdfManager;
  39510. })();
  39511. exports.LocalPdfManager = LocalPdfManager;
  39512. exports.NetworkPdfManager = NetworkPdfManager;
  39513. }));
  39514. (function (root, factory) {
  39515. {
  39516. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  39517. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager);
  39518. }
  39519. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager) {
  39520. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  39521. var InvalidPDFException = sharedUtil.InvalidPDFException;
  39522. var MessageHandler = sharedUtil.MessageHandler;
  39523. var MissingPDFException = sharedUtil.MissingPDFException;
  39524. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  39525. var PasswordException = sharedUtil.PasswordException;
  39526. var PasswordResponses = sharedUtil.PasswordResponses;
  39527. var UnknownErrorException = sharedUtil.UnknownErrorException;
  39528. var XRefParseException = sharedUtil.XRefParseException;
  39529. var arrayByteLength = sharedUtil.arrayByteLength;
  39530. var arraysToBytes = sharedUtil.arraysToBytes;
  39531. var assert = sharedUtil.assert;
  39532. var createPromiseCapability = sharedUtil.createPromiseCapability;
  39533. var error = sharedUtil.error;
  39534. var info = sharedUtil.info;
  39535. var warn = sharedUtil.warn;
  39536. var setVerbosityLevel = sharedUtil.setVerbosityLevel;
  39537. var Ref = corePrimitives.Ref;
  39538. var LocalPdfManager = corePdfManager.LocalPdfManager;
  39539. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  39540. var globalScope = sharedUtil.globalScope;
  39541. var WorkerTask = (function WorkerTaskClosure() {
  39542. function WorkerTask(name) {
  39543. this.name = name;
  39544. this.terminated = false;
  39545. this._capability = createPromiseCapability();
  39546. }
  39547. WorkerTask.prototype = {
  39548. get finished() {
  39549. return this._capability.promise;
  39550. },
  39551. finish: function () {
  39552. this._capability.resolve();
  39553. },
  39554. terminate: function () {
  39555. this.terminated = true;
  39556. },
  39557. ensureNotTerminated: function () {
  39558. if (this.terminated) {
  39559. throw new Error('Worker task was terminated');
  39560. }
  39561. }
  39562. };
  39563. return WorkerTask;
  39564. })();
  39565. /** @implements {IPDFStream} */
  39566. var PDFWorkerStream = (function PDFWorkerStreamClosure() {
  39567. function PDFWorkerStream(params, msgHandler) {
  39568. this._queuedChunks = [];
  39569. var initialData = params.initialData;
  39570. if (initialData && initialData.length > 0) {
  39571. this._queuedChunks.push(initialData);
  39572. }
  39573. this._msgHandler = msgHandler;
  39574. this._isRangeSupported = !(params.disableRange);
  39575. this._isStreamingSupported = !(params.disableStream);
  39576. this._contentLength = params.length;
  39577. this._fullRequestReader = null;
  39578. this._rangeReaders = [];
  39579. msgHandler.on('OnDataRange', this._onReceiveData.bind(this));
  39580. msgHandler.on('OnDataProgress', this._onProgress.bind(this));
  39581. }
  39582. PDFWorkerStream.prototype = {
  39583. _onReceiveData: function PDFWorkerStream_onReceiveData(args) {
  39584. if (args.begin === undefined) {
  39585. if (this._fullRequestReader) {
  39586. this._fullRequestReader._enqueue(args.chunk);
  39587. } else {
  39588. this._queuedChunks.push(args.chunk);
  39589. }
  39590. } else {
  39591. var found = this._rangeReaders.some(function (rangeReader) {
  39592. if (rangeReader._begin !== args.begin) {
  39593. return false;
  39594. }
  39595. rangeReader._enqueue(args.chunk);
  39596. return true;
  39597. });
  39598. assert(found);
  39599. }
  39600. },
  39601. _onProgress: function PDFWorkerStream_onProgress(evt) {
  39602. if (this._rangeReaders.length > 0) {
  39603. // Reporting to first range reader.
  39604. var firstReader = this._rangeReaders[0];
  39605. if (firstReader.onProgress) {
  39606. firstReader.onProgress({loaded: evt.loaded});
  39607. }
  39608. }
  39609. },
  39610. _removeRangeReader: function PDFWorkerStream_removeRangeReader(reader) {
  39611. var i = this._rangeReaders.indexOf(reader);
  39612. if (i >= 0) {
  39613. this._rangeReaders.splice(i, 1);
  39614. }
  39615. },
  39616. getFullReader: function PDFWorkerStream_getFullReader() {
  39617. assert(!this._fullRequestReader);
  39618. var queuedChunks = this._queuedChunks;
  39619. this._queuedChunks = null;
  39620. return new PDFWorkerStreamReader(this, queuedChunks);
  39621. },
  39622. getRangeReader: function PDFWorkerStream_getRangeReader(begin, end) {
  39623. var reader = new PDFWorkerStreamRangeReader(this, begin, end);
  39624. this._msgHandler.send('RequestDataRange', { begin: begin, end: end });
  39625. this._rangeReaders.push(reader);
  39626. return reader;
  39627. },
  39628. cancelAllRequests: function PDFWorkerStream_cancelAllRequests(reason) {
  39629. if (this._fullRequestReader) {
  39630. this._fullRequestReader.cancel(reason);
  39631. }
  39632. var readers = this._rangeReaders.slice(0);
  39633. readers.forEach(function (rangeReader) {
  39634. rangeReader.cancel(reason);
  39635. });
  39636. }
  39637. };
  39638. /** @implements {IPDFStreamReader} */
  39639. function PDFWorkerStreamReader(stream, queuedChunks) {
  39640. this._stream = stream;
  39641. this._done = false;
  39642. this._queuedChunks = queuedChunks || [];
  39643. this._requests = [];
  39644. this._headersReady = Promise.resolve();
  39645. stream._fullRequestReader = this;
  39646. this.onProgress = null; // not used
  39647. }
  39648. PDFWorkerStreamReader.prototype = {
  39649. _enqueue: function PDFWorkerStreamReader_enqueue(chunk) {
  39650. if (this._done) {
  39651. return; // ignore new data
  39652. }
  39653. if (this._requests.length > 0) {
  39654. var requestCapability = this._requests.shift();
  39655. requestCapability.resolve({value: chunk, done: false});
  39656. return;
  39657. }
  39658. this._queuedChunks.push(chunk);
  39659. },
  39660. get headersReady() {
  39661. return this._headersReady;
  39662. },
  39663. get isRangeSupported() {
  39664. return this._stream._isRangeSupported;
  39665. },
  39666. get isStreamingSupported() {
  39667. return this._stream._isStreamingSupported;
  39668. },
  39669. get contentLength() {
  39670. return this._stream._contentLength;
  39671. },
  39672. read: function PDFWorkerStreamReader_read() {
  39673. if (this._queuedChunks.length > 0) {
  39674. var chunk = this._queuedChunks.shift();
  39675. return Promise.resolve({value: chunk, done: false});
  39676. }
  39677. if (this._done) {
  39678. return Promise.resolve({value: undefined, done: true});
  39679. }
  39680. var requestCapability = createPromiseCapability();
  39681. this._requests.push(requestCapability);
  39682. return requestCapability.promise;
  39683. },
  39684. cancel: function PDFWorkerStreamReader_cancel(reason) {
  39685. this._done = true;
  39686. this._requests.forEach(function (requestCapability) {
  39687. requestCapability.resolve({value: undefined, done: true});
  39688. });
  39689. this._requests = [];
  39690. }
  39691. };
  39692. /** @implements {IPDFStreamRangeReader} */
  39693. function PDFWorkerStreamRangeReader(stream, begin, end) {
  39694. this._stream = stream;
  39695. this._begin = begin;
  39696. this._end = end;
  39697. this._queuedChunk = null;
  39698. this._requests = [];
  39699. this._done = false;
  39700. this.onProgress = null;
  39701. }
  39702. PDFWorkerStreamRangeReader.prototype = {
  39703. _enqueue: function PDFWorkerStreamRangeReader_enqueue(chunk) {
  39704. if (this._done) {
  39705. return; // ignore new data
  39706. }
  39707. if (this._requests.length === 0) {
  39708. this._queuedChunk = chunk;
  39709. } else {
  39710. var requestsCapability = this._requests.shift();
  39711. requestsCapability.resolve({value: chunk, done: false});
  39712. this._requests.forEach(function (requestCapability) {
  39713. requestCapability.resolve({value: undefined, done: true});
  39714. });
  39715. this._requests = [];
  39716. }
  39717. this._done = true;
  39718. this._stream._removeRangeReader(this);
  39719. },
  39720. get isStreamingSupported() {
  39721. return false;
  39722. },
  39723. read: function PDFWorkerStreamRangeReader_read() {
  39724. if (this._queuedChunk) {
  39725. return Promise.resolve({value: this._queuedChunk, done: false});
  39726. }
  39727. if (this._done) {
  39728. return Promise.resolve({value: undefined, done: true});
  39729. }
  39730. var requestCapability = createPromiseCapability();
  39731. this._requests.push(requestCapability);
  39732. return requestCapability.promise;
  39733. },
  39734. cancel: function PDFWorkerStreamRangeReader_cancel(reason) {
  39735. this._done = true;
  39736. this._requests.forEach(function (requestCapability) {
  39737. requestCapability.resolve({value: undefined, done: true});
  39738. });
  39739. this._requests = [];
  39740. this._stream._removeRangeReader(this);
  39741. }
  39742. };
  39743. return PDFWorkerStream;
  39744. })();
  39745. /** @type IPDFStream */
  39746. var PDFNetworkStream;
  39747. /**
  39748. * Sets PDFNetworkStream class to be used as alternative PDF data transport.
  39749. * @param {IPDFStream} cls - the PDF data transport.
  39750. */
  39751. function setPDFNetworkStreamClass(cls) {
  39752. PDFNetworkStream = cls;
  39753. }
  39754. var WorkerMessageHandler = {
  39755. setup: function wphSetup(handler, port) {
  39756. var testMessageProcessed = false;
  39757. handler.on('test', function wphSetupTest(data) {
  39758. if (testMessageProcessed) {
  39759. return; // we already processed 'test' message once
  39760. }
  39761. testMessageProcessed = true;
  39762. // check if Uint8Array can be sent to worker
  39763. if (!(data instanceof Uint8Array)) {
  39764. handler.send('test', 'main', false);
  39765. return;
  39766. }
  39767. // making sure postMessage transfers are working
  39768. var supportTransfers = data[0] === 255;
  39769. handler.postMessageTransfers = supportTransfers;
  39770. // check if the response property is supported by xhr
  39771. var xhr = new XMLHttpRequest();
  39772. var responseExists = 'response' in xhr;
  39773. // check if the property is actually implemented
  39774. try {
  39775. var dummy = xhr.responseType;
  39776. } catch (e) {
  39777. responseExists = false;
  39778. }
  39779. if (!responseExists) {
  39780. handler.send('test', false);
  39781. return;
  39782. }
  39783. handler.send('test', {
  39784. supportTypedArray: true,
  39785. supportTransfers: supportTransfers
  39786. });
  39787. });
  39788. handler.on('configure', function wphConfigure(data) {
  39789. setVerbosityLevel(data.verbosity);
  39790. });
  39791. handler.on('GetDocRequest', function wphSetupDoc(data) {
  39792. return WorkerMessageHandler.createDocumentHandler(data, port);
  39793. });
  39794. },
  39795. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  39796. // This context is actually holds references on pdfManager and handler,
  39797. // until the latter is destroyed.
  39798. var pdfManager;
  39799. var terminated = false;
  39800. var cancelXHRs = null;
  39801. var WorkerTasks = [];
  39802. var docId = docParams.docId;
  39803. var workerHandlerName = docParams.docId + '_worker';
  39804. var handler = new MessageHandler(workerHandlerName, docId, port);
  39805. // Ensure that postMessage transfers are correctly enabled/disabled,
  39806. // to prevent "DataCloneError" in older versions of IE (see issue 6957).
  39807. handler.postMessageTransfers = docParams.postMessageTransfers;
  39808. function ensureNotTerminated() {
  39809. if (terminated) {
  39810. throw new Error('Worker was terminated');
  39811. }
  39812. }
  39813. function startWorkerTask(task) {
  39814. WorkerTasks.push(task);
  39815. }
  39816. function finishWorkerTask(task) {
  39817. task.finish();
  39818. var i = WorkerTasks.indexOf(task);
  39819. WorkerTasks.splice(i, 1);
  39820. }
  39821. function loadDocument(recoveryMode) {
  39822. var loadDocumentCapability = createPromiseCapability();
  39823. var parseSuccess = function parseSuccess() {
  39824. var numPagesPromise = pdfManager.ensureDoc('numPages');
  39825. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  39826. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  39827. Promise.all([numPagesPromise, fingerprintPromise,
  39828. encryptedPromise]).then(function onDocReady(results) {
  39829. var doc = {
  39830. numPages: results[0],
  39831. fingerprint: results[1],
  39832. encrypted: !!results[2],
  39833. };
  39834. loadDocumentCapability.resolve(doc);
  39835. },
  39836. parseFailure);
  39837. };
  39838. var parseFailure = function parseFailure(e) {
  39839. loadDocumentCapability.reject(e);
  39840. };
  39841. pdfManager.ensureDoc('checkHeader', []).then(function() {
  39842. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  39843. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  39844. parseSuccess, parseFailure);
  39845. }, parseFailure);
  39846. }, parseFailure);
  39847. return loadDocumentCapability.promise;
  39848. }
  39849. function getPdfManager(data, evaluatorOptions) {
  39850. var pdfManagerCapability = createPromiseCapability();
  39851. var pdfManager;
  39852. var source = data.source;
  39853. if (source.data) {
  39854. try {
  39855. pdfManager = new LocalPdfManager(docId, source.data, source.password,
  39856. evaluatorOptions);
  39857. pdfManagerCapability.resolve(pdfManager);
  39858. } catch (ex) {
  39859. pdfManagerCapability.reject(ex);
  39860. }
  39861. return pdfManagerCapability.promise;
  39862. }
  39863. var pdfStream;
  39864. try {
  39865. if (source.chunkedViewerLoading) {
  39866. pdfStream = new PDFWorkerStream(source, handler);
  39867. } else {
  39868. assert(PDFNetworkStream, 'pdfjs/core/network module is not loaded');
  39869. pdfStream = new PDFNetworkStream(data);
  39870. }
  39871. } catch (ex) {
  39872. pdfManagerCapability.reject(ex);
  39873. return pdfManagerCapability.promise;
  39874. }
  39875. var fullRequest = pdfStream.getFullReader();
  39876. fullRequest.headersReady.then(function () {
  39877. if (!fullRequest.isStreamingSupported ||
  39878. !fullRequest.isRangeSupported) {
  39879. // If stream or range are disabled, it's our only way to report
  39880. // loading progress.
  39881. fullRequest.onProgress = function (evt) {
  39882. handler.send('DocProgress', {
  39883. loaded: evt.loaded,
  39884. total: evt.total
  39885. });
  39886. };
  39887. }
  39888. if (!fullRequest.isRangeSupported) {
  39889. return;
  39890. }
  39891. // We don't need auto-fetch when streaming is enabled.
  39892. var disableAutoFetch = source.disableAutoFetch ||
  39893. fullRequest.isStreamingSupported;
  39894. pdfManager = new NetworkPdfManager(docId, pdfStream, {
  39895. msgHandler: handler,
  39896. url: source.url,
  39897. password: source.password,
  39898. length: fullRequest.contentLength,
  39899. disableAutoFetch: disableAutoFetch,
  39900. rangeChunkSize: source.rangeChunkSize
  39901. }, evaluatorOptions);
  39902. pdfManagerCapability.resolve(pdfManager);
  39903. cancelXHRs = null;
  39904. }).catch(function (reason) {
  39905. pdfManagerCapability.reject(reason);
  39906. cancelXHRs = null;
  39907. });
  39908. var cachedChunks = [], loaded = 0;
  39909. var flushChunks = function () {
  39910. var pdfFile = arraysToBytes(cachedChunks);
  39911. if (source.length && pdfFile.length !== source.length) {
  39912. warn('reported HTTP length is different from actual');
  39913. }
  39914. // the data is array, instantiating directly from it
  39915. try {
  39916. pdfManager = new LocalPdfManager(docId, pdfFile, source.password,
  39917. evaluatorOptions);
  39918. pdfManagerCapability.resolve(pdfManager);
  39919. } catch (ex) {
  39920. pdfManagerCapability.reject(ex);
  39921. }
  39922. cachedChunks = [];
  39923. };
  39924. var readPromise = new Promise(function (resolve, reject) {
  39925. var readChunk = function (chunk) {
  39926. try {
  39927. ensureNotTerminated();
  39928. if (chunk.done) {
  39929. if (!pdfManager) {
  39930. flushChunks();
  39931. }
  39932. cancelXHRs = null;
  39933. return;
  39934. }
  39935. var data = chunk.value;
  39936. loaded += arrayByteLength(data);
  39937. if (!fullRequest.isStreamingSupported) {
  39938. handler.send('DocProgress', {
  39939. loaded: loaded,
  39940. total: Math.max(loaded, fullRequest.contentLength || 0)
  39941. });
  39942. }
  39943. if (pdfManager) {
  39944. pdfManager.sendProgressiveData(data);
  39945. } else {
  39946. cachedChunks.push(data);
  39947. }
  39948. fullRequest.read().then(readChunk, reject);
  39949. } catch (e) {
  39950. reject(e);
  39951. }
  39952. };
  39953. fullRequest.read().then(readChunk, reject);
  39954. });
  39955. readPromise.catch(function (e) {
  39956. pdfManagerCapability.reject(e);
  39957. cancelXHRs = null;
  39958. });
  39959. cancelXHRs = function () {
  39960. pdfStream.cancelAllRequests('abort');
  39961. };
  39962. return pdfManagerCapability.promise;
  39963. }
  39964. var setupDoc = function(data) {
  39965. var onSuccess = function(doc) {
  39966. ensureNotTerminated();
  39967. handler.send('GetDoc', { pdfInfo: doc });
  39968. };
  39969. var onFailure = function(e) {
  39970. if (e instanceof PasswordException) {
  39971. if (e.code === PasswordResponses.NEED_PASSWORD) {
  39972. handler.send('NeedPassword', e);
  39973. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  39974. handler.send('IncorrectPassword', e);
  39975. }
  39976. } else if (e instanceof InvalidPDFException) {
  39977. handler.send('InvalidPDF', e);
  39978. } else if (e instanceof MissingPDFException) {
  39979. handler.send('MissingPDF', e);
  39980. } else if (e instanceof UnexpectedResponseException) {
  39981. handler.send('UnexpectedResponse', e);
  39982. } else {
  39983. handler.send('UnknownError',
  39984. new UnknownErrorException(e.message, e.toString()));
  39985. }
  39986. };
  39987. ensureNotTerminated();
  39988. var cMapOptions = {
  39989. url: data.cMapUrl === undefined ? null : data.cMapUrl,
  39990. packed: data.cMapPacked === true
  39991. };
  39992. var evaluatorOptions = {
  39993. forceDataSchema: data.disableCreateObjectURL,
  39994. maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize,
  39995. disableFontFace: data.disableFontFace,
  39996. cMapOptions: cMapOptions
  39997. };
  39998. getPdfManager(data, evaluatorOptions).then(function (newPdfManager) {
  39999. if (terminated) {
  40000. // We were in a process of setting up the manager, but it got
  40001. // terminated in the middle.
  40002. newPdfManager.terminate();
  40003. throw new Error('Worker was terminated');
  40004. }
  40005. pdfManager = newPdfManager;
  40006. handler.send('PDFManagerReady', null);
  40007. pdfManager.onLoadedStream().then(function(stream) {
  40008. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  40009. });
  40010. }).then(function pdfManagerReady() {
  40011. ensureNotTerminated();
  40012. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  40013. ensureNotTerminated();
  40014. // Try again with recoveryMode == true
  40015. if (!(ex instanceof XRefParseException)) {
  40016. if (ex instanceof PasswordException) {
  40017. // after password exception prepare to receive a new password
  40018. // to repeat loading
  40019. pdfManager.passwordChanged().then(pdfManagerReady);
  40020. }
  40021. onFailure(ex);
  40022. return;
  40023. }
  40024. pdfManager.requestLoadedStream();
  40025. pdfManager.onLoadedStream().then(function() {
  40026. ensureNotTerminated();
  40027. loadDocument(true).then(onSuccess, onFailure);
  40028. });
  40029. }, onFailure);
  40030. }, onFailure);
  40031. };
  40032. handler.on('GetPage', function wphSetupGetPage(data) {
  40033. return pdfManager.getPage(data.pageIndex).then(function(page) {
  40034. var rotatePromise = pdfManager.ensure(page, 'rotate');
  40035. var refPromise = pdfManager.ensure(page, 'ref');
  40036. var viewPromise = pdfManager.ensure(page, 'view');
  40037. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  40038. function(results) {
  40039. return {
  40040. rotate: results[0],
  40041. ref: results[1],
  40042. view: results[2]
  40043. };
  40044. });
  40045. });
  40046. });
  40047. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  40048. var ref = new Ref(data.ref.num, data.ref.gen);
  40049. var catalog = pdfManager.pdfDocument.catalog;
  40050. return catalog.getPageIndex(ref);
  40051. });
  40052. handler.on('GetDestinations',
  40053. function wphSetupGetDestinations(data) {
  40054. return pdfManager.ensureCatalog('destinations');
  40055. }
  40056. );
  40057. handler.on('GetDestination',
  40058. function wphSetupGetDestination(data) {
  40059. return pdfManager.ensureCatalog('getDestination', [data.id]);
  40060. }
  40061. );
  40062. handler.on('GetPageLabels',
  40063. function wphSetupGetPageLabels(data) {
  40064. return pdfManager.ensureCatalog('pageLabels');
  40065. }
  40066. );
  40067. handler.on('GetAttachments',
  40068. function wphSetupGetAttachments(data) {
  40069. return pdfManager.ensureCatalog('attachments');
  40070. }
  40071. );
  40072. handler.on('GetJavaScript',
  40073. function wphSetupGetJavaScript(data) {
  40074. return pdfManager.ensureCatalog('javaScript');
  40075. }
  40076. );
  40077. handler.on('GetOutline',
  40078. function wphSetupGetOutline(data) {
  40079. return pdfManager.ensureCatalog('documentOutline');
  40080. }
  40081. );
  40082. handler.on('GetMetadata',
  40083. function wphSetupGetMetadata(data) {
  40084. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  40085. pdfManager.ensureCatalog('metadata')]);
  40086. }
  40087. );
  40088. handler.on('GetData', function wphSetupGetData(data) {
  40089. pdfManager.requestLoadedStream();
  40090. return pdfManager.onLoadedStream().then(function(stream) {
  40091. return stream.bytes;
  40092. });
  40093. });
  40094. handler.on('GetStats',
  40095. function wphSetupGetStats(data) {
  40096. return pdfManager.pdfDocument.xref.stats;
  40097. }
  40098. );
  40099. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  40100. pdfManager.updatePassword(data);
  40101. });
  40102. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  40103. return pdfManager.getPage(data.pageIndex).then(function(page) {
  40104. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  40105. });
  40106. });
  40107. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  40108. var pageIndex = data.pageIndex;
  40109. pdfManager.getPage(pageIndex).then(function(page) {
  40110. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  40111. startWorkerTask(task);
  40112. var pageNum = pageIndex + 1;
  40113. var start = Date.now();
  40114. // Pre compile the pdf page and fetch the fonts/images.
  40115. page.getOperatorList(handler, task, data.intent,
  40116. data.renderInteractiveForms).then(
  40117. function(operatorList) {
  40118. finishWorkerTask(task);
  40119. info('page=' + pageNum + ' - getOperatorList: time=' +
  40120. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  40121. }, function(e) {
  40122. finishWorkerTask(task);
  40123. if (task.terminated) {
  40124. return; // ignoring errors from the terminated thread
  40125. }
  40126. // For compatibility with older behavior, generating unknown
  40127. // unsupported feature notification on errors.
  40128. handler.send('UnsupportedFeature',
  40129. {featureId: UNSUPPORTED_FEATURES.unknown});
  40130. var minimumStackMessage =
  40131. 'worker.js: while trying to getPage() and getOperatorList()';
  40132. var wrappedException;
  40133. // Turn the error into an obj that can be serialized
  40134. if (typeof e === 'string') {
  40135. wrappedException = {
  40136. message: e,
  40137. stack: minimumStackMessage
  40138. };
  40139. } else if (typeof e === 'object') {
  40140. wrappedException = {
  40141. message: e.message || e.toString(),
  40142. stack: e.stack || minimumStackMessage
  40143. };
  40144. } else {
  40145. wrappedException = {
  40146. message: 'Unknown exception type: ' + (typeof e),
  40147. stack: minimumStackMessage
  40148. };
  40149. }
  40150. handler.send('PageError', {
  40151. pageNum: pageNum,
  40152. error: wrappedException,
  40153. intent: data.intent
  40154. });
  40155. });
  40156. });
  40157. }, this);
  40158. handler.on('GetTextContent', function wphExtractText(data) {
  40159. var pageIndex = data.pageIndex;
  40160. var normalizeWhitespace = data.normalizeWhitespace;
  40161. var combineTextItems = data.combineTextItems;
  40162. return pdfManager.getPage(pageIndex).then(function(page) {
  40163. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  40164. startWorkerTask(task);
  40165. var pageNum = pageIndex + 1;
  40166. var start = Date.now();
  40167. return page.extractTextContent(task, normalizeWhitespace,
  40168. combineTextItems).then(
  40169. function(textContent) {
  40170. finishWorkerTask(task);
  40171. info('text indexing: page=' + pageNum + ' - time=' +
  40172. (Date.now() - start) + 'ms');
  40173. return textContent;
  40174. }, function (reason) {
  40175. finishWorkerTask(task);
  40176. if (task.terminated) {
  40177. return; // ignoring errors from the terminated thread
  40178. }
  40179. throw reason;
  40180. });
  40181. });
  40182. });
  40183. handler.on('Cleanup', function wphCleanup(data) {
  40184. return pdfManager.cleanup();
  40185. });
  40186. handler.on('Terminate', function wphTerminate(data) {
  40187. terminated = true;
  40188. if (pdfManager) {
  40189. pdfManager.terminate();
  40190. pdfManager = null;
  40191. }
  40192. if (cancelXHRs) {
  40193. cancelXHRs();
  40194. }
  40195. var waitOn = [];
  40196. WorkerTasks.forEach(function (task) {
  40197. waitOn.push(task.finished);
  40198. task.terminate();
  40199. });
  40200. return Promise.all(waitOn).then(function () {
  40201. // Notice that even if we destroying handler, resolved response promise
  40202. // must be sent back.
  40203. handler.destroy();
  40204. handler = null;
  40205. });
  40206. });
  40207. handler.on('Ready', function wphReady(data) {
  40208. setupDoc(docParams);
  40209. docParams = null; // we don't need docParams anymore -- saving memory.
  40210. });
  40211. return workerHandlerName;
  40212. }
  40213. };
  40214. function initializeWorker() {
  40215. if (!('console' in globalScope)) {
  40216. var consoleTimer = {};
  40217. var workerConsole = {
  40218. log: function log() {
  40219. var args = Array.prototype.slice.call(arguments);
  40220. globalScope.postMessage({
  40221. targetName: 'main',
  40222. action: 'console_log',
  40223. data: args
  40224. });
  40225. },
  40226. error: function error() {
  40227. var args = Array.prototype.slice.call(arguments);
  40228. globalScope.postMessage({
  40229. targetName: 'main',
  40230. action: 'console_error',
  40231. data: args
  40232. });
  40233. throw 'pdf.js execution error';
  40234. },
  40235. time: function time(name) {
  40236. consoleTimer[name] = Date.now();
  40237. },
  40238. timeEnd: function timeEnd(name) {
  40239. var time = consoleTimer[name];
  40240. if (!time) {
  40241. error('Unknown timer name ' + name);
  40242. }
  40243. this.log('Timer:', name, Date.now() - time);
  40244. }
  40245. };
  40246. globalScope.console = workerConsole;
  40247. }
  40248. var handler = new MessageHandler('worker', 'main', self);
  40249. WorkerMessageHandler.setup(handler, self);
  40250. handler.send('ready', null);
  40251. }
  40252. // Worker thread (and not node.js)?
  40253. if (typeof window === 'undefined' &&
  40254. !(typeof module !== 'undefined' && module.require)) {
  40255. initializeWorker();
  40256. }
  40257. exports.setPDFNetworkStreamClass = setPDFNetworkStreamClass;
  40258. exports.WorkerTask = WorkerTask;
  40259. exports.WorkerMessageHandler = WorkerMessageHandler;
  40260. }));
  40261. var NetworkManager = (function NetworkManagerClosure() {
  40262. var OK_RESPONSE = 200;
  40263. var PARTIAL_CONTENT_RESPONSE = 206;
  40264. function NetworkManager(url, args) {
  40265. this.url = url;
  40266. args = args || {};
  40267. this.isHttp = /^https?:/i.test(url);
  40268. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  40269. this.withCredentials = args.withCredentials || false;
  40270. this.getXhr = args.getXhr ||
  40271. function NetworkManager_getXhr() {
  40272. return new XMLHttpRequest();
  40273. };
  40274. this.currXhrId = 0;
  40275. this.pendingRequests = Object.create(null);
  40276. this.loadedRequests = Object.create(null);
  40277. }
  40278. function getArrayBuffer(xhr) {
  40279. var data = xhr.response;
  40280. if (typeof data !== 'string') {
  40281. return data;
  40282. }
  40283. var length = data.length;
  40284. var array = new Uint8Array(length);
  40285. for (var i = 0; i < length; i++) {
  40286. array[i] = data.charCodeAt(i) & 0xFF;
  40287. }
  40288. return array.buffer;
  40289. }
  40290. var supportsMozChunked = (function supportsMozChunkedClosure() {
  40291. try {
  40292. var x = new XMLHttpRequest();
  40293. // Firefox 37- required .open() to be called before setting responseType.
  40294. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  40295. // Even though the URL is not visited, .open() could fail if the URL is
  40296. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  40297. // When this error occurs, this feature detection method will mistakenly
  40298. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  40299. x.open('GET', 'https://example.com');
  40300. x.responseType = 'moz-chunked-arraybuffer';
  40301. return x.responseType === 'moz-chunked-arraybuffer';
  40302. } catch (e) {
  40303. return false;
  40304. }
  40305. })();
  40306. NetworkManager.prototype = {
  40307. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  40308. var args = {
  40309. begin: begin,
  40310. end: end
  40311. };
  40312. for (var prop in listeners) {
  40313. args[prop] = listeners[prop];
  40314. }
  40315. return this.request(args);
  40316. },
  40317. requestFull: function NetworkManager_requestFull(listeners) {
  40318. return this.request(listeners);
  40319. },
  40320. request: function NetworkManager_request(args) {
  40321. var xhr = this.getXhr();
  40322. var xhrId = this.currXhrId++;
  40323. var pendingRequest = this.pendingRequests[xhrId] = {
  40324. xhr: xhr
  40325. };
  40326. xhr.open('GET', this.url);
  40327. xhr.withCredentials = this.withCredentials;
  40328. for (var property in this.httpHeaders) {
  40329. var value = this.httpHeaders[property];
  40330. if (typeof value === 'undefined') {
  40331. continue;
  40332. }
  40333. xhr.setRequestHeader(property, value);
  40334. }
  40335. if (this.isHttp && 'begin' in args && 'end' in args) {
  40336. var rangeStr = args.begin + '-' + (args.end - 1);
  40337. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  40338. pendingRequest.expectedStatus = 206;
  40339. } else {
  40340. pendingRequest.expectedStatus = 200;
  40341. }
  40342. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  40343. if (useMozChunkedLoading) {
  40344. xhr.responseType = 'moz-chunked-arraybuffer';
  40345. pendingRequest.onProgressiveData = args.onProgressiveData;
  40346. pendingRequest.mozChunked = true;
  40347. } else {
  40348. xhr.responseType = 'arraybuffer';
  40349. }
  40350. if (args.onError) {
  40351. xhr.onerror = function(evt) {
  40352. args.onError(xhr.status);
  40353. };
  40354. }
  40355. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  40356. xhr.onprogress = this.onProgress.bind(this, xhrId);
  40357. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  40358. pendingRequest.onDone = args.onDone;
  40359. pendingRequest.onError = args.onError;
  40360. pendingRequest.onProgress = args.onProgress;
  40361. xhr.send(null);
  40362. return xhrId;
  40363. },
  40364. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  40365. var pendingRequest = this.pendingRequests[xhrId];
  40366. if (!pendingRequest) {
  40367. // Maybe abortRequest was called...
  40368. return;
  40369. }
  40370. if (pendingRequest.mozChunked) {
  40371. var chunk = getArrayBuffer(pendingRequest.xhr);
  40372. pendingRequest.onProgressiveData(chunk);
  40373. }
  40374. var onProgress = pendingRequest.onProgress;
  40375. if (onProgress) {
  40376. onProgress(evt);
  40377. }
  40378. },
  40379. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  40380. var pendingRequest = this.pendingRequests[xhrId];
  40381. if (!pendingRequest) {
  40382. // Maybe abortRequest was called...
  40383. return;
  40384. }
  40385. var xhr = pendingRequest.xhr;
  40386. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  40387. pendingRequest.onHeadersReceived();
  40388. delete pendingRequest.onHeadersReceived;
  40389. }
  40390. if (xhr.readyState !== 4) {
  40391. return;
  40392. }
  40393. if (!(xhrId in this.pendingRequests)) {
  40394. // The XHR request might have been aborted in onHeadersReceived()
  40395. // callback, in which case we should abort request
  40396. return;
  40397. }
  40398. delete this.pendingRequests[xhrId];
  40399. // success status == 0 can be on ftp, file and other protocols
  40400. if (xhr.status === 0 && this.isHttp) {
  40401. if (pendingRequest.onError) {
  40402. pendingRequest.onError(xhr.status);
  40403. }
  40404. return;
  40405. }
  40406. var xhrStatus = xhr.status || OK_RESPONSE;
  40407. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  40408. // "A server MAY ignore the Range header". This means it's possible to
  40409. // get a 200 rather than a 206 response from a range request.
  40410. var ok_response_on_range_request =
  40411. xhrStatus === OK_RESPONSE &&
  40412. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  40413. if (!ok_response_on_range_request &&
  40414. xhrStatus !== pendingRequest.expectedStatus) {
  40415. if (pendingRequest.onError) {
  40416. pendingRequest.onError(xhr.status);
  40417. }
  40418. return;
  40419. }
  40420. this.loadedRequests[xhrId] = true;
  40421. var chunk = getArrayBuffer(xhr);
  40422. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  40423. var rangeHeader = xhr.getResponseHeader('Content-Range');
  40424. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  40425. var begin = parseInt(matches[1], 10);
  40426. pendingRequest.onDone({
  40427. begin: begin,
  40428. chunk: chunk
  40429. });
  40430. } else if (pendingRequest.onProgressiveData) {
  40431. pendingRequest.onDone(null);
  40432. } else if (chunk) {
  40433. pendingRequest.onDone({
  40434. begin: 0,
  40435. chunk: chunk
  40436. });
  40437. } else if (pendingRequest.onError) {
  40438. pendingRequest.onError(xhr.status);
  40439. }
  40440. },
  40441. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  40442. for (var xhrId in this.pendingRequests) {
  40443. return true;
  40444. }
  40445. return false;
  40446. },
  40447. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  40448. return this.pendingRequests[xhrId].xhr;
  40449. },
  40450. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  40451. return !!(this.pendingRequests[xhrId].onProgressiveData);
  40452. },
  40453. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  40454. return xhrId in this.pendingRequests;
  40455. },
  40456. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  40457. return xhrId in this.loadedRequests;
  40458. },
  40459. abortAllRequests: function NetworkManager_abortAllRequests() {
  40460. for (var xhrId in this.pendingRequests) {
  40461. this.abortRequest(xhrId | 0);
  40462. }
  40463. },
  40464. abortRequest: function NetworkManager_abortRequest(xhrId) {
  40465. var xhr = this.pendingRequests[xhrId].xhr;
  40466. delete this.pendingRequests[xhrId];
  40467. xhr.abort();
  40468. }
  40469. };
  40470. return NetworkManager;
  40471. })();
  40472. (function (root, factory) {
  40473. {
  40474. factory((root.pdfjsCoreNetwork = {}), root.pdfjsSharedUtil,
  40475. root.pdfjsCoreWorker);
  40476. }
  40477. }(this, function (exports, sharedUtil, coreWorker) {
  40478. var assert = sharedUtil.assert;
  40479. var createPromiseCapability = sharedUtil.createPromiseCapability;
  40480. var isInt = sharedUtil.isInt;
  40481. var MissingPDFException = sharedUtil.MissingPDFException;
  40482. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  40483. /** @implements {IPDFStream} */
  40484. function PDFNetworkStream(options) {
  40485. this._options = options;
  40486. var source = options.source;
  40487. this._manager = new NetworkManager(source.url, {
  40488. httpHeaders: source.httpHeaders,
  40489. withCredentials: source.withCredentials
  40490. });
  40491. this._rangeChunkSize = source.rangeChunkSize;
  40492. this._fullRequestReader = null;
  40493. this._rangeRequestReaders = [];
  40494. }
  40495. PDFNetworkStream.prototype = {
  40496. _onRangeRequestReaderClosed:
  40497. function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
  40498. var i = this._rangeRequestReaders.indexOf(reader);
  40499. if (i >= 0) {
  40500. this._rangeRequestReaders.splice(i, 1);
  40501. }
  40502. },
  40503. getFullReader: function PDFNetworkStream_getFullReader() {
  40504. assert(!this._fullRequestReader);
  40505. this._fullRequestReader =
  40506. new PDFNetworkStreamFullRequestReader(this._manager, this._options);
  40507. return this._fullRequestReader;
  40508. },
  40509. getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
  40510. var reader = new PDFNetworkStreamRangeRequestReader(this._manager,
  40511. begin, end);
  40512. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  40513. this._rangeRequestReaders.push(reader);
  40514. return reader;
  40515. },
  40516. cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
  40517. if (this._fullRequestReader) {
  40518. this._fullRequestReader.cancel(reason);
  40519. }
  40520. var readers = this._rangeRequestReaders.slice(0);
  40521. readers.forEach(function (reader) {
  40522. reader.cancel(reason);
  40523. });
  40524. }
  40525. };
  40526. /** @implements {IPDFStreamReader} */
  40527. function PDFNetworkStreamFullRequestReader(manager, options) {
  40528. this._manager = manager;
  40529. var source = options.source;
  40530. var args = {
  40531. onHeadersReceived: this._onHeadersReceived.bind(this),
  40532. onProgressiveData: source.disableStream ? null :
  40533. this._onProgressiveData.bind(this),
  40534. onDone: this._onDone.bind(this),
  40535. onError: this._onError.bind(this),
  40536. onProgress: this._onProgress.bind(this)
  40537. };
  40538. this._url = source.url;
  40539. this._fullRequestId = manager.requestFull(args);
  40540. this._headersReceivedCapability = createPromiseCapability();
  40541. this._disableRange = options.disableRange || false;
  40542. this._contentLength = source.length; // optional
  40543. this._rangeChunkSize = source.rangeChunkSize;
  40544. if (!this._rangeChunkSize && !this._disableRange) {
  40545. this._disableRange = true;
  40546. }
  40547. this._isStreamingSupported = false;
  40548. this._isRangeSupported = false;
  40549. this._cachedChunks = [];
  40550. this._requests = [];
  40551. this._done = false;
  40552. this._storedError = undefined;
  40553. this.onProgress = null;
  40554. }
  40555. PDFNetworkStreamFullRequestReader.prototype = {
  40556. _validateRangeRequestCapabilities: function
  40557. PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() {
  40558. if (this._disableRange) {
  40559. return false;
  40560. }
  40561. var networkManager = this._manager;
  40562. var fullRequestXhrId = this._fullRequestId;
  40563. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  40564. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  40565. return false;
  40566. }
  40567. var contentEncoding =
  40568. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  40569. if (contentEncoding !== 'identity') {
  40570. return false;
  40571. }
  40572. var length = fullRequestXhr.getResponseHeader('Content-Length');
  40573. length = parseInt(length, 10);
  40574. if (!isInt(length)) {
  40575. return false;
  40576. }
  40577. this._contentLength = length; // setting right content length
  40578. if (length <= 2 * this._rangeChunkSize) {
  40579. // The file size is smaller than the size of two chunks, so it does
  40580. // not make any sense to abort the request and retry with a range
  40581. // request.
  40582. return false;
  40583. }
  40584. return true;
  40585. },
  40586. _onHeadersReceived:
  40587. function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
  40588. if (this._validateRangeRequestCapabilities()) {
  40589. this._isRangeSupported = true;
  40590. }
  40591. var networkManager = this._manager;
  40592. var fullRequestXhrId = this._fullRequestId;
  40593. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  40594. // We can continue fetching when progressive loading is enabled,
  40595. // and we don't need the autoFetch feature.
  40596. this._isStreamingSupported = true;
  40597. } else if (this._isRangeSupported) {
  40598. // NOTE: by cancelling the full request, and then issuing range
  40599. // requests, there will be an issue for sites where you can only
  40600. // request the pdf once. However, if this is the case, then the
  40601. // server should not be returning that it can support range
  40602. // requests.
  40603. networkManager.abortRequest(fullRequestXhrId);
  40604. }
  40605. this._headersReceivedCapability.resolve();
  40606. },
  40607. _onProgressiveData:
  40608. function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
  40609. if (this._requests.length > 0) {
  40610. var requestCapability = this._requests.shift();
  40611. requestCapability.resolve({value: chunk, done: false});
  40612. } else {
  40613. this._cachedChunks.push(chunk);
  40614. }
  40615. },
  40616. _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
  40617. if (args) {
  40618. this._onProgressiveData(args.chunk);
  40619. }
  40620. this._done = true;
  40621. if (this._cachedChunks.length > 0) {
  40622. return;
  40623. }
  40624. this._requests.forEach(function (requestCapability) {
  40625. requestCapability.resolve({value: undefined, done: true});
  40626. });
  40627. this._requests = [];
  40628. },
  40629. _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
  40630. var url = this._url;
  40631. var exception;
  40632. if (status === 404 || status === 0 && /^file:/.test(url)) {
  40633. exception = new MissingPDFException('Missing PDF "' + url + '".');
  40634. } else {
  40635. exception = new UnexpectedResponseException(
  40636. 'Unexpected server response (' + status +
  40637. ') while retrieving PDF "' + url + '".', status);
  40638. }
  40639. this._storedError = exception;
  40640. this._headersReceivedCapability.reject(exception);
  40641. this._requests.forEach(function (requestCapability) {
  40642. requestCapability.reject(exception);
  40643. });
  40644. this._requests = [];
  40645. this._cachedChunks = [];
  40646. },
  40647. _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
  40648. if (this.onProgress) {
  40649. this.onProgress({
  40650. loaded: data.loaded,
  40651. total: data.lengthComputable ? data.total : this._contentLength
  40652. });
  40653. }
  40654. },
  40655. get isRangeSupported() {
  40656. return this._isRangeSupported;
  40657. },
  40658. get isStreamingSupported() {
  40659. return this._isStreamingSupported;
  40660. },
  40661. get contentLength() {
  40662. return this._contentLength;
  40663. },
  40664. get headersReady() {
  40665. return this._headersReceivedCapability.promise;
  40666. },
  40667. read: function PDFNetworkStreamFullRequestReader_read() {
  40668. if (this._storedError) {
  40669. return Promise.reject(this._storedError);
  40670. }
  40671. if (this._cachedChunks.length > 0) {
  40672. var chunk = this._cachedChunks.shift();
  40673. return Promise.resolve(chunk);
  40674. }
  40675. if (this._done) {
  40676. return Promise.resolve({value: undefined, done: true});
  40677. }
  40678. var requestCapability = createPromiseCapability();
  40679. this._requests.push(requestCapability);
  40680. return requestCapability.promise;
  40681. },
  40682. cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
  40683. this._done = true;
  40684. this._headersReceivedCapability.reject(reason);
  40685. this._requests.forEach(function (requestCapability) {
  40686. requestCapability.resolve({value: undefined, done: true});
  40687. });
  40688. this._requests = [];
  40689. if (this._manager.isPendingRequest(this._fullRequestId)) {
  40690. this._manager.abortRequest(this._fullRequestId);
  40691. }
  40692. this._fullRequestReader = null;
  40693. }
  40694. };
  40695. /** @implements {IPDFStreamRangeReader} */
  40696. function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
  40697. this._manager = manager;
  40698. var args = {
  40699. onDone: this._onDone.bind(this),
  40700. onProgress: this._onProgress.bind(this)
  40701. };
  40702. this._requestId = manager.requestRange(begin, end, args);
  40703. this._requests = [];
  40704. this._queuedChunk = null;
  40705. this._done = false;
  40706. this.onProgress = null;
  40707. this.onClosed = null;
  40708. }
  40709. PDFNetworkStreamRangeRequestReader.prototype = {
  40710. _close: function PDFNetworkStreamRangeRequestReader_close() {
  40711. if (this.onClosed) {
  40712. this.onClosed(this);
  40713. }
  40714. },
  40715. _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
  40716. var chunk = data.chunk;
  40717. if (this._requests.length > 0) {
  40718. var requestCapability = this._requests.shift();
  40719. requestCapability.resolve({value: chunk, done: false});
  40720. } else {
  40721. this._queuedChunk = chunk;
  40722. }
  40723. this._done = true;
  40724. this._requests.forEach(function (requestCapability) {
  40725. requestCapability.resolve({value: undefined, done: true});
  40726. });
  40727. this._requests = [];
  40728. this._close();
  40729. },
  40730. _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
  40731. if (!this.isStreamingSupported && this.onProgress) {
  40732. this.onProgress({
  40733. loaded: evt.loaded
  40734. });
  40735. }
  40736. },
  40737. get isStreamingSupported() {
  40738. return false; // TODO allow progressive range bytes loading
  40739. },
  40740. read: function PDFNetworkStreamRangeRequestReader_read() {
  40741. if (this._queuedChunk !== null) {
  40742. var chunk = this._queuedChunk;
  40743. this._queuedChunk = null;
  40744. return Promise.resolve({value: chunk, done: false});
  40745. }
  40746. if (this._done) {
  40747. return Promise.resolve({value: undefined, done: true});
  40748. }
  40749. var requestCapability = createPromiseCapability();
  40750. this._requests.push(requestCapability);
  40751. return requestCapability.promise;
  40752. },
  40753. cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
  40754. this._done = true;
  40755. this._requests.forEach(function (requestCapability) {
  40756. requestCapability.resolve({value: undefined, done: true});
  40757. });
  40758. this._requests = [];
  40759. if (this._manager.isPendingRequest(this._requestId)) {
  40760. this._manager.abortRequest(this._requestId);
  40761. }
  40762. this._close();
  40763. }
  40764. };
  40765. coreWorker.setPDFNetworkStreamClass(PDFNetworkStream);
  40766. exports.PDFNetworkStream = PDFNetworkStream;
  40767. exports.NetworkManager = NetworkManager;
  40768. }));
  40769. }).call(pdfjsLibs);
  40770. exports.WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
  40771. }));