pdf.worker.js 1.4 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469
  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.5.488';
  30. var pdfjsBuild = '6c263c1';
  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['controlRS'] = 0x001E;
  6639. t['controlSI'] = 0x000F;
  6640. t['controlSO'] = 0x000E;
  6641. t['controlSOT'] = 0x0002;
  6642. t['controlSTX'] = 0x0001;
  6643. t['controlSUB'] = 0x001A;
  6644. t['controlSYN'] = 0x0016;
  6645. t['controlUS'] = 0x001F;
  6646. t['controlVT'] = 0x000B;
  6647. t['copyright'] = 0x00A9;
  6648. t['copyrightsans'] = 0xF8E9;
  6649. t['copyrightserif'] = 0xF6D9;
  6650. t['cornerbracketleft'] = 0x300C;
  6651. t['cornerbracketlefthalfwidth'] = 0xFF62;
  6652. t['cornerbracketleftvertical'] = 0xFE41;
  6653. t['cornerbracketright'] = 0x300D;
  6654. t['cornerbracketrighthalfwidth'] = 0xFF63;
  6655. t['cornerbracketrightvertical'] = 0xFE42;
  6656. t['corporationsquare'] = 0x337F;
  6657. t['cosquare'] = 0x33C7;
  6658. t['coverkgsquare'] = 0x33C6;
  6659. t['cparen'] = 0x249E;
  6660. t['cruzeiro'] = 0x20A2;
  6661. t['cstretched'] = 0x0297;
  6662. t['curlyand'] = 0x22CF;
  6663. t['curlyor'] = 0x22CE;
  6664. t['currency'] = 0x00A4;
  6665. t['cyrBreve'] = 0xF6D1;
  6666. t['cyrFlex'] = 0xF6D2;
  6667. t['cyrbreve'] = 0xF6D4;
  6668. t['cyrflex'] = 0xF6D5;
  6669. t['d'] = 0x0064;
  6670. t['daarmenian'] = 0x0564;
  6671. t['dabengali'] = 0x09A6;
  6672. t['dadarabic'] = 0x0636;
  6673. t['dadeva'] = 0x0926;
  6674. t['dadfinalarabic'] = 0xFEBE;
  6675. t['dadinitialarabic'] = 0xFEBF;
  6676. t['dadmedialarabic'] = 0xFEC0;
  6677. t['dagesh'] = 0x05BC;
  6678. t['dageshhebrew'] = 0x05BC;
  6679. t['dagger'] = 0x2020;
  6680. t['daggerdbl'] = 0x2021;
  6681. t['dagujarati'] = 0x0AA6;
  6682. t['dagurmukhi'] = 0x0A26;
  6683. t['dahiragana'] = 0x3060;
  6684. t['dakatakana'] = 0x30C0;
  6685. t['dalarabic'] = 0x062F;
  6686. t['dalet'] = 0x05D3;
  6687. t['daletdagesh'] = 0xFB33;
  6688. t['daletdageshhebrew'] = 0xFB33;
  6689. t['dalethebrew'] = 0x05D3;
  6690. t['dalfinalarabic'] = 0xFEAA;
  6691. t['dammaarabic'] = 0x064F;
  6692. t['dammalowarabic'] = 0x064F;
  6693. t['dammatanaltonearabic'] = 0x064C;
  6694. t['dammatanarabic'] = 0x064C;
  6695. t['danda'] = 0x0964;
  6696. t['dargahebrew'] = 0x05A7;
  6697. t['dargalefthebrew'] = 0x05A7;
  6698. t['dasiapneumatacyrilliccmb'] = 0x0485;
  6699. t['dblGrave'] = 0xF6D3;
  6700. t['dblanglebracketleft'] = 0x300A;
  6701. t['dblanglebracketleftvertical'] = 0xFE3D;
  6702. t['dblanglebracketright'] = 0x300B;
  6703. t['dblanglebracketrightvertical'] = 0xFE3E;
  6704. t['dblarchinvertedbelowcmb'] = 0x032B;
  6705. t['dblarrowleft'] = 0x21D4;
  6706. t['dblarrowright'] = 0x21D2;
  6707. t['dbldanda'] = 0x0965;
  6708. t['dblgrave'] = 0xF6D6;
  6709. t['dblgravecmb'] = 0x030F;
  6710. t['dblintegral'] = 0x222C;
  6711. t['dbllowline'] = 0x2017;
  6712. t['dbllowlinecmb'] = 0x0333;
  6713. t['dbloverlinecmb'] = 0x033F;
  6714. t['dblprimemod'] = 0x02BA;
  6715. t['dblverticalbar'] = 0x2016;
  6716. t['dblverticallineabovecmb'] = 0x030E;
  6717. t['dbopomofo'] = 0x3109;
  6718. t['dbsquare'] = 0x33C8;
  6719. t['dcaron'] = 0x010F;
  6720. t['dcedilla'] = 0x1E11;
  6721. t['dcircle'] = 0x24D3;
  6722. t['dcircumflexbelow'] = 0x1E13;
  6723. t['dcroat'] = 0x0111;
  6724. t['ddabengali'] = 0x09A1;
  6725. t['ddadeva'] = 0x0921;
  6726. t['ddagujarati'] = 0x0AA1;
  6727. t['ddagurmukhi'] = 0x0A21;
  6728. t['ddalarabic'] = 0x0688;
  6729. t['ddalfinalarabic'] = 0xFB89;
  6730. t['dddhadeva'] = 0x095C;
  6731. t['ddhabengali'] = 0x09A2;
  6732. t['ddhadeva'] = 0x0922;
  6733. t['ddhagujarati'] = 0x0AA2;
  6734. t['ddhagurmukhi'] = 0x0A22;
  6735. t['ddotaccent'] = 0x1E0B;
  6736. t['ddotbelow'] = 0x1E0D;
  6737. t['decimalseparatorarabic'] = 0x066B;
  6738. t['decimalseparatorpersian'] = 0x066B;
  6739. t['decyrillic'] = 0x0434;
  6740. t['degree'] = 0x00B0;
  6741. t['dehihebrew'] = 0x05AD;
  6742. t['dehiragana'] = 0x3067;
  6743. t['deicoptic'] = 0x03EF;
  6744. t['dekatakana'] = 0x30C7;
  6745. t['deleteleft'] = 0x232B;
  6746. t['deleteright'] = 0x2326;
  6747. t['delta'] = 0x03B4;
  6748. t['deltaturned'] = 0x018D;
  6749. t['denominatorminusonenumeratorbengali'] = 0x09F8;
  6750. t['dezh'] = 0x02A4;
  6751. t['dhabengali'] = 0x09A7;
  6752. t['dhadeva'] = 0x0927;
  6753. t['dhagujarati'] = 0x0AA7;
  6754. t['dhagurmukhi'] = 0x0A27;
  6755. t['dhook'] = 0x0257;
  6756. t['dialytikatonos'] = 0x0385;
  6757. t['dialytikatonoscmb'] = 0x0344;
  6758. t['diamond'] = 0x2666;
  6759. t['diamondsuitwhite'] = 0x2662;
  6760. t['dieresis'] = 0x00A8;
  6761. t['dieresisacute'] = 0xF6D7;
  6762. t['dieresisbelowcmb'] = 0x0324;
  6763. t['dieresiscmb'] = 0x0308;
  6764. t['dieresisgrave'] = 0xF6D8;
  6765. t['dieresistonos'] = 0x0385;
  6766. t['dihiragana'] = 0x3062;
  6767. t['dikatakana'] = 0x30C2;
  6768. t['dittomark'] = 0x3003;
  6769. t['divide'] = 0x00F7;
  6770. t['divides'] = 0x2223;
  6771. t['divisionslash'] = 0x2215;
  6772. t['djecyrillic'] = 0x0452;
  6773. t['dkshade'] = 0x2593;
  6774. t['dlinebelow'] = 0x1E0F;
  6775. t['dlsquare'] = 0x3397;
  6776. t['dmacron'] = 0x0111;
  6777. t['dmonospace'] = 0xFF44;
  6778. t['dnblock'] = 0x2584;
  6779. t['dochadathai'] = 0x0E0E;
  6780. t['dodekthai'] = 0x0E14;
  6781. t['dohiragana'] = 0x3069;
  6782. t['dokatakana'] = 0x30C9;
  6783. t['dollar'] = 0x0024;
  6784. t['dollarinferior'] = 0xF6E3;
  6785. t['dollarmonospace'] = 0xFF04;
  6786. t['dollaroldstyle'] = 0xF724;
  6787. t['dollarsmall'] = 0xFE69;
  6788. t['dollarsuperior'] = 0xF6E4;
  6789. t['dong'] = 0x20AB;
  6790. t['dorusquare'] = 0x3326;
  6791. t['dotaccent'] = 0x02D9;
  6792. t['dotaccentcmb'] = 0x0307;
  6793. t['dotbelowcmb'] = 0x0323;
  6794. t['dotbelowcomb'] = 0x0323;
  6795. t['dotkatakana'] = 0x30FB;
  6796. t['dotlessi'] = 0x0131;
  6797. t['dotlessj'] = 0xF6BE;
  6798. t['dotlessjstrokehook'] = 0x0284;
  6799. t['dotmath'] = 0x22C5;
  6800. t['dottedcircle'] = 0x25CC;
  6801. t['doubleyodpatah'] = 0xFB1F;
  6802. t['doubleyodpatahhebrew'] = 0xFB1F;
  6803. t['downtackbelowcmb'] = 0x031E;
  6804. t['downtackmod'] = 0x02D5;
  6805. t['dparen'] = 0x249F;
  6806. t['dsuperior'] = 0xF6EB;
  6807. t['dtail'] = 0x0256;
  6808. t['dtopbar'] = 0x018C;
  6809. t['duhiragana'] = 0x3065;
  6810. t['dukatakana'] = 0x30C5;
  6811. t['dz'] = 0x01F3;
  6812. t['dzaltone'] = 0x02A3;
  6813. t['dzcaron'] = 0x01C6;
  6814. t['dzcurl'] = 0x02A5;
  6815. t['dzeabkhasiancyrillic'] = 0x04E1;
  6816. t['dzecyrillic'] = 0x0455;
  6817. t['dzhecyrillic'] = 0x045F;
  6818. t['e'] = 0x0065;
  6819. t['eacute'] = 0x00E9;
  6820. t['earth'] = 0x2641;
  6821. t['ebengali'] = 0x098F;
  6822. t['ebopomofo'] = 0x311C;
  6823. t['ebreve'] = 0x0115;
  6824. t['ecandradeva'] = 0x090D;
  6825. t['ecandragujarati'] = 0x0A8D;
  6826. t['ecandravowelsigndeva'] = 0x0945;
  6827. t['ecandravowelsigngujarati'] = 0x0AC5;
  6828. t['ecaron'] = 0x011B;
  6829. t['ecedillabreve'] = 0x1E1D;
  6830. t['echarmenian'] = 0x0565;
  6831. t['echyiwnarmenian'] = 0x0587;
  6832. t['ecircle'] = 0x24D4;
  6833. t['ecircumflex'] = 0x00EA;
  6834. t['ecircumflexacute'] = 0x1EBF;
  6835. t['ecircumflexbelow'] = 0x1E19;
  6836. t['ecircumflexdotbelow'] = 0x1EC7;
  6837. t['ecircumflexgrave'] = 0x1EC1;
  6838. t['ecircumflexhookabove'] = 0x1EC3;
  6839. t['ecircumflextilde'] = 0x1EC5;
  6840. t['ecyrillic'] = 0x0454;
  6841. t['edblgrave'] = 0x0205;
  6842. t['edeva'] = 0x090F;
  6843. t['edieresis'] = 0x00EB;
  6844. t['edot'] = 0x0117;
  6845. t['edotaccent'] = 0x0117;
  6846. t['edotbelow'] = 0x1EB9;
  6847. t['eegurmukhi'] = 0x0A0F;
  6848. t['eematragurmukhi'] = 0x0A47;
  6849. t['efcyrillic'] = 0x0444;
  6850. t['egrave'] = 0x00E8;
  6851. t['egujarati'] = 0x0A8F;
  6852. t['eharmenian'] = 0x0567;
  6853. t['ehbopomofo'] = 0x311D;
  6854. t['ehiragana'] = 0x3048;
  6855. t['ehookabove'] = 0x1EBB;
  6856. t['eibopomofo'] = 0x311F;
  6857. t['eight'] = 0x0038;
  6858. t['eightarabic'] = 0x0668;
  6859. t['eightbengali'] = 0x09EE;
  6860. t['eightcircle'] = 0x2467;
  6861. t['eightcircleinversesansserif'] = 0x2791;
  6862. t['eightdeva'] = 0x096E;
  6863. t['eighteencircle'] = 0x2471;
  6864. t['eighteenparen'] = 0x2485;
  6865. t['eighteenperiod'] = 0x2499;
  6866. t['eightgujarati'] = 0x0AEE;
  6867. t['eightgurmukhi'] = 0x0A6E;
  6868. t['eighthackarabic'] = 0x0668;
  6869. t['eighthangzhou'] = 0x3028;
  6870. t['eighthnotebeamed'] = 0x266B;
  6871. t['eightideographicparen'] = 0x3227;
  6872. t['eightinferior'] = 0x2088;
  6873. t['eightmonospace'] = 0xFF18;
  6874. t['eightoldstyle'] = 0xF738;
  6875. t['eightparen'] = 0x247B;
  6876. t['eightperiod'] = 0x248F;
  6877. t['eightpersian'] = 0x06F8;
  6878. t['eightroman'] = 0x2177;
  6879. t['eightsuperior'] = 0x2078;
  6880. t['eightthai'] = 0x0E58;
  6881. t['einvertedbreve'] = 0x0207;
  6882. t['eiotifiedcyrillic'] = 0x0465;
  6883. t['ekatakana'] = 0x30A8;
  6884. t['ekatakanahalfwidth'] = 0xFF74;
  6885. t['ekonkargurmukhi'] = 0x0A74;
  6886. t['ekorean'] = 0x3154;
  6887. t['elcyrillic'] = 0x043B;
  6888. t['element'] = 0x2208;
  6889. t['elevencircle'] = 0x246A;
  6890. t['elevenparen'] = 0x247E;
  6891. t['elevenperiod'] = 0x2492;
  6892. t['elevenroman'] = 0x217A;
  6893. t['ellipsis'] = 0x2026;
  6894. t['ellipsisvertical'] = 0x22EE;
  6895. t['emacron'] = 0x0113;
  6896. t['emacronacute'] = 0x1E17;
  6897. t['emacrongrave'] = 0x1E15;
  6898. t['emcyrillic'] = 0x043C;
  6899. t['emdash'] = 0x2014;
  6900. t['emdashvertical'] = 0xFE31;
  6901. t['emonospace'] = 0xFF45;
  6902. t['emphasismarkarmenian'] = 0x055B;
  6903. t['emptyset'] = 0x2205;
  6904. t['enbopomofo'] = 0x3123;
  6905. t['encyrillic'] = 0x043D;
  6906. t['endash'] = 0x2013;
  6907. t['endashvertical'] = 0xFE32;
  6908. t['endescendercyrillic'] = 0x04A3;
  6909. t['eng'] = 0x014B;
  6910. t['engbopomofo'] = 0x3125;
  6911. t['enghecyrillic'] = 0x04A5;
  6912. t['enhookcyrillic'] = 0x04C8;
  6913. t['enspace'] = 0x2002;
  6914. t['eogonek'] = 0x0119;
  6915. t['eokorean'] = 0x3153;
  6916. t['eopen'] = 0x025B;
  6917. t['eopenclosed'] = 0x029A;
  6918. t['eopenreversed'] = 0x025C;
  6919. t['eopenreversedclosed'] = 0x025E;
  6920. t['eopenreversedhook'] = 0x025D;
  6921. t['eparen'] = 0x24A0;
  6922. t['epsilon'] = 0x03B5;
  6923. t['epsilontonos'] = 0x03AD;
  6924. t['equal'] = 0x003D;
  6925. t['equalmonospace'] = 0xFF1D;
  6926. t['equalsmall'] = 0xFE66;
  6927. t['equalsuperior'] = 0x207C;
  6928. t['equivalence'] = 0x2261;
  6929. t['erbopomofo'] = 0x3126;
  6930. t['ercyrillic'] = 0x0440;
  6931. t['ereversed'] = 0x0258;
  6932. t['ereversedcyrillic'] = 0x044D;
  6933. t['escyrillic'] = 0x0441;
  6934. t['esdescendercyrillic'] = 0x04AB;
  6935. t['esh'] = 0x0283;
  6936. t['eshcurl'] = 0x0286;
  6937. t['eshortdeva'] = 0x090E;
  6938. t['eshortvowelsigndeva'] = 0x0946;
  6939. t['eshreversedloop'] = 0x01AA;
  6940. t['eshsquatreversed'] = 0x0285;
  6941. t['esmallhiragana'] = 0x3047;
  6942. t['esmallkatakana'] = 0x30A7;
  6943. t['esmallkatakanahalfwidth'] = 0xFF6A;
  6944. t['estimated'] = 0x212E;
  6945. t['esuperior'] = 0xF6EC;
  6946. t['eta'] = 0x03B7;
  6947. t['etarmenian'] = 0x0568;
  6948. t['etatonos'] = 0x03AE;
  6949. t['eth'] = 0x00F0;
  6950. t['etilde'] = 0x1EBD;
  6951. t['etildebelow'] = 0x1E1B;
  6952. t['etnahtafoukhhebrew'] = 0x0591;
  6953. t['etnahtafoukhlefthebrew'] = 0x0591;
  6954. t['etnahtahebrew'] = 0x0591;
  6955. t['etnahtalefthebrew'] = 0x0591;
  6956. t['eturned'] = 0x01DD;
  6957. t['eukorean'] = 0x3161;
  6958. t['euro'] = 0x20AC;
  6959. t['evowelsignbengali'] = 0x09C7;
  6960. t['evowelsigndeva'] = 0x0947;
  6961. t['evowelsigngujarati'] = 0x0AC7;
  6962. t['exclam'] = 0x0021;
  6963. t['exclamarmenian'] = 0x055C;
  6964. t['exclamdbl'] = 0x203C;
  6965. t['exclamdown'] = 0x00A1;
  6966. t['exclamdownsmall'] = 0xF7A1;
  6967. t['exclammonospace'] = 0xFF01;
  6968. t['exclamsmall'] = 0xF721;
  6969. t['existential'] = 0x2203;
  6970. t['ezh'] = 0x0292;
  6971. t['ezhcaron'] = 0x01EF;
  6972. t['ezhcurl'] = 0x0293;
  6973. t['ezhreversed'] = 0x01B9;
  6974. t['ezhtail'] = 0x01BA;
  6975. t['f'] = 0x0066;
  6976. t['fadeva'] = 0x095E;
  6977. t['fagurmukhi'] = 0x0A5E;
  6978. t['fahrenheit'] = 0x2109;
  6979. t['fathaarabic'] = 0x064E;
  6980. t['fathalowarabic'] = 0x064E;
  6981. t['fathatanarabic'] = 0x064B;
  6982. t['fbopomofo'] = 0x3108;
  6983. t['fcircle'] = 0x24D5;
  6984. t['fdotaccent'] = 0x1E1F;
  6985. t['feharabic'] = 0x0641;
  6986. t['feharmenian'] = 0x0586;
  6987. t['fehfinalarabic'] = 0xFED2;
  6988. t['fehinitialarabic'] = 0xFED3;
  6989. t['fehmedialarabic'] = 0xFED4;
  6990. t['feicoptic'] = 0x03E5;
  6991. t['female'] = 0x2640;
  6992. t['ff'] = 0xFB00;
  6993. t['ffi'] = 0xFB03;
  6994. t['ffl'] = 0xFB04;
  6995. t['fi'] = 0xFB01;
  6996. t['fifteencircle'] = 0x246E;
  6997. t['fifteenparen'] = 0x2482;
  6998. t['fifteenperiod'] = 0x2496;
  6999. t['figuredash'] = 0x2012;
  7000. t['filledbox'] = 0x25A0;
  7001. t['filledrect'] = 0x25AC;
  7002. t['finalkaf'] = 0x05DA;
  7003. t['finalkafdagesh'] = 0xFB3A;
  7004. t['finalkafdageshhebrew'] = 0xFB3A;
  7005. t['finalkafhebrew'] = 0x05DA;
  7006. t['finalmem'] = 0x05DD;
  7007. t['finalmemhebrew'] = 0x05DD;
  7008. t['finalnun'] = 0x05DF;
  7009. t['finalnunhebrew'] = 0x05DF;
  7010. t['finalpe'] = 0x05E3;
  7011. t['finalpehebrew'] = 0x05E3;
  7012. t['finaltsadi'] = 0x05E5;
  7013. t['finaltsadihebrew'] = 0x05E5;
  7014. t['firsttonechinese'] = 0x02C9;
  7015. t['fisheye'] = 0x25C9;
  7016. t['fitacyrillic'] = 0x0473;
  7017. t['five'] = 0x0035;
  7018. t['fivearabic'] = 0x0665;
  7019. t['fivebengali'] = 0x09EB;
  7020. t['fivecircle'] = 0x2464;
  7021. t['fivecircleinversesansserif'] = 0x278E;
  7022. t['fivedeva'] = 0x096B;
  7023. t['fiveeighths'] = 0x215D;
  7024. t['fivegujarati'] = 0x0AEB;
  7025. t['fivegurmukhi'] = 0x0A6B;
  7026. t['fivehackarabic'] = 0x0665;
  7027. t['fivehangzhou'] = 0x3025;
  7028. t['fiveideographicparen'] = 0x3224;
  7029. t['fiveinferior'] = 0x2085;
  7030. t['fivemonospace'] = 0xFF15;
  7031. t['fiveoldstyle'] = 0xF735;
  7032. t['fiveparen'] = 0x2478;
  7033. t['fiveperiod'] = 0x248C;
  7034. t['fivepersian'] = 0x06F5;
  7035. t['fiveroman'] = 0x2174;
  7036. t['fivesuperior'] = 0x2075;
  7037. t['fivethai'] = 0x0E55;
  7038. t['fl'] = 0xFB02;
  7039. t['florin'] = 0x0192;
  7040. t['fmonospace'] = 0xFF46;
  7041. t['fmsquare'] = 0x3399;
  7042. t['fofanthai'] = 0x0E1F;
  7043. t['fofathai'] = 0x0E1D;
  7044. t['fongmanthai'] = 0x0E4F;
  7045. t['forall'] = 0x2200;
  7046. t['four'] = 0x0034;
  7047. t['fourarabic'] = 0x0664;
  7048. t['fourbengali'] = 0x09EA;
  7049. t['fourcircle'] = 0x2463;
  7050. t['fourcircleinversesansserif'] = 0x278D;
  7051. t['fourdeva'] = 0x096A;
  7052. t['fourgujarati'] = 0x0AEA;
  7053. t['fourgurmukhi'] = 0x0A6A;
  7054. t['fourhackarabic'] = 0x0664;
  7055. t['fourhangzhou'] = 0x3024;
  7056. t['fourideographicparen'] = 0x3223;
  7057. t['fourinferior'] = 0x2084;
  7058. t['fourmonospace'] = 0xFF14;
  7059. t['fournumeratorbengali'] = 0x09F7;
  7060. t['fouroldstyle'] = 0xF734;
  7061. t['fourparen'] = 0x2477;
  7062. t['fourperiod'] = 0x248B;
  7063. t['fourpersian'] = 0x06F4;
  7064. t['fourroman'] = 0x2173;
  7065. t['foursuperior'] = 0x2074;
  7066. t['fourteencircle'] = 0x246D;
  7067. t['fourteenparen'] = 0x2481;
  7068. t['fourteenperiod'] = 0x2495;
  7069. t['fourthai'] = 0x0E54;
  7070. t['fourthtonechinese'] = 0x02CB;
  7071. t['fparen'] = 0x24A1;
  7072. t['fraction'] = 0x2044;
  7073. t['franc'] = 0x20A3;
  7074. t['g'] = 0x0067;
  7075. t['gabengali'] = 0x0997;
  7076. t['gacute'] = 0x01F5;
  7077. t['gadeva'] = 0x0917;
  7078. t['gafarabic'] = 0x06AF;
  7079. t['gaffinalarabic'] = 0xFB93;
  7080. t['gafinitialarabic'] = 0xFB94;
  7081. t['gafmedialarabic'] = 0xFB95;
  7082. t['gagujarati'] = 0x0A97;
  7083. t['gagurmukhi'] = 0x0A17;
  7084. t['gahiragana'] = 0x304C;
  7085. t['gakatakana'] = 0x30AC;
  7086. t['gamma'] = 0x03B3;
  7087. t['gammalatinsmall'] = 0x0263;
  7088. t['gammasuperior'] = 0x02E0;
  7089. t['gangiacoptic'] = 0x03EB;
  7090. t['gbopomofo'] = 0x310D;
  7091. t['gbreve'] = 0x011F;
  7092. t['gcaron'] = 0x01E7;
  7093. t['gcedilla'] = 0x0123;
  7094. t['gcircle'] = 0x24D6;
  7095. t['gcircumflex'] = 0x011D;
  7096. t['gcommaaccent'] = 0x0123;
  7097. t['gdot'] = 0x0121;
  7098. t['gdotaccent'] = 0x0121;
  7099. t['gecyrillic'] = 0x0433;
  7100. t['gehiragana'] = 0x3052;
  7101. t['gekatakana'] = 0x30B2;
  7102. t['geometricallyequal'] = 0x2251;
  7103. t['gereshaccenthebrew'] = 0x059C;
  7104. t['gereshhebrew'] = 0x05F3;
  7105. t['gereshmuqdamhebrew'] = 0x059D;
  7106. t['germandbls'] = 0x00DF;
  7107. t['gershayimaccenthebrew'] = 0x059E;
  7108. t['gershayimhebrew'] = 0x05F4;
  7109. t['getamark'] = 0x3013;
  7110. t['ghabengali'] = 0x0998;
  7111. t['ghadarmenian'] = 0x0572;
  7112. t['ghadeva'] = 0x0918;
  7113. t['ghagujarati'] = 0x0A98;
  7114. t['ghagurmukhi'] = 0x0A18;
  7115. t['ghainarabic'] = 0x063A;
  7116. t['ghainfinalarabic'] = 0xFECE;
  7117. t['ghaininitialarabic'] = 0xFECF;
  7118. t['ghainmedialarabic'] = 0xFED0;
  7119. t['ghemiddlehookcyrillic'] = 0x0495;
  7120. t['ghestrokecyrillic'] = 0x0493;
  7121. t['gheupturncyrillic'] = 0x0491;
  7122. t['ghhadeva'] = 0x095A;
  7123. t['ghhagurmukhi'] = 0x0A5A;
  7124. t['ghook'] = 0x0260;
  7125. t['ghzsquare'] = 0x3393;
  7126. t['gihiragana'] = 0x304E;
  7127. t['gikatakana'] = 0x30AE;
  7128. t['gimarmenian'] = 0x0563;
  7129. t['gimel'] = 0x05D2;
  7130. t['gimeldagesh'] = 0xFB32;
  7131. t['gimeldageshhebrew'] = 0xFB32;
  7132. t['gimelhebrew'] = 0x05D2;
  7133. t['gjecyrillic'] = 0x0453;
  7134. t['glottalinvertedstroke'] = 0x01BE;
  7135. t['glottalstop'] = 0x0294;
  7136. t['glottalstopinverted'] = 0x0296;
  7137. t['glottalstopmod'] = 0x02C0;
  7138. t['glottalstopreversed'] = 0x0295;
  7139. t['glottalstopreversedmod'] = 0x02C1;
  7140. t['glottalstopreversedsuperior'] = 0x02E4;
  7141. t['glottalstopstroke'] = 0x02A1;
  7142. t['glottalstopstrokereversed'] = 0x02A2;
  7143. t['gmacron'] = 0x1E21;
  7144. t['gmonospace'] = 0xFF47;
  7145. t['gohiragana'] = 0x3054;
  7146. t['gokatakana'] = 0x30B4;
  7147. t['gparen'] = 0x24A2;
  7148. t['gpasquare'] = 0x33AC;
  7149. t['gradient'] = 0x2207;
  7150. t['grave'] = 0x0060;
  7151. t['gravebelowcmb'] = 0x0316;
  7152. t['gravecmb'] = 0x0300;
  7153. t['gravecomb'] = 0x0300;
  7154. t['gravedeva'] = 0x0953;
  7155. t['gravelowmod'] = 0x02CE;
  7156. t['gravemonospace'] = 0xFF40;
  7157. t['gravetonecmb'] = 0x0340;
  7158. t['greater'] = 0x003E;
  7159. t['greaterequal'] = 0x2265;
  7160. t['greaterequalorless'] = 0x22DB;
  7161. t['greatermonospace'] = 0xFF1E;
  7162. t['greaterorequivalent'] = 0x2273;
  7163. t['greaterorless'] = 0x2277;
  7164. t['greateroverequal'] = 0x2267;
  7165. t['greatersmall'] = 0xFE65;
  7166. t['gscript'] = 0x0261;
  7167. t['gstroke'] = 0x01E5;
  7168. t['guhiragana'] = 0x3050;
  7169. t['guillemotleft'] = 0x00AB;
  7170. t['guillemotright'] = 0x00BB;
  7171. t['guilsinglleft'] = 0x2039;
  7172. t['guilsinglright'] = 0x203A;
  7173. t['gukatakana'] = 0x30B0;
  7174. t['guramusquare'] = 0x3318;
  7175. t['gysquare'] = 0x33C9;
  7176. t['h'] = 0x0068;
  7177. t['haabkhasiancyrillic'] = 0x04A9;
  7178. t['haaltonearabic'] = 0x06C1;
  7179. t['habengali'] = 0x09B9;
  7180. t['hadescendercyrillic'] = 0x04B3;
  7181. t['hadeva'] = 0x0939;
  7182. t['hagujarati'] = 0x0AB9;
  7183. t['hagurmukhi'] = 0x0A39;
  7184. t['haharabic'] = 0x062D;
  7185. t['hahfinalarabic'] = 0xFEA2;
  7186. t['hahinitialarabic'] = 0xFEA3;
  7187. t['hahiragana'] = 0x306F;
  7188. t['hahmedialarabic'] = 0xFEA4;
  7189. t['haitusquare'] = 0x332A;
  7190. t['hakatakana'] = 0x30CF;
  7191. t['hakatakanahalfwidth'] = 0xFF8A;
  7192. t['halantgurmukhi'] = 0x0A4D;
  7193. t['hamzaarabic'] = 0x0621;
  7194. t['hamzalowarabic'] = 0x0621;
  7195. t['hangulfiller'] = 0x3164;
  7196. t['hardsigncyrillic'] = 0x044A;
  7197. t['harpoonleftbarbup'] = 0x21BC;
  7198. t['harpoonrightbarbup'] = 0x21C0;
  7199. t['hasquare'] = 0x33CA;
  7200. t['hatafpatah'] = 0x05B2;
  7201. t['hatafpatah16'] = 0x05B2;
  7202. t['hatafpatah23'] = 0x05B2;
  7203. t['hatafpatah2f'] = 0x05B2;
  7204. t['hatafpatahhebrew'] = 0x05B2;
  7205. t['hatafpatahnarrowhebrew'] = 0x05B2;
  7206. t['hatafpatahquarterhebrew'] = 0x05B2;
  7207. t['hatafpatahwidehebrew'] = 0x05B2;
  7208. t['hatafqamats'] = 0x05B3;
  7209. t['hatafqamats1b'] = 0x05B3;
  7210. t['hatafqamats28'] = 0x05B3;
  7211. t['hatafqamats34'] = 0x05B3;
  7212. t['hatafqamatshebrew'] = 0x05B3;
  7213. t['hatafqamatsnarrowhebrew'] = 0x05B3;
  7214. t['hatafqamatsquarterhebrew'] = 0x05B3;
  7215. t['hatafqamatswidehebrew'] = 0x05B3;
  7216. t['hatafsegol'] = 0x05B1;
  7217. t['hatafsegol17'] = 0x05B1;
  7218. t['hatafsegol24'] = 0x05B1;
  7219. t['hatafsegol30'] = 0x05B1;
  7220. t['hatafsegolhebrew'] = 0x05B1;
  7221. t['hatafsegolnarrowhebrew'] = 0x05B1;
  7222. t['hatafsegolquarterhebrew'] = 0x05B1;
  7223. t['hatafsegolwidehebrew'] = 0x05B1;
  7224. t['hbar'] = 0x0127;
  7225. t['hbopomofo'] = 0x310F;
  7226. t['hbrevebelow'] = 0x1E2B;
  7227. t['hcedilla'] = 0x1E29;
  7228. t['hcircle'] = 0x24D7;
  7229. t['hcircumflex'] = 0x0125;
  7230. t['hdieresis'] = 0x1E27;
  7231. t['hdotaccent'] = 0x1E23;
  7232. t['hdotbelow'] = 0x1E25;
  7233. t['he'] = 0x05D4;
  7234. t['heart'] = 0x2665;
  7235. t['heartsuitblack'] = 0x2665;
  7236. t['heartsuitwhite'] = 0x2661;
  7237. t['hedagesh'] = 0xFB34;
  7238. t['hedageshhebrew'] = 0xFB34;
  7239. t['hehaltonearabic'] = 0x06C1;
  7240. t['heharabic'] = 0x0647;
  7241. t['hehebrew'] = 0x05D4;
  7242. t['hehfinalaltonearabic'] = 0xFBA7;
  7243. t['hehfinalalttwoarabic'] = 0xFEEA;
  7244. t['hehfinalarabic'] = 0xFEEA;
  7245. t['hehhamzaabovefinalarabic'] = 0xFBA5;
  7246. t['hehhamzaaboveisolatedarabic'] = 0xFBA4;
  7247. t['hehinitialaltonearabic'] = 0xFBA8;
  7248. t['hehinitialarabic'] = 0xFEEB;
  7249. t['hehiragana'] = 0x3078;
  7250. t['hehmedialaltonearabic'] = 0xFBA9;
  7251. t['hehmedialarabic'] = 0xFEEC;
  7252. t['heiseierasquare'] = 0x337B;
  7253. t['hekatakana'] = 0x30D8;
  7254. t['hekatakanahalfwidth'] = 0xFF8D;
  7255. t['hekutaarusquare'] = 0x3336;
  7256. t['henghook'] = 0x0267;
  7257. t['herutusquare'] = 0x3339;
  7258. t['het'] = 0x05D7;
  7259. t['hethebrew'] = 0x05D7;
  7260. t['hhook'] = 0x0266;
  7261. t['hhooksuperior'] = 0x02B1;
  7262. t['hieuhacirclekorean'] = 0x327B;
  7263. t['hieuhaparenkorean'] = 0x321B;
  7264. t['hieuhcirclekorean'] = 0x326D;
  7265. t['hieuhkorean'] = 0x314E;
  7266. t['hieuhparenkorean'] = 0x320D;
  7267. t['hihiragana'] = 0x3072;
  7268. t['hikatakana'] = 0x30D2;
  7269. t['hikatakanahalfwidth'] = 0xFF8B;
  7270. t['hiriq'] = 0x05B4;
  7271. t['hiriq14'] = 0x05B4;
  7272. t['hiriq21'] = 0x05B4;
  7273. t['hiriq2d'] = 0x05B4;
  7274. t['hiriqhebrew'] = 0x05B4;
  7275. t['hiriqnarrowhebrew'] = 0x05B4;
  7276. t['hiriqquarterhebrew'] = 0x05B4;
  7277. t['hiriqwidehebrew'] = 0x05B4;
  7278. t['hlinebelow'] = 0x1E96;
  7279. t['hmonospace'] = 0xFF48;
  7280. t['hoarmenian'] = 0x0570;
  7281. t['hohipthai'] = 0x0E2B;
  7282. t['hohiragana'] = 0x307B;
  7283. t['hokatakana'] = 0x30DB;
  7284. t['hokatakanahalfwidth'] = 0xFF8E;
  7285. t['holam'] = 0x05B9;
  7286. t['holam19'] = 0x05B9;
  7287. t['holam26'] = 0x05B9;
  7288. t['holam32'] = 0x05B9;
  7289. t['holamhebrew'] = 0x05B9;
  7290. t['holamnarrowhebrew'] = 0x05B9;
  7291. t['holamquarterhebrew'] = 0x05B9;
  7292. t['holamwidehebrew'] = 0x05B9;
  7293. t['honokhukthai'] = 0x0E2E;
  7294. t['hookabovecomb'] = 0x0309;
  7295. t['hookcmb'] = 0x0309;
  7296. t['hookpalatalizedbelowcmb'] = 0x0321;
  7297. t['hookretroflexbelowcmb'] = 0x0322;
  7298. t['hoonsquare'] = 0x3342;
  7299. t['horicoptic'] = 0x03E9;
  7300. t['horizontalbar'] = 0x2015;
  7301. t['horncmb'] = 0x031B;
  7302. t['hotsprings'] = 0x2668;
  7303. t['house'] = 0x2302;
  7304. t['hparen'] = 0x24A3;
  7305. t['hsuperior'] = 0x02B0;
  7306. t['hturned'] = 0x0265;
  7307. t['huhiragana'] = 0x3075;
  7308. t['huiitosquare'] = 0x3333;
  7309. t['hukatakana'] = 0x30D5;
  7310. t['hukatakanahalfwidth'] = 0xFF8C;
  7311. t['hungarumlaut'] = 0x02DD;
  7312. t['hungarumlautcmb'] = 0x030B;
  7313. t['hv'] = 0x0195;
  7314. t['hyphen'] = 0x002D;
  7315. t['hypheninferior'] = 0xF6E5;
  7316. t['hyphenmonospace'] = 0xFF0D;
  7317. t['hyphensmall'] = 0xFE63;
  7318. t['hyphensuperior'] = 0xF6E6;
  7319. t['hyphentwo'] = 0x2010;
  7320. t['i'] = 0x0069;
  7321. t['iacute'] = 0x00ED;
  7322. t['iacyrillic'] = 0x044F;
  7323. t['ibengali'] = 0x0987;
  7324. t['ibopomofo'] = 0x3127;
  7325. t['ibreve'] = 0x012D;
  7326. t['icaron'] = 0x01D0;
  7327. t['icircle'] = 0x24D8;
  7328. t['icircumflex'] = 0x00EE;
  7329. t['icyrillic'] = 0x0456;
  7330. t['idblgrave'] = 0x0209;
  7331. t['ideographearthcircle'] = 0x328F;
  7332. t['ideographfirecircle'] = 0x328B;
  7333. t['ideographicallianceparen'] = 0x323F;
  7334. t['ideographiccallparen'] = 0x323A;
  7335. t['ideographiccentrecircle'] = 0x32A5;
  7336. t['ideographicclose'] = 0x3006;
  7337. t['ideographiccomma'] = 0x3001;
  7338. t['ideographiccommaleft'] = 0xFF64;
  7339. t['ideographiccongratulationparen'] = 0x3237;
  7340. t['ideographiccorrectcircle'] = 0x32A3;
  7341. t['ideographicearthparen'] = 0x322F;
  7342. t['ideographicenterpriseparen'] = 0x323D;
  7343. t['ideographicexcellentcircle'] = 0x329D;
  7344. t['ideographicfestivalparen'] = 0x3240;
  7345. t['ideographicfinancialcircle'] = 0x3296;
  7346. t['ideographicfinancialparen'] = 0x3236;
  7347. t['ideographicfireparen'] = 0x322B;
  7348. t['ideographichaveparen'] = 0x3232;
  7349. t['ideographichighcircle'] = 0x32A4;
  7350. t['ideographiciterationmark'] = 0x3005;
  7351. t['ideographiclaborcircle'] = 0x3298;
  7352. t['ideographiclaborparen'] = 0x3238;
  7353. t['ideographicleftcircle'] = 0x32A7;
  7354. t['ideographiclowcircle'] = 0x32A6;
  7355. t['ideographicmedicinecircle'] = 0x32A9;
  7356. t['ideographicmetalparen'] = 0x322E;
  7357. t['ideographicmoonparen'] = 0x322A;
  7358. t['ideographicnameparen'] = 0x3234;
  7359. t['ideographicperiod'] = 0x3002;
  7360. t['ideographicprintcircle'] = 0x329E;
  7361. t['ideographicreachparen'] = 0x3243;
  7362. t['ideographicrepresentparen'] = 0x3239;
  7363. t['ideographicresourceparen'] = 0x323E;
  7364. t['ideographicrightcircle'] = 0x32A8;
  7365. t['ideographicsecretcircle'] = 0x3299;
  7366. t['ideographicselfparen'] = 0x3242;
  7367. t['ideographicsocietyparen'] = 0x3233;
  7368. t['ideographicspace'] = 0x3000;
  7369. t['ideographicspecialparen'] = 0x3235;
  7370. t['ideographicstockparen'] = 0x3231;
  7371. t['ideographicstudyparen'] = 0x323B;
  7372. t['ideographicsunparen'] = 0x3230;
  7373. t['ideographicsuperviseparen'] = 0x323C;
  7374. t['ideographicwaterparen'] = 0x322C;
  7375. t['ideographicwoodparen'] = 0x322D;
  7376. t['ideographiczero'] = 0x3007;
  7377. t['ideographmetalcircle'] = 0x328E;
  7378. t['ideographmooncircle'] = 0x328A;
  7379. t['ideographnamecircle'] = 0x3294;
  7380. t['ideographsuncircle'] = 0x3290;
  7381. t['ideographwatercircle'] = 0x328C;
  7382. t['ideographwoodcircle'] = 0x328D;
  7383. t['ideva'] = 0x0907;
  7384. t['idieresis'] = 0x00EF;
  7385. t['idieresisacute'] = 0x1E2F;
  7386. t['idieresiscyrillic'] = 0x04E5;
  7387. t['idotbelow'] = 0x1ECB;
  7388. t['iebrevecyrillic'] = 0x04D7;
  7389. t['iecyrillic'] = 0x0435;
  7390. t['ieungacirclekorean'] = 0x3275;
  7391. t['ieungaparenkorean'] = 0x3215;
  7392. t['ieungcirclekorean'] = 0x3267;
  7393. t['ieungkorean'] = 0x3147;
  7394. t['ieungparenkorean'] = 0x3207;
  7395. t['igrave'] = 0x00EC;
  7396. t['igujarati'] = 0x0A87;
  7397. t['igurmukhi'] = 0x0A07;
  7398. t['ihiragana'] = 0x3044;
  7399. t['ihookabove'] = 0x1EC9;
  7400. t['iibengali'] = 0x0988;
  7401. t['iicyrillic'] = 0x0438;
  7402. t['iideva'] = 0x0908;
  7403. t['iigujarati'] = 0x0A88;
  7404. t['iigurmukhi'] = 0x0A08;
  7405. t['iimatragurmukhi'] = 0x0A40;
  7406. t['iinvertedbreve'] = 0x020B;
  7407. t['iishortcyrillic'] = 0x0439;
  7408. t['iivowelsignbengali'] = 0x09C0;
  7409. t['iivowelsigndeva'] = 0x0940;
  7410. t['iivowelsigngujarati'] = 0x0AC0;
  7411. t['ij'] = 0x0133;
  7412. t['ikatakana'] = 0x30A4;
  7413. t['ikatakanahalfwidth'] = 0xFF72;
  7414. t['ikorean'] = 0x3163;
  7415. t['ilde'] = 0x02DC;
  7416. t['iluyhebrew'] = 0x05AC;
  7417. t['imacron'] = 0x012B;
  7418. t['imacroncyrillic'] = 0x04E3;
  7419. t['imageorapproximatelyequal'] = 0x2253;
  7420. t['imatragurmukhi'] = 0x0A3F;
  7421. t['imonospace'] = 0xFF49;
  7422. t['increment'] = 0x2206;
  7423. t['infinity'] = 0x221E;
  7424. t['iniarmenian'] = 0x056B;
  7425. t['integral'] = 0x222B;
  7426. t['integralbottom'] = 0x2321;
  7427. t['integralbt'] = 0x2321;
  7428. t['integralex'] = 0xF8F5;
  7429. t['integraltop'] = 0x2320;
  7430. t['integraltp'] = 0x2320;
  7431. t['intersection'] = 0x2229;
  7432. t['intisquare'] = 0x3305;
  7433. t['invbullet'] = 0x25D8;
  7434. t['invcircle'] = 0x25D9;
  7435. t['invsmileface'] = 0x263B;
  7436. t['iocyrillic'] = 0x0451;
  7437. t['iogonek'] = 0x012F;
  7438. t['iota'] = 0x03B9;
  7439. t['iotadieresis'] = 0x03CA;
  7440. t['iotadieresistonos'] = 0x0390;
  7441. t['iotalatin'] = 0x0269;
  7442. t['iotatonos'] = 0x03AF;
  7443. t['iparen'] = 0x24A4;
  7444. t['irigurmukhi'] = 0x0A72;
  7445. t['ismallhiragana'] = 0x3043;
  7446. t['ismallkatakana'] = 0x30A3;
  7447. t['ismallkatakanahalfwidth'] = 0xFF68;
  7448. t['issharbengali'] = 0x09FA;
  7449. t['istroke'] = 0x0268;
  7450. t['isuperior'] = 0xF6ED;
  7451. t['iterationhiragana'] = 0x309D;
  7452. t['iterationkatakana'] = 0x30FD;
  7453. t['itilde'] = 0x0129;
  7454. t['itildebelow'] = 0x1E2D;
  7455. t['iubopomofo'] = 0x3129;
  7456. t['iucyrillic'] = 0x044E;
  7457. t['ivowelsignbengali'] = 0x09BF;
  7458. t['ivowelsigndeva'] = 0x093F;
  7459. t['ivowelsigngujarati'] = 0x0ABF;
  7460. t['izhitsacyrillic'] = 0x0475;
  7461. t['izhitsadblgravecyrillic'] = 0x0477;
  7462. t['j'] = 0x006A;
  7463. t['jaarmenian'] = 0x0571;
  7464. t['jabengali'] = 0x099C;
  7465. t['jadeva'] = 0x091C;
  7466. t['jagujarati'] = 0x0A9C;
  7467. t['jagurmukhi'] = 0x0A1C;
  7468. t['jbopomofo'] = 0x3110;
  7469. t['jcaron'] = 0x01F0;
  7470. t['jcircle'] = 0x24D9;
  7471. t['jcircumflex'] = 0x0135;
  7472. t['jcrossedtail'] = 0x029D;
  7473. t['jdotlessstroke'] = 0x025F;
  7474. t['jecyrillic'] = 0x0458;
  7475. t['jeemarabic'] = 0x062C;
  7476. t['jeemfinalarabic'] = 0xFE9E;
  7477. t['jeeminitialarabic'] = 0xFE9F;
  7478. t['jeemmedialarabic'] = 0xFEA0;
  7479. t['jeharabic'] = 0x0698;
  7480. t['jehfinalarabic'] = 0xFB8B;
  7481. t['jhabengali'] = 0x099D;
  7482. t['jhadeva'] = 0x091D;
  7483. t['jhagujarati'] = 0x0A9D;
  7484. t['jhagurmukhi'] = 0x0A1D;
  7485. t['jheharmenian'] = 0x057B;
  7486. t['jis'] = 0x3004;
  7487. t['jmonospace'] = 0xFF4A;
  7488. t['jparen'] = 0x24A5;
  7489. t['jsuperior'] = 0x02B2;
  7490. t['k'] = 0x006B;
  7491. t['kabashkircyrillic'] = 0x04A1;
  7492. t['kabengali'] = 0x0995;
  7493. t['kacute'] = 0x1E31;
  7494. t['kacyrillic'] = 0x043A;
  7495. t['kadescendercyrillic'] = 0x049B;
  7496. t['kadeva'] = 0x0915;
  7497. t['kaf'] = 0x05DB;
  7498. t['kafarabic'] = 0x0643;
  7499. t['kafdagesh'] = 0xFB3B;
  7500. t['kafdageshhebrew'] = 0xFB3B;
  7501. t['kaffinalarabic'] = 0xFEDA;
  7502. t['kafhebrew'] = 0x05DB;
  7503. t['kafinitialarabic'] = 0xFEDB;
  7504. t['kafmedialarabic'] = 0xFEDC;
  7505. t['kafrafehebrew'] = 0xFB4D;
  7506. t['kagujarati'] = 0x0A95;
  7507. t['kagurmukhi'] = 0x0A15;
  7508. t['kahiragana'] = 0x304B;
  7509. t['kahookcyrillic'] = 0x04C4;
  7510. t['kakatakana'] = 0x30AB;
  7511. t['kakatakanahalfwidth'] = 0xFF76;
  7512. t['kappa'] = 0x03BA;
  7513. t['kappasymbolgreek'] = 0x03F0;
  7514. t['kapyeounmieumkorean'] = 0x3171;
  7515. t['kapyeounphieuphkorean'] = 0x3184;
  7516. t['kapyeounpieupkorean'] = 0x3178;
  7517. t['kapyeounssangpieupkorean'] = 0x3179;
  7518. t['karoriisquare'] = 0x330D;
  7519. t['kashidaautoarabic'] = 0x0640;
  7520. t['kashidaautonosidebearingarabic'] = 0x0640;
  7521. t['kasmallkatakana'] = 0x30F5;
  7522. t['kasquare'] = 0x3384;
  7523. t['kasraarabic'] = 0x0650;
  7524. t['kasratanarabic'] = 0x064D;
  7525. t['kastrokecyrillic'] = 0x049F;
  7526. t['katahiraprolongmarkhalfwidth'] = 0xFF70;
  7527. t['kaverticalstrokecyrillic'] = 0x049D;
  7528. t['kbopomofo'] = 0x310E;
  7529. t['kcalsquare'] = 0x3389;
  7530. t['kcaron'] = 0x01E9;
  7531. t['kcedilla'] = 0x0137;
  7532. t['kcircle'] = 0x24DA;
  7533. t['kcommaaccent'] = 0x0137;
  7534. t['kdotbelow'] = 0x1E33;
  7535. t['keharmenian'] = 0x0584;
  7536. t['kehiragana'] = 0x3051;
  7537. t['kekatakana'] = 0x30B1;
  7538. t['kekatakanahalfwidth'] = 0xFF79;
  7539. t['kenarmenian'] = 0x056F;
  7540. t['kesmallkatakana'] = 0x30F6;
  7541. t['kgreenlandic'] = 0x0138;
  7542. t['khabengali'] = 0x0996;
  7543. t['khacyrillic'] = 0x0445;
  7544. t['khadeva'] = 0x0916;
  7545. t['khagujarati'] = 0x0A96;
  7546. t['khagurmukhi'] = 0x0A16;
  7547. t['khaharabic'] = 0x062E;
  7548. t['khahfinalarabic'] = 0xFEA6;
  7549. t['khahinitialarabic'] = 0xFEA7;
  7550. t['khahmedialarabic'] = 0xFEA8;
  7551. t['kheicoptic'] = 0x03E7;
  7552. t['khhadeva'] = 0x0959;
  7553. t['khhagurmukhi'] = 0x0A59;
  7554. t['khieukhacirclekorean'] = 0x3278;
  7555. t['khieukhaparenkorean'] = 0x3218;
  7556. t['khieukhcirclekorean'] = 0x326A;
  7557. t['khieukhkorean'] = 0x314B;
  7558. t['khieukhparenkorean'] = 0x320A;
  7559. t['khokhaithai'] = 0x0E02;
  7560. t['khokhonthai'] = 0x0E05;
  7561. t['khokhuatthai'] = 0x0E03;
  7562. t['khokhwaithai'] = 0x0E04;
  7563. t['khomutthai'] = 0x0E5B;
  7564. t['khook'] = 0x0199;
  7565. t['khorakhangthai'] = 0x0E06;
  7566. t['khzsquare'] = 0x3391;
  7567. t['kihiragana'] = 0x304D;
  7568. t['kikatakana'] = 0x30AD;
  7569. t['kikatakanahalfwidth'] = 0xFF77;
  7570. t['kiroguramusquare'] = 0x3315;
  7571. t['kiromeetorusquare'] = 0x3316;
  7572. t['kirosquare'] = 0x3314;
  7573. t['kiyeokacirclekorean'] = 0x326E;
  7574. t['kiyeokaparenkorean'] = 0x320E;
  7575. t['kiyeokcirclekorean'] = 0x3260;
  7576. t['kiyeokkorean'] = 0x3131;
  7577. t['kiyeokparenkorean'] = 0x3200;
  7578. t['kiyeoksioskorean'] = 0x3133;
  7579. t['kjecyrillic'] = 0x045C;
  7580. t['klinebelow'] = 0x1E35;
  7581. t['klsquare'] = 0x3398;
  7582. t['kmcubedsquare'] = 0x33A6;
  7583. t['kmonospace'] = 0xFF4B;
  7584. t['kmsquaredsquare'] = 0x33A2;
  7585. t['kohiragana'] = 0x3053;
  7586. t['kohmsquare'] = 0x33C0;
  7587. t['kokaithai'] = 0x0E01;
  7588. t['kokatakana'] = 0x30B3;
  7589. t['kokatakanahalfwidth'] = 0xFF7A;
  7590. t['kooposquare'] = 0x331E;
  7591. t['koppacyrillic'] = 0x0481;
  7592. t['koreanstandardsymbol'] = 0x327F;
  7593. t['koroniscmb'] = 0x0343;
  7594. t['kparen'] = 0x24A6;
  7595. t['kpasquare'] = 0x33AA;
  7596. t['ksicyrillic'] = 0x046F;
  7597. t['ktsquare'] = 0x33CF;
  7598. t['kturned'] = 0x029E;
  7599. t['kuhiragana'] = 0x304F;
  7600. t['kukatakana'] = 0x30AF;
  7601. t['kukatakanahalfwidth'] = 0xFF78;
  7602. t['kvsquare'] = 0x33B8;
  7603. t['kwsquare'] = 0x33BE;
  7604. t['l'] = 0x006C;
  7605. t['labengali'] = 0x09B2;
  7606. t['lacute'] = 0x013A;
  7607. t['ladeva'] = 0x0932;
  7608. t['lagujarati'] = 0x0AB2;
  7609. t['lagurmukhi'] = 0x0A32;
  7610. t['lakkhangyaothai'] = 0x0E45;
  7611. t['lamaleffinalarabic'] = 0xFEFC;
  7612. t['lamalefhamzaabovefinalarabic'] = 0xFEF8;
  7613. t['lamalefhamzaaboveisolatedarabic'] = 0xFEF7;
  7614. t['lamalefhamzabelowfinalarabic'] = 0xFEFA;
  7615. t['lamalefhamzabelowisolatedarabic'] = 0xFEF9;
  7616. t['lamalefisolatedarabic'] = 0xFEFB;
  7617. t['lamalefmaddaabovefinalarabic'] = 0xFEF6;
  7618. t['lamalefmaddaaboveisolatedarabic'] = 0xFEF5;
  7619. t['lamarabic'] = 0x0644;
  7620. t['lambda'] = 0x03BB;
  7621. t['lambdastroke'] = 0x019B;
  7622. t['lamed'] = 0x05DC;
  7623. t['lameddagesh'] = 0xFB3C;
  7624. t['lameddageshhebrew'] = 0xFB3C;
  7625. t['lamedhebrew'] = 0x05DC;
  7626. t['lamfinalarabic'] = 0xFEDE;
  7627. t['lamhahinitialarabic'] = 0xFCCA;
  7628. t['laminitialarabic'] = 0xFEDF;
  7629. t['lamjeeminitialarabic'] = 0xFCC9;
  7630. t['lamkhahinitialarabic'] = 0xFCCB;
  7631. t['lamlamhehisolatedarabic'] = 0xFDF2;
  7632. t['lammedialarabic'] = 0xFEE0;
  7633. t['lammeemhahinitialarabic'] = 0xFD88;
  7634. t['lammeeminitialarabic'] = 0xFCCC;
  7635. t['largecircle'] = 0x25EF;
  7636. t['lbar'] = 0x019A;
  7637. t['lbelt'] = 0x026C;
  7638. t['lbopomofo'] = 0x310C;
  7639. t['lcaron'] = 0x013E;
  7640. t['lcedilla'] = 0x013C;
  7641. t['lcircle'] = 0x24DB;
  7642. t['lcircumflexbelow'] = 0x1E3D;
  7643. t['lcommaaccent'] = 0x013C;
  7644. t['ldot'] = 0x0140;
  7645. t['ldotaccent'] = 0x0140;
  7646. t['ldotbelow'] = 0x1E37;
  7647. t['ldotbelowmacron'] = 0x1E39;
  7648. t['leftangleabovecmb'] = 0x031A;
  7649. t['lefttackbelowcmb'] = 0x0318;
  7650. t['less'] = 0x003C;
  7651. t['lessequal'] = 0x2264;
  7652. t['lessequalorgreater'] = 0x22DA;
  7653. t['lessmonospace'] = 0xFF1C;
  7654. t['lessorequivalent'] = 0x2272;
  7655. t['lessorgreater'] = 0x2276;
  7656. t['lessoverequal'] = 0x2266;
  7657. t['lesssmall'] = 0xFE64;
  7658. t['lezh'] = 0x026E;
  7659. t['lfblock'] = 0x258C;
  7660. t['lhookretroflex'] = 0x026D;
  7661. t['lira'] = 0x20A4;
  7662. t['liwnarmenian'] = 0x056C;
  7663. t['lj'] = 0x01C9;
  7664. t['ljecyrillic'] = 0x0459;
  7665. t['ll'] = 0xF6C0;
  7666. t['lladeva'] = 0x0933;
  7667. t['llagujarati'] = 0x0AB3;
  7668. t['llinebelow'] = 0x1E3B;
  7669. t['llladeva'] = 0x0934;
  7670. t['llvocalicbengali'] = 0x09E1;
  7671. t['llvocalicdeva'] = 0x0961;
  7672. t['llvocalicvowelsignbengali'] = 0x09E3;
  7673. t['llvocalicvowelsigndeva'] = 0x0963;
  7674. t['lmiddletilde'] = 0x026B;
  7675. t['lmonospace'] = 0xFF4C;
  7676. t['lmsquare'] = 0x33D0;
  7677. t['lochulathai'] = 0x0E2C;
  7678. t['logicaland'] = 0x2227;
  7679. t['logicalnot'] = 0x00AC;
  7680. t['logicalnotreversed'] = 0x2310;
  7681. t['logicalor'] = 0x2228;
  7682. t['lolingthai'] = 0x0E25;
  7683. t['longs'] = 0x017F;
  7684. t['lowlinecenterline'] = 0xFE4E;
  7685. t['lowlinecmb'] = 0x0332;
  7686. t['lowlinedashed'] = 0xFE4D;
  7687. t['lozenge'] = 0x25CA;
  7688. t['lparen'] = 0x24A7;
  7689. t['lslash'] = 0x0142;
  7690. t['lsquare'] = 0x2113;
  7691. t['lsuperior'] = 0xF6EE;
  7692. t['ltshade'] = 0x2591;
  7693. t['luthai'] = 0x0E26;
  7694. t['lvocalicbengali'] = 0x098C;
  7695. t['lvocalicdeva'] = 0x090C;
  7696. t['lvocalicvowelsignbengali'] = 0x09E2;
  7697. t['lvocalicvowelsigndeva'] = 0x0962;
  7698. t['lxsquare'] = 0x33D3;
  7699. t['m'] = 0x006D;
  7700. t['mabengali'] = 0x09AE;
  7701. t['macron'] = 0x00AF;
  7702. t['macronbelowcmb'] = 0x0331;
  7703. t['macroncmb'] = 0x0304;
  7704. t['macronlowmod'] = 0x02CD;
  7705. t['macronmonospace'] = 0xFFE3;
  7706. t['macute'] = 0x1E3F;
  7707. t['madeva'] = 0x092E;
  7708. t['magujarati'] = 0x0AAE;
  7709. t['magurmukhi'] = 0x0A2E;
  7710. t['mahapakhhebrew'] = 0x05A4;
  7711. t['mahapakhlefthebrew'] = 0x05A4;
  7712. t['mahiragana'] = 0x307E;
  7713. t['maichattawalowleftthai'] = 0xF895;
  7714. t['maichattawalowrightthai'] = 0xF894;
  7715. t['maichattawathai'] = 0x0E4B;
  7716. t['maichattawaupperleftthai'] = 0xF893;
  7717. t['maieklowleftthai'] = 0xF88C;
  7718. t['maieklowrightthai'] = 0xF88B;
  7719. t['maiekthai'] = 0x0E48;
  7720. t['maiekupperleftthai'] = 0xF88A;
  7721. t['maihanakatleftthai'] = 0xF884;
  7722. t['maihanakatthai'] = 0x0E31;
  7723. t['maitaikhuleftthai'] = 0xF889;
  7724. t['maitaikhuthai'] = 0x0E47;
  7725. t['maitholowleftthai'] = 0xF88F;
  7726. t['maitholowrightthai'] = 0xF88E;
  7727. t['maithothai'] = 0x0E49;
  7728. t['maithoupperleftthai'] = 0xF88D;
  7729. t['maitrilowleftthai'] = 0xF892;
  7730. t['maitrilowrightthai'] = 0xF891;
  7731. t['maitrithai'] = 0x0E4A;
  7732. t['maitriupperleftthai'] = 0xF890;
  7733. t['maiyamokthai'] = 0x0E46;
  7734. t['makatakana'] = 0x30DE;
  7735. t['makatakanahalfwidth'] = 0xFF8F;
  7736. t['male'] = 0x2642;
  7737. t['mansyonsquare'] = 0x3347;
  7738. t['maqafhebrew'] = 0x05BE;
  7739. t['mars'] = 0x2642;
  7740. t['masoracirclehebrew'] = 0x05AF;
  7741. t['masquare'] = 0x3383;
  7742. t['mbopomofo'] = 0x3107;
  7743. t['mbsquare'] = 0x33D4;
  7744. t['mcircle'] = 0x24DC;
  7745. t['mcubedsquare'] = 0x33A5;
  7746. t['mdotaccent'] = 0x1E41;
  7747. t['mdotbelow'] = 0x1E43;
  7748. t['meemarabic'] = 0x0645;
  7749. t['meemfinalarabic'] = 0xFEE2;
  7750. t['meeminitialarabic'] = 0xFEE3;
  7751. t['meemmedialarabic'] = 0xFEE4;
  7752. t['meemmeeminitialarabic'] = 0xFCD1;
  7753. t['meemmeemisolatedarabic'] = 0xFC48;
  7754. t['meetorusquare'] = 0x334D;
  7755. t['mehiragana'] = 0x3081;
  7756. t['meizierasquare'] = 0x337E;
  7757. t['mekatakana'] = 0x30E1;
  7758. t['mekatakanahalfwidth'] = 0xFF92;
  7759. t['mem'] = 0x05DE;
  7760. t['memdagesh'] = 0xFB3E;
  7761. t['memdageshhebrew'] = 0xFB3E;
  7762. t['memhebrew'] = 0x05DE;
  7763. t['menarmenian'] = 0x0574;
  7764. t['merkhahebrew'] = 0x05A5;
  7765. t['merkhakefulahebrew'] = 0x05A6;
  7766. t['merkhakefulalefthebrew'] = 0x05A6;
  7767. t['merkhalefthebrew'] = 0x05A5;
  7768. t['mhook'] = 0x0271;
  7769. t['mhzsquare'] = 0x3392;
  7770. t['middledotkatakanahalfwidth'] = 0xFF65;
  7771. t['middot'] = 0x00B7;
  7772. t['mieumacirclekorean'] = 0x3272;
  7773. t['mieumaparenkorean'] = 0x3212;
  7774. t['mieumcirclekorean'] = 0x3264;
  7775. t['mieumkorean'] = 0x3141;
  7776. t['mieumpansioskorean'] = 0x3170;
  7777. t['mieumparenkorean'] = 0x3204;
  7778. t['mieumpieupkorean'] = 0x316E;
  7779. t['mieumsioskorean'] = 0x316F;
  7780. t['mihiragana'] = 0x307F;
  7781. t['mikatakana'] = 0x30DF;
  7782. t['mikatakanahalfwidth'] = 0xFF90;
  7783. t['minus'] = 0x2212;
  7784. t['minusbelowcmb'] = 0x0320;
  7785. t['minuscircle'] = 0x2296;
  7786. t['minusmod'] = 0x02D7;
  7787. t['minusplus'] = 0x2213;
  7788. t['minute'] = 0x2032;
  7789. t['miribaarusquare'] = 0x334A;
  7790. t['mirisquare'] = 0x3349;
  7791. t['mlonglegturned'] = 0x0270;
  7792. t['mlsquare'] = 0x3396;
  7793. t['mmcubedsquare'] = 0x33A3;
  7794. t['mmonospace'] = 0xFF4D;
  7795. t['mmsquaredsquare'] = 0x339F;
  7796. t['mohiragana'] = 0x3082;
  7797. t['mohmsquare'] = 0x33C1;
  7798. t['mokatakana'] = 0x30E2;
  7799. t['mokatakanahalfwidth'] = 0xFF93;
  7800. t['molsquare'] = 0x33D6;
  7801. t['momathai'] = 0x0E21;
  7802. t['moverssquare'] = 0x33A7;
  7803. t['moverssquaredsquare'] = 0x33A8;
  7804. t['mparen'] = 0x24A8;
  7805. t['mpasquare'] = 0x33AB;
  7806. t['mssquare'] = 0x33B3;
  7807. t['msuperior'] = 0xF6EF;
  7808. t['mturned'] = 0x026F;
  7809. t['mu'] = 0x00B5;
  7810. t['mu1'] = 0x00B5;
  7811. t['muasquare'] = 0x3382;
  7812. t['muchgreater'] = 0x226B;
  7813. t['muchless'] = 0x226A;
  7814. t['mufsquare'] = 0x338C;
  7815. t['mugreek'] = 0x03BC;
  7816. t['mugsquare'] = 0x338D;
  7817. t['muhiragana'] = 0x3080;
  7818. t['mukatakana'] = 0x30E0;
  7819. t['mukatakanahalfwidth'] = 0xFF91;
  7820. t['mulsquare'] = 0x3395;
  7821. t['multiply'] = 0x00D7;
  7822. t['mumsquare'] = 0x339B;
  7823. t['munahhebrew'] = 0x05A3;
  7824. t['munahlefthebrew'] = 0x05A3;
  7825. t['musicalnote'] = 0x266A;
  7826. t['musicalnotedbl'] = 0x266B;
  7827. t['musicflatsign'] = 0x266D;
  7828. t['musicsharpsign'] = 0x266F;
  7829. t['mussquare'] = 0x33B2;
  7830. t['muvsquare'] = 0x33B6;
  7831. t['muwsquare'] = 0x33BC;
  7832. t['mvmegasquare'] = 0x33B9;
  7833. t['mvsquare'] = 0x33B7;
  7834. t['mwmegasquare'] = 0x33BF;
  7835. t['mwsquare'] = 0x33BD;
  7836. t['n'] = 0x006E;
  7837. t['nabengali'] = 0x09A8;
  7838. t['nabla'] = 0x2207;
  7839. t['nacute'] = 0x0144;
  7840. t['nadeva'] = 0x0928;
  7841. t['nagujarati'] = 0x0AA8;
  7842. t['nagurmukhi'] = 0x0A28;
  7843. t['nahiragana'] = 0x306A;
  7844. t['nakatakana'] = 0x30CA;
  7845. t['nakatakanahalfwidth'] = 0xFF85;
  7846. t['napostrophe'] = 0x0149;
  7847. t['nasquare'] = 0x3381;
  7848. t['nbopomofo'] = 0x310B;
  7849. t['nbspace'] = 0x00A0;
  7850. t['ncaron'] = 0x0148;
  7851. t['ncedilla'] = 0x0146;
  7852. t['ncircle'] = 0x24DD;
  7853. t['ncircumflexbelow'] = 0x1E4B;
  7854. t['ncommaaccent'] = 0x0146;
  7855. t['ndotaccent'] = 0x1E45;
  7856. t['ndotbelow'] = 0x1E47;
  7857. t['nehiragana'] = 0x306D;
  7858. t['nekatakana'] = 0x30CD;
  7859. t['nekatakanahalfwidth'] = 0xFF88;
  7860. t['newsheqelsign'] = 0x20AA;
  7861. t['nfsquare'] = 0x338B;
  7862. t['ngabengali'] = 0x0999;
  7863. t['ngadeva'] = 0x0919;
  7864. t['ngagujarati'] = 0x0A99;
  7865. t['ngagurmukhi'] = 0x0A19;
  7866. t['ngonguthai'] = 0x0E07;
  7867. t['nhiragana'] = 0x3093;
  7868. t['nhookleft'] = 0x0272;
  7869. t['nhookretroflex'] = 0x0273;
  7870. t['nieunacirclekorean'] = 0x326F;
  7871. t['nieunaparenkorean'] = 0x320F;
  7872. t['nieuncieuckorean'] = 0x3135;
  7873. t['nieuncirclekorean'] = 0x3261;
  7874. t['nieunhieuhkorean'] = 0x3136;
  7875. t['nieunkorean'] = 0x3134;
  7876. t['nieunpansioskorean'] = 0x3168;
  7877. t['nieunparenkorean'] = 0x3201;
  7878. t['nieunsioskorean'] = 0x3167;
  7879. t['nieuntikeutkorean'] = 0x3166;
  7880. t['nihiragana'] = 0x306B;
  7881. t['nikatakana'] = 0x30CB;
  7882. t['nikatakanahalfwidth'] = 0xFF86;
  7883. t['nikhahitleftthai'] = 0xF899;
  7884. t['nikhahitthai'] = 0x0E4D;
  7885. t['nine'] = 0x0039;
  7886. t['ninearabic'] = 0x0669;
  7887. t['ninebengali'] = 0x09EF;
  7888. t['ninecircle'] = 0x2468;
  7889. t['ninecircleinversesansserif'] = 0x2792;
  7890. t['ninedeva'] = 0x096F;
  7891. t['ninegujarati'] = 0x0AEF;
  7892. t['ninegurmukhi'] = 0x0A6F;
  7893. t['ninehackarabic'] = 0x0669;
  7894. t['ninehangzhou'] = 0x3029;
  7895. t['nineideographicparen'] = 0x3228;
  7896. t['nineinferior'] = 0x2089;
  7897. t['ninemonospace'] = 0xFF19;
  7898. t['nineoldstyle'] = 0xF739;
  7899. t['nineparen'] = 0x247C;
  7900. t['nineperiod'] = 0x2490;
  7901. t['ninepersian'] = 0x06F9;
  7902. t['nineroman'] = 0x2178;
  7903. t['ninesuperior'] = 0x2079;
  7904. t['nineteencircle'] = 0x2472;
  7905. t['nineteenparen'] = 0x2486;
  7906. t['nineteenperiod'] = 0x249A;
  7907. t['ninethai'] = 0x0E59;
  7908. t['nj'] = 0x01CC;
  7909. t['njecyrillic'] = 0x045A;
  7910. t['nkatakana'] = 0x30F3;
  7911. t['nkatakanahalfwidth'] = 0xFF9D;
  7912. t['nlegrightlong'] = 0x019E;
  7913. t['nlinebelow'] = 0x1E49;
  7914. t['nmonospace'] = 0xFF4E;
  7915. t['nmsquare'] = 0x339A;
  7916. t['nnabengali'] = 0x09A3;
  7917. t['nnadeva'] = 0x0923;
  7918. t['nnagujarati'] = 0x0AA3;
  7919. t['nnagurmukhi'] = 0x0A23;
  7920. t['nnnadeva'] = 0x0929;
  7921. t['nohiragana'] = 0x306E;
  7922. t['nokatakana'] = 0x30CE;
  7923. t['nokatakanahalfwidth'] = 0xFF89;
  7924. t['nonbreakingspace'] = 0x00A0;
  7925. t['nonenthai'] = 0x0E13;
  7926. t['nonuthai'] = 0x0E19;
  7927. t['noonarabic'] = 0x0646;
  7928. t['noonfinalarabic'] = 0xFEE6;
  7929. t['noonghunnaarabic'] = 0x06BA;
  7930. t['noonghunnafinalarabic'] = 0xFB9F;
  7931. t['nooninitialarabic'] = 0xFEE7;
  7932. t['noonjeeminitialarabic'] = 0xFCD2;
  7933. t['noonjeemisolatedarabic'] = 0xFC4B;
  7934. t['noonmedialarabic'] = 0xFEE8;
  7935. t['noonmeeminitialarabic'] = 0xFCD5;
  7936. t['noonmeemisolatedarabic'] = 0xFC4E;
  7937. t['noonnoonfinalarabic'] = 0xFC8D;
  7938. t['notcontains'] = 0x220C;
  7939. t['notelement'] = 0x2209;
  7940. t['notelementof'] = 0x2209;
  7941. t['notequal'] = 0x2260;
  7942. t['notgreater'] = 0x226F;
  7943. t['notgreaternorequal'] = 0x2271;
  7944. t['notgreaternorless'] = 0x2279;
  7945. t['notidentical'] = 0x2262;
  7946. t['notless'] = 0x226E;
  7947. t['notlessnorequal'] = 0x2270;
  7948. t['notparallel'] = 0x2226;
  7949. t['notprecedes'] = 0x2280;
  7950. t['notsubset'] = 0x2284;
  7951. t['notsucceeds'] = 0x2281;
  7952. t['notsuperset'] = 0x2285;
  7953. t['nowarmenian'] = 0x0576;
  7954. t['nparen'] = 0x24A9;
  7955. t['nssquare'] = 0x33B1;
  7956. t['nsuperior'] = 0x207F;
  7957. t['ntilde'] = 0x00F1;
  7958. t['nu'] = 0x03BD;
  7959. t['nuhiragana'] = 0x306C;
  7960. t['nukatakana'] = 0x30CC;
  7961. t['nukatakanahalfwidth'] = 0xFF87;
  7962. t['nuktabengali'] = 0x09BC;
  7963. t['nuktadeva'] = 0x093C;
  7964. t['nuktagujarati'] = 0x0ABC;
  7965. t['nuktagurmukhi'] = 0x0A3C;
  7966. t['numbersign'] = 0x0023;
  7967. t['numbersignmonospace'] = 0xFF03;
  7968. t['numbersignsmall'] = 0xFE5F;
  7969. t['numeralsigngreek'] = 0x0374;
  7970. t['numeralsignlowergreek'] = 0x0375;
  7971. t['numero'] = 0x2116;
  7972. t['nun'] = 0x05E0;
  7973. t['nundagesh'] = 0xFB40;
  7974. t['nundageshhebrew'] = 0xFB40;
  7975. t['nunhebrew'] = 0x05E0;
  7976. t['nvsquare'] = 0x33B5;
  7977. t['nwsquare'] = 0x33BB;
  7978. t['nyabengali'] = 0x099E;
  7979. t['nyadeva'] = 0x091E;
  7980. t['nyagujarati'] = 0x0A9E;
  7981. t['nyagurmukhi'] = 0x0A1E;
  7982. t['o'] = 0x006F;
  7983. t['oacute'] = 0x00F3;
  7984. t['oangthai'] = 0x0E2D;
  7985. t['obarred'] = 0x0275;
  7986. t['obarredcyrillic'] = 0x04E9;
  7987. t['obarreddieresiscyrillic'] = 0x04EB;
  7988. t['obengali'] = 0x0993;
  7989. t['obopomofo'] = 0x311B;
  7990. t['obreve'] = 0x014F;
  7991. t['ocandradeva'] = 0x0911;
  7992. t['ocandragujarati'] = 0x0A91;
  7993. t['ocandravowelsigndeva'] = 0x0949;
  7994. t['ocandravowelsigngujarati'] = 0x0AC9;
  7995. t['ocaron'] = 0x01D2;
  7996. t['ocircle'] = 0x24DE;
  7997. t['ocircumflex'] = 0x00F4;
  7998. t['ocircumflexacute'] = 0x1ED1;
  7999. t['ocircumflexdotbelow'] = 0x1ED9;
  8000. t['ocircumflexgrave'] = 0x1ED3;
  8001. t['ocircumflexhookabove'] = 0x1ED5;
  8002. t['ocircumflextilde'] = 0x1ED7;
  8003. t['ocyrillic'] = 0x043E;
  8004. t['odblacute'] = 0x0151;
  8005. t['odblgrave'] = 0x020D;
  8006. t['odeva'] = 0x0913;
  8007. t['odieresis'] = 0x00F6;
  8008. t['odieresiscyrillic'] = 0x04E7;
  8009. t['odotbelow'] = 0x1ECD;
  8010. t['oe'] = 0x0153;
  8011. t['oekorean'] = 0x315A;
  8012. t['ogonek'] = 0x02DB;
  8013. t['ogonekcmb'] = 0x0328;
  8014. t['ograve'] = 0x00F2;
  8015. t['ogujarati'] = 0x0A93;
  8016. t['oharmenian'] = 0x0585;
  8017. t['ohiragana'] = 0x304A;
  8018. t['ohookabove'] = 0x1ECF;
  8019. t['ohorn'] = 0x01A1;
  8020. t['ohornacute'] = 0x1EDB;
  8021. t['ohorndotbelow'] = 0x1EE3;
  8022. t['ohorngrave'] = 0x1EDD;
  8023. t['ohornhookabove'] = 0x1EDF;
  8024. t['ohorntilde'] = 0x1EE1;
  8025. t['ohungarumlaut'] = 0x0151;
  8026. t['oi'] = 0x01A3;
  8027. t['oinvertedbreve'] = 0x020F;
  8028. t['okatakana'] = 0x30AA;
  8029. t['okatakanahalfwidth'] = 0xFF75;
  8030. t['okorean'] = 0x3157;
  8031. t['olehebrew'] = 0x05AB;
  8032. t['omacron'] = 0x014D;
  8033. t['omacronacute'] = 0x1E53;
  8034. t['omacrongrave'] = 0x1E51;
  8035. t['omdeva'] = 0x0950;
  8036. t['omega'] = 0x03C9;
  8037. t['omega1'] = 0x03D6;
  8038. t['omegacyrillic'] = 0x0461;
  8039. t['omegalatinclosed'] = 0x0277;
  8040. t['omegaroundcyrillic'] = 0x047B;
  8041. t['omegatitlocyrillic'] = 0x047D;
  8042. t['omegatonos'] = 0x03CE;
  8043. t['omgujarati'] = 0x0AD0;
  8044. t['omicron'] = 0x03BF;
  8045. t['omicrontonos'] = 0x03CC;
  8046. t['omonospace'] = 0xFF4F;
  8047. t['one'] = 0x0031;
  8048. t['onearabic'] = 0x0661;
  8049. t['onebengali'] = 0x09E7;
  8050. t['onecircle'] = 0x2460;
  8051. t['onecircleinversesansserif'] = 0x278A;
  8052. t['onedeva'] = 0x0967;
  8053. t['onedotenleader'] = 0x2024;
  8054. t['oneeighth'] = 0x215B;
  8055. t['onefitted'] = 0xF6DC;
  8056. t['onegujarati'] = 0x0AE7;
  8057. t['onegurmukhi'] = 0x0A67;
  8058. t['onehackarabic'] = 0x0661;
  8059. t['onehalf'] = 0x00BD;
  8060. t['onehangzhou'] = 0x3021;
  8061. t['oneideographicparen'] = 0x3220;
  8062. t['oneinferior'] = 0x2081;
  8063. t['onemonospace'] = 0xFF11;
  8064. t['onenumeratorbengali'] = 0x09F4;
  8065. t['oneoldstyle'] = 0xF731;
  8066. t['oneparen'] = 0x2474;
  8067. t['oneperiod'] = 0x2488;
  8068. t['onepersian'] = 0x06F1;
  8069. t['onequarter'] = 0x00BC;
  8070. t['oneroman'] = 0x2170;
  8071. t['onesuperior'] = 0x00B9;
  8072. t['onethai'] = 0x0E51;
  8073. t['onethird'] = 0x2153;
  8074. t['oogonek'] = 0x01EB;
  8075. t['oogonekmacron'] = 0x01ED;
  8076. t['oogurmukhi'] = 0x0A13;
  8077. t['oomatragurmukhi'] = 0x0A4B;
  8078. t['oopen'] = 0x0254;
  8079. t['oparen'] = 0x24AA;
  8080. t['openbullet'] = 0x25E6;
  8081. t['option'] = 0x2325;
  8082. t['ordfeminine'] = 0x00AA;
  8083. t['ordmasculine'] = 0x00BA;
  8084. t['orthogonal'] = 0x221F;
  8085. t['oshortdeva'] = 0x0912;
  8086. t['oshortvowelsigndeva'] = 0x094A;
  8087. t['oslash'] = 0x00F8;
  8088. t['oslashacute'] = 0x01FF;
  8089. t['osmallhiragana'] = 0x3049;
  8090. t['osmallkatakana'] = 0x30A9;
  8091. t['osmallkatakanahalfwidth'] = 0xFF6B;
  8092. t['ostrokeacute'] = 0x01FF;
  8093. t['osuperior'] = 0xF6F0;
  8094. t['otcyrillic'] = 0x047F;
  8095. t['otilde'] = 0x00F5;
  8096. t['otildeacute'] = 0x1E4D;
  8097. t['otildedieresis'] = 0x1E4F;
  8098. t['oubopomofo'] = 0x3121;
  8099. t['overline'] = 0x203E;
  8100. t['overlinecenterline'] = 0xFE4A;
  8101. t['overlinecmb'] = 0x0305;
  8102. t['overlinedashed'] = 0xFE49;
  8103. t['overlinedblwavy'] = 0xFE4C;
  8104. t['overlinewavy'] = 0xFE4B;
  8105. t['overscore'] = 0x00AF;
  8106. t['ovowelsignbengali'] = 0x09CB;
  8107. t['ovowelsigndeva'] = 0x094B;
  8108. t['ovowelsigngujarati'] = 0x0ACB;
  8109. t['p'] = 0x0070;
  8110. t['paampssquare'] = 0x3380;
  8111. t['paasentosquare'] = 0x332B;
  8112. t['pabengali'] = 0x09AA;
  8113. t['pacute'] = 0x1E55;
  8114. t['padeva'] = 0x092A;
  8115. t['pagedown'] = 0x21DF;
  8116. t['pageup'] = 0x21DE;
  8117. t['pagujarati'] = 0x0AAA;
  8118. t['pagurmukhi'] = 0x0A2A;
  8119. t['pahiragana'] = 0x3071;
  8120. t['paiyannoithai'] = 0x0E2F;
  8121. t['pakatakana'] = 0x30D1;
  8122. t['palatalizationcyrilliccmb'] = 0x0484;
  8123. t['palochkacyrillic'] = 0x04C0;
  8124. t['pansioskorean'] = 0x317F;
  8125. t['paragraph'] = 0x00B6;
  8126. t['parallel'] = 0x2225;
  8127. t['parenleft'] = 0x0028;
  8128. t['parenleftaltonearabic'] = 0xFD3E;
  8129. t['parenleftbt'] = 0xF8ED;
  8130. t['parenleftex'] = 0xF8EC;
  8131. t['parenleftinferior'] = 0x208D;
  8132. t['parenleftmonospace'] = 0xFF08;
  8133. t['parenleftsmall'] = 0xFE59;
  8134. t['parenleftsuperior'] = 0x207D;
  8135. t['parenlefttp'] = 0xF8EB;
  8136. t['parenleftvertical'] = 0xFE35;
  8137. t['parenright'] = 0x0029;
  8138. t['parenrightaltonearabic'] = 0xFD3F;
  8139. t['parenrightbt'] = 0xF8F8;
  8140. t['parenrightex'] = 0xF8F7;
  8141. t['parenrightinferior'] = 0x208E;
  8142. t['parenrightmonospace'] = 0xFF09;
  8143. t['parenrightsmall'] = 0xFE5A;
  8144. t['parenrightsuperior'] = 0x207E;
  8145. t['parenrighttp'] = 0xF8F6;
  8146. t['parenrightvertical'] = 0xFE36;
  8147. t['partialdiff'] = 0x2202;
  8148. t['paseqhebrew'] = 0x05C0;
  8149. t['pashtahebrew'] = 0x0599;
  8150. t['pasquare'] = 0x33A9;
  8151. t['patah'] = 0x05B7;
  8152. t['patah11'] = 0x05B7;
  8153. t['patah1d'] = 0x05B7;
  8154. t['patah2a'] = 0x05B7;
  8155. t['patahhebrew'] = 0x05B7;
  8156. t['patahnarrowhebrew'] = 0x05B7;
  8157. t['patahquarterhebrew'] = 0x05B7;
  8158. t['patahwidehebrew'] = 0x05B7;
  8159. t['pazerhebrew'] = 0x05A1;
  8160. t['pbopomofo'] = 0x3106;
  8161. t['pcircle'] = 0x24DF;
  8162. t['pdotaccent'] = 0x1E57;
  8163. t['pe'] = 0x05E4;
  8164. t['pecyrillic'] = 0x043F;
  8165. t['pedagesh'] = 0xFB44;
  8166. t['pedageshhebrew'] = 0xFB44;
  8167. t['peezisquare'] = 0x333B;
  8168. t['pefinaldageshhebrew'] = 0xFB43;
  8169. t['peharabic'] = 0x067E;
  8170. t['peharmenian'] = 0x057A;
  8171. t['pehebrew'] = 0x05E4;
  8172. t['pehfinalarabic'] = 0xFB57;
  8173. t['pehinitialarabic'] = 0xFB58;
  8174. t['pehiragana'] = 0x307A;
  8175. t['pehmedialarabic'] = 0xFB59;
  8176. t['pekatakana'] = 0x30DA;
  8177. t['pemiddlehookcyrillic'] = 0x04A7;
  8178. t['perafehebrew'] = 0xFB4E;
  8179. t['percent'] = 0x0025;
  8180. t['percentarabic'] = 0x066A;
  8181. t['percentmonospace'] = 0xFF05;
  8182. t['percentsmall'] = 0xFE6A;
  8183. t['period'] = 0x002E;
  8184. t['periodarmenian'] = 0x0589;
  8185. t['periodcentered'] = 0x00B7;
  8186. t['periodhalfwidth'] = 0xFF61;
  8187. t['periodinferior'] = 0xF6E7;
  8188. t['periodmonospace'] = 0xFF0E;
  8189. t['periodsmall'] = 0xFE52;
  8190. t['periodsuperior'] = 0xF6E8;
  8191. t['perispomenigreekcmb'] = 0x0342;
  8192. t['perpendicular'] = 0x22A5;
  8193. t['perthousand'] = 0x2030;
  8194. t['peseta'] = 0x20A7;
  8195. t['pfsquare'] = 0x338A;
  8196. t['phabengali'] = 0x09AB;
  8197. t['phadeva'] = 0x092B;
  8198. t['phagujarati'] = 0x0AAB;
  8199. t['phagurmukhi'] = 0x0A2B;
  8200. t['phi'] = 0x03C6;
  8201. t['phi1'] = 0x03D5;
  8202. t['phieuphacirclekorean'] = 0x327A;
  8203. t['phieuphaparenkorean'] = 0x321A;
  8204. t['phieuphcirclekorean'] = 0x326C;
  8205. t['phieuphkorean'] = 0x314D;
  8206. t['phieuphparenkorean'] = 0x320C;
  8207. t['philatin'] = 0x0278;
  8208. t['phinthuthai'] = 0x0E3A;
  8209. t['phisymbolgreek'] = 0x03D5;
  8210. t['phook'] = 0x01A5;
  8211. t['phophanthai'] = 0x0E1E;
  8212. t['phophungthai'] = 0x0E1C;
  8213. t['phosamphaothai'] = 0x0E20;
  8214. t['pi'] = 0x03C0;
  8215. t['pieupacirclekorean'] = 0x3273;
  8216. t['pieupaparenkorean'] = 0x3213;
  8217. t['pieupcieuckorean'] = 0x3176;
  8218. t['pieupcirclekorean'] = 0x3265;
  8219. t['pieupkiyeokkorean'] = 0x3172;
  8220. t['pieupkorean'] = 0x3142;
  8221. t['pieupparenkorean'] = 0x3205;
  8222. t['pieupsioskiyeokkorean'] = 0x3174;
  8223. t['pieupsioskorean'] = 0x3144;
  8224. t['pieupsiostikeutkorean'] = 0x3175;
  8225. t['pieupthieuthkorean'] = 0x3177;
  8226. t['pieuptikeutkorean'] = 0x3173;
  8227. t['pihiragana'] = 0x3074;
  8228. t['pikatakana'] = 0x30D4;
  8229. t['pisymbolgreek'] = 0x03D6;
  8230. t['piwrarmenian'] = 0x0583;
  8231. t['plus'] = 0x002B;
  8232. t['plusbelowcmb'] = 0x031F;
  8233. t['pluscircle'] = 0x2295;
  8234. t['plusminus'] = 0x00B1;
  8235. t['plusmod'] = 0x02D6;
  8236. t['plusmonospace'] = 0xFF0B;
  8237. t['plussmall'] = 0xFE62;
  8238. t['plussuperior'] = 0x207A;
  8239. t['pmonospace'] = 0xFF50;
  8240. t['pmsquare'] = 0x33D8;
  8241. t['pohiragana'] = 0x307D;
  8242. t['pointingindexdownwhite'] = 0x261F;
  8243. t['pointingindexleftwhite'] = 0x261C;
  8244. t['pointingindexrightwhite'] = 0x261E;
  8245. t['pointingindexupwhite'] = 0x261D;
  8246. t['pokatakana'] = 0x30DD;
  8247. t['poplathai'] = 0x0E1B;
  8248. t['postalmark'] = 0x3012;
  8249. t['postalmarkface'] = 0x3020;
  8250. t['pparen'] = 0x24AB;
  8251. t['precedes'] = 0x227A;
  8252. t['prescription'] = 0x211E;
  8253. t['primemod'] = 0x02B9;
  8254. t['primereversed'] = 0x2035;
  8255. t['product'] = 0x220F;
  8256. t['projective'] = 0x2305;
  8257. t['prolongedkana'] = 0x30FC;
  8258. t['propellor'] = 0x2318;
  8259. t['propersubset'] = 0x2282;
  8260. t['propersuperset'] = 0x2283;
  8261. t['proportion'] = 0x2237;
  8262. t['proportional'] = 0x221D;
  8263. t['psi'] = 0x03C8;
  8264. t['psicyrillic'] = 0x0471;
  8265. t['psilipneumatacyrilliccmb'] = 0x0486;
  8266. t['pssquare'] = 0x33B0;
  8267. t['puhiragana'] = 0x3077;
  8268. t['pukatakana'] = 0x30D7;
  8269. t['pvsquare'] = 0x33B4;
  8270. t['pwsquare'] = 0x33BA;
  8271. t['q'] = 0x0071;
  8272. t['qadeva'] = 0x0958;
  8273. t['qadmahebrew'] = 0x05A8;
  8274. t['qafarabic'] = 0x0642;
  8275. t['qaffinalarabic'] = 0xFED6;
  8276. t['qafinitialarabic'] = 0xFED7;
  8277. t['qafmedialarabic'] = 0xFED8;
  8278. t['qamats'] = 0x05B8;
  8279. t['qamats10'] = 0x05B8;
  8280. t['qamats1a'] = 0x05B8;
  8281. t['qamats1c'] = 0x05B8;
  8282. t['qamats27'] = 0x05B8;
  8283. t['qamats29'] = 0x05B8;
  8284. t['qamats33'] = 0x05B8;
  8285. t['qamatsde'] = 0x05B8;
  8286. t['qamatshebrew'] = 0x05B8;
  8287. t['qamatsnarrowhebrew'] = 0x05B8;
  8288. t['qamatsqatanhebrew'] = 0x05B8;
  8289. t['qamatsqatannarrowhebrew'] = 0x05B8;
  8290. t['qamatsqatanquarterhebrew'] = 0x05B8;
  8291. t['qamatsqatanwidehebrew'] = 0x05B8;
  8292. t['qamatsquarterhebrew'] = 0x05B8;
  8293. t['qamatswidehebrew'] = 0x05B8;
  8294. t['qarneyparahebrew'] = 0x059F;
  8295. t['qbopomofo'] = 0x3111;
  8296. t['qcircle'] = 0x24E0;
  8297. t['qhook'] = 0x02A0;
  8298. t['qmonospace'] = 0xFF51;
  8299. t['qof'] = 0x05E7;
  8300. t['qofdagesh'] = 0xFB47;
  8301. t['qofdageshhebrew'] = 0xFB47;
  8302. t['qofhebrew'] = 0x05E7;
  8303. t['qparen'] = 0x24AC;
  8304. t['quarternote'] = 0x2669;
  8305. t['qubuts'] = 0x05BB;
  8306. t['qubuts18'] = 0x05BB;
  8307. t['qubuts25'] = 0x05BB;
  8308. t['qubuts31'] = 0x05BB;
  8309. t['qubutshebrew'] = 0x05BB;
  8310. t['qubutsnarrowhebrew'] = 0x05BB;
  8311. t['qubutsquarterhebrew'] = 0x05BB;
  8312. t['qubutswidehebrew'] = 0x05BB;
  8313. t['question'] = 0x003F;
  8314. t['questionarabic'] = 0x061F;
  8315. t['questionarmenian'] = 0x055E;
  8316. t['questiondown'] = 0x00BF;
  8317. t['questiondownsmall'] = 0xF7BF;
  8318. t['questiongreek'] = 0x037E;
  8319. t['questionmonospace'] = 0xFF1F;
  8320. t['questionsmall'] = 0xF73F;
  8321. t['quotedbl'] = 0x0022;
  8322. t['quotedblbase'] = 0x201E;
  8323. t['quotedblleft'] = 0x201C;
  8324. t['quotedblmonospace'] = 0xFF02;
  8325. t['quotedblprime'] = 0x301E;
  8326. t['quotedblprimereversed'] = 0x301D;
  8327. t['quotedblright'] = 0x201D;
  8328. t['quoteleft'] = 0x2018;
  8329. t['quoteleftreversed'] = 0x201B;
  8330. t['quotereversed'] = 0x201B;
  8331. t['quoteright'] = 0x2019;
  8332. t['quoterightn'] = 0x0149;
  8333. t['quotesinglbase'] = 0x201A;
  8334. t['quotesingle'] = 0x0027;
  8335. t['quotesinglemonospace'] = 0xFF07;
  8336. t['r'] = 0x0072;
  8337. t['raarmenian'] = 0x057C;
  8338. t['rabengali'] = 0x09B0;
  8339. t['racute'] = 0x0155;
  8340. t['radeva'] = 0x0930;
  8341. t['radical'] = 0x221A;
  8342. t['radicalex'] = 0xF8E5;
  8343. t['radoverssquare'] = 0x33AE;
  8344. t['radoverssquaredsquare'] = 0x33AF;
  8345. t['radsquare'] = 0x33AD;
  8346. t['rafe'] = 0x05BF;
  8347. t['rafehebrew'] = 0x05BF;
  8348. t['ragujarati'] = 0x0AB0;
  8349. t['ragurmukhi'] = 0x0A30;
  8350. t['rahiragana'] = 0x3089;
  8351. t['rakatakana'] = 0x30E9;
  8352. t['rakatakanahalfwidth'] = 0xFF97;
  8353. t['ralowerdiagonalbengali'] = 0x09F1;
  8354. t['ramiddlediagonalbengali'] = 0x09F0;
  8355. t['ramshorn'] = 0x0264;
  8356. t['ratio'] = 0x2236;
  8357. t['rbopomofo'] = 0x3116;
  8358. t['rcaron'] = 0x0159;
  8359. t['rcedilla'] = 0x0157;
  8360. t['rcircle'] = 0x24E1;
  8361. t['rcommaaccent'] = 0x0157;
  8362. t['rdblgrave'] = 0x0211;
  8363. t['rdotaccent'] = 0x1E59;
  8364. t['rdotbelow'] = 0x1E5B;
  8365. t['rdotbelowmacron'] = 0x1E5D;
  8366. t['referencemark'] = 0x203B;
  8367. t['reflexsubset'] = 0x2286;
  8368. t['reflexsuperset'] = 0x2287;
  8369. t['registered'] = 0x00AE;
  8370. t['registersans'] = 0xF8E8;
  8371. t['registerserif'] = 0xF6DA;
  8372. t['reharabic'] = 0x0631;
  8373. t['reharmenian'] = 0x0580;
  8374. t['rehfinalarabic'] = 0xFEAE;
  8375. t['rehiragana'] = 0x308C;
  8376. t['rekatakana'] = 0x30EC;
  8377. t['rekatakanahalfwidth'] = 0xFF9A;
  8378. t['resh'] = 0x05E8;
  8379. t['reshdageshhebrew'] = 0xFB48;
  8380. t['reshhebrew'] = 0x05E8;
  8381. t['reversedtilde'] = 0x223D;
  8382. t['reviahebrew'] = 0x0597;
  8383. t['reviamugrashhebrew'] = 0x0597;
  8384. t['revlogicalnot'] = 0x2310;
  8385. t['rfishhook'] = 0x027E;
  8386. t['rfishhookreversed'] = 0x027F;
  8387. t['rhabengali'] = 0x09DD;
  8388. t['rhadeva'] = 0x095D;
  8389. t['rho'] = 0x03C1;
  8390. t['rhook'] = 0x027D;
  8391. t['rhookturned'] = 0x027B;
  8392. t['rhookturnedsuperior'] = 0x02B5;
  8393. t['rhosymbolgreek'] = 0x03F1;
  8394. t['rhotichookmod'] = 0x02DE;
  8395. t['rieulacirclekorean'] = 0x3271;
  8396. t['rieulaparenkorean'] = 0x3211;
  8397. t['rieulcirclekorean'] = 0x3263;
  8398. t['rieulhieuhkorean'] = 0x3140;
  8399. t['rieulkiyeokkorean'] = 0x313A;
  8400. t['rieulkiyeoksioskorean'] = 0x3169;
  8401. t['rieulkorean'] = 0x3139;
  8402. t['rieulmieumkorean'] = 0x313B;
  8403. t['rieulpansioskorean'] = 0x316C;
  8404. t['rieulparenkorean'] = 0x3203;
  8405. t['rieulphieuphkorean'] = 0x313F;
  8406. t['rieulpieupkorean'] = 0x313C;
  8407. t['rieulpieupsioskorean'] = 0x316B;
  8408. t['rieulsioskorean'] = 0x313D;
  8409. t['rieulthieuthkorean'] = 0x313E;
  8410. t['rieultikeutkorean'] = 0x316A;
  8411. t['rieulyeorinhieuhkorean'] = 0x316D;
  8412. t['rightangle'] = 0x221F;
  8413. t['righttackbelowcmb'] = 0x0319;
  8414. t['righttriangle'] = 0x22BF;
  8415. t['rihiragana'] = 0x308A;
  8416. t['rikatakana'] = 0x30EA;
  8417. t['rikatakanahalfwidth'] = 0xFF98;
  8418. t['ring'] = 0x02DA;
  8419. t['ringbelowcmb'] = 0x0325;
  8420. t['ringcmb'] = 0x030A;
  8421. t['ringhalfleft'] = 0x02BF;
  8422. t['ringhalfleftarmenian'] = 0x0559;
  8423. t['ringhalfleftbelowcmb'] = 0x031C;
  8424. t['ringhalfleftcentered'] = 0x02D3;
  8425. t['ringhalfright'] = 0x02BE;
  8426. t['ringhalfrightbelowcmb'] = 0x0339;
  8427. t['ringhalfrightcentered'] = 0x02D2;
  8428. t['rinvertedbreve'] = 0x0213;
  8429. t['rittorusquare'] = 0x3351;
  8430. t['rlinebelow'] = 0x1E5F;
  8431. t['rlongleg'] = 0x027C;
  8432. t['rlonglegturned'] = 0x027A;
  8433. t['rmonospace'] = 0xFF52;
  8434. t['rohiragana'] = 0x308D;
  8435. t['rokatakana'] = 0x30ED;
  8436. t['rokatakanahalfwidth'] = 0xFF9B;
  8437. t['roruathai'] = 0x0E23;
  8438. t['rparen'] = 0x24AD;
  8439. t['rrabengali'] = 0x09DC;
  8440. t['rradeva'] = 0x0931;
  8441. t['rragurmukhi'] = 0x0A5C;
  8442. t['rreharabic'] = 0x0691;
  8443. t['rrehfinalarabic'] = 0xFB8D;
  8444. t['rrvocalicbengali'] = 0x09E0;
  8445. t['rrvocalicdeva'] = 0x0960;
  8446. t['rrvocalicgujarati'] = 0x0AE0;
  8447. t['rrvocalicvowelsignbengali'] = 0x09C4;
  8448. t['rrvocalicvowelsigndeva'] = 0x0944;
  8449. t['rrvocalicvowelsigngujarati'] = 0x0AC4;
  8450. t['rsuperior'] = 0xF6F1;
  8451. t['rtblock'] = 0x2590;
  8452. t['rturned'] = 0x0279;
  8453. t['rturnedsuperior'] = 0x02B4;
  8454. t['ruhiragana'] = 0x308B;
  8455. t['rukatakana'] = 0x30EB;
  8456. t['rukatakanahalfwidth'] = 0xFF99;
  8457. t['rupeemarkbengali'] = 0x09F2;
  8458. t['rupeesignbengali'] = 0x09F3;
  8459. t['rupiah'] = 0xF6DD;
  8460. t['ruthai'] = 0x0E24;
  8461. t['rvocalicbengali'] = 0x098B;
  8462. t['rvocalicdeva'] = 0x090B;
  8463. t['rvocalicgujarati'] = 0x0A8B;
  8464. t['rvocalicvowelsignbengali'] = 0x09C3;
  8465. t['rvocalicvowelsigndeva'] = 0x0943;
  8466. t['rvocalicvowelsigngujarati'] = 0x0AC3;
  8467. t['s'] = 0x0073;
  8468. t['sabengali'] = 0x09B8;
  8469. t['sacute'] = 0x015B;
  8470. t['sacutedotaccent'] = 0x1E65;
  8471. t['sadarabic'] = 0x0635;
  8472. t['sadeva'] = 0x0938;
  8473. t['sadfinalarabic'] = 0xFEBA;
  8474. t['sadinitialarabic'] = 0xFEBB;
  8475. t['sadmedialarabic'] = 0xFEBC;
  8476. t['sagujarati'] = 0x0AB8;
  8477. t['sagurmukhi'] = 0x0A38;
  8478. t['sahiragana'] = 0x3055;
  8479. t['sakatakana'] = 0x30B5;
  8480. t['sakatakanahalfwidth'] = 0xFF7B;
  8481. t['sallallahoualayhewasallamarabic'] = 0xFDFA;
  8482. t['samekh'] = 0x05E1;
  8483. t['samekhdagesh'] = 0xFB41;
  8484. t['samekhdageshhebrew'] = 0xFB41;
  8485. t['samekhhebrew'] = 0x05E1;
  8486. t['saraaathai'] = 0x0E32;
  8487. t['saraaethai'] = 0x0E41;
  8488. t['saraaimaimalaithai'] = 0x0E44;
  8489. t['saraaimaimuanthai'] = 0x0E43;
  8490. t['saraamthai'] = 0x0E33;
  8491. t['saraathai'] = 0x0E30;
  8492. t['saraethai'] = 0x0E40;
  8493. t['saraiileftthai'] = 0xF886;
  8494. t['saraiithai'] = 0x0E35;
  8495. t['saraileftthai'] = 0xF885;
  8496. t['saraithai'] = 0x0E34;
  8497. t['saraothai'] = 0x0E42;
  8498. t['saraueeleftthai'] = 0xF888;
  8499. t['saraueethai'] = 0x0E37;
  8500. t['saraueleftthai'] = 0xF887;
  8501. t['sarauethai'] = 0x0E36;
  8502. t['sarauthai'] = 0x0E38;
  8503. t['sarauuthai'] = 0x0E39;
  8504. t['sbopomofo'] = 0x3119;
  8505. t['scaron'] = 0x0161;
  8506. t['scarondotaccent'] = 0x1E67;
  8507. t['scedilla'] = 0x015F;
  8508. t['schwa'] = 0x0259;
  8509. t['schwacyrillic'] = 0x04D9;
  8510. t['schwadieresiscyrillic'] = 0x04DB;
  8511. t['schwahook'] = 0x025A;
  8512. t['scircle'] = 0x24E2;
  8513. t['scircumflex'] = 0x015D;
  8514. t['scommaaccent'] = 0x0219;
  8515. t['sdotaccent'] = 0x1E61;
  8516. t['sdotbelow'] = 0x1E63;
  8517. t['sdotbelowdotaccent'] = 0x1E69;
  8518. t['seagullbelowcmb'] = 0x033C;
  8519. t['second'] = 0x2033;
  8520. t['secondtonechinese'] = 0x02CA;
  8521. t['section'] = 0x00A7;
  8522. t['seenarabic'] = 0x0633;
  8523. t['seenfinalarabic'] = 0xFEB2;
  8524. t['seeninitialarabic'] = 0xFEB3;
  8525. t['seenmedialarabic'] = 0xFEB4;
  8526. t['segol'] = 0x05B6;
  8527. t['segol13'] = 0x05B6;
  8528. t['segol1f'] = 0x05B6;
  8529. t['segol2c'] = 0x05B6;
  8530. t['segolhebrew'] = 0x05B6;
  8531. t['segolnarrowhebrew'] = 0x05B6;
  8532. t['segolquarterhebrew'] = 0x05B6;
  8533. t['segoltahebrew'] = 0x0592;
  8534. t['segolwidehebrew'] = 0x05B6;
  8535. t['seharmenian'] = 0x057D;
  8536. t['sehiragana'] = 0x305B;
  8537. t['sekatakana'] = 0x30BB;
  8538. t['sekatakanahalfwidth'] = 0xFF7E;
  8539. t['semicolon'] = 0x003B;
  8540. t['semicolonarabic'] = 0x061B;
  8541. t['semicolonmonospace'] = 0xFF1B;
  8542. t['semicolonsmall'] = 0xFE54;
  8543. t['semivoicedmarkkana'] = 0x309C;
  8544. t['semivoicedmarkkanahalfwidth'] = 0xFF9F;
  8545. t['sentisquare'] = 0x3322;
  8546. t['sentosquare'] = 0x3323;
  8547. t['seven'] = 0x0037;
  8548. t['sevenarabic'] = 0x0667;
  8549. t['sevenbengali'] = 0x09ED;
  8550. t['sevencircle'] = 0x2466;
  8551. t['sevencircleinversesansserif'] = 0x2790;
  8552. t['sevendeva'] = 0x096D;
  8553. t['seveneighths'] = 0x215E;
  8554. t['sevengujarati'] = 0x0AED;
  8555. t['sevengurmukhi'] = 0x0A6D;
  8556. t['sevenhackarabic'] = 0x0667;
  8557. t['sevenhangzhou'] = 0x3027;
  8558. t['sevenideographicparen'] = 0x3226;
  8559. t['seveninferior'] = 0x2087;
  8560. t['sevenmonospace'] = 0xFF17;
  8561. t['sevenoldstyle'] = 0xF737;
  8562. t['sevenparen'] = 0x247A;
  8563. t['sevenperiod'] = 0x248E;
  8564. t['sevenpersian'] = 0x06F7;
  8565. t['sevenroman'] = 0x2176;
  8566. t['sevensuperior'] = 0x2077;
  8567. t['seventeencircle'] = 0x2470;
  8568. t['seventeenparen'] = 0x2484;
  8569. t['seventeenperiod'] = 0x2498;
  8570. t['seventhai'] = 0x0E57;
  8571. t['sfthyphen'] = 0x00AD;
  8572. t['shaarmenian'] = 0x0577;
  8573. t['shabengali'] = 0x09B6;
  8574. t['shacyrillic'] = 0x0448;
  8575. t['shaddaarabic'] = 0x0651;
  8576. t['shaddadammaarabic'] = 0xFC61;
  8577. t['shaddadammatanarabic'] = 0xFC5E;
  8578. t['shaddafathaarabic'] = 0xFC60;
  8579. t['shaddakasraarabic'] = 0xFC62;
  8580. t['shaddakasratanarabic'] = 0xFC5F;
  8581. t['shade'] = 0x2592;
  8582. t['shadedark'] = 0x2593;
  8583. t['shadelight'] = 0x2591;
  8584. t['shademedium'] = 0x2592;
  8585. t['shadeva'] = 0x0936;
  8586. t['shagujarati'] = 0x0AB6;
  8587. t['shagurmukhi'] = 0x0A36;
  8588. t['shalshelethebrew'] = 0x0593;
  8589. t['shbopomofo'] = 0x3115;
  8590. t['shchacyrillic'] = 0x0449;
  8591. t['sheenarabic'] = 0x0634;
  8592. t['sheenfinalarabic'] = 0xFEB6;
  8593. t['sheeninitialarabic'] = 0xFEB7;
  8594. t['sheenmedialarabic'] = 0xFEB8;
  8595. t['sheicoptic'] = 0x03E3;
  8596. t['sheqel'] = 0x20AA;
  8597. t['sheqelhebrew'] = 0x20AA;
  8598. t['sheva'] = 0x05B0;
  8599. t['sheva115'] = 0x05B0;
  8600. t['sheva15'] = 0x05B0;
  8601. t['sheva22'] = 0x05B0;
  8602. t['sheva2e'] = 0x05B0;
  8603. t['shevahebrew'] = 0x05B0;
  8604. t['shevanarrowhebrew'] = 0x05B0;
  8605. t['shevaquarterhebrew'] = 0x05B0;
  8606. t['shevawidehebrew'] = 0x05B0;
  8607. t['shhacyrillic'] = 0x04BB;
  8608. t['shimacoptic'] = 0x03ED;
  8609. t['shin'] = 0x05E9;
  8610. t['shindagesh'] = 0xFB49;
  8611. t['shindageshhebrew'] = 0xFB49;
  8612. t['shindageshshindot'] = 0xFB2C;
  8613. t['shindageshshindothebrew'] = 0xFB2C;
  8614. t['shindageshsindot'] = 0xFB2D;
  8615. t['shindageshsindothebrew'] = 0xFB2D;
  8616. t['shindothebrew'] = 0x05C1;
  8617. t['shinhebrew'] = 0x05E9;
  8618. t['shinshindot'] = 0xFB2A;
  8619. t['shinshindothebrew'] = 0xFB2A;
  8620. t['shinsindot'] = 0xFB2B;
  8621. t['shinsindothebrew'] = 0xFB2B;
  8622. t['shook'] = 0x0282;
  8623. t['sigma'] = 0x03C3;
  8624. t['sigma1'] = 0x03C2;
  8625. t['sigmafinal'] = 0x03C2;
  8626. t['sigmalunatesymbolgreek'] = 0x03F2;
  8627. t['sihiragana'] = 0x3057;
  8628. t['sikatakana'] = 0x30B7;
  8629. t['sikatakanahalfwidth'] = 0xFF7C;
  8630. t['siluqhebrew'] = 0x05BD;
  8631. t['siluqlefthebrew'] = 0x05BD;
  8632. t['similar'] = 0x223C;
  8633. t['sindothebrew'] = 0x05C2;
  8634. t['siosacirclekorean'] = 0x3274;
  8635. t['siosaparenkorean'] = 0x3214;
  8636. t['sioscieuckorean'] = 0x317E;
  8637. t['sioscirclekorean'] = 0x3266;
  8638. t['sioskiyeokkorean'] = 0x317A;
  8639. t['sioskorean'] = 0x3145;
  8640. t['siosnieunkorean'] = 0x317B;
  8641. t['siosparenkorean'] = 0x3206;
  8642. t['siospieupkorean'] = 0x317D;
  8643. t['siostikeutkorean'] = 0x317C;
  8644. t['six'] = 0x0036;
  8645. t['sixarabic'] = 0x0666;
  8646. t['sixbengali'] = 0x09EC;
  8647. t['sixcircle'] = 0x2465;
  8648. t['sixcircleinversesansserif'] = 0x278F;
  8649. t['sixdeva'] = 0x096C;
  8650. t['sixgujarati'] = 0x0AEC;
  8651. t['sixgurmukhi'] = 0x0A6C;
  8652. t['sixhackarabic'] = 0x0666;
  8653. t['sixhangzhou'] = 0x3026;
  8654. t['sixideographicparen'] = 0x3225;
  8655. t['sixinferior'] = 0x2086;
  8656. t['sixmonospace'] = 0xFF16;
  8657. t['sixoldstyle'] = 0xF736;
  8658. t['sixparen'] = 0x2479;
  8659. t['sixperiod'] = 0x248D;
  8660. t['sixpersian'] = 0x06F6;
  8661. t['sixroman'] = 0x2175;
  8662. t['sixsuperior'] = 0x2076;
  8663. t['sixteencircle'] = 0x246F;
  8664. t['sixteencurrencydenominatorbengali'] = 0x09F9;
  8665. t['sixteenparen'] = 0x2483;
  8666. t['sixteenperiod'] = 0x2497;
  8667. t['sixthai'] = 0x0E56;
  8668. t['slash'] = 0x002F;
  8669. t['slashmonospace'] = 0xFF0F;
  8670. t['slong'] = 0x017F;
  8671. t['slongdotaccent'] = 0x1E9B;
  8672. t['smileface'] = 0x263A;
  8673. t['smonospace'] = 0xFF53;
  8674. t['sofpasuqhebrew'] = 0x05C3;
  8675. t['softhyphen'] = 0x00AD;
  8676. t['softsigncyrillic'] = 0x044C;
  8677. t['sohiragana'] = 0x305D;
  8678. t['sokatakana'] = 0x30BD;
  8679. t['sokatakanahalfwidth'] = 0xFF7F;
  8680. t['soliduslongoverlaycmb'] = 0x0338;
  8681. t['solidusshortoverlaycmb'] = 0x0337;
  8682. t['sorusithai'] = 0x0E29;
  8683. t['sosalathai'] = 0x0E28;
  8684. t['sosothai'] = 0x0E0B;
  8685. t['sosuathai'] = 0x0E2A;
  8686. t['space'] = 0x0020;
  8687. t['spacehackarabic'] = 0x0020;
  8688. t['spade'] = 0x2660;
  8689. t['spadesuitblack'] = 0x2660;
  8690. t['spadesuitwhite'] = 0x2664;
  8691. t['sparen'] = 0x24AE;
  8692. t['squarebelowcmb'] = 0x033B;
  8693. t['squarecc'] = 0x33C4;
  8694. t['squarecm'] = 0x339D;
  8695. t['squarediagonalcrosshatchfill'] = 0x25A9;
  8696. t['squarehorizontalfill'] = 0x25A4;
  8697. t['squarekg'] = 0x338F;
  8698. t['squarekm'] = 0x339E;
  8699. t['squarekmcapital'] = 0x33CE;
  8700. t['squareln'] = 0x33D1;
  8701. t['squarelog'] = 0x33D2;
  8702. t['squaremg'] = 0x338E;
  8703. t['squaremil'] = 0x33D5;
  8704. t['squaremm'] = 0x339C;
  8705. t['squaremsquared'] = 0x33A1;
  8706. t['squareorthogonalcrosshatchfill'] = 0x25A6;
  8707. t['squareupperlefttolowerrightfill'] = 0x25A7;
  8708. t['squareupperrighttolowerleftfill'] = 0x25A8;
  8709. t['squareverticalfill'] = 0x25A5;
  8710. t['squarewhitewithsmallblack'] = 0x25A3;
  8711. t['srsquare'] = 0x33DB;
  8712. t['ssabengali'] = 0x09B7;
  8713. t['ssadeva'] = 0x0937;
  8714. t['ssagujarati'] = 0x0AB7;
  8715. t['ssangcieuckorean'] = 0x3149;
  8716. t['ssanghieuhkorean'] = 0x3185;
  8717. t['ssangieungkorean'] = 0x3180;
  8718. t['ssangkiyeokkorean'] = 0x3132;
  8719. t['ssangnieunkorean'] = 0x3165;
  8720. t['ssangpieupkorean'] = 0x3143;
  8721. t['ssangsioskorean'] = 0x3146;
  8722. t['ssangtikeutkorean'] = 0x3138;
  8723. t['ssuperior'] = 0xF6F2;
  8724. t['sterling'] = 0x00A3;
  8725. t['sterlingmonospace'] = 0xFFE1;
  8726. t['strokelongoverlaycmb'] = 0x0336;
  8727. t['strokeshortoverlaycmb'] = 0x0335;
  8728. t['subset'] = 0x2282;
  8729. t['subsetnotequal'] = 0x228A;
  8730. t['subsetorequal'] = 0x2286;
  8731. t['succeeds'] = 0x227B;
  8732. t['suchthat'] = 0x220B;
  8733. t['suhiragana'] = 0x3059;
  8734. t['sukatakana'] = 0x30B9;
  8735. t['sukatakanahalfwidth'] = 0xFF7D;
  8736. t['sukunarabic'] = 0x0652;
  8737. t['summation'] = 0x2211;
  8738. t['sun'] = 0x263C;
  8739. t['superset'] = 0x2283;
  8740. t['supersetnotequal'] = 0x228B;
  8741. t['supersetorequal'] = 0x2287;
  8742. t['svsquare'] = 0x33DC;
  8743. t['syouwaerasquare'] = 0x337C;
  8744. t['t'] = 0x0074;
  8745. t['tabengali'] = 0x09A4;
  8746. t['tackdown'] = 0x22A4;
  8747. t['tackleft'] = 0x22A3;
  8748. t['tadeva'] = 0x0924;
  8749. t['tagujarati'] = 0x0AA4;
  8750. t['tagurmukhi'] = 0x0A24;
  8751. t['taharabic'] = 0x0637;
  8752. t['tahfinalarabic'] = 0xFEC2;
  8753. t['tahinitialarabic'] = 0xFEC3;
  8754. t['tahiragana'] = 0x305F;
  8755. t['tahmedialarabic'] = 0xFEC4;
  8756. t['taisyouerasquare'] = 0x337D;
  8757. t['takatakana'] = 0x30BF;
  8758. t['takatakanahalfwidth'] = 0xFF80;
  8759. t['tatweelarabic'] = 0x0640;
  8760. t['tau'] = 0x03C4;
  8761. t['tav'] = 0x05EA;
  8762. t['tavdages'] = 0xFB4A;
  8763. t['tavdagesh'] = 0xFB4A;
  8764. t['tavdageshhebrew'] = 0xFB4A;
  8765. t['tavhebrew'] = 0x05EA;
  8766. t['tbar'] = 0x0167;
  8767. t['tbopomofo'] = 0x310A;
  8768. t['tcaron'] = 0x0165;
  8769. t['tccurl'] = 0x02A8;
  8770. t['tcedilla'] = 0x0163;
  8771. t['tcheharabic'] = 0x0686;
  8772. t['tchehfinalarabic'] = 0xFB7B;
  8773. t['tchehinitialarabic'] = 0xFB7C;
  8774. t['tchehmedialarabic'] = 0xFB7D;
  8775. t['tcircle'] = 0x24E3;
  8776. t['tcircumflexbelow'] = 0x1E71;
  8777. t['tcommaaccent'] = 0x0163;
  8778. t['tdieresis'] = 0x1E97;
  8779. t['tdotaccent'] = 0x1E6B;
  8780. t['tdotbelow'] = 0x1E6D;
  8781. t['tecyrillic'] = 0x0442;
  8782. t['tedescendercyrillic'] = 0x04AD;
  8783. t['teharabic'] = 0x062A;
  8784. t['tehfinalarabic'] = 0xFE96;
  8785. t['tehhahinitialarabic'] = 0xFCA2;
  8786. t['tehhahisolatedarabic'] = 0xFC0C;
  8787. t['tehinitialarabic'] = 0xFE97;
  8788. t['tehiragana'] = 0x3066;
  8789. t['tehjeeminitialarabic'] = 0xFCA1;
  8790. t['tehjeemisolatedarabic'] = 0xFC0B;
  8791. t['tehmarbutaarabic'] = 0x0629;
  8792. t['tehmarbutafinalarabic'] = 0xFE94;
  8793. t['tehmedialarabic'] = 0xFE98;
  8794. t['tehmeeminitialarabic'] = 0xFCA4;
  8795. t['tehmeemisolatedarabic'] = 0xFC0E;
  8796. t['tehnoonfinalarabic'] = 0xFC73;
  8797. t['tekatakana'] = 0x30C6;
  8798. t['tekatakanahalfwidth'] = 0xFF83;
  8799. t['telephone'] = 0x2121;
  8800. t['telephoneblack'] = 0x260E;
  8801. t['telishagedolahebrew'] = 0x05A0;
  8802. t['telishaqetanahebrew'] = 0x05A9;
  8803. t['tencircle'] = 0x2469;
  8804. t['tenideographicparen'] = 0x3229;
  8805. t['tenparen'] = 0x247D;
  8806. t['tenperiod'] = 0x2491;
  8807. t['tenroman'] = 0x2179;
  8808. t['tesh'] = 0x02A7;
  8809. t['tet'] = 0x05D8;
  8810. t['tetdagesh'] = 0xFB38;
  8811. t['tetdageshhebrew'] = 0xFB38;
  8812. t['tethebrew'] = 0x05D8;
  8813. t['tetsecyrillic'] = 0x04B5;
  8814. t['tevirhebrew'] = 0x059B;
  8815. t['tevirlefthebrew'] = 0x059B;
  8816. t['thabengali'] = 0x09A5;
  8817. t['thadeva'] = 0x0925;
  8818. t['thagujarati'] = 0x0AA5;
  8819. t['thagurmukhi'] = 0x0A25;
  8820. t['thalarabic'] = 0x0630;
  8821. t['thalfinalarabic'] = 0xFEAC;
  8822. t['thanthakhatlowleftthai'] = 0xF898;
  8823. t['thanthakhatlowrightthai'] = 0xF897;
  8824. t['thanthakhatthai'] = 0x0E4C;
  8825. t['thanthakhatupperleftthai'] = 0xF896;
  8826. t['theharabic'] = 0x062B;
  8827. t['thehfinalarabic'] = 0xFE9A;
  8828. t['thehinitialarabic'] = 0xFE9B;
  8829. t['thehmedialarabic'] = 0xFE9C;
  8830. t['thereexists'] = 0x2203;
  8831. t['therefore'] = 0x2234;
  8832. t['theta'] = 0x03B8;
  8833. t['theta1'] = 0x03D1;
  8834. t['thetasymbolgreek'] = 0x03D1;
  8835. t['thieuthacirclekorean'] = 0x3279;
  8836. t['thieuthaparenkorean'] = 0x3219;
  8837. t['thieuthcirclekorean'] = 0x326B;
  8838. t['thieuthkorean'] = 0x314C;
  8839. t['thieuthparenkorean'] = 0x320B;
  8840. t['thirteencircle'] = 0x246C;
  8841. t['thirteenparen'] = 0x2480;
  8842. t['thirteenperiod'] = 0x2494;
  8843. t['thonangmonthothai'] = 0x0E11;
  8844. t['thook'] = 0x01AD;
  8845. t['thophuthaothai'] = 0x0E12;
  8846. t['thorn'] = 0x00FE;
  8847. t['thothahanthai'] = 0x0E17;
  8848. t['thothanthai'] = 0x0E10;
  8849. t['thothongthai'] = 0x0E18;
  8850. t['thothungthai'] = 0x0E16;
  8851. t['thousandcyrillic'] = 0x0482;
  8852. t['thousandsseparatorarabic'] = 0x066C;
  8853. t['thousandsseparatorpersian'] = 0x066C;
  8854. t['three'] = 0x0033;
  8855. t['threearabic'] = 0x0663;
  8856. t['threebengali'] = 0x09E9;
  8857. t['threecircle'] = 0x2462;
  8858. t['threecircleinversesansserif'] = 0x278C;
  8859. t['threedeva'] = 0x0969;
  8860. t['threeeighths'] = 0x215C;
  8861. t['threegujarati'] = 0x0AE9;
  8862. t['threegurmukhi'] = 0x0A69;
  8863. t['threehackarabic'] = 0x0663;
  8864. t['threehangzhou'] = 0x3023;
  8865. t['threeideographicparen'] = 0x3222;
  8866. t['threeinferior'] = 0x2083;
  8867. t['threemonospace'] = 0xFF13;
  8868. t['threenumeratorbengali'] = 0x09F6;
  8869. t['threeoldstyle'] = 0xF733;
  8870. t['threeparen'] = 0x2476;
  8871. t['threeperiod'] = 0x248A;
  8872. t['threepersian'] = 0x06F3;
  8873. t['threequarters'] = 0x00BE;
  8874. t['threequartersemdash'] = 0xF6DE;
  8875. t['threeroman'] = 0x2172;
  8876. t['threesuperior'] = 0x00B3;
  8877. t['threethai'] = 0x0E53;
  8878. t['thzsquare'] = 0x3394;
  8879. t['tihiragana'] = 0x3061;
  8880. t['tikatakana'] = 0x30C1;
  8881. t['tikatakanahalfwidth'] = 0xFF81;
  8882. t['tikeutacirclekorean'] = 0x3270;
  8883. t['tikeutaparenkorean'] = 0x3210;
  8884. t['tikeutcirclekorean'] = 0x3262;
  8885. t['tikeutkorean'] = 0x3137;
  8886. t['tikeutparenkorean'] = 0x3202;
  8887. t['tilde'] = 0x02DC;
  8888. t['tildebelowcmb'] = 0x0330;
  8889. t['tildecmb'] = 0x0303;
  8890. t['tildecomb'] = 0x0303;
  8891. t['tildedoublecmb'] = 0x0360;
  8892. t['tildeoperator'] = 0x223C;
  8893. t['tildeoverlaycmb'] = 0x0334;
  8894. t['tildeverticalcmb'] = 0x033E;
  8895. t['timescircle'] = 0x2297;
  8896. t['tipehahebrew'] = 0x0596;
  8897. t['tipehalefthebrew'] = 0x0596;
  8898. t['tippigurmukhi'] = 0x0A70;
  8899. t['titlocyrilliccmb'] = 0x0483;
  8900. t['tiwnarmenian'] = 0x057F;
  8901. t['tlinebelow'] = 0x1E6F;
  8902. t['tmonospace'] = 0xFF54;
  8903. t['toarmenian'] = 0x0569;
  8904. t['tohiragana'] = 0x3068;
  8905. t['tokatakana'] = 0x30C8;
  8906. t['tokatakanahalfwidth'] = 0xFF84;
  8907. t['tonebarextrahighmod'] = 0x02E5;
  8908. t['tonebarextralowmod'] = 0x02E9;
  8909. t['tonebarhighmod'] = 0x02E6;
  8910. t['tonebarlowmod'] = 0x02E8;
  8911. t['tonebarmidmod'] = 0x02E7;
  8912. t['tonefive'] = 0x01BD;
  8913. t['tonesix'] = 0x0185;
  8914. t['tonetwo'] = 0x01A8;
  8915. t['tonos'] = 0x0384;
  8916. t['tonsquare'] = 0x3327;
  8917. t['topatakthai'] = 0x0E0F;
  8918. t['tortoiseshellbracketleft'] = 0x3014;
  8919. t['tortoiseshellbracketleftsmall'] = 0xFE5D;
  8920. t['tortoiseshellbracketleftvertical'] = 0xFE39;
  8921. t['tortoiseshellbracketright'] = 0x3015;
  8922. t['tortoiseshellbracketrightsmall'] = 0xFE5E;
  8923. t['tortoiseshellbracketrightvertical'] = 0xFE3A;
  8924. t['totaothai'] = 0x0E15;
  8925. t['tpalatalhook'] = 0x01AB;
  8926. t['tparen'] = 0x24AF;
  8927. t['trademark'] = 0x2122;
  8928. t['trademarksans'] = 0xF8EA;
  8929. t['trademarkserif'] = 0xF6DB;
  8930. t['tretroflexhook'] = 0x0288;
  8931. t['triagdn'] = 0x25BC;
  8932. t['triaglf'] = 0x25C4;
  8933. t['triagrt'] = 0x25BA;
  8934. t['triagup'] = 0x25B2;
  8935. t['ts'] = 0x02A6;
  8936. t['tsadi'] = 0x05E6;
  8937. t['tsadidagesh'] = 0xFB46;
  8938. t['tsadidageshhebrew'] = 0xFB46;
  8939. t['tsadihebrew'] = 0x05E6;
  8940. t['tsecyrillic'] = 0x0446;
  8941. t['tsere'] = 0x05B5;
  8942. t['tsere12'] = 0x05B5;
  8943. t['tsere1e'] = 0x05B5;
  8944. t['tsere2b'] = 0x05B5;
  8945. t['tserehebrew'] = 0x05B5;
  8946. t['tserenarrowhebrew'] = 0x05B5;
  8947. t['tserequarterhebrew'] = 0x05B5;
  8948. t['tserewidehebrew'] = 0x05B5;
  8949. t['tshecyrillic'] = 0x045B;
  8950. t['tsuperior'] = 0xF6F3;
  8951. t['ttabengali'] = 0x099F;
  8952. t['ttadeva'] = 0x091F;
  8953. t['ttagujarati'] = 0x0A9F;
  8954. t['ttagurmukhi'] = 0x0A1F;
  8955. t['tteharabic'] = 0x0679;
  8956. t['ttehfinalarabic'] = 0xFB67;
  8957. t['ttehinitialarabic'] = 0xFB68;
  8958. t['ttehmedialarabic'] = 0xFB69;
  8959. t['tthabengali'] = 0x09A0;
  8960. t['tthadeva'] = 0x0920;
  8961. t['tthagujarati'] = 0x0AA0;
  8962. t['tthagurmukhi'] = 0x0A20;
  8963. t['tturned'] = 0x0287;
  8964. t['tuhiragana'] = 0x3064;
  8965. t['tukatakana'] = 0x30C4;
  8966. t['tukatakanahalfwidth'] = 0xFF82;
  8967. t['tusmallhiragana'] = 0x3063;
  8968. t['tusmallkatakana'] = 0x30C3;
  8969. t['tusmallkatakanahalfwidth'] = 0xFF6F;
  8970. t['twelvecircle'] = 0x246B;
  8971. t['twelveparen'] = 0x247F;
  8972. t['twelveperiod'] = 0x2493;
  8973. t['twelveroman'] = 0x217B;
  8974. t['twentycircle'] = 0x2473;
  8975. t['twentyhangzhou'] = 0x5344;
  8976. t['twentyparen'] = 0x2487;
  8977. t['twentyperiod'] = 0x249B;
  8978. t['two'] = 0x0032;
  8979. t['twoarabic'] = 0x0662;
  8980. t['twobengali'] = 0x09E8;
  8981. t['twocircle'] = 0x2461;
  8982. t['twocircleinversesansserif'] = 0x278B;
  8983. t['twodeva'] = 0x0968;
  8984. t['twodotenleader'] = 0x2025;
  8985. t['twodotleader'] = 0x2025;
  8986. t['twodotleadervertical'] = 0xFE30;
  8987. t['twogujarati'] = 0x0AE8;
  8988. t['twogurmukhi'] = 0x0A68;
  8989. t['twohackarabic'] = 0x0662;
  8990. t['twohangzhou'] = 0x3022;
  8991. t['twoideographicparen'] = 0x3221;
  8992. t['twoinferior'] = 0x2082;
  8993. t['twomonospace'] = 0xFF12;
  8994. t['twonumeratorbengali'] = 0x09F5;
  8995. t['twooldstyle'] = 0xF732;
  8996. t['twoparen'] = 0x2475;
  8997. t['twoperiod'] = 0x2489;
  8998. t['twopersian'] = 0x06F2;
  8999. t['tworoman'] = 0x2171;
  9000. t['twostroke'] = 0x01BB;
  9001. t['twosuperior'] = 0x00B2;
  9002. t['twothai'] = 0x0E52;
  9003. t['twothirds'] = 0x2154;
  9004. t['u'] = 0x0075;
  9005. t['uacute'] = 0x00FA;
  9006. t['ubar'] = 0x0289;
  9007. t['ubengali'] = 0x0989;
  9008. t['ubopomofo'] = 0x3128;
  9009. t['ubreve'] = 0x016D;
  9010. t['ucaron'] = 0x01D4;
  9011. t['ucircle'] = 0x24E4;
  9012. t['ucircumflex'] = 0x00FB;
  9013. t['ucircumflexbelow'] = 0x1E77;
  9014. t['ucyrillic'] = 0x0443;
  9015. t['udattadeva'] = 0x0951;
  9016. t['udblacute'] = 0x0171;
  9017. t['udblgrave'] = 0x0215;
  9018. t['udeva'] = 0x0909;
  9019. t['udieresis'] = 0x00FC;
  9020. t['udieresisacute'] = 0x01D8;
  9021. t['udieresisbelow'] = 0x1E73;
  9022. t['udieresiscaron'] = 0x01DA;
  9023. t['udieresiscyrillic'] = 0x04F1;
  9024. t['udieresisgrave'] = 0x01DC;
  9025. t['udieresismacron'] = 0x01D6;
  9026. t['udotbelow'] = 0x1EE5;
  9027. t['ugrave'] = 0x00F9;
  9028. t['ugujarati'] = 0x0A89;
  9029. t['ugurmukhi'] = 0x0A09;
  9030. t['uhiragana'] = 0x3046;
  9031. t['uhookabove'] = 0x1EE7;
  9032. t['uhorn'] = 0x01B0;
  9033. t['uhornacute'] = 0x1EE9;
  9034. t['uhorndotbelow'] = 0x1EF1;
  9035. t['uhorngrave'] = 0x1EEB;
  9036. t['uhornhookabove'] = 0x1EED;
  9037. t['uhorntilde'] = 0x1EEF;
  9038. t['uhungarumlaut'] = 0x0171;
  9039. t['uhungarumlautcyrillic'] = 0x04F3;
  9040. t['uinvertedbreve'] = 0x0217;
  9041. t['ukatakana'] = 0x30A6;
  9042. t['ukatakanahalfwidth'] = 0xFF73;
  9043. t['ukcyrillic'] = 0x0479;
  9044. t['ukorean'] = 0x315C;
  9045. t['umacron'] = 0x016B;
  9046. t['umacroncyrillic'] = 0x04EF;
  9047. t['umacrondieresis'] = 0x1E7B;
  9048. t['umatragurmukhi'] = 0x0A41;
  9049. t['umonospace'] = 0xFF55;
  9050. t['underscore'] = 0x005F;
  9051. t['underscoredbl'] = 0x2017;
  9052. t['underscoremonospace'] = 0xFF3F;
  9053. t['underscorevertical'] = 0xFE33;
  9054. t['underscorewavy'] = 0xFE4F;
  9055. t['union'] = 0x222A;
  9056. t['universal'] = 0x2200;
  9057. t['uogonek'] = 0x0173;
  9058. t['uparen'] = 0x24B0;
  9059. t['upblock'] = 0x2580;
  9060. t['upperdothebrew'] = 0x05C4;
  9061. t['upsilon'] = 0x03C5;
  9062. t['upsilondieresis'] = 0x03CB;
  9063. t['upsilondieresistonos'] = 0x03B0;
  9064. t['upsilonlatin'] = 0x028A;
  9065. t['upsilontonos'] = 0x03CD;
  9066. t['uptackbelowcmb'] = 0x031D;
  9067. t['uptackmod'] = 0x02D4;
  9068. t['uragurmukhi'] = 0x0A73;
  9069. t['uring'] = 0x016F;
  9070. t['ushortcyrillic'] = 0x045E;
  9071. t['usmallhiragana'] = 0x3045;
  9072. t['usmallkatakana'] = 0x30A5;
  9073. t['usmallkatakanahalfwidth'] = 0xFF69;
  9074. t['ustraightcyrillic'] = 0x04AF;
  9075. t['ustraightstrokecyrillic'] = 0x04B1;
  9076. t['utilde'] = 0x0169;
  9077. t['utildeacute'] = 0x1E79;
  9078. t['utildebelow'] = 0x1E75;
  9079. t['uubengali'] = 0x098A;
  9080. t['uudeva'] = 0x090A;
  9081. t['uugujarati'] = 0x0A8A;
  9082. t['uugurmukhi'] = 0x0A0A;
  9083. t['uumatragurmukhi'] = 0x0A42;
  9084. t['uuvowelsignbengali'] = 0x09C2;
  9085. t['uuvowelsigndeva'] = 0x0942;
  9086. t['uuvowelsigngujarati'] = 0x0AC2;
  9087. t['uvowelsignbengali'] = 0x09C1;
  9088. t['uvowelsigndeva'] = 0x0941;
  9089. t['uvowelsigngujarati'] = 0x0AC1;
  9090. t['v'] = 0x0076;
  9091. t['vadeva'] = 0x0935;
  9092. t['vagujarati'] = 0x0AB5;
  9093. t['vagurmukhi'] = 0x0A35;
  9094. t['vakatakana'] = 0x30F7;
  9095. t['vav'] = 0x05D5;
  9096. t['vavdagesh'] = 0xFB35;
  9097. t['vavdagesh65'] = 0xFB35;
  9098. t['vavdageshhebrew'] = 0xFB35;
  9099. t['vavhebrew'] = 0x05D5;
  9100. t['vavholam'] = 0xFB4B;
  9101. t['vavholamhebrew'] = 0xFB4B;
  9102. t['vavvavhebrew'] = 0x05F0;
  9103. t['vavyodhebrew'] = 0x05F1;
  9104. t['vcircle'] = 0x24E5;
  9105. t['vdotbelow'] = 0x1E7F;
  9106. t['vecyrillic'] = 0x0432;
  9107. t['veharabic'] = 0x06A4;
  9108. t['vehfinalarabic'] = 0xFB6B;
  9109. t['vehinitialarabic'] = 0xFB6C;
  9110. t['vehmedialarabic'] = 0xFB6D;
  9111. t['vekatakana'] = 0x30F9;
  9112. t['venus'] = 0x2640;
  9113. t['verticalbar'] = 0x007C;
  9114. t['verticallineabovecmb'] = 0x030D;
  9115. t['verticallinebelowcmb'] = 0x0329;
  9116. t['verticallinelowmod'] = 0x02CC;
  9117. t['verticallinemod'] = 0x02C8;
  9118. t['vewarmenian'] = 0x057E;
  9119. t['vhook'] = 0x028B;
  9120. t['vikatakana'] = 0x30F8;
  9121. t['viramabengali'] = 0x09CD;
  9122. t['viramadeva'] = 0x094D;
  9123. t['viramagujarati'] = 0x0ACD;
  9124. t['visargabengali'] = 0x0983;
  9125. t['visargadeva'] = 0x0903;
  9126. t['visargagujarati'] = 0x0A83;
  9127. t['vmonospace'] = 0xFF56;
  9128. t['voarmenian'] = 0x0578;
  9129. t['voicediterationhiragana'] = 0x309E;
  9130. t['voicediterationkatakana'] = 0x30FE;
  9131. t['voicedmarkkana'] = 0x309B;
  9132. t['voicedmarkkanahalfwidth'] = 0xFF9E;
  9133. t['vokatakana'] = 0x30FA;
  9134. t['vparen'] = 0x24B1;
  9135. t['vtilde'] = 0x1E7D;
  9136. t['vturned'] = 0x028C;
  9137. t['vuhiragana'] = 0x3094;
  9138. t['vukatakana'] = 0x30F4;
  9139. t['w'] = 0x0077;
  9140. t['wacute'] = 0x1E83;
  9141. t['waekorean'] = 0x3159;
  9142. t['wahiragana'] = 0x308F;
  9143. t['wakatakana'] = 0x30EF;
  9144. t['wakatakanahalfwidth'] = 0xFF9C;
  9145. t['wakorean'] = 0x3158;
  9146. t['wasmallhiragana'] = 0x308E;
  9147. t['wasmallkatakana'] = 0x30EE;
  9148. t['wattosquare'] = 0x3357;
  9149. t['wavedash'] = 0x301C;
  9150. t['wavyunderscorevertical'] = 0xFE34;
  9151. t['wawarabic'] = 0x0648;
  9152. t['wawfinalarabic'] = 0xFEEE;
  9153. t['wawhamzaabovearabic'] = 0x0624;
  9154. t['wawhamzaabovefinalarabic'] = 0xFE86;
  9155. t['wbsquare'] = 0x33DD;
  9156. t['wcircle'] = 0x24E6;
  9157. t['wcircumflex'] = 0x0175;
  9158. t['wdieresis'] = 0x1E85;
  9159. t['wdotaccent'] = 0x1E87;
  9160. t['wdotbelow'] = 0x1E89;
  9161. t['wehiragana'] = 0x3091;
  9162. t['weierstrass'] = 0x2118;
  9163. t['wekatakana'] = 0x30F1;
  9164. t['wekorean'] = 0x315E;
  9165. t['weokorean'] = 0x315D;
  9166. t['wgrave'] = 0x1E81;
  9167. t['whitebullet'] = 0x25E6;
  9168. t['whitecircle'] = 0x25CB;
  9169. t['whitecircleinverse'] = 0x25D9;
  9170. t['whitecornerbracketleft'] = 0x300E;
  9171. t['whitecornerbracketleftvertical'] = 0xFE43;
  9172. t['whitecornerbracketright'] = 0x300F;
  9173. t['whitecornerbracketrightvertical'] = 0xFE44;
  9174. t['whitediamond'] = 0x25C7;
  9175. t['whitediamondcontainingblacksmalldiamond'] = 0x25C8;
  9176. t['whitedownpointingsmalltriangle'] = 0x25BF;
  9177. t['whitedownpointingtriangle'] = 0x25BD;
  9178. t['whiteleftpointingsmalltriangle'] = 0x25C3;
  9179. t['whiteleftpointingtriangle'] = 0x25C1;
  9180. t['whitelenticularbracketleft'] = 0x3016;
  9181. t['whitelenticularbracketright'] = 0x3017;
  9182. t['whiterightpointingsmalltriangle'] = 0x25B9;
  9183. t['whiterightpointingtriangle'] = 0x25B7;
  9184. t['whitesmallsquare'] = 0x25AB;
  9185. t['whitesmilingface'] = 0x263A;
  9186. t['whitesquare'] = 0x25A1;
  9187. t['whitestar'] = 0x2606;
  9188. t['whitetelephone'] = 0x260F;
  9189. t['whitetortoiseshellbracketleft'] = 0x3018;
  9190. t['whitetortoiseshellbracketright'] = 0x3019;
  9191. t['whiteuppointingsmalltriangle'] = 0x25B5;
  9192. t['whiteuppointingtriangle'] = 0x25B3;
  9193. t['wihiragana'] = 0x3090;
  9194. t['wikatakana'] = 0x30F0;
  9195. t['wikorean'] = 0x315F;
  9196. t['wmonospace'] = 0xFF57;
  9197. t['wohiragana'] = 0x3092;
  9198. t['wokatakana'] = 0x30F2;
  9199. t['wokatakanahalfwidth'] = 0xFF66;
  9200. t['won'] = 0x20A9;
  9201. t['wonmonospace'] = 0xFFE6;
  9202. t['wowaenthai'] = 0x0E27;
  9203. t['wparen'] = 0x24B2;
  9204. t['wring'] = 0x1E98;
  9205. t['wsuperior'] = 0x02B7;
  9206. t['wturned'] = 0x028D;
  9207. t['wynn'] = 0x01BF;
  9208. t['x'] = 0x0078;
  9209. t['xabovecmb'] = 0x033D;
  9210. t['xbopomofo'] = 0x3112;
  9211. t['xcircle'] = 0x24E7;
  9212. t['xdieresis'] = 0x1E8D;
  9213. t['xdotaccent'] = 0x1E8B;
  9214. t['xeharmenian'] = 0x056D;
  9215. t['xi'] = 0x03BE;
  9216. t['xmonospace'] = 0xFF58;
  9217. t['xparen'] = 0x24B3;
  9218. t['xsuperior'] = 0x02E3;
  9219. t['y'] = 0x0079;
  9220. t['yaadosquare'] = 0x334E;
  9221. t['yabengali'] = 0x09AF;
  9222. t['yacute'] = 0x00FD;
  9223. t['yadeva'] = 0x092F;
  9224. t['yaekorean'] = 0x3152;
  9225. t['yagujarati'] = 0x0AAF;
  9226. t['yagurmukhi'] = 0x0A2F;
  9227. t['yahiragana'] = 0x3084;
  9228. t['yakatakana'] = 0x30E4;
  9229. t['yakatakanahalfwidth'] = 0xFF94;
  9230. t['yakorean'] = 0x3151;
  9231. t['yamakkanthai'] = 0x0E4E;
  9232. t['yasmallhiragana'] = 0x3083;
  9233. t['yasmallkatakana'] = 0x30E3;
  9234. t['yasmallkatakanahalfwidth'] = 0xFF6C;
  9235. t['yatcyrillic'] = 0x0463;
  9236. t['ycircle'] = 0x24E8;
  9237. t['ycircumflex'] = 0x0177;
  9238. t['ydieresis'] = 0x00FF;
  9239. t['ydotaccent'] = 0x1E8F;
  9240. t['ydotbelow'] = 0x1EF5;
  9241. t['yeharabic'] = 0x064A;
  9242. t['yehbarreearabic'] = 0x06D2;
  9243. t['yehbarreefinalarabic'] = 0xFBAF;
  9244. t['yehfinalarabic'] = 0xFEF2;
  9245. t['yehhamzaabovearabic'] = 0x0626;
  9246. t['yehhamzaabovefinalarabic'] = 0xFE8A;
  9247. t['yehhamzaaboveinitialarabic'] = 0xFE8B;
  9248. t['yehhamzaabovemedialarabic'] = 0xFE8C;
  9249. t['yehinitialarabic'] = 0xFEF3;
  9250. t['yehmedialarabic'] = 0xFEF4;
  9251. t['yehmeeminitialarabic'] = 0xFCDD;
  9252. t['yehmeemisolatedarabic'] = 0xFC58;
  9253. t['yehnoonfinalarabic'] = 0xFC94;
  9254. t['yehthreedotsbelowarabic'] = 0x06D1;
  9255. t['yekorean'] = 0x3156;
  9256. t['yen'] = 0x00A5;
  9257. t['yenmonospace'] = 0xFFE5;
  9258. t['yeokorean'] = 0x3155;
  9259. t['yeorinhieuhkorean'] = 0x3186;
  9260. t['yerahbenyomohebrew'] = 0x05AA;
  9261. t['yerahbenyomolefthebrew'] = 0x05AA;
  9262. t['yericyrillic'] = 0x044B;
  9263. t['yerudieresiscyrillic'] = 0x04F9;
  9264. t['yesieungkorean'] = 0x3181;
  9265. t['yesieungpansioskorean'] = 0x3183;
  9266. t['yesieungsioskorean'] = 0x3182;
  9267. t['yetivhebrew'] = 0x059A;
  9268. t['ygrave'] = 0x1EF3;
  9269. t['yhook'] = 0x01B4;
  9270. t['yhookabove'] = 0x1EF7;
  9271. t['yiarmenian'] = 0x0575;
  9272. t['yicyrillic'] = 0x0457;
  9273. t['yikorean'] = 0x3162;
  9274. t['yinyang'] = 0x262F;
  9275. t['yiwnarmenian'] = 0x0582;
  9276. t['ymonospace'] = 0xFF59;
  9277. t['yod'] = 0x05D9;
  9278. t['yoddagesh'] = 0xFB39;
  9279. t['yoddageshhebrew'] = 0xFB39;
  9280. t['yodhebrew'] = 0x05D9;
  9281. t['yodyodhebrew'] = 0x05F2;
  9282. t['yodyodpatahhebrew'] = 0xFB1F;
  9283. t['yohiragana'] = 0x3088;
  9284. t['yoikorean'] = 0x3189;
  9285. t['yokatakana'] = 0x30E8;
  9286. t['yokatakanahalfwidth'] = 0xFF96;
  9287. t['yokorean'] = 0x315B;
  9288. t['yosmallhiragana'] = 0x3087;
  9289. t['yosmallkatakana'] = 0x30E7;
  9290. t['yosmallkatakanahalfwidth'] = 0xFF6E;
  9291. t['yotgreek'] = 0x03F3;
  9292. t['yoyaekorean'] = 0x3188;
  9293. t['yoyakorean'] = 0x3187;
  9294. t['yoyakthai'] = 0x0E22;
  9295. t['yoyingthai'] = 0x0E0D;
  9296. t['yparen'] = 0x24B4;
  9297. t['ypogegrammeni'] = 0x037A;
  9298. t['ypogegrammenigreekcmb'] = 0x0345;
  9299. t['yr'] = 0x01A6;
  9300. t['yring'] = 0x1E99;
  9301. t['ysuperior'] = 0x02B8;
  9302. t['ytilde'] = 0x1EF9;
  9303. t['yturned'] = 0x028E;
  9304. t['yuhiragana'] = 0x3086;
  9305. t['yuikorean'] = 0x318C;
  9306. t['yukatakana'] = 0x30E6;
  9307. t['yukatakanahalfwidth'] = 0xFF95;
  9308. t['yukorean'] = 0x3160;
  9309. t['yusbigcyrillic'] = 0x046B;
  9310. t['yusbigiotifiedcyrillic'] = 0x046D;
  9311. t['yuslittlecyrillic'] = 0x0467;
  9312. t['yuslittleiotifiedcyrillic'] = 0x0469;
  9313. t['yusmallhiragana'] = 0x3085;
  9314. t['yusmallkatakana'] = 0x30E5;
  9315. t['yusmallkatakanahalfwidth'] = 0xFF6D;
  9316. t['yuyekorean'] = 0x318B;
  9317. t['yuyeokorean'] = 0x318A;
  9318. t['yyabengali'] = 0x09DF;
  9319. t['yyadeva'] = 0x095F;
  9320. t['z'] = 0x007A;
  9321. t['zaarmenian'] = 0x0566;
  9322. t['zacute'] = 0x017A;
  9323. t['zadeva'] = 0x095B;
  9324. t['zagurmukhi'] = 0x0A5B;
  9325. t['zaharabic'] = 0x0638;
  9326. t['zahfinalarabic'] = 0xFEC6;
  9327. t['zahinitialarabic'] = 0xFEC7;
  9328. t['zahiragana'] = 0x3056;
  9329. t['zahmedialarabic'] = 0xFEC8;
  9330. t['zainarabic'] = 0x0632;
  9331. t['zainfinalarabic'] = 0xFEB0;
  9332. t['zakatakana'] = 0x30B6;
  9333. t['zaqefgadolhebrew'] = 0x0595;
  9334. t['zaqefqatanhebrew'] = 0x0594;
  9335. t['zarqahebrew'] = 0x0598;
  9336. t['zayin'] = 0x05D6;
  9337. t['zayindagesh'] = 0xFB36;
  9338. t['zayindageshhebrew'] = 0xFB36;
  9339. t['zayinhebrew'] = 0x05D6;
  9340. t['zbopomofo'] = 0x3117;
  9341. t['zcaron'] = 0x017E;
  9342. t['zcircle'] = 0x24E9;
  9343. t['zcircumflex'] = 0x1E91;
  9344. t['zcurl'] = 0x0291;
  9345. t['zdot'] = 0x017C;
  9346. t['zdotaccent'] = 0x017C;
  9347. t['zdotbelow'] = 0x1E93;
  9348. t['zecyrillic'] = 0x0437;
  9349. t['zedescendercyrillic'] = 0x0499;
  9350. t['zedieresiscyrillic'] = 0x04DF;
  9351. t['zehiragana'] = 0x305C;
  9352. t['zekatakana'] = 0x30BC;
  9353. t['zero'] = 0x0030;
  9354. t['zeroarabic'] = 0x0660;
  9355. t['zerobengali'] = 0x09E6;
  9356. t['zerodeva'] = 0x0966;
  9357. t['zerogujarati'] = 0x0AE6;
  9358. t['zerogurmukhi'] = 0x0A66;
  9359. t['zerohackarabic'] = 0x0660;
  9360. t['zeroinferior'] = 0x2080;
  9361. t['zeromonospace'] = 0xFF10;
  9362. t['zerooldstyle'] = 0xF730;
  9363. t['zeropersian'] = 0x06F0;
  9364. t['zerosuperior'] = 0x2070;
  9365. t['zerothai'] = 0x0E50;
  9366. t['zerowidthjoiner'] = 0xFEFF;
  9367. t['zerowidthnonjoiner'] = 0x200C;
  9368. t['zerowidthspace'] = 0x200B;
  9369. t['zeta'] = 0x03B6;
  9370. t['zhbopomofo'] = 0x3113;
  9371. t['zhearmenian'] = 0x056A;
  9372. t['zhebrevecyrillic'] = 0x04C2;
  9373. t['zhecyrillic'] = 0x0436;
  9374. t['zhedescendercyrillic'] = 0x0497;
  9375. t['zhedieresiscyrillic'] = 0x04DD;
  9376. t['zihiragana'] = 0x3058;
  9377. t['zikatakana'] = 0x30B8;
  9378. t['zinorhebrew'] = 0x05AE;
  9379. t['zlinebelow'] = 0x1E95;
  9380. t['zmonospace'] = 0xFF5A;
  9381. t['zohiragana'] = 0x305E;
  9382. t['zokatakana'] = 0x30BE;
  9383. t['zparen'] = 0x24B5;
  9384. t['zretroflexhook'] = 0x0290;
  9385. t['zstroke'] = 0x01B6;
  9386. t['zuhiragana'] = 0x305A;
  9387. t['zukatakana'] = 0x30BA;
  9388. t['.notdef'] = 0x0000;
  9389. });
  9390. var getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) {
  9391. t['space'] = 0x0020;
  9392. t['a1'] = 0x2701;
  9393. t['a2'] = 0x2702;
  9394. t['a202'] = 0x2703;
  9395. t['a3'] = 0x2704;
  9396. t['a4'] = 0x260E;
  9397. t['a5'] = 0x2706;
  9398. t['a119'] = 0x2707;
  9399. t['a118'] = 0x2708;
  9400. t['a117'] = 0x2709;
  9401. t['a11'] = 0x261B;
  9402. t['a12'] = 0x261E;
  9403. t['a13'] = 0x270C;
  9404. t['a14'] = 0x270D;
  9405. t['a15'] = 0x270E;
  9406. t['a16'] = 0x270F;
  9407. t['a105'] = 0x2710;
  9408. t['a17'] = 0x2711;
  9409. t['a18'] = 0x2712;
  9410. t['a19'] = 0x2713;
  9411. t['a20'] = 0x2714;
  9412. t['a21'] = 0x2715;
  9413. t['a22'] = 0x2716;
  9414. t['a23'] = 0x2717;
  9415. t['a24'] = 0x2718;
  9416. t['a25'] = 0x2719;
  9417. t['a26'] = 0x271A;
  9418. t['a27'] = 0x271B;
  9419. t['a28'] = 0x271C;
  9420. t['a6'] = 0x271D;
  9421. t['a7'] = 0x271E;
  9422. t['a8'] = 0x271F;
  9423. t['a9'] = 0x2720;
  9424. t['a10'] = 0x2721;
  9425. t['a29'] = 0x2722;
  9426. t['a30'] = 0x2723;
  9427. t['a31'] = 0x2724;
  9428. t['a32'] = 0x2725;
  9429. t['a33'] = 0x2726;
  9430. t['a34'] = 0x2727;
  9431. t['a35'] = 0x2605;
  9432. t['a36'] = 0x2729;
  9433. t['a37'] = 0x272A;
  9434. t['a38'] = 0x272B;
  9435. t['a39'] = 0x272C;
  9436. t['a40'] = 0x272D;
  9437. t['a41'] = 0x272E;
  9438. t['a42'] = 0x272F;
  9439. t['a43'] = 0x2730;
  9440. t['a44'] = 0x2731;
  9441. t['a45'] = 0x2732;
  9442. t['a46'] = 0x2733;
  9443. t['a47'] = 0x2734;
  9444. t['a48'] = 0x2735;
  9445. t['a49'] = 0x2736;
  9446. t['a50'] = 0x2737;
  9447. t['a51'] = 0x2738;
  9448. t['a52'] = 0x2739;
  9449. t['a53'] = 0x273A;
  9450. t['a54'] = 0x273B;
  9451. t['a55'] = 0x273C;
  9452. t['a56'] = 0x273D;
  9453. t['a57'] = 0x273E;
  9454. t['a58'] = 0x273F;
  9455. t['a59'] = 0x2740;
  9456. t['a60'] = 0x2741;
  9457. t['a61'] = 0x2742;
  9458. t['a62'] = 0x2743;
  9459. t['a63'] = 0x2744;
  9460. t['a64'] = 0x2745;
  9461. t['a65'] = 0x2746;
  9462. t['a66'] = 0x2747;
  9463. t['a67'] = 0x2748;
  9464. t['a68'] = 0x2749;
  9465. t['a69'] = 0x274A;
  9466. t['a70'] = 0x274B;
  9467. t['a71'] = 0x25CF;
  9468. t['a72'] = 0x274D;
  9469. t['a73'] = 0x25A0;
  9470. t['a74'] = 0x274F;
  9471. t['a203'] = 0x2750;
  9472. t['a75'] = 0x2751;
  9473. t['a204'] = 0x2752;
  9474. t['a76'] = 0x25B2;
  9475. t['a77'] = 0x25BC;
  9476. t['a78'] = 0x25C6;
  9477. t['a79'] = 0x2756;
  9478. t['a81'] = 0x25D7;
  9479. t['a82'] = 0x2758;
  9480. t['a83'] = 0x2759;
  9481. t['a84'] = 0x275A;
  9482. t['a97'] = 0x275B;
  9483. t['a98'] = 0x275C;
  9484. t['a99'] = 0x275D;
  9485. t['a100'] = 0x275E;
  9486. t['a101'] = 0x2761;
  9487. t['a102'] = 0x2762;
  9488. t['a103'] = 0x2763;
  9489. t['a104'] = 0x2764;
  9490. t['a106'] = 0x2765;
  9491. t['a107'] = 0x2766;
  9492. t['a108'] = 0x2767;
  9493. t['a112'] = 0x2663;
  9494. t['a111'] = 0x2666;
  9495. t['a110'] = 0x2665;
  9496. t['a109'] = 0x2660;
  9497. t['a120'] = 0x2460;
  9498. t['a121'] = 0x2461;
  9499. t['a122'] = 0x2462;
  9500. t['a123'] = 0x2463;
  9501. t['a124'] = 0x2464;
  9502. t['a125'] = 0x2465;
  9503. t['a126'] = 0x2466;
  9504. t['a127'] = 0x2467;
  9505. t['a128'] = 0x2468;
  9506. t['a129'] = 0x2469;
  9507. t['a130'] = 0x2776;
  9508. t['a131'] = 0x2777;
  9509. t['a132'] = 0x2778;
  9510. t['a133'] = 0x2779;
  9511. t['a134'] = 0x277A;
  9512. t['a135'] = 0x277B;
  9513. t['a136'] = 0x277C;
  9514. t['a137'] = 0x277D;
  9515. t['a138'] = 0x277E;
  9516. t['a139'] = 0x277F;
  9517. t['a140'] = 0x2780;
  9518. t['a141'] = 0x2781;
  9519. t['a142'] = 0x2782;
  9520. t['a143'] = 0x2783;
  9521. t['a144'] = 0x2784;
  9522. t['a145'] = 0x2785;
  9523. t['a146'] = 0x2786;
  9524. t['a147'] = 0x2787;
  9525. t['a148'] = 0x2788;
  9526. t['a149'] = 0x2789;
  9527. t['a150'] = 0x278A;
  9528. t['a151'] = 0x278B;
  9529. t['a152'] = 0x278C;
  9530. t['a153'] = 0x278D;
  9531. t['a154'] = 0x278E;
  9532. t['a155'] = 0x278F;
  9533. t['a156'] = 0x2790;
  9534. t['a157'] = 0x2791;
  9535. t['a158'] = 0x2792;
  9536. t['a159'] = 0x2793;
  9537. t['a160'] = 0x2794;
  9538. t['a161'] = 0x2192;
  9539. t['a163'] = 0x2194;
  9540. t['a164'] = 0x2195;
  9541. t['a196'] = 0x2798;
  9542. t['a165'] = 0x2799;
  9543. t['a192'] = 0x279A;
  9544. t['a166'] = 0x279B;
  9545. t['a167'] = 0x279C;
  9546. t['a168'] = 0x279D;
  9547. t['a169'] = 0x279E;
  9548. t['a170'] = 0x279F;
  9549. t['a171'] = 0x27A0;
  9550. t['a172'] = 0x27A1;
  9551. t['a173'] = 0x27A2;
  9552. t['a162'] = 0x27A3;
  9553. t['a174'] = 0x27A4;
  9554. t['a175'] = 0x27A5;
  9555. t['a176'] = 0x27A6;
  9556. t['a177'] = 0x27A7;
  9557. t['a178'] = 0x27A8;
  9558. t['a179'] = 0x27A9;
  9559. t['a193'] = 0x27AA;
  9560. t['a180'] = 0x27AB;
  9561. t['a199'] = 0x27AC;
  9562. t['a181'] = 0x27AD;
  9563. t['a200'] = 0x27AE;
  9564. t['a182'] = 0x27AF;
  9565. t['a201'] = 0x27B1;
  9566. t['a183'] = 0x27B2;
  9567. t['a184'] = 0x27B3;
  9568. t['a197'] = 0x27B4;
  9569. t['a185'] = 0x27B5;
  9570. t['a194'] = 0x27B6;
  9571. t['a198'] = 0x27B7;
  9572. t['a186'] = 0x27B8;
  9573. t['a195'] = 0x27B9;
  9574. t['a187'] = 0x27BA;
  9575. t['a188'] = 0x27BB;
  9576. t['a189'] = 0x27BC;
  9577. t['a190'] = 0x27BD;
  9578. t['a191'] = 0x27BE;
  9579. t['a89'] = 0x2768; // 0xF8D7
  9580. t['a90'] = 0x2769; // 0xF8D8
  9581. t['a93'] = 0x276A; // 0xF8D9
  9582. t['a94'] = 0x276B; // 0xF8DA
  9583. t['a91'] = 0x276C; // 0xF8DB
  9584. t['a92'] = 0x276D; // 0xF8DC
  9585. t['a205'] = 0x276E; // 0xF8DD
  9586. t['a85'] = 0x276F; // 0xF8DE
  9587. t['a206'] = 0x2770; // 0xF8DF
  9588. t['a86'] = 0x2771; // 0xF8E0
  9589. t['a87'] = 0x2772; // 0xF8E1
  9590. t['a88'] = 0x2773; // 0xF8E2
  9591. t['a95'] = 0x2774; // 0xF8E3
  9592. t['a96'] = 0x2775; // 0xF8E4
  9593. t['.notdef'] = 0x0000;
  9594. });
  9595. exports.getGlyphsUnicode = getGlyphsUnicode;
  9596. exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode;
  9597. }));
  9598. (function (root, factory) {
  9599. {
  9600. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  9601. root.pdfjsCoreArithmeticDecoder);
  9602. }
  9603. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  9604. var error = sharedUtil.error;
  9605. var log2 = sharedUtil.log2;
  9606. var readInt8 = sharedUtil.readInt8;
  9607. var readUint16 = sharedUtil.readUint16;
  9608. var readUint32 = sharedUtil.readUint32;
  9609. var shadow = sharedUtil.shadow;
  9610. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  9611. var Jbig2Image = (function Jbig2ImageClosure() {
  9612. // Utility data structures
  9613. function ContextCache() {}
  9614. ContextCache.prototype = {
  9615. getContexts: function(id) {
  9616. if (id in this) {
  9617. return this[id];
  9618. }
  9619. return (this[id] = new Int8Array(1 << 16));
  9620. }
  9621. };
  9622. function DecodingContext(data, start, end) {
  9623. this.data = data;
  9624. this.start = start;
  9625. this.end = end;
  9626. }
  9627. DecodingContext.prototype = {
  9628. get decoder() {
  9629. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  9630. return shadow(this, 'decoder', decoder);
  9631. },
  9632. get contextCache() {
  9633. var cache = new ContextCache();
  9634. return shadow(this, 'contextCache', cache);
  9635. }
  9636. };
  9637. // Annex A. Arithmetic Integer Decoding Procedure
  9638. // A.2 Procedure for decoding values
  9639. function decodeInteger(contextCache, procedure, decoder) {
  9640. var contexts = contextCache.getContexts(procedure);
  9641. var prev = 1;
  9642. function readBits(length) {
  9643. var v = 0;
  9644. for (var i = 0; i < length; i++) {
  9645. var bit = decoder.readBit(contexts, prev);
  9646. prev = (prev < 256 ? (prev << 1) | bit :
  9647. (((prev << 1) | bit) & 511) | 256);
  9648. v = (v << 1) | bit;
  9649. }
  9650. return v >>> 0;
  9651. }
  9652. var sign = readBits(1);
  9653. var value = readBits(1) ?
  9654. (readBits(1) ?
  9655. (readBits(1) ?
  9656. (readBits(1) ?
  9657. (readBits(1) ?
  9658. (readBits(32) + 4436) :
  9659. readBits(12) + 340) :
  9660. readBits(8) + 84) :
  9661. readBits(6) + 20) :
  9662. readBits(4) + 4) :
  9663. readBits(2);
  9664. return (sign === 0 ? value : (value > 0 ? -value : null));
  9665. }
  9666. // A.3 The IAID decoding procedure
  9667. function decodeIAID(contextCache, decoder, codeLength) {
  9668. var contexts = contextCache.getContexts('IAID');
  9669. var prev = 1;
  9670. for (var i = 0; i < codeLength; i++) {
  9671. var bit = decoder.readBit(contexts, prev);
  9672. prev = (prev << 1) | bit;
  9673. }
  9674. if (codeLength < 31) {
  9675. return prev & ((1 << codeLength) - 1);
  9676. }
  9677. return prev & 0x7FFFFFFF;
  9678. }
  9679. // 7.3 Segment types
  9680. var SegmentTypes = [
  9681. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  9682. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  9683. null, null, null, null, null, 'patternDictionary', null, null, null,
  9684. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  9685. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  9686. null, null, null, null, null, 'IntermediateGenericRegion', null,
  9687. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  9688. 'IntermediateGenericRefinementRegion', null,
  9689. 'ImmediateGenericRefinementRegion',
  9690. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  9691. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  9692. 'Tables', null, null, null, null, null, null, null, null,
  9693. 'Extension'
  9694. ];
  9695. var CodingTemplates = [
  9696. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  9697. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  9698. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  9699. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  9700. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  9701. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  9702. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  9703. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  9704. {x: -1, y: 0}],
  9705. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  9706. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  9707. ];
  9708. var RefinementTemplates = [
  9709. {
  9710. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  9711. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  9712. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  9713. },
  9714. {
  9715. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  9716. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  9717. {x: 0, y: 1}, {x: 1, y: 1}]
  9718. }
  9719. ];
  9720. // See 6.2.5.7 Decoding the bitmap.
  9721. var ReusedContexts = [
  9722. 0x9B25, // 10011 0110010 0101
  9723. 0x0795, // 0011 110010 101
  9724. 0x00E5, // 001 11001 01
  9725. 0x0195 // 011001 0101
  9726. ];
  9727. var RefinementReusedContexts = [
  9728. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  9729. 0x0008 // '0000' + '001000'
  9730. ];
  9731. function decodeBitmapTemplate0(width, height, decodingContext) {
  9732. var decoder = decodingContext.decoder;
  9733. var contexts = decodingContext.contextCache.getContexts('GB');
  9734. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  9735. // ...ooooo....
  9736. // ..ooooooo... Context template for current pixel (X)
  9737. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  9738. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  9739. for (i = 0; i < height; i++) {
  9740. row = bitmap[i] = new Uint8Array(width);
  9741. row1 = (i < 1) ? row : bitmap[i - 1];
  9742. row2 = (i < 2) ? row : bitmap[i - 2];
  9743. // At the beginning of each row:
  9744. // Fill contextLabel with pixels that are above/right of (X)
  9745. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  9746. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  9747. (row1[3] << 4);
  9748. for (j = 0; j < width; j++) {
  9749. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  9750. // At each pixel: Clear contextLabel pixels that are shifted
  9751. // out of the context, then add new ones.
  9752. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  9753. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  9754. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  9755. }
  9756. }
  9757. return bitmap;
  9758. }
  9759. // 6.2 Generic Region Decoding Procedure
  9760. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  9761. decodingContext) {
  9762. if (mmr) {
  9763. error('JBIG2 error: MMR encoding is not supported');
  9764. }
  9765. // Use optimized version for the most common case
  9766. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  9767. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  9768. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  9769. return decodeBitmapTemplate0(width, height, decodingContext);
  9770. }
  9771. var useskip = !!skip;
  9772. var template = CodingTemplates[templateIndex].concat(at);
  9773. // Sorting is non-standard, and it is not required. But sorting increases
  9774. // the number of template bits that can be reused from the previous
  9775. // contextLabel in the main loop.
  9776. template.sort(function (a, b) {
  9777. return (a.y - b.y) || (a.x - b.x);
  9778. });
  9779. var templateLength = template.length;
  9780. var templateX = new Int8Array(templateLength);
  9781. var templateY = new Int8Array(templateLength);
  9782. var changingTemplateEntries = [];
  9783. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  9784. var c, k;
  9785. for (k = 0; k < templateLength; k++) {
  9786. templateX[k] = template[k].x;
  9787. templateY[k] = template[k].y;
  9788. minX = Math.min(minX, template[k].x);
  9789. maxX = Math.max(maxX, template[k].x);
  9790. minY = Math.min(minY, template[k].y);
  9791. // Check if the template pixel appears in two consecutive context labels,
  9792. // so it can be reused. Otherwise, we add it to the list of changing
  9793. // template entries.
  9794. if (k < templateLength - 1 &&
  9795. template[k].y === template[k + 1].y &&
  9796. template[k].x === template[k + 1].x - 1) {
  9797. reuseMask |= 1 << (templateLength - 1 - k);
  9798. } else {
  9799. changingTemplateEntries.push(k);
  9800. }
  9801. }
  9802. var changingEntriesLength = changingTemplateEntries.length;
  9803. var changingTemplateX = new Int8Array(changingEntriesLength);
  9804. var changingTemplateY = new Int8Array(changingEntriesLength);
  9805. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  9806. for (c = 0; c < changingEntriesLength; c++) {
  9807. k = changingTemplateEntries[c];
  9808. changingTemplateX[c] = template[k].x;
  9809. changingTemplateY[c] = template[k].y;
  9810. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  9811. }
  9812. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  9813. var sbb_left = -minX;
  9814. var sbb_top = -minY;
  9815. var sbb_right = width - maxX;
  9816. var pseudoPixelContext = ReusedContexts[templateIndex];
  9817. var row = new Uint8Array(width);
  9818. var bitmap = [];
  9819. var decoder = decodingContext.decoder;
  9820. var contexts = decodingContext.contextCache.getContexts('GB');
  9821. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  9822. for (var i = 0; i < height; i++) {
  9823. if (prediction) {
  9824. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  9825. ltp ^= sltp;
  9826. if (ltp) {
  9827. bitmap.push(row); // duplicate previous row
  9828. continue;
  9829. }
  9830. }
  9831. row = new Uint8Array(row);
  9832. bitmap.push(row);
  9833. for (j = 0; j < width; j++) {
  9834. if (useskip && skip[i][j]) {
  9835. row[j] = 0;
  9836. continue;
  9837. }
  9838. // Are we in the middle of a scanline, so we can reuse contextLabel
  9839. // bits?
  9840. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  9841. // If yes, we can just shift the bits that are reusable and only
  9842. // fetch the remaining ones.
  9843. contextLabel = (contextLabel << 1) & reuseMask;
  9844. for (k = 0; k < changingEntriesLength; k++) {
  9845. i0 = i + changingTemplateY[k];
  9846. j0 = j + changingTemplateX[k];
  9847. bit = bitmap[i0][j0];
  9848. if (bit) {
  9849. bit = changingTemplateBit[k];
  9850. contextLabel |= bit;
  9851. }
  9852. }
  9853. } else {
  9854. // compute the contextLabel from scratch
  9855. contextLabel = 0;
  9856. shift = templateLength - 1;
  9857. for (k = 0; k < templateLength; k++, shift--) {
  9858. j0 = j + templateX[k];
  9859. if (j0 >= 0 && j0 < width) {
  9860. i0 = i + templateY[k];
  9861. if (i0 >= 0) {
  9862. bit = bitmap[i0][j0];
  9863. if (bit) {
  9864. contextLabel |= bit << shift;
  9865. }
  9866. }
  9867. }
  9868. }
  9869. }
  9870. var pixel = decoder.readBit(contexts, contextLabel);
  9871. row[j] = pixel;
  9872. }
  9873. }
  9874. return bitmap;
  9875. }
  9876. // 6.3.2 Generic Refinement Region Decoding Procedure
  9877. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  9878. offsetX, offsetY, prediction, at,
  9879. decodingContext) {
  9880. var codingTemplate = RefinementTemplates[templateIndex].coding;
  9881. if (templateIndex === 0) {
  9882. codingTemplate = codingTemplate.concat([at[0]]);
  9883. }
  9884. var codingTemplateLength = codingTemplate.length;
  9885. var codingTemplateX = new Int32Array(codingTemplateLength);
  9886. var codingTemplateY = new Int32Array(codingTemplateLength);
  9887. var k;
  9888. for (k = 0; k < codingTemplateLength; k++) {
  9889. codingTemplateX[k] = codingTemplate[k].x;
  9890. codingTemplateY[k] = codingTemplate[k].y;
  9891. }
  9892. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  9893. if (templateIndex === 0) {
  9894. referenceTemplate = referenceTemplate.concat([at[1]]);
  9895. }
  9896. var referenceTemplateLength = referenceTemplate.length;
  9897. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  9898. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  9899. for (k = 0; k < referenceTemplateLength; k++) {
  9900. referenceTemplateX[k] = referenceTemplate[k].x;
  9901. referenceTemplateY[k] = referenceTemplate[k].y;
  9902. }
  9903. var referenceWidth = referenceBitmap[0].length;
  9904. var referenceHeight = referenceBitmap.length;
  9905. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  9906. var bitmap = [];
  9907. var decoder = decodingContext.decoder;
  9908. var contexts = decodingContext.contextCache.getContexts('GR');
  9909. var ltp = 0;
  9910. for (var i = 0; i < height; i++) {
  9911. if (prediction) {
  9912. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  9913. ltp ^= sltp;
  9914. if (ltp) {
  9915. error('JBIG2 error: prediction is not supported');
  9916. }
  9917. }
  9918. var row = new Uint8Array(width);
  9919. bitmap.push(row);
  9920. for (var j = 0; j < width; j++) {
  9921. var i0, j0;
  9922. var contextLabel = 0;
  9923. for (k = 0; k < codingTemplateLength; k++) {
  9924. i0 = i + codingTemplateY[k];
  9925. j0 = j + codingTemplateX[k];
  9926. if (i0 < 0 || j0 < 0 || j0 >= width) {
  9927. contextLabel <<= 1; // out of bound pixel
  9928. } else {
  9929. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  9930. }
  9931. }
  9932. for (k = 0; k < referenceTemplateLength; k++) {
  9933. i0 = i + referenceTemplateY[k] + offsetY;
  9934. j0 = j + referenceTemplateX[k] + offsetX;
  9935. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  9936. j0 >= referenceWidth) {
  9937. contextLabel <<= 1; // out of bound pixel
  9938. } else {
  9939. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  9940. }
  9941. }
  9942. var pixel = decoder.readBit(contexts, contextLabel);
  9943. row[j] = pixel;
  9944. }
  9945. }
  9946. return bitmap;
  9947. }
  9948. // 6.5.5 Decoding the symbol dictionary
  9949. function decodeSymbolDictionary(huffman, refinement, symbols,
  9950. numberOfNewSymbols, numberOfExportedSymbols,
  9951. huffmanTables, templateIndex, at,
  9952. refinementTemplateIndex, refinementAt,
  9953. decodingContext) {
  9954. if (huffman) {
  9955. error('JBIG2 error: huffman is not supported');
  9956. }
  9957. var newSymbols = [];
  9958. var currentHeight = 0;
  9959. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  9960. var decoder = decodingContext.decoder;
  9961. var contextCache = decodingContext.contextCache;
  9962. while (newSymbols.length < numberOfNewSymbols) {
  9963. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  9964. currentHeight += deltaHeight;
  9965. var currentWidth = 0;
  9966. var totalWidth = 0;
  9967. while (true) {
  9968. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  9969. if (deltaWidth === null) {
  9970. break; // OOB
  9971. }
  9972. currentWidth += deltaWidth;
  9973. totalWidth += currentWidth;
  9974. var bitmap;
  9975. if (refinement) {
  9976. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  9977. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  9978. if (numberOfInstances > 1) {
  9979. bitmap = decodeTextRegion(huffman, refinement,
  9980. currentWidth, currentHeight, 0,
  9981. numberOfInstances, 1, //strip size
  9982. symbols.concat(newSymbols),
  9983. symbolCodeLength,
  9984. 0, //transposed
  9985. 0, //ds offset
  9986. 1, //top left 7.4.3.1.1
  9987. 0, //OR operator
  9988. huffmanTables,
  9989. refinementTemplateIndex, refinementAt,
  9990. decodingContext);
  9991. } else {
  9992. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  9993. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  9994. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  9995. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  9996. newSymbols[symbolId - symbols.length]);
  9997. bitmap = decodeRefinement(currentWidth, currentHeight,
  9998. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  9999. decodingContext);
  10000. }
  10001. } else {
  10002. // 6.5.8.1 Direct-coded symbol bitmap
  10003. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  10004. templateIndex, false, null, at, decodingContext);
  10005. }
  10006. newSymbols.push(bitmap);
  10007. }
  10008. }
  10009. // 6.5.10 Exported symbols
  10010. var exportedSymbols = [];
  10011. var flags = [], currentFlag = false;
  10012. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  10013. while (flags.length < totalSymbolsLength) {
  10014. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  10015. while (runLength--) {
  10016. flags.push(currentFlag);
  10017. }
  10018. currentFlag = !currentFlag;
  10019. }
  10020. for (var i = 0, ii = symbols.length; i < ii; i++) {
  10021. if (flags[i]) {
  10022. exportedSymbols.push(symbols[i]);
  10023. }
  10024. }
  10025. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  10026. if (flags[i]) {
  10027. exportedSymbols.push(newSymbols[j]);
  10028. }
  10029. }
  10030. return exportedSymbols;
  10031. }
  10032. function decodeTextRegion(huffman, refinement, width, height,
  10033. defaultPixelValue, numberOfSymbolInstances,
  10034. stripSize, inputSymbols, symbolCodeLength,
  10035. transposed, dsOffset, referenceCorner,
  10036. combinationOperator, huffmanTables,
  10037. refinementTemplateIndex, refinementAt,
  10038. decodingContext) {
  10039. if (huffman) {
  10040. error('JBIG2 error: huffman is not supported');
  10041. }
  10042. // Prepare bitmap
  10043. var bitmap = [];
  10044. var i, row;
  10045. for (i = 0; i < height; i++) {
  10046. row = new Uint8Array(width);
  10047. if (defaultPixelValue) {
  10048. for (var j = 0; j < width; j++) {
  10049. row[j] = defaultPixelValue;
  10050. }
  10051. }
  10052. bitmap.push(row);
  10053. }
  10054. var decoder = decodingContext.decoder;
  10055. var contextCache = decodingContext.contextCache;
  10056. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  10057. var firstS = 0;
  10058. i = 0;
  10059. while (i < numberOfSymbolInstances) {
  10060. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  10061. stripT += deltaT;
  10062. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  10063. firstS += deltaFirstS;
  10064. var currentS = firstS;
  10065. do {
  10066. var currentT = (stripSize === 1 ? 0 :
  10067. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  10068. var t = stripSize * stripT + currentT;
  10069. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  10070. var applyRefinement = (refinement &&
  10071. decodeInteger(contextCache, 'IARI', decoder));
  10072. var symbolBitmap = inputSymbols[symbolId];
  10073. var symbolWidth = symbolBitmap[0].length;
  10074. var symbolHeight = symbolBitmap.length;
  10075. if (applyRefinement) {
  10076. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  10077. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  10078. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  10079. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  10080. symbolWidth += rdw;
  10081. symbolHeight += rdh;
  10082. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  10083. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  10084. (rdh >> 1) + rdy, false, refinementAt,
  10085. decodingContext);
  10086. }
  10087. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  10088. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  10089. var s2, t2, symbolRow;
  10090. if (transposed) {
  10091. // Place Symbol Bitmap from T1,S1
  10092. for (s2 = 0; s2 < symbolHeight; s2++) {
  10093. row = bitmap[offsetS + s2];
  10094. if (!row) {
  10095. continue;
  10096. }
  10097. symbolRow = symbolBitmap[s2];
  10098. // To ignore Parts of Symbol bitmap which goes
  10099. // outside bitmap region
  10100. var maxWidth = Math.min(width - offsetT, symbolWidth);
  10101. switch (combinationOperator) {
  10102. case 0: // OR
  10103. for (t2 = 0; t2 < maxWidth; t2++) {
  10104. row[offsetT + t2] |= symbolRow[t2];
  10105. }
  10106. break;
  10107. case 2: // XOR
  10108. for (t2 = 0; t2 < maxWidth; t2++) {
  10109. row[offsetT + t2] ^= symbolRow[t2];
  10110. }
  10111. break;
  10112. default:
  10113. error('JBIG2 error: operator ' + combinationOperator +
  10114. ' is not supported');
  10115. }
  10116. }
  10117. currentS += symbolHeight - 1;
  10118. } else {
  10119. for (t2 = 0; t2 < symbolHeight; t2++) {
  10120. row = bitmap[offsetT + t2];
  10121. if (!row) {
  10122. continue;
  10123. }
  10124. symbolRow = symbolBitmap[t2];
  10125. switch (combinationOperator) {
  10126. case 0: // OR
  10127. for (s2 = 0; s2 < symbolWidth; s2++) {
  10128. row[offsetS + s2] |= symbolRow[s2];
  10129. }
  10130. break;
  10131. case 2: // XOR
  10132. for (s2 = 0; s2 < symbolWidth; s2++) {
  10133. row[offsetS + s2] ^= symbolRow[s2];
  10134. }
  10135. break;
  10136. default:
  10137. error('JBIG2 error: operator ' + combinationOperator +
  10138. ' is not supported');
  10139. }
  10140. }
  10141. currentS += symbolWidth - 1;
  10142. }
  10143. i++;
  10144. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  10145. if (deltaS === null) {
  10146. break; // OOB
  10147. }
  10148. currentS += deltaS + dsOffset;
  10149. } while (true);
  10150. }
  10151. return bitmap;
  10152. }
  10153. function readSegmentHeader(data, start) {
  10154. var segmentHeader = {};
  10155. segmentHeader.number = readUint32(data, start);
  10156. var flags = data[start + 4];
  10157. var segmentType = flags & 0x3F;
  10158. if (!SegmentTypes[segmentType]) {
  10159. error('JBIG2 error: invalid segment type: ' + segmentType);
  10160. }
  10161. segmentHeader.type = segmentType;
  10162. segmentHeader.typeName = SegmentTypes[segmentType];
  10163. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  10164. var pageAssociationFieldSize = !!(flags & 0x40);
  10165. var referredFlags = data[start + 5];
  10166. var referredToCount = (referredFlags >> 5) & 7;
  10167. var retainBits = [referredFlags & 31];
  10168. var position = start + 6;
  10169. if (referredFlags === 7) {
  10170. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  10171. position += 3;
  10172. var bytes = (referredToCount + 7) >> 3;
  10173. retainBits[0] = data[position++];
  10174. while (--bytes > 0) {
  10175. retainBits.push(data[position++]);
  10176. }
  10177. } else if (referredFlags === 5 || referredFlags === 6) {
  10178. error('JBIG2 error: invalid referred-to flags');
  10179. }
  10180. segmentHeader.retainBits = retainBits;
  10181. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  10182. (segmentHeader.number <= 65536 ? 2 : 4));
  10183. var referredTo = [];
  10184. var i, ii;
  10185. for (i = 0; i < referredToCount; i++) {
  10186. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  10187. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  10188. readUint32(data, position)));
  10189. referredTo.push(number);
  10190. position += referredToSegmentNumberSize;
  10191. }
  10192. segmentHeader.referredTo = referredTo;
  10193. if (!pageAssociationFieldSize) {
  10194. segmentHeader.pageAssociation = data[position++];
  10195. } else {
  10196. segmentHeader.pageAssociation = readUint32(data, position);
  10197. position += 4;
  10198. }
  10199. segmentHeader.length = readUint32(data, position);
  10200. position += 4;
  10201. if (segmentHeader.length === 0xFFFFFFFF) {
  10202. // 7.2.7 Segment data length, unknown segment length
  10203. if (segmentType === 38) { // ImmediateGenericRegion
  10204. var genericRegionInfo = readRegionSegmentInformation(data, position);
  10205. var genericRegionSegmentFlags = data[position +
  10206. RegionSegmentInformationFieldLength];
  10207. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  10208. // searching for the segment end
  10209. var searchPatternLength = 6;
  10210. var searchPattern = new Uint8Array(searchPatternLength);
  10211. if (!genericRegionMmr) {
  10212. searchPattern[0] = 0xFF;
  10213. searchPattern[1] = 0xAC;
  10214. }
  10215. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  10216. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  10217. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  10218. searchPattern[5] = genericRegionInfo.height & 0xFF;
  10219. for (i = position, ii = data.length; i < ii; i++) {
  10220. var j = 0;
  10221. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  10222. j++;
  10223. }
  10224. if (j === searchPatternLength) {
  10225. segmentHeader.length = i + searchPatternLength;
  10226. break;
  10227. }
  10228. }
  10229. if (segmentHeader.length === 0xFFFFFFFF) {
  10230. error('JBIG2 error: segment end was not found');
  10231. }
  10232. } else {
  10233. error('JBIG2 error: invalid unknown segment length');
  10234. }
  10235. }
  10236. segmentHeader.headerEnd = position;
  10237. return segmentHeader;
  10238. }
  10239. function readSegments(header, data, start, end) {
  10240. var segments = [];
  10241. var position = start;
  10242. while (position < end) {
  10243. var segmentHeader = readSegmentHeader(data, position);
  10244. position = segmentHeader.headerEnd;
  10245. var segment = {
  10246. header: segmentHeader,
  10247. data: data
  10248. };
  10249. if (!header.randomAccess) {
  10250. segment.start = position;
  10251. position += segmentHeader.length;
  10252. segment.end = position;
  10253. }
  10254. segments.push(segment);
  10255. if (segmentHeader.type === 51) {
  10256. break; // end of file is found
  10257. }
  10258. }
  10259. if (header.randomAccess) {
  10260. for (var i = 0, ii = segments.length; i < ii; i++) {
  10261. segments[i].start = position;
  10262. position += segments[i].header.length;
  10263. segments[i].end = position;
  10264. }
  10265. }
  10266. return segments;
  10267. }
  10268. // 7.4.1 Region segment information field
  10269. function readRegionSegmentInformation(data, start) {
  10270. return {
  10271. width: readUint32(data, start),
  10272. height: readUint32(data, start + 4),
  10273. x: readUint32(data, start + 8),
  10274. y: readUint32(data, start + 12),
  10275. combinationOperator: data[start + 16] & 7
  10276. };
  10277. }
  10278. var RegionSegmentInformationFieldLength = 17;
  10279. function processSegment(segment, visitor) {
  10280. var header = segment.header;
  10281. var data = segment.data, position = segment.start, end = segment.end;
  10282. var args, at, i, atLength;
  10283. switch (header.type) {
  10284. case 0: // SymbolDictionary
  10285. // 7.4.2 Symbol dictionary segment syntax
  10286. var dictionary = {};
  10287. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  10288. dictionary.huffman = !!(dictionaryFlags & 1);
  10289. dictionary.refinement = !!(dictionaryFlags & 2);
  10290. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  10291. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  10292. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  10293. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  10294. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  10295. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  10296. dictionary.template = (dictionaryFlags >> 10) & 3;
  10297. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  10298. position += 2;
  10299. if (!dictionary.huffman) {
  10300. atLength = dictionary.template === 0 ? 4 : 1;
  10301. at = [];
  10302. for (i = 0; i < atLength; i++) {
  10303. at.push({
  10304. x: readInt8(data, position),
  10305. y: readInt8(data, position + 1)
  10306. });
  10307. position += 2;
  10308. }
  10309. dictionary.at = at;
  10310. }
  10311. if (dictionary.refinement && !dictionary.refinementTemplate) {
  10312. at = [];
  10313. for (i = 0; i < 2; i++) {
  10314. at.push({
  10315. x: readInt8(data, position),
  10316. y: readInt8(data, position + 1)
  10317. });
  10318. position += 2;
  10319. }
  10320. dictionary.refinementAt = at;
  10321. }
  10322. dictionary.numberOfExportedSymbols = readUint32(data, position);
  10323. position += 4;
  10324. dictionary.numberOfNewSymbols = readUint32(data, position);
  10325. position += 4;
  10326. args = [dictionary, header.number, header.referredTo,
  10327. data, position, end];
  10328. break;
  10329. case 6: // ImmediateTextRegion
  10330. case 7: // ImmediateLosslessTextRegion
  10331. var textRegion = {};
  10332. textRegion.info = readRegionSegmentInformation(data, position);
  10333. position += RegionSegmentInformationFieldLength;
  10334. var textRegionSegmentFlags = readUint16(data, position);
  10335. position += 2;
  10336. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  10337. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  10338. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  10339. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  10340. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  10341. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  10342. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  10343. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  10344. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  10345. if (textRegion.huffman) {
  10346. var textRegionHuffmanFlags = readUint16(data, position);
  10347. position += 2;
  10348. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  10349. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  10350. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  10351. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  10352. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  10353. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  10354. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  10355. textRegion.huffmanRefinementSizeSelector =
  10356. !!(textRegionHuffmanFlags & 14);
  10357. }
  10358. if (textRegion.refinement && !textRegion.refinementTemplate) {
  10359. at = [];
  10360. for (i = 0; i < 2; i++) {
  10361. at.push({
  10362. x: readInt8(data, position),
  10363. y: readInt8(data, position + 1)
  10364. });
  10365. position += 2;
  10366. }
  10367. textRegion.refinementAt = at;
  10368. }
  10369. textRegion.numberOfSymbolInstances = readUint32(data, position);
  10370. position += 4;
  10371. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  10372. if (textRegion.huffman) {
  10373. error('JBIG2 error: huffman is not supported');
  10374. }
  10375. args = [textRegion, header.referredTo, data, position, end];
  10376. break;
  10377. case 38: // ImmediateGenericRegion
  10378. case 39: // ImmediateLosslessGenericRegion
  10379. var genericRegion = {};
  10380. genericRegion.info = readRegionSegmentInformation(data, position);
  10381. position += RegionSegmentInformationFieldLength;
  10382. var genericRegionSegmentFlags = data[position++];
  10383. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  10384. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  10385. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  10386. if (!genericRegion.mmr) {
  10387. atLength = genericRegion.template === 0 ? 4 : 1;
  10388. at = [];
  10389. for (i = 0; i < atLength; i++) {
  10390. at.push({
  10391. x: readInt8(data, position),
  10392. y: readInt8(data, position + 1)
  10393. });
  10394. position += 2;
  10395. }
  10396. genericRegion.at = at;
  10397. }
  10398. args = [genericRegion, data, position, end];
  10399. break;
  10400. case 48: // PageInformation
  10401. var pageInfo = {
  10402. width: readUint32(data, position),
  10403. height: readUint32(data, position + 4),
  10404. resolutionX: readUint32(data, position + 8),
  10405. resolutionY: readUint32(data, position + 12)
  10406. };
  10407. if (pageInfo.height === 0xFFFFFFFF) {
  10408. delete pageInfo.height;
  10409. }
  10410. var pageSegmentFlags = data[position + 16];
  10411. var pageStripingInformation = readUint16(data, position + 17);
  10412. pageInfo.lossless = !!(pageSegmentFlags & 1);
  10413. pageInfo.refinement = !!(pageSegmentFlags & 2);
  10414. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  10415. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  10416. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  10417. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  10418. args = [pageInfo];
  10419. break;
  10420. case 49: // EndOfPage
  10421. break;
  10422. case 50: // EndOfStripe
  10423. break;
  10424. case 51: // EndOfFile
  10425. break;
  10426. case 62: // 7.4.15 defines 2 extension types which
  10427. // are comments and can be ignored.
  10428. break;
  10429. default:
  10430. error('JBIG2 error: segment type ' + header.typeName + '(' +
  10431. header.type + ') is not implemented');
  10432. }
  10433. var callbackName = 'on' + header.typeName;
  10434. if (callbackName in visitor) {
  10435. visitor[callbackName].apply(visitor, args);
  10436. }
  10437. }
  10438. function processSegments(segments, visitor) {
  10439. for (var i = 0, ii = segments.length; i < ii; i++) {
  10440. processSegment(segments[i], visitor);
  10441. }
  10442. }
  10443. function parseJbig2(data, start, end) {
  10444. var position = start;
  10445. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  10446. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  10447. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  10448. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  10449. error('JBIG2 error: invalid header');
  10450. }
  10451. var header = {};
  10452. position += 8;
  10453. var flags = data[position++];
  10454. header.randomAccess = !(flags & 1);
  10455. if (!(flags & 2)) {
  10456. header.numberOfPages = readUint32(data, position);
  10457. position += 4;
  10458. }
  10459. var segments = readSegments(header, data, position, end);
  10460. error('Not implemented');
  10461. // processSegments(segments, new SimpleSegmentVisitor());
  10462. }
  10463. function parseJbig2Chunks(chunks) {
  10464. var visitor = new SimpleSegmentVisitor();
  10465. for (var i = 0, ii = chunks.length; i < ii; i++) {
  10466. var chunk = chunks[i];
  10467. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  10468. processSegments(segments, visitor);
  10469. }
  10470. return visitor.buffer;
  10471. }
  10472. function SimpleSegmentVisitor() {}
  10473. SimpleSegmentVisitor.prototype = {
  10474. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  10475. this.currentPageInfo = info;
  10476. var rowSize = (info.width + 7) >> 3;
  10477. var buffer = new Uint8Array(rowSize * info.height);
  10478. // The contents of ArrayBuffers are initialized to 0.
  10479. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  10480. if (info.defaultPixelValue) {
  10481. for (var i = 0, ii = buffer.length; i < ii; i++) {
  10482. buffer[i] = 0xFF;
  10483. }
  10484. }
  10485. this.buffer = buffer;
  10486. },
  10487. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  10488. var pageInfo = this.currentPageInfo;
  10489. var width = regionInfo.width, height = regionInfo.height;
  10490. var rowSize = (pageInfo.width + 7) >> 3;
  10491. var combinationOperator = pageInfo.combinationOperatorOverride ?
  10492. regionInfo.combinationOperator : pageInfo.combinationOperator;
  10493. var buffer = this.buffer;
  10494. var mask0 = 128 >> (regionInfo.x & 7);
  10495. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  10496. var i, j, mask, offset;
  10497. switch (combinationOperator) {
  10498. case 0: // OR
  10499. for (i = 0; i < height; i++) {
  10500. mask = mask0;
  10501. offset = offset0;
  10502. for (j = 0; j < width; j++) {
  10503. if (bitmap[i][j]) {
  10504. buffer[offset] |= mask;
  10505. }
  10506. mask >>= 1;
  10507. if (!mask) {
  10508. mask = 128;
  10509. offset++;
  10510. }
  10511. }
  10512. offset0 += rowSize;
  10513. }
  10514. break;
  10515. case 2: // XOR
  10516. for (i = 0; i < height; i++) {
  10517. mask = mask0;
  10518. offset = offset0;
  10519. for (j = 0; j < width; j++) {
  10520. if (bitmap[i][j]) {
  10521. buffer[offset] ^= mask;
  10522. }
  10523. mask >>= 1;
  10524. if (!mask) {
  10525. mask = 128;
  10526. offset++;
  10527. }
  10528. }
  10529. offset0 += rowSize;
  10530. }
  10531. break;
  10532. default:
  10533. error('JBIG2 error: operator ' + combinationOperator +
  10534. ' is not supported');
  10535. }
  10536. },
  10537. onImmediateGenericRegion:
  10538. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  10539. start, end) {
  10540. var regionInfo = region.info;
  10541. var decodingContext = new DecodingContext(data, start, end);
  10542. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  10543. region.template, region.prediction, null,
  10544. region.at, decodingContext);
  10545. this.drawBitmap(regionInfo, bitmap);
  10546. },
  10547. onImmediateLosslessGenericRegion:
  10548. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  10549. this.onImmediateGenericRegion.apply(this, arguments);
  10550. },
  10551. onSymbolDictionary:
  10552. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  10553. currentSegment,
  10554. referredSegments,
  10555. data, start, end) {
  10556. var huffmanTables;
  10557. if (dictionary.huffman) {
  10558. error('JBIG2 error: huffman is not supported');
  10559. }
  10560. // Combines exported symbols from all referred segments
  10561. var symbols = this.symbols;
  10562. if (!symbols) {
  10563. this.symbols = symbols = {};
  10564. }
  10565. var inputSymbols = [];
  10566. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  10567. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  10568. }
  10569. var decodingContext = new DecodingContext(data, start, end);
  10570. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  10571. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  10572. dictionary.numberOfExportedSymbols, huffmanTables,
  10573. dictionary.template, dictionary.at,
  10574. dictionary.refinementTemplate, dictionary.refinementAt,
  10575. decodingContext);
  10576. },
  10577. onImmediateTextRegion:
  10578. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  10579. referredSegments,
  10580. data, start, end) {
  10581. var regionInfo = region.info;
  10582. var huffmanTables;
  10583. // Combines exported symbols from all referred segments
  10584. var symbols = this.symbols;
  10585. var inputSymbols = [];
  10586. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  10587. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  10588. }
  10589. var symbolCodeLength = log2(inputSymbols.length);
  10590. var decodingContext = new DecodingContext(data, start, end);
  10591. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  10592. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  10593. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  10594. symbolCodeLength, region.transposed, region.dsOffset,
  10595. region.referenceCorner, region.combinationOperator, huffmanTables,
  10596. region.refinementTemplate, region.refinementAt, decodingContext);
  10597. this.drawBitmap(regionInfo, bitmap);
  10598. },
  10599. onImmediateLosslessTextRegion:
  10600. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  10601. this.onImmediateTextRegion.apply(this, arguments);
  10602. }
  10603. };
  10604. function Jbig2Image() {}
  10605. Jbig2Image.prototype = {
  10606. parseChunks: function Jbig2Image_parseChunks(chunks) {
  10607. return parseJbig2Chunks(chunks);
  10608. }
  10609. };
  10610. return Jbig2Image;
  10611. })();
  10612. exports.Jbig2Image = Jbig2Image;
  10613. }));
  10614. (function (root, factory) {
  10615. {
  10616. factory((root.pdfjsCoreJpg = {}), root.pdfjsSharedUtil);
  10617. }
  10618. }(this, function (exports, sharedUtil) {
  10619. var error = sharedUtil.error;
  10620. /**
  10621. * This code was forked from https://github.com/notmasteryet/jpgjs.
  10622. * The original version was created by GitHub user notmasteryet.
  10623. *
  10624. * - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  10625. * (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  10626. * - The JFIF specification can be found in the JPEG File Interchange Format
  10627. * (www.w3.org/Graphics/JPEG/jfif3.pdf)
  10628. * - The Adobe Application-Specific JPEG markers in the
  10629. * Supporting the DCT Filters in PostScript Level 2, Technical Note #5116
  10630. * (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  10631. */
  10632. var JpegImage = (function jpegImage() {
  10633. var dctZigZag = new Uint8Array([
  10634. 0,
  10635. 1, 8,
  10636. 16, 9, 2,
  10637. 3, 10, 17, 24,
  10638. 32, 25, 18, 11, 4,
  10639. 5, 12, 19, 26, 33, 40,
  10640. 48, 41, 34, 27, 20, 13, 6,
  10641. 7, 14, 21, 28, 35, 42, 49, 56,
  10642. 57, 50, 43, 36, 29, 22, 15,
  10643. 23, 30, 37, 44, 51, 58,
  10644. 59, 52, 45, 38, 31,
  10645. 39, 46, 53, 60,
  10646. 61, 54, 47,
  10647. 55, 62,
  10648. 63
  10649. ]);
  10650. var dctCos1 = 4017; // cos(pi/16)
  10651. var dctSin1 = 799; // sin(pi/16)
  10652. var dctCos3 = 3406; // cos(3*pi/16)
  10653. var dctSin3 = 2276; // sin(3*pi/16)
  10654. var dctCos6 = 1567; // cos(6*pi/16)
  10655. var dctSin6 = 3784; // sin(6*pi/16)
  10656. var dctSqrt2 = 5793; // sqrt(2)
  10657. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  10658. function constructor() {
  10659. }
  10660. function buildHuffmanTable(codeLengths, values) {
  10661. var k = 0, code = [], i, j, length = 16;
  10662. while (length > 0 && !codeLengths[length - 1]) {
  10663. length--;
  10664. }
  10665. code.push({children: [], index: 0});
  10666. var p = code[0], q;
  10667. for (i = 0; i < length; i++) {
  10668. for (j = 0; j < codeLengths[i]; j++) {
  10669. p = code.pop();
  10670. p.children[p.index] = values[k];
  10671. while (p.index > 0) {
  10672. p = code.pop();
  10673. }
  10674. p.index++;
  10675. code.push(p);
  10676. while (code.length <= i) {
  10677. code.push(q = {children: [], index: 0});
  10678. p.children[p.index] = q.children;
  10679. p = q;
  10680. }
  10681. k++;
  10682. }
  10683. if (i + 1 < length) {
  10684. // p here points to last code
  10685. code.push(q = {children: [], index: 0});
  10686. p.children[p.index] = q.children;
  10687. p = q;
  10688. }
  10689. }
  10690. return code[0].children;
  10691. }
  10692. function getBlockBufferOffset(component, row, col) {
  10693. return 64 * ((component.blocksPerLine + 1) * row + col);
  10694. }
  10695. function decodeScan(data, offset, frame, components, resetInterval,
  10696. spectralStart, spectralEnd, successivePrev, successive) {
  10697. var mcusPerLine = frame.mcusPerLine;
  10698. var progressive = frame.progressive;
  10699. var startOffset = offset, bitsData = 0, bitsCount = 0;
  10700. function readBit() {
  10701. if (bitsCount > 0) {
  10702. bitsCount--;
  10703. return (bitsData >> bitsCount) & 1;
  10704. }
  10705. bitsData = data[offset++];
  10706. if (bitsData === 0xFF) {
  10707. var nextByte = data[offset++];
  10708. if (nextByte) {
  10709. error('JPEG error: unexpected marker ' +
  10710. ((bitsData << 8) | nextByte).toString(16));
  10711. }
  10712. // unstuff 0
  10713. }
  10714. bitsCount = 7;
  10715. return bitsData >>> 7;
  10716. }
  10717. function decodeHuffman(tree) {
  10718. var node = tree;
  10719. while (true) {
  10720. node = node[readBit()];
  10721. if (typeof node === 'number') {
  10722. return node;
  10723. }
  10724. if (typeof node !== 'object') {
  10725. error('JPEG error: invalid huffman sequence');
  10726. }
  10727. }
  10728. }
  10729. function receive(length) {
  10730. var n = 0;
  10731. while (length > 0) {
  10732. n = (n << 1) | readBit();
  10733. length--;
  10734. }
  10735. return n;
  10736. }
  10737. function receiveAndExtend(length) {
  10738. if (length === 1) {
  10739. return readBit() === 1 ? 1 : -1;
  10740. }
  10741. var n = receive(length);
  10742. if (n >= 1 << (length - 1)) {
  10743. return n;
  10744. }
  10745. return n + (-1 << length) + 1;
  10746. }
  10747. function decodeBaseline(component, offset) {
  10748. var t = decodeHuffman(component.huffmanTableDC);
  10749. var diff = t === 0 ? 0 : receiveAndExtend(t);
  10750. component.blockData[offset] = (component.pred += diff);
  10751. var k = 1;
  10752. while (k < 64) {
  10753. var rs = decodeHuffman(component.huffmanTableAC);
  10754. var s = rs & 15, r = rs >> 4;
  10755. if (s === 0) {
  10756. if (r < 15) {
  10757. break;
  10758. }
  10759. k += 16;
  10760. continue;
  10761. }
  10762. k += r;
  10763. var z = dctZigZag[k];
  10764. component.blockData[offset + z] = receiveAndExtend(s);
  10765. k++;
  10766. }
  10767. }
  10768. function decodeDCFirst(component, offset) {
  10769. var t = decodeHuffman(component.huffmanTableDC);
  10770. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  10771. component.blockData[offset] = (component.pred += diff);
  10772. }
  10773. function decodeDCSuccessive(component, offset) {
  10774. component.blockData[offset] |= readBit() << successive;
  10775. }
  10776. var eobrun = 0;
  10777. function decodeACFirst(component, offset) {
  10778. if (eobrun > 0) {
  10779. eobrun--;
  10780. return;
  10781. }
  10782. var k = spectralStart, e = spectralEnd;
  10783. while (k <= e) {
  10784. var rs = decodeHuffman(component.huffmanTableAC);
  10785. var s = rs & 15, r = rs >> 4;
  10786. if (s === 0) {
  10787. if (r < 15) {
  10788. eobrun = receive(r) + (1 << r) - 1;
  10789. break;
  10790. }
  10791. k += 16;
  10792. continue;
  10793. }
  10794. k += r;
  10795. var z = dctZigZag[k];
  10796. component.blockData[offset + z] =
  10797. receiveAndExtend(s) * (1 << successive);
  10798. k++;
  10799. }
  10800. }
  10801. var successiveACState = 0, successiveACNextValue;
  10802. function decodeACSuccessive(component, offset) {
  10803. var k = spectralStart;
  10804. var e = spectralEnd;
  10805. var r = 0;
  10806. var s;
  10807. var rs;
  10808. while (k <= e) {
  10809. var z = dctZigZag[k];
  10810. switch (successiveACState) {
  10811. case 0: // initial state
  10812. rs = decodeHuffman(component.huffmanTableAC);
  10813. s = rs & 15;
  10814. r = rs >> 4;
  10815. if (s === 0) {
  10816. if (r < 15) {
  10817. eobrun = receive(r) + (1 << r);
  10818. successiveACState = 4;
  10819. } else {
  10820. r = 16;
  10821. successiveACState = 1;
  10822. }
  10823. } else {
  10824. if (s !== 1) {
  10825. error('JPEG error: invalid ACn encoding');
  10826. }
  10827. successiveACNextValue = receiveAndExtend(s);
  10828. successiveACState = r ? 2 : 3;
  10829. }
  10830. continue;
  10831. case 1: // skipping r zero items
  10832. case 2:
  10833. if (component.blockData[offset + z]) {
  10834. component.blockData[offset + z] += (readBit() << successive);
  10835. } else {
  10836. r--;
  10837. if (r === 0) {
  10838. successiveACState = successiveACState === 2 ? 3 : 0;
  10839. }
  10840. }
  10841. break;
  10842. case 3: // set value for a zero item
  10843. if (component.blockData[offset + z]) {
  10844. component.blockData[offset + z] += (readBit() << successive);
  10845. } else {
  10846. component.blockData[offset + z] =
  10847. successiveACNextValue << successive;
  10848. successiveACState = 0;
  10849. }
  10850. break;
  10851. case 4: // eob
  10852. if (component.blockData[offset + z]) {
  10853. component.blockData[offset + z] += (readBit() << successive);
  10854. }
  10855. break;
  10856. }
  10857. k++;
  10858. }
  10859. if (successiveACState === 4) {
  10860. eobrun--;
  10861. if (eobrun === 0) {
  10862. successiveACState = 0;
  10863. }
  10864. }
  10865. }
  10866. function decodeMcu(component, decode, mcu, row, col) {
  10867. var mcuRow = (mcu / mcusPerLine) | 0;
  10868. var mcuCol = mcu % mcusPerLine;
  10869. var blockRow = mcuRow * component.v + row;
  10870. var blockCol = mcuCol * component.h + col;
  10871. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  10872. decode(component, offset);
  10873. }
  10874. function decodeBlock(component, decode, mcu) {
  10875. var blockRow = (mcu / component.blocksPerLine) | 0;
  10876. var blockCol = mcu % component.blocksPerLine;
  10877. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  10878. decode(component, offset);
  10879. }
  10880. var componentsLength = components.length;
  10881. var component, i, j, k, n;
  10882. var decodeFn;
  10883. if (progressive) {
  10884. if (spectralStart === 0) {
  10885. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  10886. } else {
  10887. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  10888. }
  10889. } else {
  10890. decodeFn = decodeBaseline;
  10891. }
  10892. var mcu = 0, marker;
  10893. var mcuExpected;
  10894. if (componentsLength === 1) {
  10895. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  10896. } else {
  10897. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  10898. }
  10899. if (!resetInterval) {
  10900. resetInterval = mcuExpected;
  10901. }
  10902. var h, v;
  10903. while (mcu < mcuExpected) {
  10904. // reset interval stuff
  10905. for (i = 0; i < componentsLength; i++) {
  10906. components[i].pred = 0;
  10907. }
  10908. eobrun = 0;
  10909. if (componentsLength === 1) {
  10910. component = components[0];
  10911. for (n = 0; n < resetInterval; n++) {
  10912. decodeBlock(component, decodeFn, mcu);
  10913. mcu++;
  10914. }
  10915. } else {
  10916. for (n = 0; n < resetInterval; n++) {
  10917. for (i = 0; i < componentsLength; i++) {
  10918. component = components[i];
  10919. h = component.h;
  10920. v = component.v;
  10921. for (j = 0; j < v; j++) {
  10922. for (k = 0; k < h; k++) {
  10923. decodeMcu(component, decodeFn, mcu, j, k);
  10924. }
  10925. }
  10926. }
  10927. mcu++;
  10928. }
  10929. }
  10930. // find marker
  10931. bitsCount = 0;
  10932. marker = (data[offset] << 8) | data[offset + 1];
  10933. if (marker <= 0xFF00) {
  10934. error('JPEG error: marker was not found');
  10935. }
  10936. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  10937. offset += 2;
  10938. } else {
  10939. break;
  10940. }
  10941. }
  10942. return offset - startOffset;
  10943. }
  10944. // A port of poppler's IDCT method which in turn is taken from:
  10945. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  10946. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  10947. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  10948. // 988-991.
  10949. function quantizeAndInverse(component, blockBufferOffset, p) {
  10950. var qt = component.quantizationTable, blockData = component.blockData;
  10951. var v0, v1, v2, v3, v4, v5, v6, v7;
  10952. var p0, p1, p2, p3, p4, p5, p6, p7;
  10953. var t;
  10954. if (!qt) {
  10955. error('JPEG error: missing required Quantization Table.');
  10956. }
  10957. // inverse DCT on rows
  10958. for (var row = 0; row < 64; row += 8) {
  10959. // gather block data
  10960. p0 = blockData[blockBufferOffset + row];
  10961. p1 = blockData[blockBufferOffset + row + 1];
  10962. p2 = blockData[blockBufferOffset + row + 2];
  10963. p3 = blockData[blockBufferOffset + row + 3];
  10964. p4 = blockData[blockBufferOffset + row + 4];
  10965. p5 = blockData[blockBufferOffset + row + 5];
  10966. p6 = blockData[blockBufferOffset + row + 6];
  10967. p7 = blockData[blockBufferOffset + row + 7];
  10968. // dequant p0
  10969. p0 *= qt[row];
  10970. // check for all-zero AC coefficients
  10971. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  10972. t = (dctSqrt2 * p0 + 512) >> 10;
  10973. p[row] = t;
  10974. p[row + 1] = t;
  10975. p[row + 2] = t;
  10976. p[row + 3] = t;
  10977. p[row + 4] = t;
  10978. p[row + 5] = t;
  10979. p[row + 6] = t;
  10980. p[row + 7] = t;
  10981. continue;
  10982. }
  10983. // dequant p1 ... p7
  10984. p1 *= qt[row + 1];
  10985. p2 *= qt[row + 2];
  10986. p3 *= qt[row + 3];
  10987. p4 *= qt[row + 4];
  10988. p5 *= qt[row + 5];
  10989. p6 *= qt[row + 6];
  10990. p7 *= qt[row + 7];
  10991. // stage 4
  10992. v0 = (dctSqrt2 * p0 + 128) >> 8;
  10993. v1 = (dctSqrt2 * p4 + 128) >> 8;
  10994. v2 = p2;
  10995. v3 = p6;
  10996. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  10997. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  10998. v5 = p3 << 4;
  10999. v6 = p5 << 4;
  11000. // stage 3
  11001. v0 = (v0 + v1 + 1) >> 1;
  11002. v1 = v0 - v1;
  11003. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  11004. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  11005. v3 = t;
  11006. v4 = (v4 + v6 + 1) >> 1;
  11007. v6 = v4 - v6;
  11008. v7 = (v7 + v5 + 1) >> 1;
  11009. v5 = v7 - v5;
  11010. // stage 2
  11011. v0 = (v0 + v3 + 1) >> 1;
  11012. v3 = v0 - v3;
  11013. v1 = (v1 + v2 + 1) >> 1;
  11014. v2 = v1 - v2;
  11015. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  11016. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  11017. v7 = t;
  11018. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  11019. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  11020. v6 = t;
  11021. // stage 1
  11022. p[row] = v0 + v7;
  11023. p[row + 7] = v0 - v7;
  11024. p[row + 1] = v1 + v6;
  11025. p[row + 6] = v1 - v6;
  11026. p[row + 2] = v2 + v5;
  11027. p[row + 5] = v2 - v5;
  11028. p[row + 3] = v3 + v4;
  11029. p[row + 4] = v3 - v4;
  11030. }
  11031. // inverse DCT on columns
  11032. for (var col = 0; col < 8; ++col) {
  11033. p0 = p[col];
  11034. p1 = p[col + 8];
  11035. p2 = p[col + 16];
  11036. p3 = p[col + 24];
  11037. p4 = p[col + 32];
  11038. p5 = p[col + 40];
  11039. p6 = p[col + 48];
  11040. p7 = p[col + 56];
  11041. // check for all-zero AC coefficients
  11042. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  11043. t = (dctSqrt2 * p0 + 8192) >> 14;
  11044. // convert to 8 bit
  11045. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  11046. blockData[blockBufferOffset + col] = t;
  11047. blockData[blockBufferOffset + col + 8] = t;
  11048. blockData[blockBufferOffset + col + 16] = t;
  11049. blockData[blockBufferOffset + col + 24] = t;
  11050. blockData[blockBufferOffset + col + 32] = t;
  11051. blockData[blockBufferOffset + col + 40] = t;
  11052. blockData[blockBufferOffset + col + 48] = t;
  11053. blockData[blockBufferOffset + col + 56] = t;
  11054. continue;
  11055. }
  11056. // stage 4
  11057. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  11058. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  11059. v2 = p2;
  11060. v3 = p6;
  11061. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  11062. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  11063. v5 = p3;
  11064. v6 = p5;
  11065. // stage 3
  11066. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  11067. // converting to UInt8 range later.
  11068. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  11069. v1 = v0 - v1;
  11070. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  11071. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  11072. v3 = t;
  11073. v4 = (v4 + v6 + 1) >> 1;
  11074. v6 = v4 - v6;
  11075. v7 = (v7 + v5 + 1) >> 1;
  11076. v5 = v7 - v5;
  11077. // stage 2
  11078. v0 = (v0 + v3 + 1) >> 1;
  11079. v3 = v0 - v3;
  11080. v1 = (v1 + v2 + 1) >> 1;
  11081. v2 = v1 - v2;
  11082. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  11083. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  11084. v7 = t;
  11085. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  11086. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  11087. v6 = t;
  11088. // stage 1
  11089. p0 = v0 + v7;
  11090. p7 = v0 - v7;
  11091. p1 = v1 + v6;
  11092. p6 = v1 - v6;
  11093. p2 = v2 + v5;
  11094. p5 = v2 - v5;
  11095. p3 = v3 + v4;
  11096. p4 = v3 - v4;
  11097. // convert to 8-bit integers
  11098. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  11099. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  11100. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  11101. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  11102. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  11103. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  11104. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  11105. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  11106. // store block data
  11107. blockData[blockBufferOffset + col] = p0;
  11108. blockData[blockBufferOffset + col + 8] = p1;
  11109. blockData[blockBufferOffset + col + 16] = p2;
  11110. blockData[blockBufferOffset + col + 24] = p3;
  11111. blockData[blockBufferOffset + col + 32] = p4;
  11112. blockData[blockBufferOffset + col + 40] = p5;
  11113. blockData[blockBufferOffset + col + 48] = p6;
  11114. blockData[blockBufferOffset + col + 56] = p7;
  11115. }
  11116. }
  11117. function buildComponentData(frame, component) {
  11118. var blocksPerLine = component.blocksPerLine;
  11119. var blocksPerColumn = component.blocksPerColumn;
  11120. var computationBuffer = new Int16Array(64);
  11121. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  11122. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  11123. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  11124. quantizeAndInverse(component, offset, computationBuffer);
  11125. }
  11126. }
  11127. return component.blockData;
  11128. }
  11129. function clamp0to255(a) {
  11130. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  11131. }
  11132. constructor.prototype = {
  11133. parse: function parse(data) {
  11134. function readUint16() {
  11135. var value = (data[offset] << 8) | data[offset + 1];
  11136. offset += 2;
  11137. return value;
  11138. }
  11139. function readDataBlock() {
  11140. var length = readUint16();
  11141. var array = data.subarray(offset, offset + length - 2);
  11142. offset += array.length;
  11143. return array;
  11144. }
  11145. function prepareComponents(frame) {
  11146. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  11147. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  11148. for (var i = 0; i < frame.components.length; i++) {
  11149. component = frame.components[i];
  11150. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  11151. component.h / frame.maxH);
  11152. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  11153. component.v / frame.maxV);
  11154. var blocksPerLineForMcu = mcusPerLine * component.h;
  11155. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  11156. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  11157. (blocksPerLineForMcu + 1);
  11158. component.blockData = new Int16Array(blocksBufferSize);
  11159. component.blocksPerLine = blocksPerLine;
  11160. component.blocksPerColumn = blocksPerColumn;
  11161. }
  11162. frame.mcusPerLine = mcusPerLine;
  11163. frame.mcusPerColumn = mcusPerColumn;
  11164. }
  11165. var offset = 0;
  11166. var jfif = null;
  11167. var adobe = null;
  11168. var frame, resetInterval;
  11169. var quantizationTables = [];
  11170. var huffmanTablesAC = [], huffmanTablesDC = [];
  11171. var fileMarker = readUint16();
  11172. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  11173. error('JPEG error: SOI not found');
  11174. }
  11175. fileMarker = readUint16();
  11176. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  11177. var i, j, l;
  11178. switch(fileMarker) {
  11179. case 0xFFE0: // APP0 (Application Specific)
  11180. case 0xFFE1: // APP1
  11181. case 0xFFE2: // APP2
  11182. case 0xFFE3: // APP3
  11183. case 0xFFE4: // APP4
  11184. case 0xFFE5: // APP5
  11185. case 0xFFE6: // APP6
  11186. case 0xFFE7: // APP7
  11187. case 0xFFE8: // APP8
  11188. case 0xFFE9: // APP9
  11189. case 0xFFEA: // APP10
  11190. case 0xFFEB: // APP11
  11191. case 0xFFEC: // APP12
  11192. case 0xFFED: // APP13
  11193. case 0xFFEE: // APP14
  11194. case 0xFFEF: // APP15
  11195. case 0xFFFE: // COM (Comment)
  11196. var appData = readDataBlock();
  11197. if (fileMarker === 0xFFE0) {
  11198. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  11199. appData[2] === 0x49 && appData[3] === 0x46 &&
  11200. appData[4] === 0) { // 'JFIF\x00'
  11201. jfif = {
  11202. version: { major: appData[5], minor: appData[6] },
  11203. densityUnits: appData[7],
  11204. xDensity: (appData[8] << 8) | appData[9],
  11205. yDensity: (appData[10] << 8) | appData[11],
  11206. thumbWidth: appData[12],
  11207. thumbHeight: appData[13],
  11208. thumbData: appData.subarray(14, 14 +
  11209. 3 * appData[12] * appData[13])
  11210. };
  11211. }
  11212. }
  11213. // TODO APP1 - Exif
  11214. if (fileMarker === 0xFFEE) {
  11215. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  11216. appData[2] === 0x6F && appData[3] === 0x62 &&
  11217. appData[4] === 0x65) { // 'Adobe'
  11218. adobe = {
  11219. version: (appData[5] << 8) | appData[6],
  11220. flags0: (appData[7] << 8) | appData[8],
  11221. flags1: (appData[9] << 8) | appData[10],
  11222. transformCode: appData[11]
  11223. };
  11224. }
  11225. }
  11226. break;
  11227. case 0xFFDB: // DQT (Define Quantization Tables)
  11228. var quantizationTablesLength = readUint16();
  11229. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  11230. var z;
  11231. while (offset < quantizationTablesEnd) {
  11232. var quantizationTableSpec = data[offset++];
  11233. var tableData = new Uint16Array(64);
  11234. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  11235. for (j = 0; j < 64; j++) {
  11236. z = dctZigZag[j];
  11237. tableData[z] = data[offset++];
  11238. }
  11239. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  11240. for (j = 0; j < 64; j++) {
  11241. z = dctZigZag[j];
  11242. tableData[z] = readUint16();
  11243. }
  11244. } else {
  11245. error('JPEG error: DQT - invalid table spec');
  11246. }
  11247. quantizationTables[quantizationTableSpec & 15] = tableData;
  11248. }
  11249. break;
  11250. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  11251. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  11252. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  11253. if (frame) {
  11254. error('JPEG error: Only single frame JPEGs supported');
  11255. }
  11256. readUint16(); // skip data length
  11257. frame = {};
  11258. frame.extended = (fileMarker === 0xFFC1);
  11259. frame.progressive = (fileMarker === 0xFFC2);
  11260. frame.precision = data[offset++];
  11261. frame.scanLines = readUint16();
  11262. frame.samplesPerLine = readUint16();
  11263. frame.components = [];
  11264. frame.componentIds = {};
  11265. var componentsCount = data[offset++], componentId;
  11266. var maxH = 0, maxV = 0;
  11267. for (i = 0; i < componentsCount; i++) {
  11268. componentId = data[offset];
  11269. var h = data[offset + 1] >> 4;
  11270. var v = data[offset + 1] & 15;
  11271. if (maxH < h) {
  11272. maxH = h;
  11273. }
  11274. if (maxV < v) {
  11275. maxV = v;
  11276. }
  11277. var qId = data[offset + 2];
  11278. l = frame.components.push({
  11279. h: h,
  11280. v: v,
  11281. quantizationId: qId,
  11282. quantizationTable: null, // See comment below.
  11283. });
  11284. frame.componentIds[componentId] = l - 1;
  11285. offset += 3;
  11286. }
  11287. frame.maxH = maxH;
  11288. frame.maxV = maxV;
  11289. prepareComponents(frame);
  11290. break;
  11291. case 0xFFC4: // DHT (Define Huffman Tables)
  11292. var huffmanLength = readUint16();
  11293. for (i = 2; i < huffmanLength;) {
  11294. var huffmanTableSpec = data[offset++];
  11295. var codeLengths = new Uint8Array(16);
  11296. var codeLengthSum = 0;
  11297. for (j = 0; j < 16; j++, offset++) {
  11298. codeLengthSum += (codeLengths[j] = data[offset]);
  11299. }
  11300. var huffmanValues = new Uint8Array(codeLengthSum);
  11301. for (j = 0; j < codeLengthSum; j++, offset++) {
  11302. huffmanValues[j] = data[offset];
  11303. }
  11304. i += 17 + codeLengthSum;
  11305. ((huffmanTableSpec >> 4) === 0 ?
  11306. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  11307. buildHuffmanTable(codeLengths, huffmanValues);
  11308. }
  11309. break;
  11310. case 0xFFDD: // DRI (Define Restart Interval)
  11311. readUint16(); // skip data length
  11312. resetInterval = readUint16();
  11313. break;
  11314. case 0xFFDA: // SOS (Start of Scan)
  11315. var scanLength = readUint16();
  11316. var selectorsCount = data[offset++];
  11317. var components = [], component;
  11318. for (i = 0; i < selectorsCount; i++) {
  11319. var componentIndex = frame.componentIds[data[offset++]];
  11320. component = frame.components[componentIndex];
  11321. var tableSpec = data[offset++];
  11322. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  11323. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  11324. components.push(component);
  11325. }
  11326. var spectralStart = data[offset++];
  11327. var spectralEnd = data[offset++];
  11328. var successiveApproximation = data[offset++];
  11329. var processed = decodeScan(data, offset,
  11330. frame, components, resetInterval,
  11331. spectralStart, spectralEnd,
  11332. successiveApproximation >> 4, successiveApproximation & 15);
  11333. offset += processed;
  11334. break;
  11335. case 0xFFFF: // Fill bytes
  11336. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  11337. offset--;
  11338. }
  11339. break;
  11340. default:
  11341. if (data[offset - 3] === 0xFF &&
  11342. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  11343. // could be incorrect encoding -- last 0xFF byte of the previous
  11344. // block was eaten by the encoder
  11345. offset -= 3;
  11346. break;
  11347. }
  11348. error('JPEG error: unknown marker ' + fileMarker.toString(16));
  11349. }
  11350. fileMarker = readUint16();
  11351. }
  11352. this.width = frame.samplesPerLine;
  11353. this.height = frame.scanLines;
  11354. this.jfif = jfif;
  11355. this.adobe = adobe;
  11356. this.components = [];
  11357. for (i = 0; i < frame.components.length; i++) {
  11358. component = frame.components[i];
  11359. // Prevent errors when DQT markers are placed after SOF{n} markers,
  11360. // by assigning the `quantizationTable` entry after the entire image
  11361. // has been parsed (fixes issue7406.pdf).
  11362. var quantizationTable = quantizationTables[component.quantizationId];
  11363. if (quantizationTable) {
  11364. component.quantizationTable = quantizationTable;
  11365. }
  11366. this.components.push({
  11367. output: buildComponentData(frame, component),
  11368. scaleX: component.h / frame.maxH,
  11369. scaleY: component.v / frame.maxV,
  11370. blocksPerLine: component.blocksPerLine,
  11371. blocksPerColumn: component.blocksPerColumn
  11372. });
  11373. }
  11374. this.numComponents = this.components.length;
  11375. },
  11376. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  11377. var scaleX = this.width / width, scaleY = this.height / height;
  11378. var component, componentScaleX, componentScaleY, blocksPerScanline;
  11379. var x, y, i, j, k;
  11380. var index;
  11381. var offset = 0;
  11382. var output;
  11383. var numComponents = this.components.length;
  11384. var dataLength = width * height * numComponents;
  11385. var data = new Uint8Array(dataLength);
  11386. var xScaleBlockOffset = new Uint32Array(width);
  11387. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  11388. for (i = 0; i < numComponents; i++) {
  11389. component = this.components[i];
  11390. componentScaleX = component.scaleX * scaleX;
  11391. componentScaleY = component.scaleY * scaleY;
  11392. offset = i;
  11393. output = component.output;
  11394. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  11395. // precalculate the xScaleBlockOffset
  11396. for (x = 0; x < width; x++) {
  11397. j = 0 | (x * componentScaleX);
  11398. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  11399. }
  11400. // linearize the blocks of the component
  11401. for (y = 0; y < height; y++) {
  11402. j = 0 | (y * componentScaleY);
  11403. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  11404. for (x = 0; x < width; x++) {
  11405. data[offset] = output[index + xScaleBlockOffset[x]];
  11406. offset += numComponents;
  11407. }
  11408. }
  11409. }
  11410. // decodeTransform contains pairs of multiplier (-256..256) and additive
  11411. var transform = this.decodeTransform;
  11412. if (transform) {
  11413. for (i = 0; i < dataLength;) {
  11414. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  11415. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  11416. }
  11417. }
  11418. }
  11419. return data;
  11420. },
  11421. _isColorConversionNeeded: function isColorConversionNeeded() {
  11422. if (this.adobe && this.adobe.transformCode) {
  11423. // The adobe transform marker overrides any previous setting
  11424. return true;
  11425. } else if (this.numComponents === 3) {
  11426. return true;
  11427. } else {
  11428. return false;
  11429. }
  11430. },
  11431. _convertYccToRgb: function convertYccToRgb(data) {
  11432. var Y, Cb, Cr;
  11433. for (var i = 0, length = data.length; i < length; i += 3) {
  11434. Y = data[i ];
  11435. Cb = data[i + 1];
  11436. Cr = data[i + 2];
  11437. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  11438. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  11439. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  11440. }
  11441. return data;
  11442. },
  11443. _convertYcckToRgb: function convertYcckToRgb(data) {
  11444. var Y, Cb, Cr, k;
  11445. var offset = 0;
  11446. for (var i = 0, length = data.length; i < length; i += 4) {
  11447. Y = data[i];
  11448. Cb = data[i + 1];
  11449. Cr = data[i + 2];
  11450. k = data[i + 3];
  11451. var r = -122.67195406894 +
  11452. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  11453. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  11454. 0.154362151871126) +
  11455. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  11456. 0.00477271405408747 * k + 1.53380253221734) +
  11457. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  11458. 0.48357088451265) +
  11459. k * (-0.000336197177618394 * k + 0.484791561490776);
  11460. var g = 107.268039397724 +
  11461. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  11462. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  11463. 0.176491792462875) +
  11464. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  11465. 0.000770482631801132 * k - 0.151051492775562) +
  11466. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  11467. 0.25802910206845) +
  11468. k * (-0.000318913117588328 * k - 0.213742400323665);
  11469. var b = -20.810012546947 +
  11470. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  11471. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  11472. 0.814272968359295) +
  11473. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  11474. 0.000560833691242812 * k - 0.195152027534049) +
  11475. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  11476. 0.116935020465145) +
  11477. k * (-0.000343531996510555 * k + 0.24165260232407);
  11478. data[offset++] = clamp0to255(r);
  11479. data[offset++] = clamp0to255(g);
  11480. data[offset++] = clamp0to255(b);
  11481. }
  11482. return data;
  11483. },
  11484. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  11485. var Y, Cb, Cr;
  11486. for (var i = 0, length = data.length; i < length; i += 4) {
  11487. Y = data[i];
  11488. Cb = data[i + 1];
  11489. Cr = data[i + 2];
  11490. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  11491. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  11492. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  11493. // K in data[i + 3] is unchanged
  11494. }
  11495. return data;
  11496. },
  11497. _convertCmykToRgb: function convertCmykToRgb(data) {
  11498. var c, m, y, k;
  11499. var offset = 0;
  11500. var min = -255 * 255 * 255;
  11501. var scale = 1 / 255 / 255;
  11502. for (var i = 0, length = data.length; i < length; i += 4) {
  11503. c = data[i];
  11504. m = data[i + 1];
  11505. y = data[i + 2];
  11506. k = data[i + 3];
  11507. var r =
  11508. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  11509. 18.82290502165302 * y + 212.25662451639585 * k -
  11510. 72734.4411664936) +
  11511. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  11512. 17.873870861415444 * k - 1401.7366389350734) +
  11513. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  11514. 4465.541406466231) -
  11515. k * (21.86122147463605 * k + 48317.86113160301);
  11516. var g =
  11517. c * (8.841041422036149 * c + 60.118027045597366 * m +
  11518. 6.871425592049007 * y + 31.159100130055922 * k -
  11519. 20220.756542821975) +
  11520. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  11521. 131.35250912493976 * k - 48691.05921601825) +
  11522. y * (4.444339102852739 * y + 9.8632861493405 * k -
  11523. 6341.191035517494) -
  11524. k * (20.737325471181034 * k + 47890.15695978492);
  11525. var b =
  11526. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  11527. 30.89978309703729 * y - 0.23883238689178934 * k -
  11528. 3616.812083916688) +
  11529. m * (10.49593273432072 * m + 63.02378494754052 * y +
  11530. 50.606957656360734 * k - 28620.90484698408) +
  11531. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  11532. 49363.43385999684) -
  11533. k * (22.33816807309886 * k + 45932.16563550634);
  11534. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  11535. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  11536. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  11537. }
  11538. return data;
  11539. },
  11540. getData: function getData(width, height, forceRGBoutput) {
  11541. if (this.numComponents > 4) {
  11542. error('JPEG error: Unsupported color mode');
  11543. }
  11544. // type of data: Uint8Array(width * height * numComponents)
  11545. var data = this._getLinearizedBlockData(width, height);
  11546. if (this.numComponents === 1 && forceRGBoutput) {
  11547. var dataLength = data.length;
  11548. var rgbData = new Uint8Array(dataLength * 3);
  11549. var offset = 0;
  11550. for (var i = 0; i < dataLength; i++) {
  11551. var grayColor = data[i];
  11552. rgbData[offset++] = grayColor;
  11553. rgbData[offset++] = grayColor;
  11554. rgbData[offset++] = grayColor;
  11555. }
  11556. return rgbData;
  11557. } else if (this.numComponents === 3) {
  11558. return this._convertYccToRgb(data);
  11559. } else if (this.numComponents === 4) {
  11560. if (this._isColorConversionNeeded()) {
  11561. if (forceRGBoutput) {
  11562. return this._convertYcckToRgb(data);
  11563. } else {
  11564. return this._convertYcckToCmyk(data);
  11565. }
  11566. } else if (forceRGBoutput) {
  11567. return this._convertCmykToRgb(data);
  11568. }
  11569. }
  11570. return data;
  11571. }
  11572. };
  11573. return constructor;
  11574. })();
  11575. exports.JpegImage = JpegImage;
  11576. }));
  11577. (function (root, factory) {
  11578. {
  11579. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  11580. root.pdfjsCoreArithmeticDecoder);
  11581. }
  11582. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  11583. var info = sharedUtil.info;
  11584. var warn = sharedUtil.warn;
  11585. var error = sharedUtil.error;
  11586. var log2 = sharedUtil.log2;
  11587. var readUint16 = sharedUtil.readUint16;
  11588. var readUint32 = sharedUtil.readUint32;
  11589. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  11590. var JpxImage = (function JpxImageClosure() {
  11591. // Table E.1
  11592. var SubbandsGainLog2 = {
  11593. 'LL': 0,
  11594. 'LH': 1,
  11595. 'HL': 1,
  11596. 'HH': 2
  11597. };
  11598. function JpxImage() {
  11599. this.failOnCorruptedImage = false;
  11600. }
  11601. JpxImage.prototype = {
  11602. parse: function JpxImage_parse(data) {
  11603. var head = readUint16(data, 0);
  11604. // No box header, immediate start of codestream (SOC)
  11605. if (head === 0xFF4F) {
  11606. this.parseCodestream(data, 0, data.length);
  11607. return;
  11608. }
  11609. var position = 0, length = data.length;
  11610. while (position < length) {
  11611. var headerSize = 8;
  11612. var lbox = readUint32(data, position);
  11613. var tbox = readUint32(data, position + 4);
  11614. position += headerSize;
  11615. if (lbox === 1) {
  11616. // XLBox: read UInt64 according to spec.
  11617. // JavaScript's int precision of 53 bit should be sufficient here.
  11618. lbox = readUint32(data, position) * 4294967296 +
  11619. readUint32(data, position + 4);
  11620. position += 8;
  11621. headerSize += 8;
  11622. }
  11623. if (lbox === 0) {
  11624. lbox = length - position + headerSize;
  11625. }
  11626. if (lbox < headerSize) {
  11627. error('JPX Error: Invalid box field size');
  11628. }
  11629. var dataLength = lbox - headerSize;
  11630. var jumpDataLength = true;
  11631. switch (tbox) {
  11632. case 0x6A703268: // 'jp2h'
  11633. jumpDataLength = false; // parsing child boxes
  11634. break;
  11635. case 0x636F6C72: // 'colr'
  11636. // Colorspaces are not used, the CS from the PDF is used.
  11637. var method = data[position];
  11638. if (method === 1) {
  11639. // enumerated colorspace
  11640. var colorspace = readUint32(data, position + 3);
  11641. switch (colorspace) {
  11642. case 16: // this indicates a sRGB colorspace
  11643. case 17: // this indicates a grayscale colorspace
  11644. case 18: // this indicates a YUV colorspace
  11645. break;
  11646. default:
  11647. warn('Unknown colorspace ' + colorspace);
  11648. break;
  11649. }
  11650. } else if (method === 2) {
  11651. info('ICC profile not supported');
  11652. }
  11653. break;
  11654. case 0x6A703263: // 'jp2c'
  11655. this.parseCodestream(data, position, position + dataLength);
  11656. break;
  11657. case 0x6A502020: // 'jP\024\024'
  11658. if (0x0d0a870a !== readUint32(data, position)) {
  11659. warn('Invalid JP2 signature');
  11660. }
  11661. break;
  11662. // The following header types are valid but currently not used:
  11663. case 0x6A501A1A: // 'jP\032\032'
  11664. case 0x66747970: // 'ftyp'
  11665. case 0x72726571: // 'rreq'
  11666. case 0x72657320: // 'res '
  11667. case 0x69686472: // 'ihdr'
  11668. break;
  11669. default:
  11670. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  11671. (tbox >> 16) & 0xFF,
  11672. (tbox >> 8) & 0xFF,
  11673. tbox & 0xFF);
  11674. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  11675. break;
  11676. }
  11677. if (jumpDataLength) {
  11678. position += dataLength;
  11679. }
  11680. }
  11681. },
  11682. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  11683. var newByte = stream.getByte();
  11684. while (newByte >= 0) {
  11685. var oldByte = newByte;
  11686. newByte = stream.getByte();
  11687. var code = (oldByte << 8) | newByte;
  11688. // Image and tile size (SIZ)
  11689. if (code === 0xFF51) {
  11690. stream.skip(4);
  11691. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  11692. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  11693. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  11694. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  11695. stream.skip(16);
  11696. var Csiz = stream.getUint16(); // Byte 36
  11697. this.width = Xsiz - XOsiz;
  11698. this.height = Ysiz - YOsiz;
  11699. this.componentsCount = Csiz;
  11700. // Results are always returned as Uint8Arrays
  11701. this.bitsPerComponent = 8;
  11702. return;
  11703. }
  11704. }
  11705. error('JPX Error: No size marker found in JPX stream');
  11706. },
  11707. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  11708. var context = {};
  11709. var doNotRecover = false;
  11710. try {
  11711. var position = start;
  11712. while (position + 1 < end) {
  11713. var code = readUint16(data, position);
  11714. position += 2;
  11715. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  11716. switch (code) {
  11717. case 0xFF4F: // Start of codestream (SOC)
  11718. context.mainHeader = true;
  11719. break;
  11720. case 0xFFD9: // End of codestream (EOC)
  11721. break;
  11722. case 0xFF51: // Image and tile size (SIZ)
  11723. length = readUint16(data, position);
  11724. var siz = {};
  11725. siz.Xsiz = readUint32(data, position + 4);
  11726. siz.Ysiz = readUint32(data, position + 8);
  11727. siz.XOsiz = readUint32(data, position + 12);
  11728. siz.YOsiz = readUint32(data, position + 16);
  11729. siz.XTsiz = readUint32(data, position + 20);
  11730. siz.YTsiz = readUint32(data, position + 24);
  11731. siz.XTOsiz = readUint32(data, position + 28);
  11732. siz.YTOsiz = readUint32(data, position + 32);
  11733. var componentsCount = readUint16(data, position + 36);
  11734. siz.Csiz = componentsCount;
  11735. var components = [];
  11736. j = position + 38;
  11737. for (var i = 0; i < componentsCount; i++) {
  11738. var component = {
  11739. precision: (data[j] & 0x7F) + 1,
  11740. isSigned: !!(data[j] & 0x80),
  11741. XRsiz: data[j + 1],
  11742. YRsiz: data[j + 1]
  11743. };
  11744. calculateComponentDimensions(component, siz);
  11745. components.push(component);
  11746. }
  11747. context.SIZ = siz;
  11748. context.components = components;
  11749. calculateTileGrids(context, components);
  11750. context.QCC = [];
  11751. context.COC = [];
  11752. break;
  11753. case 0xFF5C: // Quantization default (QCD)
  11754. length = readUint16(data, position);
  11755. var qcd = {};
  11756. j = position + 2;
  11757. sqcd = data[j++];
  11758. switch (sqcd & 0x1F) {
  11759. case 0:
  11760. spqcdSize = 8;
  11761. scalarExpounded = true;
  11762. break;
  11763. case 1:
  11764. spqcdSize = 16;
  11765. scalarExpounded = false;
  11766. break;
  11767. case 2:
  11768. spqcdSize = 16;
  11769. scalarExpounded = true;
  11770. break;
  11771. default:
  11772. throw new Error('Invalid SQcd value ' + sqcd);
  11773. }
  11774. qcd.noQuantization = (spqcdSize === 8);
  11775. qcd.scalarExpounded = scalarExpounded;
  11776. qcd.guardBits = sqcd >> 5;
  11777. spqcds = [];
  11778. while (j < length + position) {
  11779. var spqcd = {};
  11780. if (spqcdSize === 8) {
  11781. spqcd.epsilon = data[j++] >> 3;
  11782. spqcd.mu = 0;
  11783. } else {
  11784. spqcd.epsilon = data[j] >> 3;
  11785. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  11786. j += 2;
  11787. }
  11788. spqcds.push(spqcd);
  11789. }
  11790. qcd.SPqcds = spqcds;
  11791. if (context.mainHeader) {
  11792. context.QCD = qcd;
  11793. } else {
  11794. context.currentTile.QCD = qcd;
  11795. context.currentTile.QCC = [];
  11796. }
  11797. break;
  11798. case 0xFF5D: // Quantization component (QCC)
  11799. length = readUint16(data, position);
  11800. var qcc = {};
  11801. j = position + 2;
  11802. var cqcc;
  11803. if (context.SIZ.Csiz < 257) {
  11804. cqcc = data[j++];
  11805. } else {
  11806. cqcc = readUint16(data, j);
  11807. j += 2;
  11808. }
  11809. sqcd = data[j++];
  11810. switch (sqcd & 0x1F) {
  11811. case 0:
  11812. spqcdSize = 8;
  11813. scalarExpounded = true;
  11814. break;
  11815. case 1:
  11816. spqcdSize = 16;
  11817. scalarExpounded = false;
  11818. break;
  11819. case 2:
  11820. spqcdSize = 16;
  11821. scalarExpounded = true;
  11822. break;
  11823. default:
  11824. throw new Error('Invalid SQcd value ' + sqcd);
  11825. }
  11826. qcc.noQuantization = (spqcdSize === 8);
  11827. qcc.scalarExpounded = scalarExpounded;
  11828. qcc.guardBits = sqcd >> 5;
  11829. spqcds = [];
  11830. while (j < (length + position)) {
  11831. spqcd = {};
  11832. if (spqcdSize === 8) {
  11833. spqcd.epsilon = data[j++] >> 3;
  11834. spqcd.mu = 0;
  11835. } else {
  11836. spqcd.epsilon = data[j] >> 3;
  11837. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  11838. j += 2;
  11839. }
  11840. spqcds.push(spqcd);
  11841. }
  11842. qcc.SPqcds = spqcds;
  11843. if (context.mainHeader) {
  11844. context.QCC[cqcc] = qcc;
  11845. } else {
  11846. context.currentTile.QCC[cqcc] = qcc;
  11847. }
  11848. break;
  11849. case 0xFF52: // Coding style default (COD)
  11850. length = readUint16(data, position);
  11851. var cod = {};
  11852. j = position + 2;
  11853. var scod = data[j++];
  11854. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  11855. cod.sopMarkerUsed = !!(scod & 2);
  11856. cod.ephMarkerUsed = !!(scod & 4);
  11857. cod.progressionOrder = data[j++];
  11858. cod.layersCount = readUint16(data, j);
  11859. j += 2;
  11860. cod.multipleComponentTransform = data[j++];
  11861. cod.decompositionLevelsCount = data[j++];
  11862. cod.xcb = (data[j++] & 0xF) + 2;
  11863. cod.ycb = (data[j++] & 0xF) + 2;
  11864. var blockStyle = data[j++];
  11865. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  11866. cod.resetContextProbabilities = !!(blockStyle & 2);
  11867. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  11868. cod.verticalyStripe = !!(blockStyle & 8);
  11869. cod.predictableTermination = !!(blockStyle & 16);
  11870. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  11871. cod.reversibleTransformation = data[j++];
  11872. if (cod.entropyCoderWithCustomPrecincts) {
  11873. var precinctsSizes = [];
  11874. while (j < length + position) {
  11875. var precinctsSize = data[j++];
  11876. precinctsSizes.push({
  11877. PPx: precinctsSize & 0xF,
  11878. PPy: precinctsSize >> 4
  11879. });
  11880. }
  11881. cod.precinctsSizes = precinctsSizes;
  11882. }
  11883. var unsupported = [];
  11884. if (cod.selectiveArithmeticCodingBypass) {
  11885. unsupported.push('selectiveArithmeticCodingBypass');
  11886. }
  11887. if (cod.resetContextProbabilities) {
  11888. unsupported.push('resetContextProbabilities');
  11889. }
  11890. if (cod.terminationOnEachCodingPass) {
  11891. unsupported.push('terminationOnEachCodingPass');
  11892. }
  11893. if (cod.verticalyStripe) {
  11894. unsupported.push('verticalyStripe');
  11895. }
  11896. if (cod.predictableTermination) {
  11897. unsupported.push('predictableTermination');
  11898. }
  11899. if (unsupported.length > 0) {
  11900. doNotRecover = true;
  11901. throw new Error('Unsupported COD options (' +
  11902. unsupported.join(', ') + ')');
  11903. }
  11904. if (context.mainHeader) {
  11905. context.COD = cod;
  11906. } else {
  11907. context.currentTile.COD = cod;
  11908. context.currentTile.COC = [];
  11909. }
  11910. break;
  11911. case 0xFF90: // Start of tile-part (SOT)
  11912. length = readUint16(data, position);
  11913. tile = {};
  11914. tile.index = readUint16(data, position + 2);
  11915. tile.length = readUint32(data, position + 4);
  11916. tile.dataEnd = tile.length + position - 2;
  11917. tile.partIndex = data[position + 8];
  11918. tile.partsCount = data[position + 9];
  11919. context.mainHeader = false;
  11920. if (tile.partIndex === 0) {
  11921. // reset component specific settings
  11922. tile.COD = context.COD;
  11923. tile.COC = context.COC.slice(0); // clone of the global COC
  11924. tile.QCD = context.QCD;
  11925. tile.QCC = context.QCC.slice(0); // clone of the global COC
  11926. }
  11927. context.currentTile = tile;
  11928. break;
  11929. case 0xFF93: // Start of data (SOD)
  11930. tile = context.currentTile;
  11931. if (tile.partIndex === 0) {
  11932. initializeTile(context, tile.index);
  11933. buildPackets(context);
  11934. }
  11935. // moving to the end of the data
  11936. length = tile.dataEnd - position;
  11937. parseTilePackets(context, data, position, length);
  11938. break;
  11939. case 0xFF55: // Tile-part lengths, main header (TLM)
  11940. case 0xFF57: // Packet length, main header (PLM)
  11941. case 0xFF58: // Packet length, tile-part header (PLT)
  11942. case 0xFF64: // Comment (COM)
  11943. length = readUint16(data, position);
  11944. // skipping content
  11945. break;
  11946. case 0xFF53: // Coding style component (COC)
  11947. throw new Error('Codestream code 0xFF53 (COC) is ' +
  11948. 'not implemented');
  11949. default:
  11950. throw new Error('Unknown codestream code: ' + code.toString(16));
  11951. }
  11952. position += length;
  11953. }
  11954. } catch (e) {
  11955. if (doNotRecover || this.failOnCorruptedImage) {
  11956. error('JPX Error: ' + e.message);
  11957. } else {
  11958. warn('JPX: Trying to recover from: ' + e.message);
  11959. }
  11960. }
  11961. this.tiles = transformComponents(context);
  11962. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  11963. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  11964. this.componentsCount = context.SIZ.Csiz;
  11965. }
  11966. };
  11967. function calculateComponentDimensions(component, siz) {
  11968. // Section B.2 Component mapping
  11969. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  11970. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  11971. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  11972. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  11973. component.width = component.x1 - component.x0;
  11974. component.height = component.y1 - component.y0;
  11975. }
  11976. function calculateTileGrids(context, components) {
  11977. var siz = context.SIZ;
  11978. // Section B.3 Division into tile and tile-components
  11979. var tile, tiles = [];
  11980. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  11981. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  11982. for (var q = 0; q < numYtiles; q++) {
  11983. for (var p = 0; p < numXtiles; p++) {
  11984. tile = {};
  11985. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  11986. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  11987. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  11988. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  11989. tile.width = tile.tx1 - tile.tx0;
  11990. tile.height = tile.ty1 - tile.ty0;
  11991. tile.components = [];
  11992. tiles.push(tile);
  11993. }
  11994. }
  11995. context.tiles = tiles;
  11996. var componentsCount = siz.Csiz;
  11997. for (var i = 0, ii = componentsCount; i < ii; i++) {
  11998. var component = components[i];
  11999. for (var j = 0, jj = tiles.length; j < jj; j++) {
  12000. var tileComponent = {};
  12001. tile = tiles[j];
  12002. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  12003. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  12004. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  12005. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  12006. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  12007. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  12008. tile.components[i] = tileComponent;
  12009. }
  12010. }
  12011. }
  12012. function getBlocksDimensions(context, component, r) {
  12013. var codOrCoc = component.codingStyleParameters;
  12014. var result = {};
  12015. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  12016. result.PPx = 15;
  12017. result.PPy = 15;
  12018. } else {
  12019. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  12020. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  12021. }
  12022. // calculate codeblock size as described in section B.7
  12023. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  12024. Math.min(codOrCoc.xcb, result.PPx));
  12025. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  12026. Math.min(codOrCoc.ycb, result.PPy));
  12027. return result;
  12028. }
  12029. function buildPrecincts(context, resolution, dimensions) {
  12030. // Section B.6 Division resolution to precincts
  12031. var precinctWidth = 1 << dimensions.PPx;
  12032. var precinctHeight = 1 << dimensions.PPy;
  12033. // Jasper introduces codeblock groups for mapping each subband codeblocks
  12034. // to precincts. Precinct partition divides a resolution according to width
  12035. // and height parameters. The subband that belongs to the resolution level
  12036. // has a different size than the level, unless it is the zero resolution.
  12037. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  12038. // The precinct partitioning for a particular subband is derived from a
  12039. // partitioning of its parent LL band (i.e., the LL band at the next higher
  12040. // resolution level)... The LL band associated with each resolution level is
  12041. // divided into precincts... Each of the resulting precinct regions is then
  12042. // mapped into its child subbands (if any) at the next lower resolution
  12043. // level. This is accomplished by using the coordinate transformation
  12044. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  12045. // coordinates of a point in the LL band and child subband, respectively.
  12046. var isZeroRes = resolution.resLevel === 0;
  12047. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  12048. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  12049. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  12050. Math.ceil(resolution.trx1 / precinctWidth) -
  12051. Math.floor(resolution.trx0 / precinctWidth) : 0);
  12052. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  12053. Math.ceil(resolution.try1 / precinctHeight) -
  12054. Math.floor(resolution.try0 / precinctHeight) : 0);
  12055. var numprecincts = numprecinctswide * numprecinctshigh;
  12056. resolution.precinctParameters = {
  12057. precinctWidth: precinctWidth,
  12058. precinctHeight: precinctHeight,
  12059. numprecinctswide: numprecinctswide,
  12060. numprecinctshigh: numprecinctshigh,
  12061. numprecincts: numprecincts,
  12062. precinctWidthInSubband: precinctWidthInSubband,
  12063. precinctHeightInSubband: precinctHeightInSubband
  12064. };
  12065. }
  12066. function buildCodeblocks(context, subband, dimensions) {
  12067. // Section B.7 Division sub-band into code-blocks
  12068. var xcb_ = dimensions.xcb_;
  12069. var ycb_ = dimensions.ycb_;
  12070. var codeblockWidth = 1 << xcb_;
  12071. var codeblockHeight = 1 << ycb_;
  12072. var cbx0 = subband.tbx0 >> xcb_;
  12073. var cby0 = subband.tby0 >> ycb_;
  12074. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  12075. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  12076. var precinctParameters = subband.resolution.precinctParameters;
  12077. var codeblocks = [];
  12078. var precincts = [];
  12079. var i, j, codeblock, precinctNumber;
  12080. for (j = cby0; j < cby1; j++) {
  12081. for (i = cbx0; i < cbx1; i++) {
  12082. codeblock = {
  12083. cbx: i,
  12084. cby: j,
  12085. tbx0: codeblockWidth * i,
  12086. tby0: codeblockHeight * j,
  12087. tbx1: codeblockWidth * (i + 1),
  12088. tby1: codeblockHeight * (j + 1)
  12089. };
  12090. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  12091. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  12092. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  12093. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  12094. // Calculate precinct number for this codeblock, codeblock position
  12095. // should be relative to its subband, use actual dimension and position
  12096. // See comment about codeblock group width and height
  12097. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  12098. precinctParameters.precinctWidthInSubband);
  12099. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  12100. precinctParameters.precinctHeightInSubband);
  12101. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  12102. codeblock.precinctNumber = precinctNumber;
  12103. codeblock.subbandType = subband.type;
  12104. codeblock.Lblock = 3;
  12105. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  12106. codeblock.tby1_ <= codeblock.tby0_) {
  12107. continue;
  12108. }
  12109. codeblocks.push(codeblock);
  12110. // building precinct for the sub-band
  12111. var precinct = precincts[precinctNumber];
  12112. if (precinct !== undefined) {
  12113. if (i < precinct.cbxMin) {
  12114. precinct.cbxMin = i;
  12115. } else if (i > precinct.cbxMax) {
  12116. precinct.cbxMax = i;
  12117. }
  12118. if (j < precinct.cbyMin) {
  12119. precinct.cbxMin = j;
  12120. } else if (j > precinct.cbyMax) {
  12121. precinct.cbyMax = j;
  12122. }
  12123. } else {
  12124. precincts[precinctNumber] = precinct = {
  12125. cbxMin: i,
  12126. cbyMin: j,
  12127. cbxMax: i,
  12128. cbyMax: j
  12129. };
  12130. }
  12131. codeblock.precinct = precinct;
  12132. }
  12133. }
  12134. subband.codeblockParameters = {
  12135. codeblockWidth: xcb_,
  12136. codeblockHeight: ycb_,
  12137. numcodeblockwide: cbx1 - cbx0 + 1,
  12138. numcodeblockhigh: cby1 - cby0 + 1
  12139. };
  12140. subband.codeblocks = codeblocks;
  12141. subband.precincts = precincts;
  12142. }
  12143. function createPacket(resolution, precinctNumber, layerNumber) {
  12144. var precinctCodeblocks = [];
  12145. // Section B.10.8 Order of info in packet
  12146. var subbands = resolution.subbands;
  12147. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  12148. for (var i = 0, ii = subbands.length; i < ii; i++) {
  12149. var subband = subbands[i];
  12150. var codeblocks = subband.codeblocks;
  12151. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  12152. var codeblock = codeblocks[j];
  12153. if (codeblock.precinctNumber !== precinctNumber) {
  12154. continue;
  12155. }
  12156. precinctCodeblocks.push(codeblock);
  12157. }
  12158. }
  12159. return {
  12160. layerNumber: layerNumber,
  12161. codeblocks: precinctCodeblocks
  12162. };
  12163. }
  12164. function LayerResolutionComponentPositionIterator(context) {
  12165. var siz = context.SIZ;
  12166. var tileIndex = context.currentTile.index;
  12167. var tile = context.tiles[tileIndex];
  12168. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12169. var componentsCount = siz.Csiz;
  12170. var maxDecompositionLevelsCount = 0;
  12171. for (var q = 0; q < componentsCount; q++) {
  12172. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12173. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12174. }
  12175. var l = 0, r = 0, i = 0, k = 0;
  12176. this.nextPacket = function JpxImage_nextPacket() {
  12177. // Section B.12.1.1 Layer-resolution-component-position
  12178. for (; l < layersCount; l++) {
  12179. for (; r <= maxDecompositionLevelsCount; r++) {
  12180. for (; i < componentsCount; i++) {
  12181. var component = tile.components[i];
  12182. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12183. continue;
  12184. }
  12185. var resolution = component.resolutions[r];
  12186. var numprecincts = resolution.precinctParameters.numprecincts;
  12187. for (; k < numprecincts;) {
  12188. var packet = createPacket(resolution, k, l);
  12189. k++;
  12190. return packet;
  12191. }
  12192. k = 0;
  12193. }
  12194. i = 0;
  12195. }
  12196. r = 0;
  12197. }
  12198. error('JPX Error: Out of packets');
  12199. };
  12200. }
  12201. function ResolutionLayerComponentPositionIterator(context) {
  12202. var siz = context.SIZ;
  12203. var tileIndex = context.currentTile.index;
  12204. var tile = context.tiles[tileIndex];
  12205. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12206. var componentsCount = siz.Csiz;
  12207. var maxDecompositionLevelsCount = 0;
  12208. for (var q = 0; q < componentsCount; q++) {
  12209. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12210. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12211. }
  12212. var r = 0, l = 0, i = 0, k = 0;
  12213. this.nextPacket = function JpxImage_nextPacket() {
  12214. // Section B.12.1.2 Resolution-layer-component-position
  12215. for (; r <= maxDecompositionLevelsCount; r++) {
  12216. for (; l < layersCount; l++) {
  12217. for (; i < componentsCount; i++) {
  12218. var component = tile.components[i];
  12219. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12220. continue;
  12221. }
  12222. var resolution = component.resolutions[r];
  12223. var numprecincts = resolution.precinctParameters.numprecincts;
  12224. for (; k < numprecincts;) {
  12225. var packet = createPacket(resolution, k, l);
  12226. k++;
  12227. return packet;
  12228. }
  12229. k = 0;
  12230. }
  12231. i = 0;
  12232. }
  12233. l = 0;
  12234. }
  12235. error('JPX Error: Out of packets');
  12236. };
  12237. }
  12238. function ResolutionPositionComponentLayerIterator(context) {
  12239. var siz = context.SIZ;
  12240. var tileIndex = context.currentTile.index;
  12241. var tile = context.tiles[tileIndex];
  12242. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12243. var componentsCount = siz.Csiz;
  12244. var l, r, c, p;
  12245. var maxDecompositionLevelsCount = 0;
  12246. for (c = 0; c < componentsCount; c++) {
  12247. var component = tile.components[c];
  12248. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12249. component.codingStyleParameters.decompositionLevelsCount);
  12250. }
  12251. var maxNumPrecinctsInLevel = new Int32Array(
  12252. maxDecompositionLevelsCount + 1);
  12253. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  12254. var maxNumPrecincts = 0;
  12255. for (c = 0; c < componentsCount; ++c) {
  12256. var resolutions = tile.components[c].resolutions;
  12257. if (r < resolutions.length) {
  12258. maxNumPrecincts = Math.max(maxNumPrecincts,
  12259. resolutions[r].precinctParameters.numprecincts);
  12260. }
  12261. }
  12262. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  12263. }
  12264. l = 0;
  12265. r = 0;
  12266. c = 0;
  12267. p = 0;
  12268. this.nextPacket = function JpxImage_nextPacket() {
  12269. // Section B.12.1.3 Resolution-position-component-layer
  12270. for (; r <= maxDecompositionLevelsCount; r++) {
  12271. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  12272. for (; c < componentsCount; c++) {
  12273. var component = tile.components[c];
  12274. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12275. continue;
  12276. }
  12277. var resolution = component.resolutions[r];
  12278. var numprecincts = resolution.precinctParameters.numprecincts;
  12279. if (p >= numprecincts) {
  12280. continue;
  12281. }
  12282. for (; l < layersCount;) {
  12283. var packet = createPacket(resolution, p, l);
  12284. l++;
  12285. return packet;
  12286. }
  12287. l = 0;
  12288. }
  12289. c = 0;
  12290. }
  12291. p = 0;
  12292. }
  12293. error('JPX Error: Out of packets');
  12294. };
  12295. }
  12296. function PositionComponentResolutionLayerIterator(context) {
  12297. var siz = context.SIZ;
  12298. var tileIndex = context.currentTile.index;
  12299. var tile = context.tiles[tileIndex];
  12300. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12301. var componentsCount = siz.Csiz;
  12302. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12303. var precinctsIterationSizes = precinctsSizes;
  12304. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12305. this.nextPacket = function JpxImage_nextPacket() {
  12306. // Section B.12.1.4 Position-component-resolution-layer
  12307. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12308. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12309. for (; c < componentsCount; c++) {
  12310. var component = tile.components[c];
  12311. var decompositionLevelsCount =
  12312. component.codingStyleParameters.decompositionLevelsCount;
  12313. for (; r <= decompositionLevelsCount; r++) {
  12314. var resolution = component.resolutions[r];
  12315. var sizeInImageScale =
  12316. precinctsSizes.components[c].resolutions[r];
  12317. var k = getPrecinctIndexIfExist(
  12318. px,
  12319. py,
  12320. sizeInImageScale,
  12321. precinctsIterationSizes,
  12322. resolution);
  12323. if (k === null) {
  12324. continue;
  12325. }
  12326. for (; l < layersCount;) {
  12327. var packet = createPacket(resolution, k, l);
  12328. l++;
  12329. return packet;
  12330. }
  12331. l = 0;
  12332. }
  12333. r = 0;
  12334. }
  12335. c = 0;
  12336. }
  12337. px = 0;
  12338. }
  12339. error('JPX Error: Out of packets');
  12340. };
  12341. }
  12342. function ComponentPositionResolutionLayerIterator(context) {
  12343. var siz = context.SIZ;
  12344. var tileIndex = context.currentTile.index;
  12345. var tile = context.tiles[tileIndex];
  12346. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12347. var componentsCount = siz.Csiz;
  12348. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12349. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12350. this.nextPacket = function JpxImage_nextPacket() {
  12351. // Section B.12.1.5 Component-position-resolution-layer
  12352. for (; c < componentsCount; ++c) {
  12353. var component = tile.components[c];
  12354. var precinctsIterationSizes = precinctsSizes.components[c];
  12355. var decompositionLevelsCount =
  12356. component.codingStyleParameters.decompositionLevelsCount;
  12357. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12358. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12359. for (; r <= decompositionLevelsCount; r++) {
  12360. var resolution = component.resolutions[r];
  12361. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  12362. var k = getPrecinctIndexIfExist(
  12363. px,
  12364. py,
  12365. sizeInImageScale,
  12366. precinctsIterationSizes,
  12367. resolution);
  12368. if (k === null) {
  12369. continue;
  12370. }
  12371. for (; l < layersCount;) {
  12372. var packet = createPacket(resolution, k, l);
  12373. l++;
  12374. return packet;
  12375. }
  12376. l = 0;
  12377. }
  12378. r = 0;
  12379. }
  12380. px = 0;
  12381. }
  12382. py = 0;
  12383. }
  12384. error('JPX Error: Out of packets');
  12385. };
  12386. }
  12387. function getPrecinctIndexIfExist(
  12388. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  12389. var posX = pxIndex * precinctIterationSizes.minWidth;
  12390. var posY = pyIndex * precinctIterationSizes.minHeight;
  12391. if (posX % sizeInImageScale.width !== 0 ||
  12392. posY % sizeInImageScale.height !== 0) {
  12393. return null;
  12394. }
  12395. var startPrecinctRowIndex =
  12396. (posY / sizeInImageScale.width) *
  12397. resolution.precinctParameters.numprecinctswide;
  12398. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  12399. }
  12400. function getPrecinctSizesInImageScale(tile) {
  12401. var componentsCount = tile.components.length;
  12402. var minWidth = Number.MAX_VALUE;
  12403. var minHeight = Number.MAX_VALUE;
  12404. var maxNumWide = 0;
  12405. var maxNumHigh = 0;
  12406. var sizePerComponent = new Array(componentsCount);
  12407. for (var c = 0; c < componentsCount; c++) {
  12408. var component = tile.components[c];
  12409. var decompositionLevelsCount =
  12410. component.codingStyleParameters.decompositionLevelsCount;
  12411. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  12412. var minWidthCurrentComponent = Number.MAX_VALUE;
  12413. var minHeightCurrentComponent = Number.MAX_VALUE;
  12414. var maxNumWideCurrentComponent = 0;
  12415. var maxNumHighCurrentComponent = 0;
  12416. var scale = 1;
  12417. for (var r = decompositionLevelsCount; r >= 0; --r) {
  12418. var resolution = component.resolutions[r];
  12419. var widthCurrentResolution =
  12420. scale * resolution.precinctParameters.precinctWidth;
  12421. var heightCurrentResolution =
  12422. scale * resolution.precinctParameters.precinctHeight;
  12423. minWidthCurrentComponent = Math.min(
  12424. minWidthCurrentComponent,
  12425. widthCurrentResolution);
  12426. minHeightCurrentComponent = Math.min(
  12427. minHeightCurrentComponent,
  12428. heightCurrentResolution);
  12429. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  12430. resolution.precinctParameters.numprecinctswide);
  12431. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  12432. resolution.precinctParameters.numprecinctshigh);
  12433. sizePerResolution[r] = {
  12434. width: widthCurrentResolution,
  12435. height: heightCurrentResolution
  12436. };
  12437. scale <<= 1;
  12438. }
  12439. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  12440. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  12441. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  12442. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  12443. sizePerComponent[c] = {
  12444. resolutions: sizePerResolution,
  12445. minWidth: minWidthCurrentComponent,
  12446. minHeight: minHeightCurrentComponent,
  12447. maxNumWide: maxNumWideCurrentComponent,
  12448. maxNumHigh: maxNumHighCurrentComponent
  12449. };
  12450. }
  12451. return {
  12452. components: sizePerComponent,
  12453. minWidth: minWidth,
  12454. minHeight: minHeight,
  12455. maxNumWide: maxNumWide,
  12456. maxNumHigh: maxNumHigh
  12457. };
  12458. }
  12459. function buildPackets(context) {
  12460. var siz = context.SIZ;
  12461. var tileIndex = context.currentTile.index;
  12462. var tile = context.tiles[tileIndex];
  12463. var componentsCount = siz.Csiz;
  12464. // Creating resolutions and sub-bands for each component
  12465. for (var c = 0; c < componentsCount; c++) {
  12466. var component = tile.components[c];
  12467. var decompositionLevelsCount =
  12468. component.codingStyleParameters.decompositionLevelsCount;
  12469. // Section B.5 Resolution levels and sub-bands
  12470. var resolutions = [];
  12471. var subbands = [];
  12472. for (var r = 0; r <= decompositionLevelsCount; r++) {
  12473. var blocksDimensions = getBlocksDimensions(context, component, r);
  12474. var resolution = {};
  12475. var scale = 1 << (decompositionLevelsCount - r);
  12476. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  12477. resolution.try0 = Math.ceil(component.tcy0 / scale);
  12478. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  12479. resolution.try1 = Math.ceil(component.tcy1 / scale);
  12480. resolution.resLevel = r;
  12481. buildPrecincts(context, resolution, blocksDimensions);
  12482. resolutions.push(resolution);
  12483. var subband;
  12484. if (r === 0) {
  12485. // one sub-band (LL) with last decomposition
  12486. subband = {};
  12487. subband.type = 'LL';
  12488. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  12489. subband.tby0 = Math.ceil(component.tcy0 / scale);
  12490. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  12491. subband.tby1 = Math.ceil(component.tcy1 / scale);
  12492. subband.resolution = resolution;
  12493. buildCodeblocks(context, subband, blocksDimensions);
  12494. subbands.push(subband);
  12495. resolution.subbands = [subband];
  12496. } else {
  12497. var bscale = 1 << (decompositionLevelsCount - r + 1);
  12498. var resolutionSubbands = [];
  12499. // three sub-bands (HL, LH and HH) with rest of decompositions
  12500. subband = {};
  12501. subband.type = 'HL';
  12502. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  12503. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  12504. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  12505. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  12506. subband.resolution = resolution;
  12507. buildCodeblocks(context, subband, blocksDimensions);
  12508. subbands.push(subband);
  12509. resolutionSubbands.push(subband);
  12510. subband = {};
  12511. subband.type = 'LH';
  12512. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  12513. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  12514. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  12515. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  12516. subband.resolution = resolution;
  12517. buildCodeblocks(context, subband, blocksDimensions);
  12518. subbands.push(subband);
  12519. resolutionSubbands.push(subband);
  12520. subband = {};
  12521. subband.type = 'HH';
  12522. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  12523. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  12524. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  12525. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  12526. subband.resolution = resolution;
  12527. buildCodeblocks(context, subband, blocksDimensions);
  12528. subbands.push(subband);
  12529. resolutionSubbands.push(subband);
  12530. resolution.subbands = resolutionSubbands;
  12531. }
  12532. }
  12533. component.resolutions = resolutions;
  12534. component.subbands = subbands;
  12535. }
  12536. // Generate the packets sequence
  12537. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  12538. switch (progressionOrder) {
  12539. case 0:
  12540. tile.packetsIterator =
  12541. new LayerResolutionComponentPositionIterator(context);
  12542. break;
  12543. case 1:
  12544. tile.packetsIterator =
  12545. new ResolutionLayerComponentPositionIterator(context);
  12546. break;
  12547. case 2:
  12548. tile.packetsIterator =
  12549. new ResolutionPositionComponentLayerIterator(context);
  12550. break;
  12551. case 3:
  12552. tile.packetsIterator =
  12553. new PositionComponentResolutionLayerIterator(context);
  12554. break;
  12555. case 4:
  12556. tile.packetsIterator =
  12557. new ComponentPositionResolutionLayerIterator(context);
  12558. break;
  12559. default:
  12560. error('JPX Error: Unsupported progression order ' + progressionOrder);
  12561. }
  12562. }
  12563. function parseTilePackets(context, data, offset, dataLength) {
  12564. var position = 0;
  12565. var buffer, bufferSize = 0, skipNextBit = false;
  12566. function readBits(count) {
  12567. while (bufferSize < count) {
  12568. var b = data[offset + position];
  12569. position++;
  12570. if (skipNextBit) {
  12571. buffer = (buffer << 7) | b;
  12572. bufferSize += 7;
  12573. skipNextBit = false;
  12574. } else {
  12575. buffer = (buffer << 8) | b;
  12576. bufferSize += 8;
  12577. }
  12578. if (b === 0xFF) {
  12579. skipNextBit = true;
  12580. }
  12581. }
  12582. bufferSize -= count;
  12583. return (buffer >>> bufferSize) & ((1 << count) - 1);
  12584. }
  12585. function skipMarkerIfEqual(value) {
  12586. if (data[offset + position - 1] === 0xFF &&
  12587. data[offset + position] === value) {
  12588. skipBytes(1);
  12589. return true;
  12590. } else if (data[offset + position] === 0xFF &&
  12591. data[offset + position + 1] === value) {
  12592. skipBytes(2);
  12593. return true;
  12594. }
  12595. return false;
  12596. }
  12597. function skipBytes(count) {
  12598. position += count;
  12599. }
  12600. function alignToByte() {
  12601. bufferSize = 0;
  12602. if (skipNextBit) {
  12603. position++;
  12604. skipNextBit = false;
  12605. }
  12606. }
  12607. function readCodingpasses() {
  12608. if (readBits(1) === 0) {
  12609. return 1;
  12610. }
  12611. if (readBits(1) === 0) {
  12612. return 2;
  12613. }
  12614. var value = readBits(2);
  12615. if (value < 3) {
  12616. return value + 3;
  12617. }
  12618. value = readBits(5);
  12619. if (value < 31) {
  12620. return value + 6;
  12621. }
  12622. value = readBits(7);
  12623. return value + 37;
  12624. }
  12625. var tileIndex = context.currentTile.index;
  12626. var tile = context.tiles[tileIndex];
  12627. var sopMarkerUsed = context.COD.sopMarkerUsed;
  12628. var ephMarkerUsed = context.COD.ephMarkerUsed;
  12629. var packetsIterator = tile.packetsIterator;
  12630. while (position < dataLength) {
  12631. alignToByte();
  12632. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  12633. // Skip also marker segment length and packet sequence ID
  12634. skipBytes(4);
  12635. }
  12636. var packet = packetsIterator.nextPacket();
  12637. if (!readBits(1)) {
  12638. continue;
  12639. }
  12640. var layerNumber = packet.layerNumber;
  12641. var queue = [], codeblock;
  12642. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  12643. codeblock = packet.codeblocks[i];
  12644. var precinct = codeblock.precinct;
  12645. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  12646. var codeblockRow = codeblock.cby - precinct.cbyMin;
  12647. var codeblockIncluded = false;
  12648. var firstTimeInclusion = false;
  12649. var valueReady;
  12650. if (codeblock['included'] !== undefined) {
  12651. codeblockIncluded = !!readBits(1);
  12652. } else {
  12653. // reading inclusion tree
  12654. precinct = codeblock.precinct;
  12655. var inclusionTree, zeroBitPlanesTree;
  12656. if (precinct['inclusionTree'] !== undefined) {
  12657. inclusionTree = precinct.inclusionTree;
  12658. } else {
  12659. // building inclusion and zero bit-planes trees
  12660. var width = precinct.cbxMax - precinct.cbxMin + 1;
  12661. var height = precinct.cbyMax - precinct.cbyMin + 1;
  12662. inclusionTree = new InclusionTree(width, height, layerNumber);
  12663. zeroBitPlanesTree = new TagTree(width, height);
  12664. precinct.inclusionTree = inclusionTree;
  12665. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  12666. }
  12667. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  12668. while (true) {
  12669. if (readBits(1)) {
  12670. valueReady = !inclusionTree.nextLevel();
  12671. if (valueReady) {
  12672. codeblock.included = true;
  12673. codeblockIncluded = firstTimeInclusion = true;
  12674. break;
  12675. }
  12676. } else {
  12677. inclusionTree.incrementValue(layerNumber);
  12678. break;
  12679. }
  12680. }
  12681. }
  12682. }
  12683. if (!codeblockIncluded) {
  12684. continue;
  12685. }
  12686. if (firstTimeInclusion) {
  12687. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  12688. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  12689. while (true) {
  12690. if (readBits(1)) {
  12691. valueReady = !zeroBitPlanesTree.nextLevel();
  12692. if (valueReady) {
  12693. break;
  12694. }
  12695. } else {
  12696. zeroBitPlanesTree.incrementValue();
  12697. }
  12698. }
  12699. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  12700. }
  12701. var codingpasses = readCodingpasses();
  12702. while (readBits(1)) {
  12703. codeblock.Lblock++;
  12704. }
  12705. var codingpassesLog2 = log2(codingpasses);
  12706. // rounding down log2
  12707. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  12708. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  12709. var codedDataLength = readBits(bits);
  12710. queue.push({
  12711. codeblock: codeblock,
  12712. codingpasses: codingpasses,
  12713. dataLength: codedDataLength
  12714. });
  12715. }
  12716. alignToByte();
  12717. if (ephMarkerUsed) {
  12718. skipMarkerIfEqual(0x92);
  12719. }
  12720. while (queue.length > 0) {
  12721. var packetItem = queue.shift();
  12722. codeblock = packetItem.codeblock;
  12723. if (codeblock['data'] === undefined) {
  12724. codeblock.data = [];
  12725. }
  12726. codeblock.data.push({
  12727. data: data,
  12728. start: offset + position,
  12729. end: offset + position + packetItem.dataLength,
  12730. codingpasses: packetItem.codingpasses
  12731. });
  12732. position += packetItem.dataLength;
  12733. }
  12734. }
  12735. return position;
  12736. }
  12737. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  12738. delta, mb, reversible, segmentationSymbolUsed) {
  12739. var x0 = subband.tbx0;
  12740. var y0 = subband.tby0;
  12741. var width = subband.tbx1 - subband.tbx0;
  12742. var codeblocks = subband.codeblocks;
  12743. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  12744. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  12745. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  12746. var codeblock = codeblocks[i];
  12747. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  12748. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  12749. if (blockWidth === 0 || blockHeight === 0) {
  12750. continue;
  12751. }
  12752. if (codeblock['data'] === undefined) {
  12753. continue;
  12754. }
  12755. var bitModel, currentCodingpassType;
  12756. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  12757. codeblock.zeroBitPlanes, mb);
  12758. currentCodingpassType = 2; // first bit plane starts from cleanup
  12759. // collect data
  12760. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  12761. var j, jj, dataItem;
  12762. for (j = 0, jj = data.length; j < jj; j++) {
  12763. dataItem = data[j];
  12764. totalLength += dataItem.end - dataItem.start;
  12765. codingpasses += dataItem.codingpasses;
  12766. }
  12767. var encodedData = new Uint8Array(totalLength);
  12768. var position = 0;
  12769. for (j = 0, jj = data.length; j < jj; j++) {
  12770. dataItem = data[j];
  12771. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  12772. encodedData.set(chunk, position);
  12773. position += chunk.length;
  12774. }
  12775. // decoding the item
  12776. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  12777. bitModel.setDecoder(decoder);
  12778. for (j = 0; j < codingpasses; j++) {
  12779. switch (currentCodingpassType) {
  12780. case 0:
  12781. bitModel.runSignificancePropagationPass();
  12782. break;
  12783. case 1:
  12784. bitModel.runMagnitudeRefinementPass();
  12785. break;
  12786. case 2:
  12787. bitModel.runCleanupPass();
  12788. if (segmentationSymbolUsed) {
  12789. bitModel.checkSegmentationSymbol();
  12790. }
  12791. break;
  12792. }
  12793. currentCodingpassType = (currentCodingpassType + 1) % 3;
  12794. }
  12795. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  12796. var sign = bitModel.coefficentsSign;
  12797. var magnitude = bitModel.coefficentsMagnitude;
  12798. var bitsDecoded = bitModel.bitsDecoded;
  12799. var magnitudeCorrection = reversible ? 0 : 0.5;
  12800. var k, n, nb;
  12801. position = 0;
  12802. // Do the interleaving of Section F.3.3 here, so we do not need
  12803. // to copy later. LL level is not interleaved, just copied.
  12804. var interleave = (subband.type !== 'LL');
  12805. for (j = 0; j < blockHeight; j++) {
  12806. var row = (offset / width) | 0; // row in the non-interleaved subband
  12807. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  12808. for (k = 0; k < blockWidth; k++) {
  12809. n = magnitude[position];
  12810. if (n !== 0) {
  12811. n = (n + magnitudeCorrection) * delta;
  12812. if (sign[position] !== 0) {
  12813. n = -n;
  12814. }
  12815. nb = bitsDecoded[position];
  12816. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  12817. if (reversible && (nb >= mb)) {
  12818. coefficients[pos] = n;
  12819. } else {
  12820. coefficients[pos] = n * (1 << (mb - nb));
  12821. }
  12822. }
  12823. offset++;
  12824. position++;
  12825. }
  12826. offset += width - blockWidth;
  12827. }
  12828. }
  12829. }
  12830. function transformTile(context, tile, c) {
  12831. var component = tile.components[c];
  12832. var codingStyleParameters = component.codingStyleParameters;
  12833. var quantizationParameters = component.quantizationParameters;
  12834. var decompositionLevelsCount =
  12835. codingStyleParameters.decompositionLevelsCount;
  12836. var spqcds = quantizationParameters.SPqcds;
  12837. var scalarExpounded = quantizationParameters.scalarExpounded;
  12838. var guardBits = quantizationParameters.guardBits;
  12839. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  12840. var precision = context.components[c].precision;
  12841. var reversible = codingStyleParameters.reversibleTransformation;
  12842. var transform = (reversible ? new ReversibleTransform() :
  12843. new IrreversibleTransform());
  12844. var subbandCoefficients = [];
  12845. var b = 0;
  12846. for (var i = 0; i <= decompositionLevelsCount; i++) {
  12847. var resolution = component.resolutions[i];
  12848. var width = resolution.trx1 - resolution.trx0;
  12849. var height = resolution.try1 - resolution.try0;
  12850. // Allocate space for the whole sublevel.
  12851. var coefficients = new Float32Array(width * height);
  12852. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  12853. var mu, epsilon;
  12854. if (!scalarExpounded) {
  12855. // formula E-5
  12856. mu = spqcds[0].mu;
  12857. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  12858. } else {
  12859. mu = spqcds[b].mu;
  12860. epsilon = spqcds[b].epsilon;
  12861. b++;
  12862. }
  12863. var subband = resolution.subbands[j];
  12864. var gainLog2 = SubbandsGainLog2[subband.type];
  12865. // calculate quantization coefficient (Section E.1.1.1)
  12866. var delta = (reversible ? 1 :
  12867. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  12868. var mb = (guardBits + epsilon - 1);
  12869. // In the first resolution level, copyCoefficients will fill the
  12870. // whole array with coefficients. In the succeeding passes,
  12871. // copyCoefficients will consecutively fill in the values that belong
  12872. // to the interleaved positions of the HL, LH, and HH coefficients.
  12873. // The LL coefficients will then be interleaved in Transform.iterate().
  12874. copyCoefficients(coefficients, width, height, subband, delta, mb,
  12875. reversible, segmentationSymbolUsed);
  12876. }
  12877. subbandCoefficients.push({
  12878. width: width,
  12879. height: height,
  12880. items: coefficients
  12881. });
  12882. }
  12883. var result = transform.calculate(subbandCoefficients,
  12884. component.tcx0, component.tcy0);
  12885. return {
  12886. left: component.tcx0,
  12887. top: component.tcy0,
  12888. width: result.width,
  12889. height: result.height,
  12890. items: result.items
  12891. };
  12892. }
  12893. function transformComponents(context) {
  12894. var siz = context.SIZ;
  12895. var components = context.components;
  12896. var componentsCount = siz.Csiz;
  12897. var resultImages = [];
  12898. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  12899. var tile = context.tiles[i];
  12900. var transformedTiles = [];
  12901. var c;
  12902. for (c = 0; c < componentsCount; c++) {
  12903. transformedTiles[c] = transformTile(context, tile, c);
  12904. }
  12905. var tile0 = transformedTiles[0];
  12906. var out = new Uint8Array(tile0.items.length * componentsCount);
  12907. var result = {
  12908. left: tile0.left,
  12909. top: tile0.top,
  12910. width: tile0.width,
  12911. height: tile0.height,
  12912. items: out
  12913. };
  12914. // Section G.2.2 Inverse multi component transform
  12915. var shift, offset, max, min, maxK;
  12916. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  12917. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  12918. var fourComponents = componentsCount === 4;
  12919. var y0items = transformedTiles[0].items;
  12920. var y1items = transformedTiles[1].items;
  12921. var y2items = transformedTiles[2].items;
  12922. var y3items = fourComponents ? transformedTiles[3].items : null;
  12923. // HACK: The multiple component transform formulas below assume that
  12924. // all components have the same precision. With this in mind, we
  12925. // compute shift and offset only once.
  12926. shift = components[0].precision - 8;
  12927. offset = (128 << shift) + 0.5;
  12928. max = 255 * (1 << shift);
  12929. maxK = max * 0.5;
  12930. min = -maxK;
  12931. var component0 = tile.components[0];
  12932. var alpha01 = componentsCount - 3;
  12933. jj = y0items.length;
  12934. if (!component0.codingStyleParameters.reversibleTransformation) {
  12935. // inverse irreversible multiple component transform
  12936. for (j = 0; j < jj; j++, pos += alpha01) {
  12937. y0 = y0items[j] + offset;
  12938. y1 = y1items[j];
  12939. y2 = y2items[j];
  12940. r = y0 + 1.402 * y2;
  12941. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  12942. b = y0 + 1.772 * y1;
  12943. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  12944. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  12945. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  12946. }
  12947. } else {
  12948. // inverse reversible multiple component transform
  12949. for (j = 0; j < jj; j++, pos += alpha01) {
  12950. y0 = y0items[j] + offset;
  12951. y1 = y1items[j];
  12952. y2 = y2items[j];
  12953. g = y0 - ((y2 + y1) >> 2);
  12954. r = g + y2;
  12955. b = g + y1;
  12956. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  12957. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  12958. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  12959. }
  12960. }
  12961. if (fourComponents) {
  12962. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  12963. k = y3items[j];
  12964. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  12965. }
  12966. }
  12967. } else { // no multi-component transform
  12968. for (c = 0; c < componentsCount; c++) {
  12969. var items = transformedTiles[c].items;
  12970. shift = components[c].precision - 8;
  12971. offset = (128 << shift) + 0.5;
  12972. max = (127.5 * (1 << shift));
  12973. min = -max;
  12974. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  12975. val = items[j];
  12976. out[pos] = val <= min ? 0 :
  12977. val >= max ? 255 : (val + offset) >> shift;
  12978. pos += componentsCount;
  12979. }
  12980. }
  12981. }
  12982. resultImages.push(result);
  12983. }
  12984. return resultImages;
  12985. }
  12986. function initializeTile(context, tileIndex) {
  12987. var siz = context.SIZ;
  12988. var componentsCount = siz.Csiz;
  12989. var tile = context.tiles[tileIndex];
  12990. for (var c = 0; c < componentsCount; c++) {
  12991. var component = tile.components[c];
  12992. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  12993. context.currentTile.QCC[c] : context.currentTile.QCD);
  12994. component.quantizationParameters = qcdOrQcc;
  12995. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  12996. context.currentTile.COC[c] : context.currentTile.COD);
  12997. component.codingStyleParameters = codOrCoc;
  12998. }
  12999. tile.codingStyleDefaultParameters = context.currentTile.COD;
  13000. }
  13001. // Section B.10.2 Tag trees
  13002. var TagTree = (function TagTreeClosure() {
  13003. function TagTree(width, height) {
  13004. var levelsLength = log2(Math.max(width, height)) + 1;
  13005. this.levels = [];
  13006. for (var i = 0; i < levelsLength; i++) {
  13007. var level = {
  13008. width: width,
  13009. height: height,
  13010. items: []
  13011. };
  13012. this.levels.push(level);
  13013. width = Math.ceil(width / 2);
  13014. height = Math.ceil(height / 2);
  13015. }
  13016. }
  13017. TagTree.prototype = {
  13018. reset: function TagTree_reset(i, j) {
  13019. var currentLevel = 0, value = 0, level;
  13020. while (currentLevel < this.levels.length) {
  13021. level = this.levels[currentLevel];
  13022. var index = i + j * level.width;
  13023. if (level.items[index] !== undefined) {
  13024. value = level.items[index];
  13025. break;
  13026. }
  13027. level.index = index;
  13028. i >>= 1;
  13029. j >>= 1;
  13030. currentLevel++;
  13031. }
  13032. currentLevel--;
  13033. level = this.levels[currentLevel];
  13034. level.items[level.index] = value;
  13035. this.currentLevel = currentLevel;
  13036. delete this.value;
  13037. },
  13038. incrementValue: function TagTree_incrementValue() {
  13039. var level = this.levels[this.currentLevel];
  13040. level.items[level.index]++;
  13041. },
  13042. nextLevel: function TagTree_nextLevel() {
  13043. var currentLevel = this.currentLevel;
  13044. var level = this.levels[currentLevel];
  13045. var value = level.items[level.index];
  13046. currentLevel--;
  13047. if (currentLevel < 0) {
  13048. this.value = value;
  13049. return false;
  13050. }
  13051. this.currentLevel = currentLevel;
  13052. level = this.levels[currentLevel];
  13053. level.items[level.index] = value;
  13054. return true;
  13055. }
  13056. };
  13057. return TagTree;
  13058. })();
  13059. var InclusionTree = (function InclusionTreeClosure() {
  13060. function InclusionTree(width, height, defaultValue) {
  13061. var levelsLength = log2(Math.max(width, height)) + 1;
  13062. this.levels = [];
  13063. for (var i = 0; i < levelsLength; i++) {
  13064. var items = new Uint8Array(width * height);
  13065. for (var j = 0, jj = items.length; j < jj; j++) {
  13066. items[j] = defaultValue;
  13067. }
  13068. var level = {
  13069. width: width,
  13070. height: height,
  13071. items: items
  13072. };
  13073. this.levels.push(level);
  13074. width = Math.ceil(width / 2);
  13075. height = Math.ceil(height / 2);
  13076. }
  13077. }
  13078. InclusionTree.prototype = {
  13079. reset: function InclusionTree_reset(i, j, stopValue) {
  13080. var currentLevel = 0;
  13081. while (currentLevel < this.levels.length) {
  13082. var level = this.levels[currentLevel];
  13083. var index = i + j * level.width;
  13084. level.index = index;
  13085. var value = level.items[index];
  13086. if (value === 0xFF) {
  13087. break;
  13088. }
  13089. if (value > stopValue) {
  13090. this.currentLevel = currentLevel;
  13091. // already know about this one, propagating the value to top levels
  13092. this.propagateValues();
  13093. return false;
  13094. }
  13095. i >>= 1;
  13096. j >>= 1;
  13097. currentLevel++;
  13098. }
  13099. this.currentLevel = currentLevel - 1;
  13100. return true;
  13101. },
  13102. incrementValue: function InclusionTree_incrementValue(stopValue) {
  13103. var level = this.levels[this.currentLevel];
  13104. level.items[level.index] = stopValue + 1;
  13105. this.propagateValues();
  13106. },
  13107. propagateValues: function InclusionTree_propagateValues() {
  13108. var levelIndex = this.currentLevel;
  13109. var level = this.levels[levelIndex];
  13110. var currentValue = level.items[level.index];
  13111. while (--levelIndex >= 0) {
  13112. level = this.levels[levelIndex];
  13113. level.items[level.index] = currentValue;
  13114. }
  13115. },
  13116. nextLevel: function InclusionTree_nextLevel() {
  13117. var currentLevel = this.currentLevel;
  13118. var level = this.levels[currentLevel];
  13119. var value = level.items[level.index];
  13120. level.items[level.index] = 0xFF;
  13121. currentLevel--;
  13122. if (currentLevel < 0) {
  13123. return false;
  13124. }
  13125. this.currentLevel = currentLevel;
  13126. level = this.levels[currentLevel];
  13127. level.items[level.index] = value;
  13128. return true;
  13129. }
  13130. };
  13131. return InclusionTree;
  13132. })();
  13133. // Section D. Coefficient bit modeling
  13134. var BitModel = (function BitModelClosure() {
  13135. var UNIFORM_CONTEXT = 17;
  13136. var RUNLENGTH_CONTEXT = 18;
  13137. // Table D-1
  13138. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  13139. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  13140. var LLAndLHContextsLabel = new Uint8Array([
  13141. 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,
  13142. 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,
  13143. 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
  13144. ]);
  13145. var HLContextLabel = new Uint8Array([
  13146. 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,
  13147. 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,
  13148. 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
  13149. ]);
  13150. var HHContextLabel = new Uint8Array([
  13151. 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,
  13152. 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,
  13153. 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
  13154. ]);
  13155. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  13156. this.width = width;
  13157. this.height = height;
  13158. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  13159. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  13160. var coefficientCount = width * height;
  13161. // coefficients outside the encoding region treated as insignificant
  13162. // add border state cells for significanceState
  13163. this.neighborsSignificance = new Uint8Array(coefficientCount);
  13164. this.coefficentsSign = new Uint8Array(coefficientCount);
  13165. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  13166. mb > 6 ? new Uint16Array(coefficientCount) :
  13167. new Uint8Array(coefficientCount);
  13168. this.processingFlags = new Uint8Array(coefficientCount);
  13169. var bitsDecoded = new Uint8Array(coefficientCount);
  13170. if (zeroBitPlanes !== 0) {
  13171. for (var i = 0; i < coefficientCount; i++) {
  13172. bitsDecoded[i] = zeroBitPlanes;
  13173. }
  13174. }
  13175. this.bitsDecoded = bitsDecoded;
  13176. this.reset();
  13177. }
  13178. BitModel.prototype = {
  13179. setDecoder: function BitModel_setDecoder(decoder) {
  13180. this.decoder = decoder;
  13181. },
  13182. reset: function BitModel_reset() {
  13183. // We have 17 contexts that are accessed via context labels,
  13184. // plus the uniform and runlength context.
  13185. this.contexts = new Int8Array(19);
  13186. // Contexts are packed into 1 byte:
  13187. // highest 7 bits carry the index, lowest bit carries mps
  13188. this.contexts[0] = (4 << 1) | 0;
  13189. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  13190. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  13191. },
  13192. setNeighborsSignificance:
  13193. function BitModel_setNeighborsSignificance(row, column, index) {
  13194. var neighborsSignificance = this.neighborsSignificance;
  13195. var width = this.width, height = this.height;
  13196. var left = (column > 0);
  13197. var right = (column + 1 < width);
  13198. var i;
  13199. if (row > 0) {
  13200. i = index - width;
  13201. if (left) {
  13202. neighborsSignificance[i - 1] += 0x10;
  13203. }
  13204. if (right) {
  13205. neighborsSignificance[i + 1] += 0x10;
  13206. }
  13207. neighborsSignificance[i] += 0x04;
  13208. }
  13209. if (row + 1 < height) {
  13210. i = index + width;
  13211. if (left) {
  13212. neighborsSignificance[i - 1] += 0x10;
  13213. }
  13214. if (right) {
  13215. neighborsSignificance[i + 1] += 0x10;
  13216. }
  13217. neighborsSignificance[i] += 0x04;
  13218. }
  13219. if (left) {
  13220. neighborsSignificance[index - 1] += 0x01;
  13221. }
  13222. if (right) {
  13223. neighborsSignificance[index + 1] += 0x01;
  13224. }
  13225. neighborsSignificance[index] |= 0x80;
  13226. },
  13227. runSignificancePropagationPass:
  13228. function BitModel_runSignificancePropagationPass() {
  13229. var decoder = this.decoder;
  13230. var width = this.width, height = this.height;
  13231. var coefficentsMagnitude = this.coefficentsMagnitude;
  13232. var coefficentsSign = this.coefficentsSign;
  13233. var neighborsSignificance = this.neighborsSignificance;
  13234. var processingFlags = this.processingFlags;
  13235. var contexts = this.contexts;
  13236. var labels = this.contextLabelTable;
  13237. var bitsDecoded = this.bitsDecoded;
  13238. var processedInverseMask = ~1;
  13239. var processedMask = 1;
  13240. var firstMagnitudeBitMask = 2;
  13241. for (var i0 = 0; i0 < height; i0 += 4) {
  13242. for (var j = 0; j < width; j++) {
  13243. var index = i0 * width + j;
  13244. for (var i1 = 0; i1 < 4; i1++, index += width) {
  13245. var i = i0 + i1;
  13246. if (i >= height) {
  13247. break;
  13248. }
  13249. // clear processed flag first
  13250. processingFlags[index] &= processedInverseMask;
  13251. if (coefficentsMagnitude[index] ||
  13252. !neighborsSignificance[index]) {
  13253. continue;
  13254. }
  13255. var contextLabel = labels[neighborsSignificance[index]];
  13256. var decision = decoder.readBit(contexts, contextLabel);
  13257. if (decision) {
  13258. var sign = this.decodeSignBit(i, j, index);
  13259. coefficentsSign[index] = sign;
  13260. coefficentsMagnitude[index] = 1;
  13261. this.setNeighborsSignificance(i, j, index);
  13262. processingFlags[index] |= firstMagnitudeBitMask;
  13263. }
  13264. bitsDecoded[index]++;
  13265. processingFlags[index] |= processedMask;
  13266. }
  13267. }
  13268. }
  13269. },
  13270. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  13271. var width = this.width, height = this.height;
  13272. var coefficentsMagnitude = this.coefficentsMagnitude;
  13273. var coefficentsSign = this.coefficentsSign;
  13274. var contribution, sign0, sign1, significance1;
  13275. var contextLabel, decoded;
  13276. // calculate horizontal contribution
  13277. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  13278. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  13279. sign1 = coefficentsSign[index + 1];
  13280. if (significance1) {
  13281. sign0 = coefficentsSign[index - 1];
  13282. contribution = 1 - sign1 - sign0;
  13283. } else {
  13284. contribution = 1 - sign1 - sign1;
  13285. }
  13286. } else if (significance1) {
  13287. sign0 = coefficentsSign[index - 1];
  13288. contribution = 1 - sign0 - sign0;
  13289. } else {
  13290. contribution = 0;
  13291. }
  13292. var horizontalContribution = 3 * contribution;
  13293. // calculate vertical contribution and combine with the horizontal
  13294. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  13295. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  13296. sign1 = coefficentsSign[index + width];
  13297. if (significance1) {
  13298. sign0 = coefficentsSign[index - width];
  13299. contribution = 1 - sign1 - sign0 + horizontalContribution;
  13300. } else {
  13301. contribution = 1 - sign1 - sign1 + horizontalContribution;
  13302. }
  13303. } else if (significance1) {
  13304. sign0 = coefficentsSign[index - width];
  13305. contribution = 1 - sign0 - sign0 + horizontalContribution;
  13306. } else {
  13307. contribution = horizontalContribution;
  13308. }
  13309. if (contribution >= 0) {
  13310. contextLabel = 9 + contribution;
  13311. decoded = this.decoder.readBit(this.contexts, contextLabel);
  13312. } else {
  13313. contextLabel = 9 - contribution;
  13314. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  13315. }
  13316. return decoded;
  13317. },
  13318. runMagnitudeRefinementPass:
  13319. function BitModel_runMagnitudeRefinementPass() {
  13320. var decoder = this.decoder;
  13321. var width = this.width, height = this.height;
  13322. var coefficentsMagnitude = this.coefficentsMagnitude;
  13323. var neighborsSignificance = this.neighborsSignificance;
  13324. var contexts = this.contexts;
  13325. var bitsDecoded = this.bitsDecoded;
  13326. var processingFlags = this.processingFlags;
  13327. var processedMask = 1;
  13328. var firstMagnitudeBitMask = 2;
  13329. var length = width * height;
  13330. var width4 = width * 4;
  13331. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  13332. indexNext = Math.min(length, index0 + width4);
  13333. for (var j = 0; j < width; j++) {
  13334. for (var index = index0 + j; index < indexNext; index += width) {
  13335. // significant but not those that have just become
  13336. if (!coefficentsMagnitude[index] ||
  13337. (processingFlags[index] & processedMask) !== 0) {
  13338. continue;
  13339. }
  13340. var contextLabel = 16;
  13341. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  13342. processingFlags[index] ^= firstMagnitudeBitMask;
  13343. // first refinement
  13344. var significance = neighborsSignificance[index] & 127;
  13345. contextLabel = significance === 0 ? 15 : 14;
  13346. }
  13347. var bit = decoder.readBit(contexts, contextLabel);
  13348. coefficentsMagnitude[index] =
  13349. (coefficentsMagnitude[index] << 1) | bit;
  13350. bitsDecoded[index]++;
  13351. processingFlags[index] |= processedMask;
  13352. }
  13353. }
  13354. }
  13355. },
  13356. runCleanupPass: function BitModel_runCleanupPass() {
  13357. var decoder = this.decoder;
  13358. var width = this.width, height = this.height;
  13359. var neighborsSignificance = this.neighborsSignificance;
  13360. var coefficentsMagnitude = this.coefficentsMagnitude;
  13361. var coefficentsSign = this.coefficentsSign;
  13362. var contexts = this.contexts;
  13363. var labels = this.contextLabelTable;
  13364. var bitsDecoded = this.bitsDecoded;
  13365. var processingFlags = this.processingFlags;
  13366. var processedMask = 1;
  13367. var firstMagnitudeBitMask = 2;
  13368. var oneRowDown = width;
  13369. var twoRowsDown = width * 2;
  13370. var threeRowsDown = width * 3;
  13371. var iNext;
  13372. for (var i0 = 0; i0 < height; i0 = iNext) {
  13373. iNext = Math.min(i0 + 4, height);
  13374. var indexBase = i0 * width;
  13375. var checkAllEmpty = i0 + 3 < height;
  13376. for (var j = 0; j < width; j++) {
  13377. var index0 = indexBase + j;
  13378. // using the property: labels[neighborsSignificance[index]] === 0
  13379. // when neighborsSignificance[index] === 0
  13380. var allEmpty = (checkAllEmpty &&
  13381. processingFlags[index0] === 0 &&
  13382. processingFlags[index0 + oneRowDown] === 0 &&
  13383. processingFlags[index0 + twoRowsDown] === 0 &&
  13384. processingFlags[index0 + threeRowsDown] === 0 &&
  13385. neighborsSignificance[index0] === 0 &&
  13386. neighborsSignificance[index0 + oneRowDown] === 0 &&
  13387. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  13388. neighborsSignificance[index0 + threeRowsDown] === 0);
  13389. var i1 = 0, index = index0;
  13390. var i = i0, sign;
  13391. if (allEmpty) {
  13392. var hasSignificantCoefficent =
  13393. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  13394. if (!hasSignificantCoefficent) {
  13395. bitsDecoded[index0]++;
  13396. bitsDecoded[index0 + oneRowDown]++;
  13397. bitsDecoded[index0 + twoRowsDown]++;
  13398. bitsDecoded[index0 + threeRowsDown]++;
  13399. continue; // next column
  13400. }
  13401. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  13402. decoder.readBit(contexts, UNIFORM_CONTEXT);
  13403. if (i1 !== 0) {
  13404. i = i0 + i1;
  13405. index += i1 * width;
  13406. }
  13407. sign = this.decodeSignBit(i, j, index);
  13408. coefficentsSign[index] = sign;
  13409. coefficentsMagnitude[index] = 1;
  13410. this.setNeighborsSignificance(i, j, index);
  13411. processingFlags[index] |= firstMagnitudeBitMask;
  13412. index = index0;
  13413. for (var i2 = i0; i2 <= i; i2++, index += width) {
  13414. bitsDecoded[index]++;
  13415. }
  13416. i1++;
  13417. }
  13418. for (i = i0 + i1; i < iNext; i++, index += width) {
  13419. if (coefficentsMagnitude[index] ||
  13420. (processingFlags[index] & processedMask) !== 0) {
  13421. continue;
  13422. }
  13423. var contextLabel = labels[neighborsSignificance[index]];
  13424. var decision = decoder.readBit(contexts, contextLabel);
  13425. if (decision === 1) {
  13426. sign = this.decodeSignBit(i, j, index);
  13427. coefficentsSign[index] = sign;
  13428. coefficentsMagnitude[index] = 1;
  13429. this.setNeighborsSignificance(i, j, index);
  13430. processingFlags[index] |= firstMagnitudeBitMask;
  13431. }
  13432. bitsDecoded[index]++;
  13433. }
  13434. }
  13435. }
  13436. },
  13437. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  13438. var decoder = this.decoder;
  13439. var contexts = this.contexts;
  13440. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  13441. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  13442. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  13443. decoder.readBit(contexts, UNIFORM_CONTEXT);
  13444. if (symbol !== 0xA) {
  13445. error('JPX Error: Invalid segmentation symbol');
  13446. }
  13447. }
  13448. };
  13449. return BitModel;
  13450. })();
  13451. // Section F, Discrete wavelet transformation
  13452. var Transform = (function TransformClosure() {
  13453. function Transform() {}
  13454. Transform.prototype.calculate =
  13455. function transformCalculate(subbands, u0, v0) {
  13456. var ll = subbands[0];
  13457. for (var i = 1, ii = subbands.length; i < ii; i++) {
  13458. ll = this.iterate(ll, subbands[i], u0, v0);
  13459. }
  13460. return ll;
  13461. };
  13462. Transform.prototype.extend = function extend(buffer, offset, size) {
  13463. // Section F.3.7 extending... using max extension of 4
  13464. var i1 = offset - 1, j1 = offset + 1;
  13465. var i2 = offset + size - 2, j2 = offset + size;
  13466. buffer[i1--] = buffer[j1++];
  13467. buffer[j2++] = buffer[i2--];
  13468. buffer[i1--] = buffer[j1++];
  13469. buffer[j2++] = buffer[i2--];
  13470. buffer[i1--] = buffer[j1++];
  13471. buffer[j2++] = buffer[i2--];
  13472. buffer[i1] = buffer[j1];
  13473. buffer[j2] = buffer[i2];
  13474. };
  13475. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  13476. u0, v0) {
  13477. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  13478. var width = hl_lh_hh.width;
  13479. var height = hl_lh_hh.height;
  13480. var items = hl_lh_hh.items;
  13481. var i, j, k, l, u, v;
  13482. // Interleave LL according to Section F.3.3
  13483. for (k = 0, i = 0; i < llHeight; i++) {
  13484. l = i * 2 * width;
  13485. for (j = 0; j < llWidth; j++, k++, l += 2) {
  13486. items[l] = llItems[k];
  13487. }
  13488. }
  13489. // The LL band is not needed anymore.
  13490. llItems = ll.items = null;
  13491. var bufferPadding = 4;
  13492. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  13493. // Section F.3.4 HOR_SR
  13494. if (width === 1) {
  13495. // if width = 1, when u0 even keep items as is, when odd divide by 2
  13496. if ((u0 & 1) !== 0) {
  13497. for (v = 0, k = 0; v < height; v++, k += width) {
  13498. items[k] *= 0.5;
  13499. }
  13500. }
  13501. } else {
  13502. for (v = 0, k = 0; v < height; v++, k += width) {
  13503. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  13504. this.extend(rowBuffer, bufferPadding, width);
  13505. this.filter(rowBuffer, bufferPadding, width);
  13506. items.set(
  13507. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  13508. k);
  13509. }
  13510. }
  13511. // Accesses to the items array can take long, because it may not fit into
  13512. // CPU cache and has to be fetched from main memory. Since subsequent
  13513. // accesses to the items array are not local when reading columns, we
  13514. // have a cache miss every time. To reduce cache misses, get up to
  13515. // 'numBuffers' items at a time and store them into the individual
  13516. // buffers. The colBuffers should be small enough to fit into CPU cache.
  13517. var numBuffers = 16;
  13518. var colBuffers = [];
  13519. for (i = 0; i < numBuffers; i++) {
  13520. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  13521. }
  13522. var b, currentBuffer = 0;
  13523. ll = bufferPadding + height;
  13524. // Section F.3.5 VER_SR
  13525. if (height === 1) {
  13526. // if height = 1, when v0 even keep items as is, when odd divide by 2
  13527. if ((v0 & 1) !== 0) {
  13528. for (u = 0; u < width; u++) {
  13529. items[u] *= 0.5;
  13530. }
  13531. }
  13532. } else {
  13533. for (u = 0; u < width; u++) {
  13534. // if we ran out of buffers, copy several image columns at once
  13535. if (currentBuffer === 0) {
  13536. numBuffers = Math.min(width - u, numBuffers);
  13537. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  13538. for (b = 0; b < numBuffers; b++) {
  13539. colBuffers[b][l] = items[k + b];
  13540. }
  13541. }
  13542. currentBuffer = numBuffers;
  13543. }
  13544. currentBuffer--;
  13545. var buffer = colBuffers[currentBuffer];
  13546. this.extend(buffer, bufferPadding, height);
  13547. this.filter(buffer, bufferPadding, height);
  13548. // If this is last buffer in this group of buffers, flush all buffers.
  13549. if (currentBuffer === 0) {
  13550. k = u - numBuffers + 1;
  13551. for (l = bufferPadding; l < ll; k += width, l++) {
  13552. for (b = 0; b < numBuffers; b++) {
  13553. items[k + b] = colBuffers[b][l];
  13554. }
  13555. }
  13556. }
  13557. }
  13558. }
  13559. return {
  13560. width: width,
  13561. height: height,
  13562. items: items
  13563. };
  13564. };
  13565. return Transform;
  13566. })();
  13567. // Section 3.8.2 Irreversible 9-7 filter
  13568. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  13569. function IrreversibleTransform() {
  13570. Transform.call(this);
  13571. }
  13572. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  13573. IrreversibleTransform.prototype.filter =
  13574. function irreversibleTransformFilter(x, offset, length) {
  13575. var len = length >> 1;
  13576. offset = offset | 0;
  13577. var j, n, current, next;
  13578. var alpha = -1.586134342059924;
  13579. var beta = -0.052980118572961;
  13580. var gamma = 0.882911075530934;
  13581. var delta = 0.443506852043971;
  13582. var K = 1.230174104914001;
  13583. var K_ = 1 / K;
  13584. // step 1 is combined with step 3
  13585. // step 2
  13586. j = offset - 3;
  13587. for (n = len + 4; n--; j += 2) {
  13588. x[j] *= K_;
  13589. }
  13590. // step 1 & 3
  13591. j = offset - 2;
  13592. current = delta * x[j -1];
  13593. for (n = len + 3; n--; j += 2) {
  13594. next = delta * x[j + 1];
  13595. x[j] = K * x[j] - current - next;
  13596. if (n--) {
  13597. j += 2;
  13598. current = delta * x[j + 1];
  13599. x[j] = K * x[j] - current - next;
  13600. } else {
  13601. break;
  13602. }
  13603. }
  13604. // step 4
  13605. j = offset - 1;
  13606. current = gamma * x[j - 1];
  13607. for (n = len + 2; n--; j += 2) {
  13608. next = gamma * x[j + 1];
  13609. x[j] -= current + next;
  13610. if (n--) {
  13611. j += 2;
  13612. current = gamma * x[j + 1];
  13613. x[j] -= current + next;
  13614. } else {
  13615. break;
  13616. }
  13617. }
  13618. // step 5
  13619. j = offset;
  13620. current = beta * x[j - 1];
  13621. for (n = len + 1; n--; j += 2) {
  13622. next = beta * x[j + 1];
  13623. x[j] -= current + next;
  13624. if (n--) {
  13625. j += 2;
  13626. current = beta * x[j + 1];
  13627. x[j] -= current + next;
  13628. } else {
  13629. break;
  13630. }
  13631. }
  13632. // step 6
  13633. if (len !== 0) {
  13634. j = offset + 1;
  13635. current = alpha * x[j - 1];
  13636. for (n = len; n--; j += 2) {
  13637. next = alpha * x[j + 1];
  13638. x[j] -= current + next;
  13639. if (n--) {
  13640. j += 2;
  13641. current = alpha * x[j + 1];
  13642. x[j] -= current + next;
  13643. } else {
  13644. break;
  13645. }
  13646. }
  13647. }
  13648. };
  13649. return IrreversibleTransform;
  13650. })();
  13651. // Section 3.8.1 Reversible 5-3 filter
  13652. var ReversibleTransform = (function ReversibleTransformClosure() {
  13653. function ReversibleTransform() {
  13654. Transform.call(this);
  13655. }
  13656. ReversibleTransform.prototype = Object.create(Transform.prototype);
  13657. ReversibleTransform.prototype.filter =
  13658. function reversibleTransformFilter(x, offset, length) {
  13659. var len = length >> 1;
  13660. offset = offset | 0;
  13661. var j, n;
  13662. for (j = offset, n = len + 1; n--; j += 2) {
  13663. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  13664. }
  13665. for (j = offset + 1, n = len; n--; j += 2) {
  13666. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  13667. }
  13668. };
  13669. return ReversibleTransform;
  13670. })();
  13671. return JpxImage;
  13672. })();
  13673. exports.JpxImage = JpxImage;
  13674. }));
  13675. (function (root, factory) {
  13676. {
  13677. factory((root.pdfjsCoreMetrics = {}), root.pdfjsSharedUtil);
  13678. }
  13679. }(this, function (exports, sharedUtil) {
  13680. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  13681. // The Metrics object contains glyph widths (in glyph space units).
  13682. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  13683. // space unit corresponds to 1/1000th of text space unit.
  13684. var getMetrics = getLookupTableFactory(function (t) {
  13685. t['Courier'] = 600;
  13686. t['Courier-Bold'] = 600;
  13687. t['Courier-BoldOblique'] = 600;
  13688. t['Courier-Oblique'] = 600;
  13689. t['Helvetica'] = getLookupTableFactory(function (t) {
  13690. t['space'] = 278;
  13691. t['exclam'] = 278;
  13692. t['quotedbl'] = 355;
  13693. t['numbersign'] = 556;
  13694. t['dollar'] = 556;
  13695. t['percent'] = 889;
  13696. t['ampersand'] = 667;
  13697. t['quoteright'] = 222;
  13698. t['parenleft'] = 333;
  13699. t['parenright'] = 333;
  13700. t['asterisk'] = 389;
  13701. t['plus'] = 584;
  13702. t['comma'] = 278;
  13703. t['hyphen'] = 333;
  13704. t['period'] = 278;
  13705. t['slash'] = 278;
  13706. t['zero'] = 556;
  13707. t['one'] = 556;
  13708. t['two'] = 556;
  13709. t['three'] = 556;
  13710. t['four'] = 556;
  13711. t['five'] = 556;
  13712. t['six'] = 556;
  13713. t['seven'] = 556;
  13714. t['eight'] = 556;
  13715. t['nine'] = 556;
  13716. t['colon'] = 278;
  13717. t['semicolon'] = 278;
  13718. t['less'] = 584;
  13719. t['equal'] = 584;
  13720. t['greater'] = 584;
  13721. t['question'] = 556;
  13722. t['at'] = 1015;
  13723. t['A'] = 667;
  13724. t['B'] = 667;
  13725. t['C'] = 722;
  13726. t['D'] = 722;
  13727. t['E'] = 667;
  13728. t['F'] = 611;
  13729. t['G'] = 778;
  13730. t['H'] = 722;
  13731. t['I'] = 278;
  13732. t['J'] = 500;
  13733. t['K'] = 667;
  13734. t['L'] = 556;
  13735. t['M'] = 833;
  13736. t['N'] = 722;
  13737. t['O'] = 778;
  13738. t['P'] = 667;
  13739. t['Q'] = 778;
  13740. t['R'] = 722;
  13741. t['S'] = 667;
  13742. t['T'] = 611;
  13743. t['U'] = 722;
  13744. t['V'] = 667;
  13745. t['W'] = 944;
  13746. t['X'] = 667;
  13747. t['Y'] = 667;
  13748. t['Z'] = 611;
  13749. t['bracketleft'] = 278;
  13750. t['backslash'] = 278;
  13751. t['bracketright'] = 278;
  13752. t['asciicircum'] = 469;
  13753. t['underscore'] = 556;
  13754. t['quoteleft'] = 222;
  13755. t['a'] = 556;
  13756. t['b'] = 556;
  13757. t['c'] = 500;
  13758. t['d'] = 556;
  13759. t['e'] = 556;
  13760. t['f'] = 278;
  13761. t['g'] = 556;
  13762. t['h'] = 556;
  13763. t['i'] = 222;
  13764. t['j'] = 222;
  13765. t['k'] = 500;
  13766. t['l'] = 222;
  13767. t['m'] = 833;
  13768. t['n'] = 556;
  13769. t['o'] = 556;
  13770. t['p'] = 556;
  13771. t['q'] = 556;
  13772. t['r'] = 333;
  13773. t['s'] = 500;
  13774. t['t'] = 278;
  13775. t['u'] = 556;
  13776. t['v'] = 500;
  13777. t['w'] = 722;
  13778. t['x'] = 500;
  13779. t['y'] = 500;
  13780. t['z'] = 500;
  13781. t['braceleft'] = 334;
  13782. t['bar'] = 260;
  13783. t['braceright'] = 334;
  13784. t['asciitilde'] = 584;
  13785. t['exclamdown'] = 333;
  13786. t['cent'] = 556;
  13787. t['sterling'] = 556;
  13788. t['fraction'] = 167;
  13789. t['yen'] = 556;
  13790. t['florin'] = 556;
  13791. t['section'] = 556;
  13792. t['currency'] = 556;
  13793. t['quotesingle'] = 191;
  13794. t['quotedblleft'] = 333;
  13795. t['guillemotleft'] = 556;
  13796. t['guilsinglleft'] = 333;
  13797. t['guilsinglright'] = 333;
  13798. t['fi'] = 500;
  13799. t['fl'] = 500;
  13800. t['endash'] = 556;
  13801. t['dagger'] = 556;
  13802. t['daggerdbl'] = 556;
  13803. t['periodcentered'] = 278;
  13804. t['paragraph'] = 537;
  13805. t['bullet'] = 350;
  13806. t['quotesinglbase'] = 222;
  13807. t['quotedblbase'] = 333;
  13808. t['quotedblright'] = 333;
  13809. t['guillemotright'] = 556;
  13810. t['ellipsis'] = 1000;
  13811. t['perthousand'] = 1000;
  13812. t['questiondown'] = 611;
  13813. t['grave'] = 333;
  13814. t['acute'] = 333;
  13815. t['circumflex'] = 333;
  13816. t['tilde'] = 333;
  13817. t['macron'] = 333;
  13818. t['breve'] = 333;
  13819. t['dotaccent'] = 333;
  13820. t['dieresis'] = 333;
  13821. t['ring'] = 333;
  13822. t['cedilla'] = 333;
  13823. t['hungarumlaut'] = 333;
  13824. t['ogonek'] = 333;
  13825. t['caron'] = 333;
  13826. t['emdash'] = 1000;
  13827. t['AE'] = 1000;
  13828. t['ordfeminine'] = 370;
  13829. t['Lslash'] = 556;
  13830. t['Oslash'] = 778;
  13831. t['OE'] = 1000;
  13832. t['ordmasculine'] = 365;
  13833. t['ae'] = 889;
  13834. t['dotlessi'] = 278;
  13835. t['lslash'] = 222;
  13836. t['oslash'] = 611;
  13837. t['oe'] = 944;
  13838. t['germandbls'] = 611;
  13839. t['Idieresis'] = 278;
  13840. t['eacute'] = 556;
  13841. t['abreve'] = 556;
  13842. t['uhungarumlaut'] = 556;
  13843. t['ecaron'] = 556;
  13844. t['Ydieresis'] = 667;
  13845. t['divide'] = 584;
  13846. t['Yacute'] = 667;
  13847. t['Acircumflex'] = 667;
  13848. t['aacute'] = 556;
  13849. t['Ucircumflex'] = 722;
  13850. t['yacute'] = 500;
  13851. t['scommaaccent'] = 500;
  13852. t['ecircumflex'] = 556;
  13853. t['Uring'] = 722;
  13854. t['Udieresis'] = 722;
  13855. t['aogonek'] = 556;
  13856. t['Uacute'] = 722;
  13857. t['uogonek'] = 556;
  13858. t['Edieresis'] = 667;
  13859. t['Dcroat'] = 722;
  13860. t['commaaccent'] = 250;
  13861. t['copyright'] = 737;
  13862. t['Emacron'] = 667;
  13863. t['ccaron'] = 500;
  13864. t['aring'] = 556;
  13865. t['Ncommaaccent'] = 722;
  13866. t['lacute'] = 222;
  13867. t['agrave'] = 556;
  13868. t['Tcommaaccent'] = 611;
  13869. t['Cacute'] = 722;
  13870. t['atilde'] = 556;
  13871. t['Edotaccent'] = 667;
  13872. t['scaron'] = 500;
  13873. t['scedilla'] = 500;
  13874. t['iacute'] = 278;
  13875. t['lozenge'] = 471;
  13876. t['Rcaron'] = 722;
  13877. t['Gcommaaccent'] = 778;
  13878. t['ucircumflex'] = 556;
  13879. t['acircumflex'] = 556;
  13880. t['Amacron'] = 667;
  13881. t['rcaron'] = 333;
  13882. t['ccedilla'] = 500;
  13883. t['Zdotaccent'] = 611;
  13884. t['Thorn'] = 667;
  13885. t['Omacron'] = 778;
  13886. t['Racute'] = 722;
  13887. t['Sacute'] = 667;
  13888. t['dcaron'] = 643;
  13889. t['Umacron'] = 722;
  13890. t['uring'] = 556;
  13891. t['threesuperior'] = 333;
  13892. t['Ograve'] = 778;
  13893. t['Agrave'] = 667;
  13894. t['Abreve'] = 667;
  13895. t['multiply'] = 584;
  13896. t['uacute'] = 556;
  13897. t['Tcaron'] = 611;
  13898. t['partialdiff'] = 476;
  13899. t['ydieresis'] = 500;
  13900. t['Nacute'] = 722;
  13901. t['icircumflex'] = 278;
  13902. t['Ecircumflex'] = 667;
  13903. t['adieresis'] = 556;
  13904. t['edieresis'] = 556;
  13905. t['cacute'] = 500;
  13906. t['nacute'] = 556;
  13907. t['umacron'] = 556;
  13908. t['Ncaron'] = 722;
  13909. t['Iacute'] = 278;
  13910. t['plusminus'] = 584;
  13911. t['brokenbar'] = 260;
  13912. t['registered'] = 737;
  13913. t['Gbreve'] = 778;
  13914. t['Idotaccent'] = 278;
  13915. t['summation'] = 600;
  13916. t['Egrave'] = 667;
  13917. t['racute'] = 333;
  13918. t['omacron'] = 556;
  13919. t['Zacute'] = 611;
  13920. t['Zcaron'] = 611;
  13921. t['greaterequal'] = 549;
  13922. t['Eth'] = 722;
  13923. t['Ccedilla'] = 722;
  13924. t['lcommaaccent'] = 222;
  13925. t['tcaron'] = 317;
  13926. t['eogonek'] = 556;
  13927. t['Uogonek'] = 722;
  13928. t['Aacute'] = 667;
  13929. t['Adieresis'] = 667;
  13930. t['egrave'] = 556;
  13931. t['zacute'] = 500;
  13932. t['iogonek'] = 222;
  13933. t['Oacute'] = 778;
  13934. t['oacute'] = 556;
  13935. t['amacron'] = 556;
  13936. t['sacute'] = 500;
  13937. t['idieresis'] = 278;
  13938. t['Ocircumflex'] = 778;
  13939. t['Ugrave'] = 722;
  13940. t['Delta'] = 612;
  13941. t['thorn'] = 556;
  13942. t['twosuperior'] = 333;
  13943. t['Odieresis'] = 778;
  13944. t['mu'] = 556;
  13945. t['igrave'] = 278;
  13946. t['ohungarumlaut'] = 556;
  13947. t['Eogonek'] = 667;
  13948. t['dcroat'] = 556;
  13949. t['threequarters'] = 834;
  13950. t['Scedilla'] = 667;
  13951. t['lcaron'] = 299;
  13952. t['Kcommaaccent'] = 667;
  13953. t['Lacute'] = 556;
  13954. t['trademark'] = 1000;
  13955. t['edotaccent'] = 556;
  13956. t['Igrave'] = 278;
  13957. t['Imacron'] = 278;
  13958. t['Lcaron'] = 556;
  13959. t['onehalf'] = 834;
  13960. t['lessequal'] = 549;
  13961. t['ocircumflex'] = 556;
  13962. t['ntilde'] = 556;
  13963. t['Uhungarumlaut'] = 722;
  13964. t['Eacute'] = 667;
  13965. t['emacron'] = 556;
  13966. t['gbreve'] = 556;
  13967. t['onequarter'] = 834;
  13968. t['Scaron'] = 667;
  13969. t['Scommaaccent'] = 667;
  13970. t['Ohungarumlaut'] = 778;
  13971. t['degree'] = 400;
  13972. t['ograve'] = 556;
  13973. t['Ccaron'] = 722;
  13974. t['ugrave'] = 556;
  13975. t['radical'] = 453;
  13976. t['Dcaron'] = 722;
  13977. t['rcommaaccent'] = 333;
  13978. t['Ntilde'] = 722;
  13979. t['otilde'] = 556;
  13980. t['Rcommaaccent'] = 722;
  13981. t['Lcommaaccent'] = 556;
  13982. t['Atilde'] = 667;
  13983. t['Aogonek'] = 667;
  13984. t['Aring'] = 667;
  13985. t['Otilde'] = 778;
  13986. t['zdotaccent'] = 500;
  13987. t['Ecaron'] = 667;
  13988. t['Iogonek'] = 278;
  13989. t['kcommaaccent'] = 500;
  13990. t['minus'] = 584;
  13991. t['Icircumflex'] = 278;
  13992. t['ncaron'] = 556;
  13993. t['tcommaaccent'] = 278;
  13994. t['logicalnot'] = 584;
  13995. t['odieresis'] = 556;
  13996. t['udieresis'] = 556;
  13997. t['notequal'] = 549;
  13998. t['gcommaaccent'] = 556;
  13999. t['eth'] = 556;
  14000. t['zcaron'] = 500;
  14001. t['ncommaaccent'] = 556;
  14002. t['onesuperior'] = 333;
  14003. t['imacron'] = 278;
  14004. t['Euro'] = 556;
  14005. });
  14006. t['Helvetica-Bold'] = getLookupTableFactory(function (t) {
  14007. t['space'] = 278;
  14008. t['exclam'] = 333;
  14009. t['quotedbl'] = 474;
  14010. t['numbersign'] = 556;
  14011. t['dollar'] = 556;
  14012. t['percent'] = 889;
  14013. t['ampersand'] = 722;
  14014. t['quoteright'] = 278;
  14015. t['parenleft'] = 333;
  14016. t['parenright'] = 333;
  14017. t['asterisk'] = 389;
  14018. t['plus'] = 584;
  14019. t['comma'] = 278;
  14020. t['hyphen'] = 333;
  14021. t['period'] = 278;
  14022. t['slash'] = 278;
  14023. t['zero'] = 556;
  14024. t['one'] = 556;
  14025. t['two'] = 556;
  14026. t['three'] = 556;
  14027. t['four'] = 556;
  14028. t['five'] = 556;
  14029. t['six'] = 556;
  14030. t['seven'] = 556;
  14031. t['eight'] = 556;
  14032. t['nine'] = 556;
  14033. t['colon'] = 333;
  14034. t['semicolon'] = 333;
  14035. t['less'] = 584;
  14036. t['equal'] = 584;
  14037. t['greater'] = 584;
  14038. t['question'] = 611;
  14039. t['at'] = 975;
  14040. t['A'] = 722;
  14041. t['B'] = 722;
  14042. t['C'] = 722;
  14043. t['D'] = 722;
  14044. t['E'] = 667;
  14045. t['F'] = 611;
  14046. t['G'] = 778;
  14047. t['H'] = 722;
  14048. t['I'] = 278;
  14049. t['J'] = 556;
  14050. t['K'] = 722;
  14051. t['L'] = 611;
  14052. t['M'] = 833;
  14053. t['N'] = 722;
  14054. t['O'] = 778;
  14055. t['P'] = 667;
  14056. t['Q'] = 778;
  14057. t['R'] = 722;
  14058. t['S'] = 667;
  14059. t['T'] = 611;
  14060. t['U'] = 722;
  14061. t['V'] = 667;
  14062. t['W'] = 944;
  14063. t['X'] = 667;
  14064. t['Y'] = 667;
  14065. t['Z'] = 611;
  14066. t['bracketleft'] = 333;
  14067. t['backslash'] = 278;
  14068. t['bracketright'] = 333;
  14069. t['asciicircum'] = 584;
  14070. t['underscore'] = 556;
  14071. t['quoteleft'] = 278;
  14072. t['a'] = 556;
  14073. t['b'] = 611;
  14074. t['c'] = 556;
  14075. t['d'] = 611;
  14076. t['e'] = 556;
  14077. t['f'] = 333;
  14078. t['g'] = 611;
  14079. t['h'] = 611;
  14080. t['i'] = 278;
  14081. t['j'] = 278;
  14082. t['k'] = 556;
  14083. t['l'] = 278;
  14084. t['m'] = 889;
  14085. t['n'] = 611;
  14086. t['o'] = 611;
  14087. t['p'] = 611;
  14088. t['q'] = 611;
  14089. t['r'] = 389;
  14090. t['s'] = 556;
  14091. t['t'] = 333;
  14092. t['u'] = 611;
  14093. t['v'] = 556;
  14094. t['w'] = 778;
  14095. t['x'] = 556;
  14096. t['y'] = 556;
  14097. t['z'] = 500;
  14098. t['braceleft'] = 389;
  14099. t['bar'] = 280;
  14100. t['braceright'] = 389;
  14101. t['asciitilde'] = 584;
  14102. t['exclamdown'] = 333;
  14103. t['cent'] = 556;
  14104. t['sterling'] = 556;
  14105. t['fraction'] = 167;
  14106. t['yen'] = 556;
  14107. t['florin'] = 556;
  14108. t['section'] = 556;
  14109. t['currency'] = 556;
  14110. t['quotesingle'] = 238;
  14111. t['quotedblleft'] = 500;
  14112. t['guillemotleft'] = 556;
  14113. t['guilsinglleft'] = 333;
  14114. t['guilsinglright'] = 333;
  14115. t['fi'] = 611;
  14116. t['fl'] = 611;
  14117. t['endash'] = 556;
  14118. t['dagger'] = 556;
  14119. t['daggerdbl'] = 556;
  14120. t['periodcentered'] = 278;
  14121. t['paragraph'] = 556;
  14122. t['bullet'] = 350;
  14123. t['quotesinglbase'] = 278;
  14124. t['quotedblbase'] = 500;
  14125. t['quotedblright'] = 500;
  14126. t['guillemotright'] = 556;
  14127. t['ellipsis'] = 1000;
  14128. t['perthousand'] = 1000;
  14129. t['questiondown'] = 611;
  14130. t['grave'] = 333;
  14131. t['acute'] = 333;
  14132. t['circumflex'] = 333;
  14133. t['tilde'] = 333;
  14134. t['macron'] = 333;
  14135. t['breve'] = 333;
  14136. t['dotaccent'] = 333;
  14137. t['dieresis'] = 333;
  14138. t['ring'] = 333;
  14139. t['cedilla'] = 333;
  14140. t['hungarumlaut'] = 333;
  14141. t['ogonek'] = 333;
  14142. t['caron'] = 333;
  14143. t['emdash'] = 1000;
  14144. t['AE'] = 1000;
  14145. t['ordfeminine'] = 370;
  14146. t['Lslash'] = 611;
  14147. t['Oslash'] = 778;
  14148. t['OE'] = 1000;
  14149. t['ordmasculine'] = 365;
  14150. t['ae'] = 889;
  14151. t['dotlessi'] = 278;
  14152. t['lslash'] = 278;
  14153. t['oslash'] = 611;
  14154. t['oe'] = 944;
  14155. t['germandbls'] = 611;
  14156. t['Idieresis'] = 278;
  14157. t['eacute'] = 556;
  14158. t['abreve'] = 556;
  14159. t['uhungarumlaut'] = 611;
  14160. t['ecaron'] = 556;
  14161. t['Ydieresis'] = 667;
  14162. t['divide'] = 584;
  14163. t['Yacute'] = 667;
  14164. t['Acircumflex'] = 722;
  14165. t['aacute'] = 556;
  14166. t['Ucircumflex'] = 722;
  14167. t['yacute'] = 556;
  14168. t['scommaaccent'] = 556;
  14169. t['ecircumflex'] = 556;
  14170. t['Uring'] = 722;
  14171. t['Udieresis'] = 722;
  14172. t['aogonek'] = 556;
  14173. t['Uacute'] = 722;
  14174. t['uogonek'] = 611;
  14175. t['Edieresis'] = 667;
  14176. t['Dcroat'] = 722;
  14177. t['commaaccent'] = 250;
  14178. t['copyright'] = 737;
  14179. t['Emacron'] = 667;
  14180. t['ccaron'] = 556;
  14181. t['aring'] = 556;
  14182. t['Ncommaaccent'] = 722;
  14183. t['lacute'] = 278;
  14184. t['agrave'] = 556;
  14185. t['Tcommaaccent'] = 611;
  14186. t['Cacute'] = 722;
  14187. t['atilde'] = 556;
  14188. t['Edotaccent'] = 667;
  14189. t['scaron'] = 556;
  14190. t['scedilla'] = 556;
  14191. t['iacute'] = 278;
  14192. t['lozenge'] = 494;
  14193. t['Rcaron'] = 722;
  14194. t['Gcommaaccent'] = 778;
  14195. t['ucircumflex'] = 611;
  14196. t['acircumflex'] = 556;
  14197. t['Amacron'] = 722;
  14198. t['rcaron'] = 389;
  14199. t['ccedilla'] = 556;
  14200. t['Zdotaccent'] = 611;
  14201. t['Thorn'] = 667;
  14202. t['Omacron'] = 778;
  14203. t['Racute'] = 722;
  14204. t['Sacute'] = 667;
  14205. t['dcaron'] = 743;
  14206. t['Umacron'] = 722;
  14207. t['uring'] = 611;
  14208. t['threesuperior'] = 333;
  14209. t['Ograve'] = 778;
  14210. t['Agrave'] = 722;
  14211. t['Abreve'] = 722;
  14212. t['multiply'] = 584;
  14213. t['uacute'] = 611;
  14214. t['Tcaron'] = 611;
  14215. t['partialdiff'] = 494;
  14216. t['ydieresis'] = 556;
  14217. t['Nacute'] = 722;
  14218. t['icircumflex'] = 278;
  14219. t['Ecircumflex'] = 667;
  14220. t['adieresis'] = 556;
  14221. t['edieresis'] = 556;
  14222. t['cacute'] = 556;
  14223. t['nacute'] = 611;
  14224. t['umacron'] = 611;
  14225. t['Ncaron'] = 722;
  14226. t['Iacute'] = 278;
  14227. t['plusminus'] = 584;
  14228. t['brokenbar'] = 280;
  14229. t['registered'] = 737;
  14230. t['Gbreve'] = 778;
  14231. t['Idotaccent'] = 278;
  14232. t['summation'] = 600;
  14233. t['Egrave'] = 667;
  14234. t['racute'] = 389;
  14235. t['omacron'] = 611;
  14236. t['Zacute'] = 611;
  14237. t['Zcaron'] = 611;
  14238. t['greaterequal'] = 549;
  14239. t['Eth'] = 722;
  14240. t['Ccedilla'] = 722;
  14241. t['lcommaaccent'] = 278;
  14242. t['tcaron'] = 389;
  14243. t['eogonek'] = 556;
  14244. t['Uogonek'] = 722;
  14245. t['Aacute'] = 722;
  14246. t['Adieresis'] = 722;
  14247. t['egrave'] = 556;
  14248. t['zacute'] = 500;
  14249. t['iogonek'] = 278;
  14250. t['Oacute'] = 778;
  14251. t['oacute'] = 611;
  14252. t['amacron'] = 556;
  14253. t['sacute'] = 556;
  14254. t['idieresis'] = 278;
  14255. t['Ocircumflex'] = 778;
  14256. t['Ugrave'] = 722;
  14257. t['Delta'] = 612;
  14258. t['thorn'] = 611;
  14259. t['twosuperior'] = 333;
  14260. t['Odieresis'] = 778;
  14261. t['mu'] = 611;
  14262. t['igrave'] = 278;
  14263. t['ohungarumlaut'] = 611;
  14264. t['Eogonek'] = 667;
  14265. t['dcroat'] = 611;
  14266. t['threequarters'] = 834;
  14267. t['Scedilla'] = 667;
  14268. t['lcaron'] = 400;
  14269. t['Kcommaaccent'] = 722;
  14270. t['Lacute'] = 611;
  14271. t['trademark'] = 1000;
  14272. t['edotaccent'] = 556;
  14273. t['Igrave'] = 278;
  14274. t['Imacron'] = 278;
  14275. t['Lcaron'] = 611;
  14276. t['onehalf'] = 834;
  14277. t['lessequal'] = 549;
  14278. t['ocircumflex'] = 611;
  14279. t['ntilde'] = 611;
  14280. t['Uhungarumlaut'] = 722;
  14281. t['Eacute'] = 667;
  14282. t['emacron'] = 556;
  14283. t['gbreve'] = 611;
  14284. t['onequarter'] = 834;
  14285. t['Scaron'] = 667;
  14286. t['Scommaaccent'] = 667;
  14287. t['Ohungarumlaut'] = 778;
  14288. t['degree'] = 400;
  14289. t['ograve'] = 611;
  14290. t['Ccaron'] = 722;
  14291. t['ugrave'] = 611;
  14292. t['radical'] = 549;
  14293. t['Dcaron'] = 722;
  14294. t['rcommaaccent'] = 389;
  14295. t['Ntilde'] = 722;
  14296. t['otilde'] = 611;
  14297. t['Rcommaaccent'] = 722;
  14298. t['Lcommaaccent'] = 611;
  14299. t['Atilde'] = 722;
  14300. t['Aogonek'] = 722;
  14301. t['Aring'] = 722;
  14302. t['Otilde'] = 778;
  14303. t['zdotaccent'] = 500;
  14304. t['Ecaron'] = 667;
  14305. t['Iogonek'] = 278;
  14306. t['kcommaaccent'] = 556;
  14307. t['minus'] = 584;
  14308. t['Icircumflex'] = 278;
  14309. t['ncaron'] = 611;
  14310. t['tcommaaccent'] = 333;
  14311. t['logicalnot'] = 584;
  14312. t['odieresis'] = 611;
  14313. t['udieresis'] = 611;
  14314. t['notequal'] = 549;
  14315. t['gcommaaccent'] = 611;
  14316. t['eth'] = 611;
  14317. t['zcaron'] = 500;
  14318. t['ncommaaccent'] = 611;
  14319. t['onesuperior'] = 333;
  14320. t['imacron'] = 278;
  14321. t['Euro'] = 556;
  14322. });
  14323. t['Helvetica-BoldOblique'] = getLookupTableFactory(function (t) {
  14324. t['space'] = 278;
  14325. t['exclam'] = 333;
  14326. t['quotedbl'] = 474;
  14327. t['numbersign'] = 556;
  14328. t['dollar'] = 556;
  14329. t['percent'] = 889;
  14330. t['ampersand'] = 722;
  14331. t['quoteright'] = 278;
  14332. t['parenleft'] = 333;
  14333. t['parenright'] = 333;
  14334. t['asterisk'] = 389;
  14335. t['plus'] = 584;
  14336. t['comma'] = 278;
  14337. t['hyphen'] = 333;
  14338. t['period'] = 278;
  14339. t['slash'] = 278;
  14340. t['zero'] = 556;
  14341. t['one'] = 556;
  14342. t['two'] = 556;
  14343. t['three'] = 556;
  14344. t['four'] = 556;
  14345. t['five'] = 556;
  14346. t['six'] = 556;
  14347. t['seven'] = 556;
  14348. t['eight'] = 556;
  14349. t['nine'] = 556;
  14350. t['colon'] = 333;
  14351. t['semicolon'] = 333;
  14352. t['less'] = 584;
  14353. t['equal'] = 584;
  14354. t['greater'] = 584;
  14355. t['question'] = 611;
  14356. t['at'] = 975;
  14357. t['A'] = 722;
  14358. t['B'] = 722;
  14359. t['C'] = 722;
  14360. t['D'] = 722;
  14361. t['E'] = 667;
  14362. t['F'] = 611;
  14363. t['G'] = 778;
  14364. t['H'] = 722;
  14365. t['I'] = 278;
  14366. t['J'] = 556;
  14367. t['K'] = 722;
  14368. t['L'] = 611;
  14369. t['M'] = 833;
  14370. t['N'] = 722;
  14371. t['O'] = 778;
  14372. t['P'] = 667;
  14373. t['Q'] = 778;
  14374. t['R'] = 722;
  14375. t['S'] = 667;
  14376. t['T'] = 611;
  14377. t['U'] = 722;
  14378. t['V'] = 667;
  14379. t['W'] = 944;
  14380. t['X'] = 667;
  14381. t['Y'] = 667;
  14382. t['Z'] = 611;
  14383. t['bracketleft'] = 333;
  14384. t['backslash'] = 278;
  14385. t['bracketright'] = 333;
  14386. t['asciicircum'] = 584;
  14387. t['underscore'] = 556;
  14388. t['quoteleft'] = 278;
  14389. t['a'] = 556;
  14390. t['b'] = 611;
  14391. t['c'] = 556;
  14392. t['d'] = 611;
  14393. t['e'] = 556;
  14394. t['f'] = 333;
  14395. t['g'] = 611;
  14396. t['h'] = 611;
  14397. t['i'] = 278;
  14398. t['j'] = 278;
  14399. t['k'] = 556;
  14400. t['l'] = 278;
  14401. t['m'] = 889;
  14402. t['n'] = 611;
  14403. t['o'] = 611;
  14404. t['p'] = 611;
  14405. t['q'] = 611;
  14406. t['r'] = 389;
  14407. t['s'] = 556;
  14408. t['t'] = 333;
  14409. t['u'] = 611;
  14410. t['v'] = 556;
  14411. t['w'] = 778;
  14412. t['x'] = 556;
  14413. t['y'] = 556;
  14414. t['z'] = 500;
  14415. t['braceleft'] = 389;
  14416. t['bar'] = 280;
  14417. t['braceright'] = 389;
  14418. t['asciitilde'] = 584;
  14419. t['exclamdown'] = 333;
  14420. t['cent'] = 556;
  14421. t['sterling'] = 556;
  14422. t['fraction'] = 167;
  14423. t['yen'] = 556;
  14424. t['florin'] = 556;
  14425. t['section'] = 556;
  14426. t['currency'] = 556;
  14427. t['quotesingle'] = 238;
  14428. t['quotedblleft'] = 500;
  14429. t['guillemotleft'] = 556;
  14430. t['guilsinglleft'] = 333;
  14431. t['guilsinglright'] = 333;
  14432. t['fi'] = 611;
  14433. t['fl'] = 611;
  14434. t['endash'] = 556;
  14435. t['dagger'] = 556;
  14436. t['daggerdbl'] = 556;
  14437. t['periodcentered'] = 278;
  14438. t['paragraph'] = 556;
  14439. t['bullet'] = 350;
  14440. t['quotesinglbase'] = 278;
  14441. t['quotedblbase'] = 500;
  14442. t['quotedblright'] = 500;
  14443. t['guillemotright'] = 556;
  14444. t['ellipsis'] = 1000;
  14445. t['perthousand'] = 1000;
  14446. t['questiondown'] = 611;
  14447. t['grave'] = 333;
  14448. t['acute'] = 333;
  14449. t['circumflex'] = 333;
  14450. t['tilde'] = 333;
  14451. t['macron'] = 333;
  14452. t['breve'] = 333;
  14453. t['dotaccent'] = 333;
  14454. t['dieresis'] = 333;
  14455. t['ring'] = 333;
  14456. t['cedilla'] = 333;
  14457. t['hungarumlaut'] = 333;
  14458. t['ogonek'] = 333;
  14459. t['caron'] = 333;
  14460. t['emdash'] = 1000;
  14461. t['AE'] = 1000;
  14462. t['ordfeminine'] = 370;
  14463. t['Lslash'] = 611;
  14464. t['Oslash'] = 778;
  14465. t['OE'] = 1000;
  14466. t['ordmasculine'] = 365;
  14467. t['ae'] = 889;
  14468. t['dotlessi'] = 278;
  14469. t['lslash'] = 278;
  14470. t['oslash'] = 611;
  14471. t['oe'] = 944;
  14472. t['germandbls'] = 611;
  14473. t['Idieresis'] = 278;
  14474. t['eacute'] = 556;
  14475. t['abreve'] = 556;
  14476. t['uhungarumlaut'] = 611;
  14477. t['ecaron'] = 556;
  14478. t['Ydieresis'] = 667;
  14479. t['divide'] = 584;
  14480. t['Yacute'] = 667;
  14481. t['Acircumflex'] = 722;
  14482. t['aacute'] = 556;
  14483. t['Ucircumflex'] = 722;
  14484. t['yacute'] = 556;
  14485. t['scommaaccent'] = 556;
  14486. t['ecircumflex'] = 556;
  14487. t['Uring'] = 722;
  14488. t['Udieresis'] = 722;
  14489. t['aogonek'] = 556;
  14490. t['Uacute'] = 722;
  14491. t['uogonek'] = 611;
  14492. t['Edieresis'] = 667;
  14493. t['Dcroat'] = 722;
  14494. t['commaaccent'] = 250;
  14495. t['copyright'] = 737;
  14496. t['Emacron'] = 667;
  14497. t['ccaron'] = 556;
  14498. t['aring'] = 556;
  14499. t['Ncommaaccent'] = 722;
  14500. t['lacute'] = 278;
  14501. t['agrave'] = 556;
  14502. t['Tcommaaccent'] = 611;
  14503. t['Cacute'] = 722;
  14504. t['atilde'] = 556;
  14505. t['Edotaccent'] = 667;
  14506. t['scaron'] = 556;
  14507. t['scedilla'] = 556;
  14508. t['iacute'] = 278;
  14509. t['lozenge'] = 494;
  14510. t['Rcaron'] = 722;
  14511. t['Gcommaaccent'] = 778;
  14512. t['ucircumflex'] = 611;
  14513. t['acircumflex'] = 556;
  14514. t['Amacron'] = 722;
  14515. t['rcaron'] = 389;
  14516. t['ccedilla'] = 556;
  14517. t['Zdotaccent'] = 611;
  14518. t['Thorn'] = 667;
  14519. t['Omacron'] = 778;
  14520. t['Racute'] = 722;
  14521. t['Sacute'] = 667;
  14522. t['dcaron'] = 743;
  14523. t['Umacron'] = 722;
  14524. t['uring'] = 611;
  14525. t['threesuperior'] = 333;
  14526. t['Ograve'] = 778;
  14527. t['Agrave'] = 722;
  14528. t['Abreve'] = 722;
  14529. t['multiply'] = 584;
  14530. t['uacute'] = 611;
  14531. t['Tcaron'] = 611;
  14532. t['partialdiff'] = 494;
  14533. t['ydieresis'] = 556;
  14534. t['Nacute'] = 722;
  14535. t['icircumflex'] = 278;
  14536. t['Ecircumflex'] = 667;
  14537. t['adieresis'] = 556;
  14538. t['edieresis'] = 556;
  14539. t['cacute'] = 556;
  14540. t['nacute'] = 611;
  14541. t['umacron'] = 611;
  14542. t['Ncaron'] = 722;
  14543. t['Iacute'] = 278;
  14544. t['plusminus'] = 584;
  14545. t['brokenbar'] = 280;
  14546. t['registered'] = 737;
  14547. t['Gbreve'] = 778;
  14548. t['Idotaccent'] = 278;
  14549. t['summation'] = 600;
  14550. t['Egrave'] = 667;
  14551. t['racute'] = 389;
  14552. t['omacron'] = 611;
  14553. t['Zacute'] = 611;
  14554. t['Zcaron'] = 611;
  14555. t['greaterequal'] = 549;
  14556. t['Eth'] = 722;
  14557. t['Ccedilla'] = 722;
  14558. t['lcommaaccent'] = 278;
  14559. t['tcaron'] = 389;
  14560. t['eogonek'] = 556;
  14561. t['Uogonek'] = 722;
  14562. t['Aacute'] = 722;
  14563. t['Adieresis'] = 722;
  14564. t['egrave'] = 556;
  14565. t['zacute'] = 500;
  14566. t['iogonek'] = 278;
  14567. t['Oacute'] = 778;
  14568. t['oacute'] = 611;
  14569. t['amacron'] = 556;
  14570. t['sacute'] = 556;
  14571. t['idieresis'] = 278;
  14572. t['Ocircumflex'] = 778;
  14573. t['Ugrave'] = 722;
  14574. t['Delta'] = 612;
  14575. t['thorn'] = 611;
  14576. t['twosuperior'] = 333;
  14577. t['Odieresis'] = 778;
  14578. t['mu'] = 611;
  14579. t['igrave'] = 278;
  14580. t['ohungarumlaut'] = 611;
  14581. t['Eogonek'] = 667;
  14582. t['dcroat'] = 611;
  14583. t['threequarters'] = 834;
  14584. t['Scedilla'] = 667;
  14585. t['lcaron'] = 400;
  14586. t['Kcommaaccent'] = 722;
  14587. t['Lacute'] = 611;
  14588. t['trademark'] = 1000;
  14589. t['edotaccent'] = 556;
  14590. t['Igrave'] = 278;
  14591. t['Imacron'] = 278;
  14592. t['Lcaron'] = 611;
  14593. t['onehalf'] = 834;
  14594. t['lessequal'] = 549;
  14595. t['ocircumflex'] = 611;
  14596. t['ntilde'] = 611;
  14597. t['Uhungarumlaut'] = 722;
  14598. t['Eacute'] = 667;
  14599. t['emacron'] = 556;
  14600. t['gbreve'] = 611;
  14601. t['onequarter'] = 834;
  14602. t['Scaron'] = 667;
  14603. t['Scommaaccent'] = 667;
  14604. t['Ohungarumlaut'] = 778;
  14605. t['degree'] = 400;
  14606. t['ograve'] = 611;
  14607. t['Ccaron'] = 722;
  14608. t['ugrave'] = 611;
  14609. t['radical'] = 549;
  14610. t['Dcaron'] = 722;
  14611. t['rcommaaccent'] = 389;
  14612. t['Ntilde'] = 722;
  14613. t['otilde'] = 611;
  14614. t['Rcommaaccent'] = 722;
  14615. t['Lcommaaccent'] = 611;
  14616. t['Atilde'] = 722;
  14617. t['Aogonek'] = 722;
  14618. t['Aring'] = 722;
  14619. t['Otilde'] = 778;
  14620. t['zdotaccent'] = 500;
  14621. t['Ecaron'] = 667;
  14622. t['Iogonek'] = 278;
  14623. t['kcommaaccent'] = 556;
  14624. t['minus'] = 584;
  14625. t['Icircumflex'] = 278;
  14626. t['ncaron'] = 611;
  14627. t['tcommaaccent'] = 333;
  14628. t['logicalnot'] = 584;
  14629. t['odieresis'] = 611;
  14630. t['udieresis'] = 611;
  14631. t['notequal'] = 549;
  14632. t['gcommaaccent'] = 611;
  14633. t['eth'] = 611;
  14634. t['zcaron'] = 500;
  14635. t['ncommaaccent'] = 611;
  14636. t['onesuperior'] = 333;
  14637. t['imacron'] = 278;
  14638. t['Euro'] = 556;
  14639. });
  14640. t['Helvetica-Oblique'] = getLookupTableFactory(function (t) {
  14641. t['space'] = 278;
  14642. t['exclam'] = 278;
  14643. t['quotedbl'] = 355;
  14644. t['numbersign'] = 556;
  14645. t['dollar'] = 556;
  14646. t['percent'] = 889;
  14647. t['ampersand'] = 667;
  14648. t['quoteright'] = 222;
  14649. t['parenleft'] = 333;
  14650. t['parenright'] = 333;
  14651. t['asterisk'] = 389;
  14652. t['plus'] = 584;
  14653. t['comma'] = 278;
  14654. t['hyphen'] = 333;
  14655. t['period'] = 278;
  14656. t['slash'] = 278;
  14657. t['zero'] = 556;
  14658. t['one'] = 556;
  14659. t['two'] = 556;
  14660. t['three'] = 556;
  14661. t['four'] = 556;
  14662. t['five'] = 556;
  14663. t['six'] = 556;
  14664. t['seven'] = 556;
  14665. t['eight'] = 556;
  14666. t['nine'] = 556;
  14667. t['colon'] = 278;
  14668. t['semicolon'] = 278;
  14669. t['less'] = 584;
  14670. t['equal'] = 584;
  14671. t['greater'] = 584;
  14672. t['question'] = 556;
  14673. t['at'] = 1015;
  14674. t['A'] = 667;
  14675. t['B'] = 667;
  14676. t['C'] = 722;
  14677. t['D'] = 722;
  14678. t['E'] = 667;
  14679. t['F'] = 611;
  14680. t['G'] = 778;
  14681. t['H'] = 722;
  14682. t['I'] = 278;
  14683. t['J'] = 500;
  14684. t['K'] = 667;
  14685. t['L'] = 556;
  14686. t['M'] = 833;
  14687. t['N'] = 722;
  14688. t['O'] = 778;
  14689. t['P'] = 667;
  14690. t['Q'] = 778;
  14691. t['R'] = 722;
  14692. t['S'] = 667;
  14693. t['T'] = 611;
  14694. t['U'] = 722;
  14695. t['V'] = 667;
  14696. t['W'] = 944;
  14697. t['X'] = 667;
  14698. t['Y'] = 667;
  14699. t['Z'] = 611;
  14700. t['bracketleft'] = 278;
  14701. t['backslash'] = 278;
  14702. t['bracketright'] = 278;
  14703. t['asciicircum'] = 469;
  14704. t['underscore'] = 556;
  14705. t['quoteleft'] = 222;
  14706. t['a'] = 556;
  14707. t['b'] = 556;
  14708. t['c'] = 500;
  14709. t['d'] = 556;
  14710. t['e'] = 556;
  14711. t['f'] = 278;
  14712. t['g'] = 556;
  14713. t['h'] = 556;
  14714. t['i'] = 222;
  14715. t['j'] = 222;
  14716. t['k'] = 500;
  14717. t['l'] = 222;
  14718. t['m'] = 833;
  14719. t['n'] = 556;
  14720. t['o'] = 556;
  14721. t['p'] = 556;
  14722. t['q'] = 556;
  14723. t['r'] = 333;
  14724. t['s'] = 500;
  14725. t['t'] = 278;
  14726. t['u'] = 556;
  14727. t['v'] = 500;
  14728. t['w'] = 722;
  14729. t['x'] = 500;
  14730. t['y'] = 500;
  14731. t['z'] = 500;
  14732. t['braceleft'] = 334;
  14733. t['bar'] = 260;
  14734. t['braceright'] = 334;
  14735. t['asciitilde'] = 584;
  14736. t['exclamdown'] = 333;
  14737. t['cent'] = 556;
  14738. t['sterling'] = 556;
  14739. t['fraction'] = 167;
  14740. t['yen'] = 556;
  14741. t['florin'] = 556;
  14742. t['section'] = 556;
  14743. t['currency'] = 556;
  14744. t['quotesingle'] = 191;
  14745. t['quotedblleft'] = 333;
  14746. t['guillemotleft'] = 556;
  14747. t['guilsinglleft'] = 333;
  14748. t['guilsinglright'] = 333;
  14749. t['fi'] = 500;
  14750. t['fl'] = 500;
  14751. t['endash'] = 556;
  14752. t['dagger'] = 556;
  14753. t['daggerdbl'] = 556;
  14754. t['periodcentered'] = 278;
  14755. t['paragraph'] = 537;
  14756. t['bullet'] = 350;
  14757. t['quotesinglbase'] = 222;
  14758. t['quotedblbase'] = 333;
  14759. t['quotedblright'] = 333;
  14760. t['guillemotright'] = 556;
  14761. t['ellipsis'] = 1000;
  14762. t['perthousand'] = 1000;
  14763. t['questiondown'] = 611;
  14764. t['grave'] = 333;
  14765. t['acute'] = 333;
  14766. t['circumflex'] = 333;
  14767. t['tilde'] = 333;
  14768. t['macron'] = 333;
  14769. t['breve'] = 333;
  14770. t['dotaccent'] = 333;
  14771. t['dieresis'] = 333;
  14772. t['ring'] = 333;
  14773. t['cedilla'] = 333;
  14774. t['hungarumlaut'] = 333;
  14775. t['ogonek'] = 333;
  14776. t['caron'] = 333;
  14777. t['emdash'] = 1000;
  14778. t['AE'] = 1000;
  14779. t['ordfeminine'] = 370;
  14780. t['Lslash'] = 556;
  14781. t['Oslash'] = 778;
  14782. t['OE'] = 1000;
  14783. t['ordmasculine'] = 365;
  14784. t['ae'] = 889;
  14785. t['dotlessi'] = 278;
  14786. t['lslash'] = 222;
  14787. t['oslash'] = 611;
  14788. t['oe'] = 944;
  14789. t['germandbls'] = 611;
  14790. t['Idieresis'] = 278;
  14791. t['eacute'] = 556;
  14792. t['abreve'] = 556;
  14793. t['uhungarumlaut'] = 556;
  14794. t['ecaron'] = 556;
  14795. t['Ydieresis'] = 667;
  14796. t['divide'] = 584;
  14797. t['Yacute'] = 667;
  14798. t['Acircumflex'] = 667;
  14799. t['aacute'] = 556;
  14800. t['Ucircumflex'] = 722;
  14801. t['yacute'] = 500;
  14802. t['scommaaccent'] = 500;
  14803. t['ecircumflex'] = 556;
  14804. t['Uring'] = 722;
  14805. t['Udieresis'] = 722;
  14806. t['aogonek'] = 556;
  14807. t['Uacute'] = 722;
  14808. t['uogonek'] = 556;
  14809. t['Edieresis'] = 667;
  14810. t['Dcroat'] = 722;
  14811. t['commaaccent'] = 250;
  14812. t['copyright'] = 737;
  14813. t['Emacron'] = 667;
  14814. t['ccaron'] = 500;
  14815. t['aring'] = 556;
  14816. t['Ncommaaccent'] = 722;
  14817. t['lacute'] = 222;
  14818. t['agrave'] = 556;
  14819. t['Tcommaaccent'] = 611;
  14820. t['Cacute'] = 722;
  14821. t['atilde'] = 556;
  14822. t['Edotaccent'] = 667;
  14823. t['scaron'] = 500;
  14824. t['scedilla'] = 500;
  14825. t['iacute'] = 278;
  14826. t['lozenge'] = 471;
  14827. t['Rcaron'] = 722;
  14828. t['Gcommaaccent'] = 778;
  14829. t['ucircumflex'] = 556;
  14830. t['acircumflex'] = 556;
  14831. t['Amacron'] = 667;
  14832. t['rcaron'] = 333;
  14833. t['ccedilla'] = 500;
  14834. t['Zdotaccent'] = 611;
  14835. t['Thorn'] = 667;
  14836. t['Omacron'] = 778;
  14837. t['Racute'] = 722;
  14838. t['Sacute'] = 667;
  14839. t['dcaron'] = 643;
  14840. t['Umacron'] = 722;
  14841. t['uring'] = 556;
  14842. t['threesuperior'] = 333;
  14843. t['Ograve'] = 778;
  14844. t['Agrave'] = 667;
  14845. t['Abreve'] = 667;
  14846. t['multiply'] = 584;
  14847. t['uacute'] = 556;
  14848. t['Tcaron'] = 611;
  14849. t['partialdiff'] = 476;
  14850. t['ydieresis'] = 500;
  14851. t['Nacute'] = 722;
  14852. t['icircumflex'] = 278;
  14853. t['Ecircumflex'] = 667;
  14854. t['adieresis'] = 556;
  14855. t['edieresis'] = 556;
  14856. t['cacute'] = 500;
  14857. t['nacute'] = 556;
  14858. t['umacron'] = 556;
  14859. t['Ncaron'] = 722;
  14860. t['Iacute'] = 278;
  14861. t['plusminus'] = 584;
  14862. t['brokenbar'] = 260;
  14863. t['registered'] = 737;
  14864. t['Gbreve'] = 778;
  14865. t['Idotaccent'] = 278;
  14866. t['summation'] = 600;
  14867. t['Egrave'] = 667;
  14868. t['racute'] = 333;
  14869. t['omacron'] = 556;
  14870. t['Zacute'] = 611;
  14871. t['Zcaron'] = 611;
  14872. t['greaterequal'] = 549;
  14873. t['Eth'] = 722;
  14874. t['Ccedilla'] = 722;
  14875. t['lcommaaccent'] = 222;
  14876. t['tcaron'] = 317;
  14877. t['eogonek'] = 556;
  14878. t['Uogonek'] = 722;
  14879. t['Aacute'] = 667;
  14880. t['Adieresis'] = 667;
  14881. t['egrave'] = 556;
  14882. t['zacute'] = 500;
  14883. t['iogonek'] = 222;
  14884. t['Oacute'] = 778;
  14885. t['oacute'] = 556;
  14886. t['amacron'] = 556;
  14887. t['sacute'] = 500;
  14888. t['idieresis'] = 278;
  14889. t['Ocircumflex'] = 778;
  14890. t['Ugrave'] = 722;
  14891. t['Delta'] = 612;
  14892. t['thorn'] = 556;
  14893. t['twosuperior'] = 333;
  14894. t['Odieresis'] = 778;
  14895. t['mu'] = 556;
  14896. t['igrave'] = 278;
  14897. t['ohungarumlaut'] = 556;
  14898. t['Eogonek'] = 667;
  14899. t['dcroat'] = 556;
  14900. t['threequarters'] = 834;
  14901. t['Scedilla'] = 667;
  14902. t['lcaron'] = 299;
  14903. t['Kcommaaccent'] = 667;
  14904. t['Lacute'] = 556;
  14905. t['trademark'] = 1000;
  14906. t['edotaccent'] = 556;
  14907. t['Igrave'] = 278;
  14908. t['Imacron'] = 278;
  14909. t['Lcaron'] = 556;
  14910. t['onehalf'] = 834;
  14911. t['lessequal'] = 549;
  14912. t['ocircumflex'] = 556;
  14913. t['ntilde'] = 556;
  14914. t['Uhungarumlaut'] = 722;
  14915. t['Eacute'] = 667;
  14916. t['emacron'] = 556;
  14917. t['gbreve'] = 556;
  14918. t['onequarter'] = 834;
  14919. t['Scaron'] = 667;
  14920. t['Scommaaccent'] = 667;
  14921. t['Ohungarumlaut'] = 778;
  14922. t['degree'] = 400;
  14923. t['ograve'] = 556;
  14924. t['Ccaron'] = 722;
  14925. t['ugrave'] = 556;
  14926. t['radical'] = 453;
  14927. t['Dcaron'] = 722;
  14928. t['rcommaaccent'] = 333;
  14929. t['Ntilde'] = 722;
  14930. t['otilde'] = 556;
  14931. t['Rcommaaccent'] = 722;
  14932. t['Lcommaaccent'] = 556;
  14933. t['Atilde'] = 667;
  14934. t['Aogonek'] = 667;
  14935. t['Aring'] = 667;
  14936. t['Otilde'] = 778;
  14937. t['zdotaccent'] = 500;
  14938. t['Ecaron'] = 667;
  14939. t['Iogonek'] = 278;
  14940. t['kcommaaccent'] = 500;
  14941. t['minus'] = 584;
  14942. t['Icircumflex'] = 278;
  14943. t['ncaron'] = 556;
  14944. t['tcommaaccent'] = 278;
  14945. t['logicalnot'] = 584;
  14946. t['odieresis'] = 556;
  14947. t['udieresis'] = 556;
  14948. t['notequal'] = 549;
  14949. t['gcommaaccent'] = 556;
  14950. t['eth'] = 556;
  14951. t['zcaron'] = 500;
  14952. t['ncommaaccent'] = 556;
  14953. t['onesuperior'] = 333;
  14954. t['imacron'] = 278;
  14955. t['Euro'] = 556;
  14956. });
  14957. t['Symbol'] = getLookupTableFactory(function (t) {
  14958. t['space'] = 250;
  14959. t['exclam'] = 333;
  14960. t['universal'] = 713;
  14961. t['numbersign'] = 500;
  14962. t['existential'] = 549;
  14963. t['percent'] = 833;
  14964. t['ampersand'] = 778;
  14965. t['suchthat'] = 439;
  14966. t['parenleft'] = 333;
  14967. t['parenright'] = 333;
  14968. t['asteriskmath'] = 500;
  14969. t['plus'] = 549;
  14970. t['comma'] = 250;
  14971. t['minus'] = 549;
  14972. t['period'] = 250;
  14973. t['slash'] = 278;
  14974. t['zero'] = 500;
  14975. t['one'] = 500;
  14976. t['two'] = 500;
  14977. t['three'] = 500;
  14978. t['four'] = 500;
  14979. t['five'] = 500;
  14980. t['six'] = 500;
  14981. t['seven'] = 500;
  14982. t['eight'] = 500;
  14983. t['nine'] = 500;
  14984. t['colon'] = 278;
  14985. t['semicolon'] = 278;
  14986. t['less'] = 549;
  14987. t['equal'] = 549;
  14988. t['greater'] = 549;
  14989. t['question'] = 444;
  14990. t['congruent'] = 549;
  14991. t['Alpha'] = 722;
  14992. t['Beta'] = 667;
  14993. t['Chi'] = 722;
  14994. t['Delta'] = 612;
  14995. t['Epsilon'] = 611;
  14996. t['Phi'] = 763;
  14997. t['Gamma'] = 603;
  14998. t['Eta'] = 722;
  14999. t['Iota'] = 333;
  15000. t['theta1'] = 631;
  15001. t['Kappa'] = 722;
  15002. t['Lambda'] = 686;
  15003. t['Mu'] = 889;
  15004. t['Nu'] = 722;
  15005. t['Omicron'] = 722;
  15006. t['Pi'] = 768;
  15007. t['Theta'] = 741;
  15008. t['Rho'] = 556;
  15009. t['Sigma'] = 592;
  15010. t['Tau'] = 611;
  15011. t['Upsilon'] = 690;
  15012. t['sigma1'] = 439;
  15013. t['Omega'] = 768;
  15014. t['Xi'] = 645;
  15015. t['Psi'] = 795;
  15016. t['Zeta'] = 611;
  15017. t['bracketleft'] = 333;
  15018. t['therefore'] = 863;
  15019. t['bracketright'] = 333;
  15020. t['perpendicular'] = 658;
  15021. t['underscore'] = 500;
  15022. t['radicalex'] = 500;
  15023. t['alpha'] = 631;
  15024. t['beta'] = 549;
  15025. t['chi'] = 549;
  15026. t['delta'] = 494;
  15027. t['epsilon'] = 439;
  15028. t['phi'] = 521;
  15029. t['gamma'] = 411;
  15030. t['eta'] = 603;
  15031. t['iota'] = 329;
  15032. t['phi1'] = 603;
  15033. t['kappa'] = 549;
  15034. t['lambda'] = 549;
  15035. t['mu'] = 576;
  15036. t['nu'] = 521;
  15037. t['omicron'] = 549;
  15038. t['pi'] = 549;
  15039. t['theta'] = 521;
  15040. t['rho'] = 549;
  15041. t['sigma'] = 603;
  15042. t['tau'] = 439;
  15043. t['upsilon'] = 576;
  15044. t['omega1'] = 713;
  15045. t['omega'] = 686;
  15046. t['xi'] = 493;
  15047. t['psi'] = 686;
  15048. t['zeta'] = 494;
  15049. t['braceleft'] = 480;
  15050. t['bar'] = 200;
  15051. t['braceright'] = 480;
  15052. t['similar'] = 549;
  15053. t['Euro'] = 750;
  15054. t['Upsilon1'] = 620;
  15055. t['minute'] = 247;
  15056. t['lessequal'] = 549;
  15057. t['fraction'] = 167;
  15058. t['infinity'] = 713;
  15059. t['florin'] = 500;
  15060. t['club'] = 753;
  15061. t['diamond'] = 753;
  15062. t['heart'] = 753;
  15063. t['spade'] = 753;
  15064. t['arrowboth'] = 1042;
  15065. t['arrowleft'] = 987;
  15066. t['arrowup'] = 603;
  15067. t['arrowright'] = 987;
  15068. t['arrowdown'] = 603;
  15069. t['degree'] = 400;
  15070. t['plusminus'] = 549;
  15071. t['second'] = 411;
  15072. t['greaterequal'] = 549;
  15073. t['multiply'] = 549;
  15074. t['proportional'] = 713;
  15075. t['partialdiff'] = 494;
  15076. t['bullet'] = 460;
  15077. t['divide'] = 549;
  15078. t['notequal'] = 549;
  15079. t['equivalence'] = 549;
  15080. t['approxequal'] = 549;
  15081. t['ellipsis'] = 1000;
  15082. t['arrowvertex'] = 603;
  15083. t['arrowhorizex'] = 1000;
  15084. t['carriagereturn'] = 658;
  15085. t['aleph'] = 823;
  15086. t['Ifraktur'] = 686;
  15087. t['Rfraktur'] = 795;
  15088. t['weierstrass'] = 987;
  15089. t['circlemultiply'] = 768;
  15090. t['circleplus'] = 768;
  15091. t['emptyset'] = 823;
  15092. t['intersection'] = 768;
  15093. t['union'] = 768;
  15094. t['propersuperset'] = 713;
  15095. t['reflexsuperset'] = 713;
  15096. t['notsubset'] = 713;
  15097. t['propersubset'] = 713;
  15098. t['reflexsubset'] = 713;
  15099. t['element'] = 713;
  15100. t['notelement'] = 713;
  15101. t['angle'] = 768;
  15102. t['gradient'] = 713;
  15103. t['registerserif'] = 790;
  15104. t['copyrightserif'] = 790;
  15105. t['trademarkserif'] = 890;
  15106. t['product'] = 823;
  15107. t['radical'] = 549;
  15108. t['dotmath'] = 250;
  15109. t['logicalnot'] = 713;
  15110. t['logicaland'] = 603;
  15111. t['logicalor'] = 603;
  15112. t['arrowdblboth'] = 1042;
  15113. t['arrowdblleft'] = 987;
  15114. t['arrowdblup'] = 603;
  15115. t['arrowdblright'] = 987;
  15116. t['arrowdbldown'] = 603;
  15117. t['lozenge'] = 494;
  15118. t['angleleft'] = 329;
  15119. t['registersans'] = 790;
  15120. t['copyrightsans'] = 790;
  15121. t['trademarksans'] = 786;
  15122. t['summation'] = 713;
  15123. t['parenlefttp'] = 384;
  15124. t['parenleftex'] = 384;
  15125. t['parenleftbt'] = 384;
  15126. t['bracketlefttp'] = 384;
  15127. t['bracketleftex'] = 384;
  15128. t['bracketleftbt'] = 384;
  15129. t['bracelefttp'] = 494;
  15130. t['braceleftmid'] = 494;
  15131. t['braceleftbt'] = 494;
  15132. t['braceex'] = 494;
  15133. t['angleright'] = 329;
  15134. t['integral'] = 274;
  15135. t['integraltp'] = 686;
  15136. t['integralex'] = 686;
  15137. t['integralbt'] = 686;
  15138. t['parenrighttp'] = 384;
  15139. t['parenrightex'] = 384;
  15140. t['parenrightbt'] = 384;
  15141. t['bracketrighttp'] = 384;
  15142. t['bracketrightex'] = 384;
  15143. t['bracketrightbt'] = 384;
  15144. t['bracerighttp'] = 494;
  15145. t['bracerightmid'] = 494;
  15146. t['bracerightbt'] = 494;
  15147. t['apple'] = 790;
  15148. });
  15149. t['Times-Roman'] = getLookupTableFactory(function (t) {
  15150. t['space'] = 250;
  15151. t['exclam'] = 333;
  15152. t['quotedbl'] = 408;
  15153. t['numbersign'] = 500;
  15154. t['dollar'] = 500;
  15155. t['percent'] = 833;
  15156. t['ampersand'] = 778;
  15157. t['quoteright'] = 333;
  15158. t['parenleft'] = 333;
  15159. t['parenright'] = 333;
  15160. t['asterisk'] = 500;
  15161. t['plus'] = 564;
  15162. t['comma'] = 250;
  15163. t['hyphen'] = 333;
  15164. t['period'] = 250;
  15165. t['slash'] = 278;
  15166. t['zero'] = 500;
  15167. t['one'] = 500;
  15168. t['two'] = 500;
  15169. t['three'] = 500;
  15170. t['four'] = 500;
  15171. t['five'] = 500;
  15172. t['six'] = 500;
  15173. t['seven'] = 500;
  15174. t['eight'] = 500;
  15175. t['nine'] = 500;
  15176. t['colon'] = 278;
  15177. t['semicolon'] = 278;
  15178. t['less'] = 564;
  15179. t['equal'] = 564;
  15180. t['greater'] = 564;
  15181. t['question'] = 444;
  15182. t['at'] = 921;
  15183. t['A'] = 722;
  15184. t['B'] = 667;
  15185. t['C'] = 667;
  15186. t['D'] = 722;
  15187. t['E'] = 611;
  15188. t['F'] = 556;
  15189. t['G'] = 722;
  15190. t['H'] = 722;
  15191. t['I'] = 333;
  15192. t['J'] = 389;
  15193. t['K'] = 722;
  15194. t['L'] = 611;
  15195. t['M'] = 889;
  15196. t['N'] = 722;
  15197. t['O'] = 722;
  15198. t['P'] = 556;
  15199. t['Q'] = 722;
  15200. t['R'] = 667;
  15201. t['S'] = 556;
  15202. t['T'] = 611;
  15203. t['U'] = 722;
  15204. t['V'] = 722;
  15205. t['W'] = 944;
  15206. t['X'] = 722;
  15207. t['Y'] = 722;
  15208. t['Z'] = 611;
  15209. t['bracketleft'] = 333;
  15210. t['backslash'] = 278;
  15211. t['bracketright'] = 333;
  15212. t['asciicircum'] = 469;
  15213. t['underscore'] = 500;
  15214. t['quoteleft'] = 333;
  15215. t['a'] = 444;
  15216. t['b'] = 500;
  15217. t['c'] = 444;
  15218. t['d'] = 500;
  15219. t['e'] = 444;
  15220. t['f'] = 333;
  15221. t['g'] = 500;
  15222. t['h'] = 500;
  15223. t['i'] = 278;
  15224. t['j'] = 278;
  15225. t['k'] = 500;
  15226. t['l'] = 278;
  15227. t['m'] = 778;
  15228. t['n'] = 500;
  15229. t['o'] = 500;
  15230. t['p'] = 500;
  15231. t['q'] = 500;
  15232. t['r'] = 333;
  15233. t['s'] = 389;
  15234. t['t'] = 278;
  15235. t['u'] = 500;
  15236. t['v'] = 500;
  15237. t['w'] = 722;
  15238. t['x'] = 500;
  15239. t['y'] = 500;
  15240. t['z'] = 444;
  15241. t['braceleft'] = 480;
  15242. t['bar'] = 200;
  15243. t['braceright'] = 480;
  15244. t['asciitilde'] = 541;
  15245. t['exclamdown'] = 333;
  15246. t['cent'] = 500;
  15247. t['sterling'] = 500;
  15248. t['fraction'] = 167;
  15249. t['yen'] = 500;
  15250. t['florin'] = 500;
  15251. t['section'] = 500;
  15252. t['currency'] = 500;
  15253. t['quotesingle'] = 180;
  15254. t['quotedblleft'] = 444;
  15255. t['guillemotleft'] = 500;
  15256. t['guilsinglleft'] = 333;
  15257. t['guilsinglright'] = 333;
  15258. t['fi'] = 556;
  15259. t['fl'] = 556;
  15260. t['endash'] = 500;
  15261. t['dagger'] = 500;
  15262. t['daggerdbl'] = 500;
  15263. t['periodcentered'] = 250;
  15264. t['paragraph'] = 453;
  15265. t['bullet'] = 350;
  15266. t['quotesinglbase'] = 333;
  15267. t['quotedblbase'] = 444;
  15268. t['quotedblright'] = 444;
  15269. t['guillemotright'] = 500;
  15270. t['ellipsis'] = 1000;
  15271. t['perthousand'] = 1000;
  15272. t['questiondown'] = 444;
  15273. t['grave'] = 333;
  15274. t['acute'] = 333;
  15275. t['circumflex'] = 333;
  15276. t['tilde'] = 333;
  15277. t['macron'] = 333;
  15278. t['breve'] = 333;
  15279. t['dotaccent'] = 333;
  15280. t['dieresis'] = 333;
  15281. t['ring'] = 333;
  15282. t['cedilla'] = 333;
  15283. t['hungarumlaut'] = 333;
  15284. t['ogonek'] = 333;
  15285. t['caron'] = 333;
  15286. t['emdash'] = 1000;
  15287. t['AE'] = 889;
  15288. t['ordfeminine'] = 276;
  15289. t['Lslash'] = 611;
  15290. t['Oslash'] = 722;
  15291. t['OE'] = 889;
  15292. t['ordmasculine'] = 310;
  15293. t['ae'] = 667;
  15294. t['dotlessi'] = 278;
  15295. t['lslash'] = 278;
  15296. t['oslash'] = 500;
  15297. t['oe'] = 722;
  15298. t['germandbls'] = 500;
  15299. t['Idieresis'] = 333;
  15300. t['eacute'] = 444;
  15301. t['abreve'] = 444;
  15302. t['uhungarumlaut'] = 500;
  15303. t['ecaron'] = 444;
  15304. t['Ydieresis'] = 722;
  15305. t['divide'] = 564;
  15306. t['Yacute'] = 722;
  15307. t['Acircumflex'] = 722;
  15308. t['aacute'] = 444;
  15309. t['Ucircumflex'] = 722;
  15310. t['yacute'] = 500;
  15311. t['scommaaccent'] = 389;
  15312. t['ecircumflex'] = 444;
  15313. t['Uring'] = 722;
  15314. t['Udieresis'] = 722;
  15315. t['aogonek'] = 444;
  15316. t['Uacute'] = 722;
  15317. t['uogonek'] = 500;
  15318. t['Edieresis'] = 611;
  15319. t['Dcroat'] = 722;
  15320. t['commaaccent'] = 250;
  15321. t['copyright'] = 760;
  15322. t['Emacron'] = 611;
  15323. t['ccaron'] = 444;
  15324. t['aring'] = 444;
  15325. t['Ncommaaccent'] = 722;
  15326. t['lacute'] = 278;
  15327. t['agrave'] = 444;
  15328. t['Tcommaaccent'] = 611;
  15329. t['Cacute'] = 667;
  15330. t['atilde'] = 444;
  15331. t['Edotaccent'] = 611;
  15332. t['scaron'] = 389;
  15333. t['scedilla'] = 389;
  15334. t['iacute'] = 278;
  15335. t['lozenge'] = 471;
  15336. t['Rcaron'] = 667;
  15337. t['Gcommaaccent'] = 722;
  15338. t['ucircumflex'] = 500;
  15339. t['acircumflex'] = 444;
  15340. t['Amacron'] = 722;
  15341. t['rcaron'] = 333;
  15342. t['ccedilla'] = 444;
  15343. t['Zdotaccent'] = 611;
  15344. t['Thorn'] = 556;
  15345. t['Omacron'] = 722;
  15346. t['Racute'] = 667;
  15347. t['Sacute'] = 556;
  15348. t['dcaron'] = 588;
  15349. t['Umacron'] = 722;
  15350. t['uring'] = 500;
  15351. t['threesuperior'] = 300;
  15352. t['Ograve'] = 722;
  15353. t['Agrave'] = 722;
  15354. t['Abreve'] = 722;
  15355. t['multiply'] = 564;
  15356. t['uacute'] = 500;
  15357. t['Tcaron'] = 611;
  15358. t['partialdiff'] = 476;
  15359. t['ydieresis'] = 500;
  15360. t['Nacute'] = 722;
  15361. t['icircumflex'] = 278;
  15362. t['Ecircumflex'] = 611;
  15363. t['adieresis'] = 444;
  15364. t['edieresis'] = 444;
  15365. t['cacute'] = 444;
  15366. t['nacute'] = 500;
  15367. t['umacron'] = 500;
  15368. t['Ncaron'] = 722;
  15369. t['Iacute'] = 333;
  15370. t['plusminus'] = 564;
  15371. t['brokenbar'] = 200;
  15372. t['registered'] = 760;
  15373. t['Gbreve'] = 722;
  15374. t['Idotaccent'] = 333;
  15375. t['summation'] = 600;
  15376. t['Egrave'] = 611;
  15377. t['racute'] = 333;
  15378. t['omacron'] = 500;
  15379. t['Zacute'] = 611;
  15380. t['Zcaron'] = 611;
  15381. t['greaterequal'] = 549;
  15382. t['Eth'] = 722;
  15383. t['Ccedilla'] = 667;
  15384. t['lcommaaccent'] = 278;
  15385. t['tcaron'] = 326;
  15386. t['eogonek'] = 444;
  15387. t['Uogonek'] = 722;
  15388. t['Aacute'] = 722;
  15389. t['Adieresis'] = 722;
  15390. t['egrave'] = 444;
  15391. t['zacute'] = 444;
  15392. t['iogonek'] = 278;
  15393. t['Oacute'] = 722;
  15394. t['oacute'] = 500;
  15395. t['amacron'] = 444;
  15396. t['sacute'] = 389;
  15397. t['idieresis'] = 278;
  15398. t['Ocircumflex'] = 722;
  15399. t['Ugrave'] = 722;
  15400. t['Delta'] = 612;
  15401. t['thorn'] = 500;
  15402. t['twosuperior'] = 300;
  15403. t['Odieresis'] = 722;
  15404. t['mu'] = 500;
  15405. t['igrave'] = 278;
  15406. t['ohungarumlaut'] = 500;
  15407. t['Eogonek'] = 611;
  15408. t['dcroat'] = 500;
  15409. t['threequarters'] = 750;
  15410. t['Scedilla'] = 556;
  15411. t['lcaron'] = 344;
  15412. t['Kcommaaccent'] = 722;
  15413. t['Lacute'] = 611;
  15414. t['trademark'] = 980;
  15415. t['edotaccent'] = 444;
  15416. t['Igrave'] = 333;
  15417. t['Imacron'] = 333;
  15418. t['Lcaron'] = 611;
  15419. t['onehalf'] = 750;
  15420. t['lessequal'] = 549;
  15421. t['ocircumflex'] = 500;
  15422. t['ntilde'] = 500;
  15423. t['Uhungarumlaut'] = 722;
  15424. t['Eacute'] = 611;
  15425. t['emacron'] = 444;
  15426. t['gbreve'] = 500;
  15427. t['onequarter'] = 750;
  15428. t['Scaron'] = 556;
  15429. t['Scommaaccent'] = 556;
  15430. t['Ohungarumlaut'] = 722;
  15431. t['degree'] = 400;
  15432. t['ograve'] = 500;
  15433. t['Ccaron'] = 667;
  15434. t['ugrave'] = 500;
  15435. t['radical'] = 453;
  15436. t['Dcaron'] = 722;
  15437. t['rcommaaccent'] = 333;
  15438. t['Ntilde'] = 722;
  15439. t['otilde'] = 500;
  15440. t['Rcommaaccent'] = 667;
  15441. t['Lcommaaccent'] = 611;
  15442. t['Atilde'] = 722;
  15443. t['Aogonek'] = 722;
  15444. t['Aring'] = 722;
  15445. t['Otilde'] = 722;
  15446. t['zdotaccent'] = 444;
  15447. t['Ecaron'] = 611;
  15448. t['Iogonek'] = 333;
  15449. t['kcommaaccent'] = 500;
  15450. t['minus'] = 564;
  15451. t['Icircumflex'] = 333;
  15452. t['ncaron'] = 500;
  15453. t['tcommaaccent'] = 278;
  15454. t['logicalnot'] = 564;
  15455. t['odieresis'] = 500;
  15456. t['udieresis'] = 500;
  15457. t['notequal'] = 549;
  15458. t['gcommaaccent'] = 500;
  15459. t['eth'] = 500;
  15460. t['zcaron'] = 444;
  15461. t['ncommaaccent'] = 500;
  15462. t['onesuperior'] = 300;
  15463. t['imacron'] = 278;
  15464. t['Euro'] = 500;
  15465. });
  15466. t['Times-Bold'] = getLookupTableFactory(function (t) {
  15467. t['space'] = 250;
  15468. t['exclam'] = 333;
  15469. t['quotedbl'] = 555;
  15470. t['numbersign'] = 500;
  15471. t['dollar'] = 500;
  15472. t['percent'] = 1000;
  15473. t['ampersand'] = 833;
  15474. t['quoteright'] = 333;
  15475. t['parenleft'] = 333;
  15476. t['parenright'] = 333;
  15477. t['asterisk'] = 500;
  15478. t['plus'] = 570;
  15479. t['comma'] = 250;
  15480. t['hyphen'] = 333;
  15481. t['period'] = 250;
  15482. t['slash'] = 278;
  15483. t['zero'] = 500;
  15484. t['one'] = 500;
  15485. t['two'] = 500;
  15486. t['three'] = 500;
  15487. t['four'] = 500;
  15488. t['five'] = 500;
  15489. t['six'] = 500;
  15490. t['seven'] = 500;
  15491. t['eight'] = 500;
  15492. t['nine'] = 500;
  15493. t['colon'] = 333;
  15494. t['semicolon'] = 333;
  15495. t['less'] = 570;
  15496. t['equal'] = 570;
  15497. t['greater'] = 570;
  15498. t['question'] = 500;
  15499. t['at'] = 930;
  15500. t['A'] = 722;
  15501. t['B'] = 667;
  15502. t['C'] = 722;
  15503. t['D'] = 722;
  15504. t['E'] = 667;
  15505. t['F'] = 611;
  15506. t['G'] = 778;
  15507. t['H'] = 778;
  15508. t['I'] = 389;
  15509. t['J'] = 500;
  15510. t['K'] = 778;
  15511. t['L'] = 667;
  15512. t['M'] = 944;
  15513. t['N'] = 722;
  15514. t['O'] = 778;
  15515. t['P'] = 611;
  15516. t['Q'] = 778;
  15517. t['R'] = 722;
  15518. t['S'] = 556;
  15519. t['T'] = 667;
  15520. t['U'] = 722;
  15521. t['V'] = 722;
  15522. t['W'] = 1000;
  15523. t['X'] = 722;
  15524. t['Y'] = 722;
  15525. t['Z'] = 667;
  15526. t['bracketleft'] = 333;
  15527. t['backslash'] = 278;
  15528. t['bracketright'] = 333;
  15529. t['asciicircum'] = 581;
  15530. t['underscore'] = 500;
  15531. t['quoteleft'] = 333;
  15532. t['a'] = 500;
  15533. t['b'] = 556;
  15534. t['c'] = 444;
  15535. t['d'] = 556;
  15536. t['e'] = 444;
  15537. t['f'] = 333;
  15538. t['g'] = 500;
  15539. t['h'] = 556;
  15540. t['i'] = 278;
  15541. t['j'] = 333;
  15542. t['k'] = 556;
  15543. t['l'] = 278;
  15544. t['m'] = 833;
  15545. t['n'] = 556;
  15546. t['o'] = 500;
  15547. t['p'] = 556;
  15548. t['q'] = 556;
  15549. t['r'] = 444;
  15550. t['s'] = 389;
  15551. t['t'] = 333;
  15552. t['u'] = 556;
  15553. t['v'] = 500;
  15554. t['w'] = 722;
  15555. t['x'] = 500;
  15556. t['y'] = 500;
  15557. t['z'] = 444;
  15558. t['braceleft'] = 394;
  15559. t['bar'] = 220;
  15560. t['braceright'] = 394;
  15561. t['asciitilde'] = 520;
  15562. t['exclamdown'] = 333;
  15563. t['cent'] = 500;
  15564. t['sterling'] = 500;
  15565. t['fraction'] = 167;
  15566. t['yen'] = 500;
  15567. t['florin'] = 500;
  15568. t['section'] = 500;
  15569. t['currency'] = 500;
  15570. t['quotesingle'] = 278;
  15571. t['quotedblleft'] = 500;
  15572. t['guillemotleft'] = 500;
  15573. t['guilsinglleft'] = 333;
  15574. t['guilsinglright'] = 333;
  15575. t['fi'] = 556;
  15576. t['fl'] = 556;
  15577. t['endash'] = 500;
  15578. t['dagger'] = 500;
  15579. t['daggerdbl'] = 500;
  15580. t['periodcentered'] = 250;
  15581. t['paragraph'] = 540;
  15582. t['bullet'] = 350;
  15583. t['quotesinglbase'] = 333;
  15584. t['quotedblbase'] = 500;
  15585. t['quotedblright'] = 500;
  15586. t['guillemotright'] = 500;
  15587. t['ellipsis'] = 1000;
  15588. t['perthousand'] = 1000;
  15589. t['questiondown'] = 500;
  15590. t['grave'] = 333;
  15591. t['acute'] = 333;
  15592. t['circumflex'] = 333;
  15593. t['tilde'] = 333;
  15594. t['macron'] = 333;
  15595. t['breve'] = 333;
  15596. t['dotaccent'] = 333;
  15597. t['dieresis'] = 333;
  15598. t['ring'] = 333;
  15599. t['cedilla'] = 333;
  15600. t['hungarumlaut'] = 333;
  15601. t['ogonek'] = 333;
  15602. t['caron'] = 333;
  15603. t['emdash'] = 1000;
  15604. t['AE'] = 1000;
  15605. t['ordfeminine'] = 300;
  15606. t['Lslash'] = 667;
  15607. t['Oslash'] = 778;
  15608. t['OE'] = 1000;
  15609. t['ordmasculine'] = 330;
  15610. t['ae'] = 722;
  15611. t['dotlessi'] = 278;
  15612. t['lslash'] = 278;
  15613. t['oslash'] = 500;
  15614. t['oe'] = 722;
  15615. t['germandbls'] = 556;
  15616. t['Idieresis'] = 389;
  15617. t['eacute'] = 444;
  15618. t['abreve'] = 500;
  15619. t['uhungarumlaut'] = 556;
  15620. t['ecaron'] = 444;
  15621. t['Ydieresis'] = 722;
  15622. t['divide'] = 570;
  15623. t['Yacute'] = 722;
  15624. t['Acircumflex'] = 722;
  15625. t['aacute'] = 500;
  15626. t['Ucircumflex'] = 722;
  15627. t['yacute'] = 500;
  15628. t['scommaaccent'] = 389;
  15629. t['ecircumflex'] = 444;
  15630. t['Uring'] = 722;
  15631. t['Udieresis'] = 722;
  15632. t['aogonek'] = 500;
  15633. t['Uacute'] = 722;
  15634. t['uogonek'] = 556;
  15635. t['Edieresis'] = 667;
  15636. t['Dcroat'] = 722;
  15637. t['commaaccent'] = 250;
  15638. t['copyright'] = 747;
  15639. t['Emacron'] = 667;
  15640. t['ccaron'] = 444;
  15641. t['aring'] = 500;
  15642. t['Ncommaaccent'] = 722;
  15643. t['lacute'] = 278;
  15644. t['agrave'] = 500;
  15645. t['Tcommaaccent'] = 667;
  15646. t['Cacute'] = 722;
  15647. t['atilde'] = 500;
  15648. t['Edotaccent'] = 667;
  15649. t['scaron'] = 389;
  15650. t['scedilla'] = 389;
  15651. t['iacute'] = 278;
  15652. t['lozenge'] = 494;
  15653. t['Rcaron'] = 722;
  15654. t['Gcommaaccent'] = 778;
  15655. t['ucircumflex'] = 556;
  15656. t['acircumflex'] = 500;
  15657. t['Amacron'] = 722;
  15658. t['rcaron'] = 444;
  15659. t['ccedilla'] = 444;
  15660. t['Zdotaccent'] = 667;
  15661. t['Thorn'] = 611;
  15662. t['Omacron'] = 778;
  15663. t['Racute'] = 722;
  15664. t['Sacute'] = 556;
  15665. t['dcaron'] = 672;
  15666. t['Umacron'] = 722;
  15667. t['uring'] = 556;
  15668. t['threesuperior'] = 300;
  15669. t['Ograve'] = 778;
  15670. t['Agrave'] = 722;
  15671. t['Abreve'] = 722;
  15672. t['multiply'] = 570;
  15673. t['uacute'] = 556;
  15674. t['Tcaron'] = 667;
  15675. t['partialdiff'] = 494;
  15676. t['ydieresis'] = 500;
  15677. t['Nacute'] = 722;
  15678. t['icircumflex'] = 278;
  15679. t['Ecircumflex'] = 667;
  15680. t['adieresis'] = 500;
  15681. t['edieresis'] = 444;
  15682. t['cacute'] = 444;
  15683. t['nacute'] = 556;
  15684. t['umacron'] = 556;
  15685. t['Ncaron'] = 722;
  15686. t['Iacute'] = 389;
  15687. t['plusminus'] = 570;
  15688. t['brokenbar'] = 220;
  15689. t['registered'] = 747;
  15690. t['Gbreve'] = 778;
  15691. t['Idotaccent'] = 389;
  15692. t['summation'] = 600;
  15693. t['Egrave'] = 667;
  15694. t['racute'] = 444;
  15695. t['omacron'] = 500;
  15696. t['Zacute'] = 667;
  15697. t['Zcaron'] = 667;
  15698. t['greaterequal'] = 549;
  15699. t['Eth'] = 722;
  15700. t['Ccedilla'] = 722;
  15701. t['lcommaaccent'] = 278;
  15702. t['tcaron'] = 416;
  15703. t['eogonek'] = 444;
  15704. t['Uogonek'] = 722;
  15705. t['Aacute'] = 722;
  15706. t['Adieresis'] = 722;
  15707. t['egrave'] = 444;
  15708. t['zacute'] = 444;
  15709. t['iogonek'] = 278;
  15710. t['Oacute'] = 778;
  15711. t['oacute'] = 500;
  15712. t['amacron'] = 500;
  15713. t['sacute'] = 389;
  15714. t['idieresis'] = 278;
  15715. t['Ocircumflex'] = 778;
  15716. t['Ugrave'] = 722;
  15717. t['Delta'] = 612;
  15718. t['thorn'] = 556;
  15719. t['twosuperior'] = 300;
  15720. t['Odieresis'] = 778;
  15721. t['mu'] = 556;
  15722. t['igrave'] = 278;
  15723. t['ohungarumlaut'] = 500;
  15724. t['Eogonek'] = 667;
  15725. t['dcroat'] = 556;
  15726. t['threequarters'] = 750;
  15727. t['Scedilla'] = 556;
  15728. t['lcaron'] = 394;
  15729. t['Kcommaaccent'] = 778;
  15730. t['Lacute'] = 667;
  15731. t['trademark'] = 1000;
  15732. t['edotaccent'] = 444;
  15733. t['Igrave'] = 389;
  15734. t['Imacron'] = 389;
  15735. t['Lcaron'] = 667;
  15736. t['onehalf'] = 750;
  15737. t['lessequal'] = 549;
  15738. t['ocircumflex'] = 500;
  15739. t['ntilde'] = 556;
  15740. t['Uhungarumlaut'] = 722;
  15741. t['Eacute'] = 667;
  15742. t['emacron'] = 444;
  15743. t['gbreve'] = 500;
  15744. t['onequarter'] = 750;
  15745. t['Scaron'] = 556;
  15746. t['Scommaaccent'] = 556;
  15747. t['Ohungarumlaut'] = 778;
  15748. t['degree'] = 400;
  15749. t['ograve'] = 500;
  15750. t['Ccaron'] = 722;
  15751. t['ugrave'] = 556;
  15752. t['radical'] = 549;
  15753. t['Dcaron'] = 722;
  15754. t['rcommaaccent'] = 444;
  15755. t['Ntilde'] = 722;
  15756. t['otilde'] = 500;
  15757. t['Rcommaaccent'] = 722;
  15758. t['Lcommaaccent'] = 667;
  15759. t['Atilde'] = 722;
  15760. t['Aogonek'] = 722;
  15761. t['Aring'] = 722;
  15762. t['Otilde'] = 778;
  15763. t['zdotaccent'] = 444;
  15764. t['Ecaron'] = 667;
  15765. t['Iogonek'] = 389;
  15766. t['kcommaaccent'] = 556;
  15767. t['minus'] = 570;
  15768. t['Icircumflex'] = 389;
  15769. t['ncaron'] = 556;
  15770. t['tcommaaccent'] = 333;
  15771. t['logicalnot'] = 570;
  15772. t['odieresis'] = 500;
  15773. t['udieresis'] = 556;
  15774. t['notequal'] = 549;
  15775. t['gcommaaccent'] = 500;
  15776. t['eth'] = 500;
  15777. t['zcaron'] = 444;
  15778. t['ncommaaccent'] = 556;
  15779. t['onesuperior'] = 300;
  15780. t['imacron'] = 278;
  15781. t['Euro'] = 500;
  15782. });
  15783. t['Times-BoldItalic'] = getLookupTableFactory(function (t) {
  15784. t['space'] = 250;
  15785. t['exclam'] = 389;
  15786. t['quotedbl'] = 555;
  15787. t['numbersign'] = 500;
  15788. t['dollar'] = 500;
  15789. t['percent'] = 833;
  15790. t['ampersand'] = 778;
  15791. t['quoteright'] = 333;
  15792. t['parenleft'] = 333;
  15793. t['parenright'] = 333;
  15794. t['asterisk'] = 500;
  15795. t['plus'] = 570;
  15796. t['comma'] = 250;
  15797. t['hyphen'] = 333;
  15798. t['period'] = 250;
  15799. t['slash'] = 278;
  15800. t['zero'] = 500;
  15801. t['one'] = 500;
  15802. t['two'] = 500;
  15803. t['three'] = 500;
  15804. t['four'] = 500;
  15805. t['five'] = 500;
  15806. t['six'] = 500;
  15807. t['seven'] = 500;
  15808. t['eight'] = 500;
  15809. t['nine'] = 500;
  15810. t['colon'] = 333;
  15811. t['semicolon'] = 333;
  15812. t['less'] = 570;
  15813. t['equal'] = 570;
  15814. t['greater'] = 570;
  15815. t['question'] = 500;
  15816. t['at'] = 832;
  15817. t['A'] = 667;
  15818. t['B'] = 667;
  15819. t['C'] = 667;
  15820. t['D'] = 722;
  15821. t['E'] = 667;
  15822. t['F'] = 667;
  15823. t['G'] = 722;
  15824. t['H'] = 778;
  15825. t['I'] = 389;
  15826. t['J'] = 500;
  15827. t['K'] = 667;
  15828. t['L'] = 611;
  15829. t['M'] = 889;
  15830. t['N'] = 722;
  15831. t['O'] = 722;
  15832. t['P'] = 611;
  15833. t['Q'] = 722;
  15834. t['R'] = 667;
  15835. t['S'] = 556;
  15836. t['T'] = 611;
  15837. t['U'] = 722;
  15838. t['V'] = 667;
  15839. t['W'] = 889;
  15840. t['X'] = 667;
  15841. t['Y'] = 611;
  15842. t['Z'] = 611;
  15843. t['bracketleft'] = 333;
  15844. t['backslash'] = 278;
  15845. t['bracketright'] = 333;
  15846. t['asciicircum'] = 570;
  15847. t['underscore'] = 500;
  15848. t['quoteleft'] = 333;
  15849. t['a'] = 500;
  15850. t['b'] = 500;
  15851. t['c'] = 444;
  15852. t['d'] = 500;
  15853. t['e'] = 444;
  15854. t['f'] = 333;
  15855. t['g'] = 500;
  15856. t['h'] = 556;
  15857. t['i'] = 278;
  15858. t['j'] = 278;
  15859. t['k'] = 500;
  15860. t['l'] = 278;
  15861. t['m'] = 778;
  15862. t['n'] = 556;
  15863. t['o'] = 500;
  15864. t['p'] = 500;
  15865. t['q'] = 500;
  15866. t['r'] = 389;
  15867. t['s'] = 389;
  15868. t['t'] = 278;
  15869. t['u'] = 556;
  15870. t['v'] = 444;
  15871. t['w'] = 667;
  15872. t['x'] = 500;
  15873. t['y'] = 444;
  15874. t['z'] = 389;
  15875. t['braceleft'] = 348;
  15876. t['bar'] = 220;
  15877. t['braceright'] = 348;
  15878. t['asciitilde'] = 570;
  15879. t['exclamdown'] = 389;
  15880. t['cent'] = 500;
  15881. t['sterling'] = 500;
  15882. t['fraction'] = 167;
  15883. t['yen'] = 500;
  15884. t['florin'] = 500;
  15885. t['section'] = 500;
  15886. t['currency'] = 500;
  15887. t['quotesingle'] = 278;
  15888. t['quotedblleft'] = 500;
  15889. t['guillemotleft'] = 500;
  15890. t['guilsinglleft'] = 333;
  15891. t['guilsinglright'] = 333;
  15892. t['fi'] = 556;
  15893. t['fl'] = 556;
  15894. t['endash'] = 500;
  15895. t['dagger'] = 500;
  15896. t['daggerdbl'] = 500;
  15897. t['periodcentered'] = 250;
  15898. t['paragraph'] = 500;
  15899. t['bullet'] = 350;
  15900. t['quotesinglbase'] = 333;
  15901. t['quotedblbase'] = 500;
  15902. t['quotedblright'] = 500;
  15903. t['guillemotright'] = 500;
  15904. t['ellipsis'] = 1000;
  15905. t['perthousand'] = 1000;
  15906. t['questiondown'] = 500;
  15907. t['grave'] = 333;
  15908. t['acute'] = 333;
  15909. t['circumflex'] = 333;
  15910. t['tilde'] = 333;
  15911. t['macron'] = 333;
  15912. t['breve'] = 333;
  15913. t['dotaccent'] = 333;
  15914. t['dieresis'] = 333;
  15915. t['ring'] = 333;
  15916. t['cedilla'] = 333;
  15917. t['hungarumlaut'] = 333;
  15918. t['ogonek'] = 333;
  15919. t['caron'] = 333;
  15920. t['emdash'] = 1000;
  15921. t['AE'] = 944;
  15922. t['ordfeminine'] = 266;
  15923. t['Lslash'] = 611;
  15924. t['Oslash'] = 722;
  15925. t['OE'] = 944;
  15926. t['ordmasculine'] = 300;
  15927. t['ae'] = 722;
  15928. t['dotlessi'] = 278;
  15929. t['lslash'] = 278;
  15930. t['oslash'] = 500;
  15931. t['oe'] = 722;
  15932. t['germandbls'] = 500;
  15933. t['Idieresis'] = 389;
  15934. t['eacute'] = 444;
  15935. t['abreve'] = 500;
  15936. t['uhungarumlaut'] = 556;
  15937. t['ecaron'] = 444;
  15938. t['Ydieresis'] = 611;
  15939. t['divide'] = 570;
  15940. t['Yacute'] = 611;
  15941. t['Acircumflex'] = 667;
  15942. t['aacute'] = 500;
  15943. t['Ucircumflex'] = 722;
  15944. t['yacute'] = 444;
  15945. t['scommaaccent'] = 389;
  15946. t['ecircumflex'] = 444;
  15947. t['Uring'] = 722;
  15948. t['Udieresis'] = 722;
  15949. t['aogonek'] = 500;
  15950. t['Uacute'] = 722;
  15951. t['uogonek'] = 556;
  15952. t['Edieresis'] = 667;
  15953. t['Dcroat'] = 722;
  15954. t['commaaccent'] = 250;
  15955. t['copyright'] = 747;
  15956. t['Emacron'] = 667;
  15957. t['ccaron'] = 444;
  15958. t['aring'] = 500;
  15959. t['Ncommaaccent'] = 722;
  15960. t['lacute'] = 278;
  15961. t['agrave'] = 500;
  15962. t['Tcommaaccent'] = 611;
  15963. t['Cacute'] = 667;
  15964. t['atilde'] = 500;
  15965. t['Edotaccent'] = 667;
  15966. t['scaron'] = 389;
  15967. t['scedilla'] = 389;
  15968. t['iacute'] = 278;
  15969. t['lozenge'] = 494;
  15970. t['Rcaron'] = 667;
  15971. t['Gcommaaccent'] = 722;
  15972. t['ucircumflex'] = 556;
  15973. t['acircumflex'] = 500;
  15974. t['Amacron'] = 667;
  15975. t['rcaron'] = 389;
  15976. t['ccedilla'] = 444;
  15977. t['Zdotaccent'] = 611;
  15978. t['Thorn'] = 611;
  15979. t['Omacron'] = 722;
  15980. t['Racute'] = 667;
  15981. t['Sacute'] = 556;
  15982. t['dcaron'] = 608;
  15983. t['Umacron'] = 722;
  15984. t['uring'] = 556;
  15985. t['threesuperior'] = 300;
  15986. t['Ograve'] = 722;
  15987. t['Agrave'] = 667;
  15988. t['Abreve'] = 667;
  15989. t['multiply'] = 570;
  15990. t['uacute'] = 556;
  15991. t['Tcaron'] = 611;
  15992. t['partialdiff'] = 494;
  15993. t['ydieresis'] = 444;
  15994. t['Nacute'] = 722;
  15995. t['icircumflex'] = 278;
  15996. t['Ecircumflex'] = 667;
  15997. t['adieresis'] = 500;
  15998. t['edieresis'] = 444;
  15999. t['cacute'] = 444;
  16000. t['nacute'] = 556;
  16001. t['umacron'] = 556;
  16002. t['Ncaron'] = 722;
  16003. t['Iacute'] = 389;
  16004. t['plusminus'] = 570;
  16005. t['brokenbar'] = 220;
  16006. t['registered'] = 747;
  16007. t['Gbreve'] = 722;
  16008. t['Idotaccent'] = 389;
  16009. t['summation'] = 600;
  16010. t['Egrave'] = 667;
  16011. t['racute'] = 389;
  16012. t['omacron'] = 500;
  16013. t['Zacute'] = 611;
  16014. t['Zcaron'] = 611;
  16015. t['greaterequal'] = 549;
  16016. t['Eth'] = 722;
  16017. t['Ccedilla'] = 667;
  16018. t['lcommaaccent'] = 278;
  16019. t['tcaron'] = 366;
  16020. t['eogonek'] = 444;
  16021. t['Uogonek'] = 722;
  16022. t['Aacute'] = 667;
  16023. t['Adieresis'] = 667;
  16024. t['egrave'] = 444;
  16025. t['zacute'] = 389;
  16026. t['iogonek'] = 278;
  16027. t['Oacute'] = 722;
  16028. t['oacute'] = 500;
  16029. t['amacron'] = 500;
  16030. t['sacute'] = 389;
  16031. t['idieresis'] = 278;
  16032. t['Ocircumflex'] = 722;
  16033. t['Ugrave'] = 722;
  16034. t['Delta'] = 612;
  16035. t['thorn'] = 500;
  16036. t['twosuperior'] = 300;
  16037. t['Odieresis'] = 722;
  16038. t['mu'] = 576;
  16039. t['igrave'] = 278;
  16040. t['ohungarumlaut'] = 500;
  16041. t['Eogonek'] = 667;
  16042. t['dcroat'] = 500;
  16043. t['threequarters'] = 750;
  16044. t['Scedilla'] = 556;
  16045. t['lcaron'] = 382;
  16046. t['Kcommaaccent'] = 667;
  16047. t['Lacute'] = 611;
  16048. t['trademark'] = 1000;
  16049. t['edotaccent'] = 444;
  16050. t['Igrave'] = 389;
  16051. t['Imacron'] = 389;
  16052. t['Lcaron'] = 611;
  16053. t['onehalf'] = 750;
  16054. t['lessequal'] = 549;
  16055. t['ocircumflex'] = 500;
  16056. t['ntilde'] = 556;
  16057. t['Uhungarumlaut'] = 722;
  16058. t['Eacute'] = 667;
  16059. t['emacron'] = 444;
  16060. t['gbreve'] = 500;
  16061. t['onequarter'] = 750;
  16062. t['Scaron'] = 556;
  16063. t['Scommaaccent'] = 556;
  16064. t['Ohungarumlaut'] = 722;
  16065. t['degree'] = 400;
  16066. t['ograve'] = 500;
  16067. t['Ccaron'] = 667;
  16068. t['ugrave'] = 556;
  16069. t['radical'] = 549;
  16070. t['Dcaron'] = 722;
  16071. t['rcommaaccent'] = 389;
  16072. t['Ntilde'] = 722;
  16073. t['otilde'] = 500;
  16074. t['Rcommaaccent'] = 667;
  16075. t['Lcommaaccent'] = 611;
  16076. t['Atilde'] = 667;
  16077. t['Aogonek'] = 667;
  16078. t['Aring'] = 667;
  16079. t['Otilde'] = 722;
  16080. t['zdotaccent'] = 389;
  16081. t['Ecaron'] = 667;
  16082. t['Iogonek'] = 389;
  16083. t['kcommaaccent'] = 500;
  16084. t['minus'] = 606;
  16085. t['Icircumflex'] = 389;
  16086. t['ncaron'] = 556;
  16087. t['tcommaaccent'] = 278;
  16088. t['logicalnot'] = 606;
  16089. t['odieresis'] = 500;
  16090. t['udieresis'] = 556;
  16091. t['notequal'] = 549;
  16092. t['gcommaaccent'] = 500;
  16093. t['eth'] = 500;
  16094. t['zcaron'] = 389;
  16095. t['ncommaaccent'] = 556;
  16096. t['onesuperior'] = 300;
  16097. t['imacron'] = 278;
  16098. t['Euro'] = 500;
  16099. });
  16100. t['Times-Italic'] = getLookupTableFactory(function (t) {
  16101. t['space'] = 250;
  16102. t['exclam'] = 333;
  16103. t['quotedbl'] = 420;
  16104. t['numbersign'] = 500;
  16105. t['dollar'] = 500;
  16106. t['percent'] = 833;
  16107. t['ampersand'] = 778;
  16108. t['quoteright'] = 333;
  16109. t['parenleft'] = 333;
  16110. t['parenright'] = 333;
  16111. t['asterisk'] = 500;
  16112. t['plus'] = 675;
  16113. t['comma'] = 250;
  16114. t['hyphen'] = 333;
  16115. t['period'] = 250;
  16116. t['slash'] = 278;
  16117. t['zero'] = 500;
  16118. t['one'] = 500;
  16119. t['two'] = 500;
  16120. t['three'] = 500;
  16121. t['four'] = 500;
  16122. t['five'] = 500;
  16123. t['six'] = 500;
  16124. t['seven'] = 500;
  16125. t['eight'] = 500;
  16126. t['nine'] = 500;
  16127. t['colon'] = 333;
  16128. t['semicolon'] = 333;
  16129. t['less'] = 675;
  16130. t['equal'] = 675;
  16131. t['greater'] = 675;
  16132. t['question'] = 500;
  16133. t['at'] = 920;
  16134. t['A'] = 611;
  16135. t['B'] = 611;
  16136. t['C'] = 667;
  16137. t['D'] = 722;
  16138. t['E'] = 611;
  16139. t['F'] = 611;
  16140. t['G'] = 722;
  16141. t['H'] = 722;
  16142. t['I'] = 333;
  16143. t['J'] = 444;
  16144. t['K'] = 667;
  16145. t['L'] = 556;
  16146. t['M'] = 833;
  16147. t['N'] = 667;
  16148. t['O'] = 722;
  16149. t['P'] = 611;
  16150. t['Q'] = 722;
  16151. t['R'] = 611;
  16152. t['S'] = 500;
  16153. t['T'] = 556;
  16154. t['U'] = 722;
  16155. t['V'] = 611;
  16156. t['W'] = 833;
  16157. t['X'] = 611;
  16158. t['Y'] = 556;
  16159. t['Z'] = 556;
  16160. t['bracketleft'] = 389;
  16161. t['backslash'] = 278;
  16162. t['bracketright'] = 389;
  16163. t['asciicircum'] = 422;
  16164. t['underscore'] = 500;
  16165. t['quoteleft'] = 333;
  16166. t['a'] = 500;
  16167. t['b'] = 500;
  16168. t['c'] = 444;
  16169. t['d'] = 500;
  16170. t['e'] = 444;
  16171. t['f'] = 278;
  16172. t['g'] = 500;
  16173. t['h'] = 500;
  16174. t['i'] = 278;
  16175. t['j'] = 278;
  16176. t['k'] = 444;
  16177. t['l'] = 278;
  16178. t['m'] = 722;
  16179. t['n'] = 500;
  16180. t['o'] = 500;
  16181. t['p'] = 500;
  16182. t['q'] = 500;
  16183. t['r'] = 389;
  16184. t['s'] = 389;
  16185. t['t'] = 278;
  16186. t['u'] = 500;
  16187. t['v'] = 444;
  16188. t['w'] = 667;
  16189. t['x'] = 444;
  16190. t['y'] = 444;
  16191. t['z'] = 389;
  16192. t['braceleft'] = 400;
  16193. t['bar'] = 275;
  16194. t['braceright'] = 400;
  16195. t['asciitilde'] = 541;
  16196. t['exclamdown'] = 389;
  16197. t['cent'] = 500;
  16198. t['sterling'] = 500;
  16199. t['fraction'] = 167;
  16200. t['yen'] = 500;
  16201. t['florin'] = 500;
  16202. t['section'] = 500;
  16203. t['currency'] = 500;
  16204. t['quotesingle'] = 214;
  16205. t['quotedblleft'] = 556;
  16206. t['guillemotleft'] = 500;
  16207. t['guilsinglleft'] = 333;
  16208. t['guilsinglright'] = 333;
  16209. t['fi'] = 500;
  16210. t['fl'] = 500;
  16211. t['endash'] = 500;
  16212. t['dagger'] = 500;
  16213. t['daggerdbl'] = 500;
  16214. t['periodcentered'] = 250;
  16215. t['paragraph'] = 523;
  16216. t['bullet'] = 350;
  16217. t['quotesinglbase'] = 333;
  16218. t['quotedblbase'] = 556;
  16219. t['quotedblright'] = 556;
  16220. t['guillemotright'] = 500;
  16221. t['ellipsis'] = 889;
  16222. t['perthousand'] = 1000;
  16223. t['questiondown'] = 500;
  16224. t['grave'] = 333;
  16225. t['acute'] = 333;
  16226. t['circumflex'] = 333;
  16227. t['tilde'] = 333;
  16228. t['macron'] = 333;
  16229. t['breve'] = 333;
  16230. t['dotaccent'] = 333;
  16231. t['dieresis'] = 333;
  16232. t['ring'] = 333;
  16233. t['cedilla'] = 333;
  16234. t['hungarumlaut'] = 333;
  16235. t['ogonek'] = 333;
  16236. t['caron'] = 333;
  16237. t['emdash'] = 889;
  16238. t['AE'] = 889;
  16239. t['ordfeminine'] = 276;
  16240. t['Lslash'] = 556;
  16241. t['Oslash'] = 722;
  16242. t['OE'] = 944;
  16243. t['ordmasculine'] = 310;
  16244. t['ae'] = 667;
  16245. t['dotlessi'] = 278;
  16246. t['lslash'] = 278;
  16247. t['oslash'] = 500;
  16248. t['oe'] = 667;
  16249. t['germandbls'] = 500;
  16250. t['Idieresis'] = 333;
  16251. t['eacute'] = 444;
  16252. t['abreve'] = 500;
  16253. t['uhungarumlaut'] = 500;
  16254. t['ecaron'] = 444;
  16255. t['Ydieresis'] = 556;
  16256. t['divide'] = 675;
  16257. t['Yacute'] = 556;
  16258. t['Acircumflex'] = 611;
  16259. t['aacute'] = 500;
  16260. t['Ucircumflex'] = 722;
  16261. t['yacute'] = 444;
  16262. t['scommaaccent'] = 389;
  16263. t['ecircumflex'] = 444;
  16264. t['Uring'] = 722;
  16265. t['Udieresis'] = 722;
  16266. t['aogonek'] = 500;
  16267. t['Uacute'] = 722;
  16268. t['uogonek'] = 500;
  16269. t['Edieresis'] = 611;
  16270. t['Dcroat'] = 722;
  16271. t['commaaccent'] = 250;
  16272. t['copyright'] = 760;
  16273. t['Emacron'] = 611;
  16274. t['ccaron'] = 444;
  16275. t['aring'] = 500;
  16276. t['Ncommaaccent'] = 667;
  16277. t['lacute'] = 278;
  16278. t['agrave'] = 500;
  16279. t['Tcommaaccent'] = 556;
  16280. t['Cacute'] = 667;
  16281. t['atilde'] = 500;
  16282. t['Edotaccent'] = 611;
  16283. t['scaron'] = 389;
  16284. t['scedilla'] = 389;
  16285. t['iacute'] = 278;
  16286. t['lozenge'] = 471;
  16287. t['Rcaron'] = 611;
  16288. t['Gcommaaccent'] = 722;
  16289. t['ucircumflex'] = 500;
  16290. t['acircumflex'] = 500;
  16291. t['Amacron'] = 611;
  16292. t['rcaron'] = 389;
  16293. t['ccedilla'] = 444;
  16294. t['Zdotaccent'] = 556;
  16295. t['Thorn'] = 611;
  16296. t['Omacron'] = 722;
  16297. t['Racute'] = 611;
  16298. t['Sacute'] = 500;
  16299. t['dcaron'] = 544;
  16300. t['Umacron'] = 722;
  16301. t['uring'] = 500;
  16302. t['threesuperior'] = 300;
  16303. t['Ograve'] = 722;
  16304. t['Agrave'] = 611;
  16305. t['Abreve'] = 611;
  16306. t['multiply'] = 675;
  16307. t['uacute'] = 500;
  16308. t['Tcaron'] = 556;
  16309. t['partialdiff'] = 476;
  16310. t['ydieresis'] = 444;
  16311. t['Nacute'] = 667;
  16312. t['icircumflex'] = 278;
  16313. t['Ecircumflex'] = 611;
  16314. t['adieresis'] = 500;
  16315. t['edieresis'] = 444;
  16316. t['cacute'] = 444;
  16317. t['nacute'] = 500;
  16318. t['umacron'] = 500;
  16319. t['Ncaron'] = 667;
  16320. t['Iacute'] = 333;
  16321. t['plusminus'] = 675;
  16322. t['brokenbar'] = 275;
  16323. t['registered'] = 760;
  16324. t['Gbreve'] = 722;
  16325. t['Idotaccent'] = 333;
  16326. t['summation'] = 600;
  16327. t['Egrave'] = 611;
  16328. t['racute'] = 389;
  16329. t['omacron'] = 500;
  16330. t['Zacute'] = 556;
  16331. t['Zcaron'] = 556;
  16332. t['greaterequal'] = 549;
  16333. t['Eth'] = 722;
  16334. t['Ccedilla'] = 667;
  16335. t['lcommaaccent'] = 278;
  16336. t['tcaron'] = 300;
  16337. t['eogonek'] = 444;
  16338. t['Uogonek'] = 722;
  16339. t['Aacute'] = 611;
  16340. t['Adieresis'] = 611;
  16341. t['egrave'] = 444;
  16342. t['zacute'] = 389;
  16343. t['iogonek'] = 278;
  16344. t['Oacute'] = 722;
  16345. t['oacute'] = 500;
  16346. t['amacron'] = 500;
  16347. t['sacute'] = 389;
  16348. t['idieresis'] = 278;
  16349. t['Ocircumflex'] = 722;
  16350. t['Ugrave'] = 722;
  16351. t['Delta'] = 612;
  16352. t['thorn'] = 500;
  16353. t['twosuperior'] = 300;
  16354. t['Odieresis'] = 722;
  16355. t['mu'] = 500;
  16356. t['igrave'] = 278;
  16357. t['ohungarumlaut'] = 500;
  16358. t['Eogonek'] = 611;
  16359. t['dcroat'] = 500;
  16360. t['threequarters'] = 750;
  16361. t['Scedilla'] = 500;
  16362. t['lcaron'] = 300;
  16363. t['Kcommaaccent'] = 667;
  16364. t['Lacute'] = 556;
  16365. t['trademark'] = 980;
  16366. t['edotaccent'] = 444;
  16367. t['Igrave'] = 333;
  16368. t['Imacron'] = 333;
  16369. t['Lcaron'] = 611;
  16370. t['onehalf'] = 750;
  16371. t['lessequal'] = 549;
  16372. t['ocircumflex'] = 500;
  16373. t['ntilde'] = 500;
  16374. t['Uhungarumlaut'] = 722;
  16375. t['Eacute'] = 611;
  16376. t['emacron'] = 444;
  16377. t['gbreve'] = 500;
  16378. t['onequarter'] = 750;
  16379. t['Scaron'] = 500;
  16380. t['Scommaaccent'] = 500;
  16381. t['Ohungarumlaut'] = 722;
  16382. t['degree'] = 400;
  16383. t['ograve'] = 500;
  16384. t['Ccaron'] = 667;
  16385. t['ugrave'] = 500;
  16386. t['radical'] = 453;
  16387. t['Dcaron'] = 722;
  16388. t['rcommaaccent'] = 389;
  16389. t['Ntilde'] = 667;
  16390. t['otilde'] = 500;
  16391. t['Rcommaaccent'] = 611;
  16392. t['Lcommaaccent'] = 556;
  16393. t['Atilde'] = 611;
  16394. t['Aogonek'] = 611;
  16395. t['Aring'] = 611;
  16396. t['Otilde'] = 722;
  16397. t['zdotaccent'] = 389;
  16398. t['Ecaron'] = 611;
  16399. t['Iogonek'] = 333;
  16400. t['kcommaaccent'] = 444;
  16401. t['minus'] = 675;
  16402. t['Icircumflex'] = 333;
  16403. t['ncaron'] = 500;
  16404. t['tcommaaccent'] = 278;
  16405. t['logicalnot'] = 675;
  16406. t['odieresis'] = 500;
  16407. t['udieresis'] = 500;
  16408. t['notequal'] = 549;
  16409. t['gcommaaccent'] = 500;
  16410. t['eth'] = 500;
  16411. t['zcaron'] = 389;
  16412. t['ncommaaccent'] = 500;
  16413. t['onesuperior'] = 300;
  16414. t['imacron'] = 278;
  16415. t['Euro'] = 500;
  16416. });
  16417. t['ZapfDingbats'] = getLookupTableFactory(function (t) {
  16418. t['space'] = 278;
  16419. t['a1'] = 974;
  16420. t['a2'] = 961;
  16421. t['a202'] = 974;
  16422. t['a3'] = 980;
  16423. t['a4'] = 719;
  16424. t['a5'] = 789;
  16425. t['a119'] = 790;
  16426. t['a118'] = 791;
  16427. t['a117'] = 690;
  16428. t['a11'] = 960;
  16429. t['a12'] = 939;
  16430. t['a13'] = 549;
  16431. t['a14'] = 855;
  16432. t['a15'] = 911;
  16433. t['a16'] = 933;
  16434. t['a105'] = 911;
  16435. t['a17'] = 945;
  16436. t['a18'] = 974;
  16437. t['a19'] = 755;
  16438. t['a20'] = 846;
  16439. t['a21'] = 762;
  16440. t['a22'] = 761;
  16441. t['a23'] = 571;
  16442. t['a24'] = 677;
  16443. t['a25'] = 763;
  16444. t['a26'] = 760;
  16445. t['a27'] = 759;
  16446. t['a28'] = 754;
  16447. t['a6'] = 494;
  16448. t['a7'] = 552;
  16449. t['a8'] = 537;
  16450. t['a9'] = 577;
  16451. t['a10'] = 692;
  16452. t['a29'] = 786;
  16453. t['a30'] = 788;
  16454. t['a31'] = 788;
  16455. t['a32'] = 790;
  16456. t['a33'] = 793;
  16457. t['a34'] = 794;
  16458. t['a35'] = 816;
  16459. t['a36'] = 823;
  16460. t['a37'] = 789;
  16461. t['a38'] = 841;
  16462. t['a39'] = 823;
  16463. t['a40'] = 833;
  16464. t['a41'] = 816;
  16465. t['a42'] = 831;
  16466. t['a43'] = 923;
  16467. t['a44'] = 744;
  16468. t['a45'] = 723;
  16469. t['a46'] = 749;
  16470. t['a47'] = 790;
  16471. t['a48'] = 792;
  16472. t['a49'] = 695;
  16473. t['a50'] = 776;
  16474. t['a51'] = 768;
  16475. t['a52'] = 792;
  16476. t['a53'] = 759;
  16477. t['a54'] = 707;
  16478. t['a55'] = 708;
  16479. t['a56'] = 682;
  16480. t['a57'] = 701;
  16481. t['a58'] = 826;
  16482. t['a59'] = 815;
  16483. t['a60'] = 789;
  16484. t['a61'] = 789;
  16485. t['a62'] = 707;
  16486. t['a63'] = 687;
  16487. t['a64'] = 696;
  16488. t['a65'] = 689;
  16489. t['a66'] = 786;
  16490. t['a67'] = 787;
  16491. t['a68'] = 713;
  16492. t['a69'] = 791;
  16493. t['a70'] = 785;
  16494. t['a71'] = 791;
  16495. t['a72'] = 873;
  16496. t['a73'] = 761;
  16497. t['a74'] = 762;
  16498. t['a203'] = 762;
  16499. t['a75'] = 759;
  16500. t['a204'] = 759;
  16501. t['a76'] = 892;
  16502. t['a77'] = 892;
  16503. t['a78'] = 788;
  16504. t['a79'] = 784;
  16505. t['a81'] = 438;
  16506. t['a82'] = 138;
  16507. t['a83'] = 277;
  16508. t['a84'] = 415;
  16509. t['a97'] = 392;
  16510. t['a98'] = 392;
  16511. t['a99'] = 668;
  16512. t['a100'] = 668;
  16513. t['a89'] = 390;
  16514. t['a90'] = 390;
  16515. t['a93'] = 317;
  16516. t['a94'] = 317;
  16517. t['a91'] = 276;
  16518. t['a92'] = 276;
  16519. t['a205'] = 509;
  16520. t['a85'] = 509;
  16521. t['a206'] = 410;
  16522. t['a86'] = 410;
  16523. t['a87'] = 234;
  16524. t['a88'] = 234;
  16525. t['a95'] = 334;
  16526. t['a96'] = 334;
  16527. t['a101'] = 732;
  16528. t['a102'] = 544;
  16529. t['a103'] = 544;
  16530. t['a104'] = 910;
  16531. t['a106'] = 667;
  16532. t['a107'] = 760;
  16533. t['a108'] = 760;
  16534. t['a112'] = 776;
  16535. t['a111'] = 595;
  16536. t['a110'] = 694;
  16537. t['a109'] = 626;
  16538. t['a120'] = 788;
  16539. t['a121'] = 788;
  16540. t['a122'] = 788;
  16541. t['a123'] = 788;
  16542. t['a124'] = 788;
  16543. t['a125'] = 788;
  16544. t['a126'] = 788;
  16545. t['a127'] = 788;
  16546. t['a128'] = 788;
  16547. t['a129'] = 788;
  16548. t['a130'] = 788;
  16549. t['a131'] = 788;
  16550. t['a132'] = 788;
  16551. t['a133'] = 788;
  16552. t['a134'] = 788;
  16553. t['a135'] = 788;
  16554. t['a136'] = 788;
  16555. t['a137'] = 788;
  16556. t['a138'] = 788;
  16557. t['a139'] = 788;
  16558. t['a140'] = 788;
  16559. t['a141'] = 788;
  16560. t['a142'] = 788;
  16561. t['a143'] = 788;
  16562. t['a144'] = 788;
  16563. t['a145'] = 788;
  16564. t['a146'] = 788;
  16565. t['a147'] = 788;
  16566. t['a148'] = 788;
  16567. t['a149'] = 788;
  16568. t['a150'] = 788;
  16569. t['a151'] = 788;
  16570. t['a152'] = 788;
  16571. t['a153'] = 788;
  16572. t['a154'] = 788;
  16573. t['a155'] = 788;
  16574. t['a156'] = 788;
  16575. t['a157'] = 788;
  16576. t['a158'] = 788;
  16577. t['a159'] = 788;
  16578. t['a160'] = 894;
  16579. t['a161'] = 838;
  16580. t['a163'] = 1016;
  16581. t['a164'] = 458;
  16582. t['a196'] = 748;
  16583. t['a165'] = 924;
  16584. t['a192'] = 748;
  16585. t['a166'] = 918;
  16586. t['a167'] = 927;
  16587. t['a168'] = 928;
  16588. t['a169'] = 928;
  16589. t['a170'] = 834;
  16590. t['a171'] = 873;
  16591. t['a172'] = 828;
  16592. t['a173'] = 924;
  16593. t['a162'] = 924;
  16594. t['a174'] = 917;
  16595. t['a175'] = 930;
  16596. t['a176'] = 931;
  16597. t['a177'] = 463;
  16598. t['a178'] = 883;
  16599. t['a179'] = 836;
  16600. t['a193'] = 836;
  16601. t['a180'] = 867;
  16602. t['a199'] = 867;
  16603. t['a181'] = 696;
  16604. t['a200'] = 696;
  16605. t['a182'] = 874;
  16606. t['a201'] = 874;
  16607. t['a183'] = 760;
  16608. t['a184'] = 946;
  16609. t['a197'] = 771;
  16610. t['a185'] = 865;
  16611. t['a194'] = 771;
  16612. t['a198'] = 888;
  16613. t['a186'] = 967;
  16614. t['a195'] = 888;
  16615. t['a187'] = 831;
  16616. t['a188'] = 873;
  16617. t['a189'] = 927;
  16618. t['a190'] = 970;
  16619. t['a191'] = 918;
  16620. });
  16621. });
  16622. exports.getMetrics = getMetrics;
  16623. }));
  16624. (function (root, factory) {
  16625. {
  16626. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  16627. }
  16628. }(this, function (exports, sharedUtil) {
  16629. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  16630. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  16631. // Workaround for missing math precision in JS.
  16632. var MASK_HIGH = 0xffff0000;
  16633. var MASK_LOW = 0xffff;
  16634. function MurmurHash3_64 (seed) {
  16635. var SEED = 0xc3d2e1f0;
  16636. this.h1 = seed ? seed & 0xffffffff : SEED;
  16637. this.h2 = seed ? seed & 0xffffffff : SEED;
  16638. }
  16639. var alwaysUseUint32ArrayView = false;
  16640. // old webkits have issues with non-aligned arrays
  16641. try {
  16642. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  16643. } catch (e) {
  16644. alwaysUseUint32ArrayView = true;
  16645. }
  16646. MurmurHash3_64.prototype = {
  16647. update: function MurmurHash3_64_update(input) {
  16648. var useUint32ArrayView = alwaysUseUint32ArrayView;
  16649. var i;
  16650. if (typeof input === 'string') {
  16651. var data = new Uint8Array(input.length * 2);
  16652. var length = 0;
  16653. for (i = 0; i < input.length; i++) {
  16654. var code = input.charCodeAt(i);
  16655. if (code <= 0xff) {
  16656. data[length++] = code;
  16657. }
  16658. else {
  16659. data[length++] = code >>> 8;
  16660. data[length++] = code & 0xff;
  16661. }
  16662. }
  16663. } else if (input instanceof Uint8Array) {
  16664. data = input;
  16665. length = data.length;
  16666. } else if (typeof input === 'object' && ('length' in input)) {
  16667. // processing regular arrays as well, e.g. for IE9
  16668. data = input;
  16669. length = data.length;
  16670. useUint32ArrayView = true;
  16671. } else {
  16672. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  16673. 'Input must be a string or array.');
  16674. }
  16675. var blockCounts = length >> 2;
  16676. var tailLength = length - blockCounts * 4;
  16677. // we don't care about endianness here
  16678. var dataUint32 = useUint32ArrayView ?
  16679. new Uint32ArrayView(data, blockCounts) :
  16680. new Uint32Array(data.buffer, 0, blockCounts);
  16681. var k1 = 0;
  16682. var k2 = 0;
  16683. var h1 = this.h1;
  16684. var h2 = this.h2;
  16685. var C1 = 0xcc9e2d51;
  16686. var C2 = 0x1b873593;
  16687. var C1_LOW = C1 & MASK_LOW;
  16688. var C2_LOW = C2 & MASK_LOW;
  16689. for (i = 0; i < blockCounts; i++) {
  16690. if (i & 1) {
  16691. k1 = dataUint32[i];
  16692. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  16693. k1 = k1 << 15 | k1 >>> 17;
  16694. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  16695. h1 ^= k1;
  16696. h1 = h1 << 13 | h1 >>> 19;
  16697. h1 = h1 * 5 + 0xe6546b64;
  16698. } else {
  16699. k2 = dataUint32[i];
  16700. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  16701. k2 = k2 << 15 | k2 >>> 17;
  16702. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  16703. h2 ^= k2;
  16704. h2 = h2 << 13 | h2 >>> 19;
  16705. h2 = h2 * 5 + 0xe6546b64;
  16706. }
  16707. }
  16708. k1 = 0;
  16709. switch (tailLength) {
  16710. case 3:
  16711. k1 ^= data[blockCounts * 4 + 2] << 16;
  16712. /* falls through */
  16713. case 2:
  16714. k1 ^= data[blockCounts * 4 + 1] << 8;
  16715. /* falls through */
  16716. case 1:
  16717. k1 ^= data[blockCounts * 4];
  16718. /* falls through */
  16719. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  16720. k1 = k1 << 15 | k1 >>> 17;
  16721. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  16722. if (blockCounts & 1) {
  16723. h1 ^= k1;
  16724. } else {
  16725. h2 ^= k1;
  16726. }
  16727. }
  16728. this.h1 = h1;
  16729. this.h2 = h2;
  16730. return this;
  16731. },
  16732. hexdigest: function MurmurHash3_64_hexdigest () {
  16733. var h1 = this.h1;
  16734. var h2 = this.h2;
  16735. h1 ^= h2 >>> 1;
  16736. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  16737. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  16738. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  16739. h1 ^= h2 >>> 1;
  16740. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  16741. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  16742. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  16743. h1 ^= h2 >>> 1;
  16744. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  16745. var hex = (arr[i] >>> 0).toString(16);
  16746. while (hex.length < 8) {
  16747. hex = '0' + hex;
  16748. }
  16749. str += hex;
  16750. }
  16751. return str;
  16752. }
  16753. };
  16754. return MurmurHash3_64;
  16755. })();
  16756. exports.MurmurHash3_64 = MurmurHash3_64;
  16757. }));
  16758. (function (root, factory) {
  16759. {
  16760. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  16761. }
  16762. }(this, function (exports, sharedUtil) {
  16763. var isArray = sharedUtil.isArray;
  16764. var Name = (function NameClosure() {
  16765. function Name(name) {
  16766. this.name = name;
  16767. }
  16768. Name.prototype = {};
  16769. var nameCache = Object.create(null);
  16770. Name.get = function Name_get(name) {
  16771. var nameValue = nameCache[name];
  16772. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  16773. };
  16774. return Name;
  16775. })();
  16776. var Cmd = (function CmdClosure() {
  16777. function Cmd(cmd) {
  16778. this.cmd = cmd;
  16779. }
  16780. Cmd.prototype = {};
  16781. var cmdCache = Object.create(null);
  16782. Cmd.get = function Cmd_get(cmd) {
  16783. var cmdValue = cmdCache[cmd];
  16784. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  16785. };
  16786. return Cmd;
  16787. })();
  16788. var Dict = (function DictClosure() {
  16789. var nonSerializable = function nonSerializableClosure() {
  16790. return nonSerializable; // creating closure on some variable
  16791. };
  16792. // xref is optional
  16793. function Dict(xref) {
  16794. // Map should only be used internally, use functions below to access.
  16795. this.map = Object.create(null);
  16796. this.xref = xref;
  16797. this.objId = null;
  16798. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  16799. }
  16800. Dict.prototype = {
  16801. assignXref: function Dict_assignXref(newXref) {
  16802. this.xref = newXref;
  16803. },
  16804. // automatically dereferences Ref objects
  16805. get: function Dict_get(key1, key2, key3) {
  16806. var value;
  16807. var xref = this.xref;
  16808. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  16809. typeof key2 === 'undefined') {
  16810. return xref ? xref.fetchIfRef(value) : value;
  16811. }
  16812. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  16813. typeof key3 === 'undefined') {
  16814. return xref ? xref.fetchIfRef(value) : value;
  16815. }
  16816. value = this.map[key3] || null;
  16817. return xref ? xref.fetchIfRef(value) : value;
  16818. },
  16819. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  16820. getAsync: function Dict_getAsync(key1, key2, key3) {
  16821. var value;
  16822. var xref = this.xref;
  16823. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  16824. typeof key2 === 'undefined') {
  16825. if (xref) {
  16826. return xref.fetchIfRefAsync(value);
  16827. }
  16828. return Promise.resolve(value);
  16829. }
  16830. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  16831. typeof key3 === 'undefined') {
  16832. if (xref) {
  16833. return xref.fetchIfRefAsync(value);
  16834. }
  16835. return Promise.resolve(value);
  16836. }
  16837. value = this.map[key3] || null;
  16838. if (xref) {
  16839. return xref.fetchIfRefAsync(value);
  16840. }
  16841. return Promise.resolve(value);
  16842. },
  16843. // Same as get(), but dereferences all elements if the result is an Array.
  16844. getArray: function Dict_getArray(key1, key2, key3) {
  16845. var value = this.get(key1, key2, key3);
  16846. var xref = this.xref;
  16847. if (!isArray(value) || !xref) {
  16848. return value;
  16849. }
  16850. value = value.slice(); // Ensure that we don't modify the Dict data.
  16851. for (var i = 0, ii = value.length; i < ii; i++) {
  16852. if (!isRef(value[i])) {
  16853. continue;
  16854. }
  16855. value[i] = xref.fetch(value[i]);
  16856. }
  16857. return value;
  16858. },
  16859. // no dereferencing
  16860. getRaw: function Dict_getRaw(key) {
  16861. return this.map[key];
  16862. },
  16863. getKeys: function Dict_getKeys() {
  16864. return Object.keys(this.map);
  16865. },
  16866. set: function Dict_set(key, value) {
  16867. this.map[key] = value;
  16868. },
  16869. has: function Dict_has(key) {
  16870. return key in this.map;
  16871. },
  16872. forEach: function Dict_forEach(callback) {
  16873. for (var key in this.map) {
  16874. callback(key, this.get(key));
  16875. }
  16876. }
  16877. };
  16878. Dict.empty = new Dict(null);
  16879. Dict.merge = function Dict_merge(xref, dictArray) {
  16880. var mergedDict = new Dict(xref);
  16881. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  16882. var dict = dictArray[i];
  16883. if (!isDict(dict)) {
  16884. continue;
  16885. }
  16886. for (var keyName in dict.map) {
  16887. if (mergedDict.map[keyName]) {
  16888. continue;
  16889. }
  16890. mergedDict.map[keyName] = dict.map[keyName];
  16891. }
  16892. }
  16893. return mergedDict;
  16894. };
  16895. return Dict;
  16896. })();
  16897. var Ref = (function RefClosure() {
  16898. function Ref(num, gen) {
  16899. this.num = num;
  16900. this.gen = gen;
  16901. }
  16902. Ref.prototype = {
  16903. toString: function Ref_toString() {
  16904. // This function is hot, so we make the string as compact as possible.
  16905. // |this.gen| is almost always zero, so we treat that case specially.
  16906. var str = this.num + 'R';
  16907. if (this.gen !== 0) {
  16908. str += this.gen;
  16909. }
  16910. return str;
  16911. }
  16912. };
  16913. return Ref;
  16914. })();
  16915. // The reference is identified by number and generation.
  16916. // This structure stores only one instance of the reference.
  16917. var RefSet = (function RefSetClosure() {
  16918. function RefSet() {
  16919. this.dict = Object.create(null);
  16920. }
  16921. RefSet.prototype = {
  16922. has: function RefSet_has(ref) {
  16923. return ref.toString() in this.dict;
  16924. },
  16925. put: function RefSet_put(ref) {
  16926. this.dict[ref.toString()] = true;
  16927. },
  16928. remove: function RefSet_remove(ref) {
  16929. delete this.dict[ref.toString()];
  16930. }
  16931. };
  16932. return RefSet;
  16933. })();
  16934. var RefSetCache = (function RefSetCacheClosure() {
  16935. function RefSetCache() {
  16936. this.dict = Object.create(null);
  16937. }
  16938. RefSetCache.prototype = {
  16939. get: function RefSetCache_get(ref) {
  16940. return this.dict[ref.toString()];
  16941. },
  16942. has: function RefSetCache_has(ref) {
  16943. return ref.toString() in this.dict;
  16944. },
  16945. put: function RefSetCache_put(ref, obj) {
  16946. this.dict[ref.toString()] = obj;
  16947. },
  16948. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  16949. this.dict[ref.toString()] = this.get(aliasRef);
  16950. },
  16951. forEach: function RefSetCache_forEach(fn, thisArg) {
  16952. for (var i in this.dict) {
  16953. fn.call(thisArg, this.dict[i]);
  16954. }
  16955. },
  16956. clear: function RefSetCache_clear() {
  16957. this.dict = Object.create(null);
  16958. }
  16959. };
  16960. return RefSetCache;
  16961. })();
  16962. function isName(v, name) {
  16963. return v instanceof Name && (name === undefined || v.name === name);
  16964. }
  16965. function isCmd(v, cmd) {
  16966. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  16967. }
  16968. function isDict(v, type) {
  16969. return v instanceof Dict &&
  16970. (type === undefined || isName(v.get('Type'), type));
  16971. }
  16972. function isRef(v) {
  16973. return v instanceof Ref;
  16974. }
  16975. function isRefsEqual(v1, v2) {
  16976. return v1.num === v2.num && v1.gen === v2.gen;
  16977. }
  16978. function isStream(v) {
  16979. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  16980. }
  16981. exports.Cmd = Cmd;
  16982. exports.Dict = Dict;
  16983. exports.Name = Name;
  16984. exports.Ref = Ref;
  16985. exports.RefSet = RefSet;
  16986. exports.RefSetCache = RefSetCache;
  16987. exports.isCmd = isCmd;
  16988. exports.isDict = isDict;
  16989. exports.isName = isName;
  16990. exports.isRef = isRef;
  16991. exports.isRefsEqual = isRefsEqual;
  16992. exports.isStream = isStream;
  16993. }));
  16994. (function (root, factory) {
  16995. {
  16996. factory((root.pdfjsCoreStandardFonts = {}), root.pdfjsSharedUtil);
  16997. }
  16998. }(this, function (exports, sharedUtil) {
  16999. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  17000. /**
  17001. * Hold a map of decoded fonts and of the standard fourteen Type1
  17002. * fonts and their acronyms.
  17003. */
  17004. var getStdFontMap = getLookupTableFactory(function (t) {
  17005. t['ArialNarrow'] = 'Helvetica';
  17006. t['ArialNarrow-Bold'] = 'Helvetica-Bold';
  17007. t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique';
  17008. t['ArialNarrow-Italic'] = 'Helvetica-Oblique';
  17009. t['ArialBlack'] = 'Helvetica';
  17010. t['ArialBlack-Bold'] = 'Helvetica-Bold';
  17011. t['ArialBlack-BoldItalic'] = 'Helvetica-BoldOblique';
  17012. t['ArialBlack-Italic'] = 'Helvetica-Oblique';
  17013. t['Arial'] = 'Helvetica';
  17014. t['Arial-Bold'] = 'Helvetica-Bold';
  17015. t['Arial-BoldItalic'] = 'Helvetica-BoldOblique';
  17016. t['Arial-Italic'] = 'Helvetica-Oblique';
  17017. t['Arial-BoldItalicMT'] = 'Helvetica-BoldOblique';
  17018. t['Arial-BoldMT'] = 'Helvetica-Bold';
  17019. t['Arial-ItalicMT'] = 'Helvetica-Oblique';
  17020. t['ArialMT'] = 'Helvetica';
  17021. t['Courier-Bold'] = 'Courier-Bold';
  17022. t['Courier-BoldItalic'] = 'Courier-BoldOblique';
  17023. t['Courier-Italic'] = 'Courier-Oblique';
  17024. t['CourierNew'] = 'Courier';
  17025. t['CourierNew-Bold'] = 'Courier-Bold';
  17026. t['CourierNew-BoldItalic'] = 'Courier-BoldOblique';
  17027. t['CourierNew-Italic'] = 'Courier-Oblique';
  17028. t['CourierNewPS-BoldItalicMT'] = 'Courier-BoldOblique';
  17029. t['CourierNewPS-BoldMT'] = 'Courier-Bold';
  17030. t['CourierNewPS-ItalicMT'] = 'Courier-Oblique';
  17031. t['CourierNewPSMT'] = 'Courier';
  17032. t['Helvetica'] = 'Helvetica';
  17033. t['Helvetica-Bold'] = 'Helvetica-Bold';
  17034. t['Helvetica-BoldItalic'] = 'Helvetica-BoldOblique';
  17035. t['Helvetica-BoldOblique'] = 'Helvetica-BoldOblique';
  17036. t['Helvetica-Italic'] = 'Helvetica-Oblique';
  17037. t['Helvetica-Oblique'] = 'Helvetica-Oblique';
  17038. t['Symbol-Bold'] = 'Symbol';
  17039. t['Symbol-BoldItalic'] = 'Symbol';
  17040. t['Symbol-Italic'] = 'Symbol';
  17041. t['TimesNewRoman'] = 'Times-Roman';
  17042. t['TimesNewRoman-Bold'] = 'Times-Bold';
  17043. t['TimesNewRoman-BoldItalic'] = 'Times-BoldItalic';
  17044. t['TimesNewRoman-Italic'] = 'Times-Italic';
  17045. t['TimesNewRomanPS'] = 'Times-Roman';
  17046. t['TimesNewRomanPS-Bold'] = 'Times-Bold';
  17047. t['TimesNewRomanPS-BoldItalic'] = 'Times-BoldItalic';
  17048. t['TimesNewRomanPS-BoldItalicMT'] = 'Times-BoldItalic';
  17049. t['TimesNewRomanPS-BoldMT'] = 'Times-Bold';
  17050. t['TimesNewRomanPS-Italic'] = 'Times-Italic';
  17051. t['TimesNewRomanPS-ItalicMT'] = 'Times-Italic';
  17052. t['TimesNewRomanPSMT'] = 'Times-Roman';
  17053. t['TimesNewRomanPSMT-Bold'] = 'Times-Bold';
  17054. t['TimesNewRomanPSMT-BoldItalic'] = 'Times-BoldItalic';
  17055. t['TimesNewRomanPSMT-Italic'] = 'Times-Italic';
  17056. });
  17057. /**
  17058. * Holds the map of the non-standard fonts that might be included as
  17059. * a standard fonts without glyph data.
  17060. */
  17061. var getNonStdFontMap = getLookupTableFactory(function (t) {
  17062. t['CenturyGothic'] = 'Helvetica';
  17063. t['CenturyGothic-Bold'] = 'Helvetica-Bold';
  17064. t['CenturyGothic-BoldItalic'] = 'Helvetica-BoldOblique';
  17065. t['CenturyGothic-Italic'] = 'Helvetica-Oblique';
  17066. t['ComicSansMS'] = 'Comic Sans MS';
  17067. t['ComicSansMS-Bold'] = 'Comic Sans MS-Bold';
  17068. t['ComicSansMS-BoldItalic'] = 'Comic Sans MS-BoldItalic';
  17069. t['ComicSansMS-Italic'] = 'Comic Sans MS-Italic';
  17070. t['LucidaConsole'] = 'Courier';
  17071. t['LucidaConsole-Bold'] = 'Courier-Bold';
  17072. t['LucidaConsole-BoldItalic'] = 'Courier-BoldOblique';
  17073. t['LucidaConsole-Italic'] = 'Courier-Oblique';
  17074. t['MS-Gothic'] = 'MS Gothic';
  17075. t['MS-Gothic-Bold'] = 'MS Gothic-Bold';
  17076. t['MS-Gothic-BoldItalic'] = 'MS Gothic-BoldItalic';
  17077. t['MS-Gothic-Italic'] = 'MS Gothic-Italic';
  17078. t['MS-Mincho'] = 'MS Mincho';
  17079. t['MS-Mincho-Bold'] = 'MS Mincho-Bold';
  17080. t['MS-Mincho-BoldItalic'] = 'MS Mincho-BoldItalic';
  17081. t['MS-Mincho-Italic'] = 'MS Mincho-Italic';
  17082. t['MS-PGothic'] = 'MS PGothic';
  17083. t['MS-PGothic-Bold'] = 'MS PGothic-Bold';
  17084. t['MS-PGothic-BoldItalic'] = 'MS PGothic-BoldItalic';
  17085. t['MS-PGothic-Italic'] = 'MS PGothic-Italic';
  17086. t['MS-PMincho'] = 'MS PMincho';
  17087. t['MS-PMincho-Bold'] = 'MS PMincho-Bold';
  17088. t['MS-PMincho-BoldItalic'] = 'MS PMincho-BoldItalic';
  17089. t['MS-PMincho-Italic'] = 'MS PMincho-Italic';
  17090. t['Wingdings'] = 'ZapfDingbats';
  17091. });
  17092. var getSerifFonts = getLookupTableFactory(function (t) {
  17093. t['Adobe Jenson'] = true;
  17094. t['Adobe Text'] = true;
  17095. t['Albertus'] = true;
  17096. t['Aldus'] = true;
  17097. t['Alexandria'] = true;
  17098. t['Algerian'] = true;
  17099. t['American Typewriter'] = true;
  17100. t['Antiqua'] = true;
  17101. t['Apex'] = true;
  17102. t['Arno'] = true;
  17103. t['Aster'] = true;
  17104. t['Aurora'] = true;
  17105. t['Baskerville'] = true;
  17106. t['Bell'] = true;
  17107. t['Bembo'] = true;
  17108. t['Bembo Schoolbook'] = true;
  17109. t['Benguiat'] = true;
  17110. t['Berkeley Old Style'] = true;
  17111. t['Bernhard Modern'] = true;
  17112. t['Berthold City'] = true;
  17113. t['Bodoni'] = true;
  17114. t['Bauer Bodoni'] = true;
  17115. t['Book Antiqua'] = true;
  17116. t['Bookman'] = true;
  17117. t['Bordeaux Roman'] = true;
  17118. t['Californian FB'] = true;
  17119. t['Calisto'] = true;
  17120. t['Calvert'] = true;
  17121. t['Capitals'] = true;
  17122. t['Cambria'] = true;
  17123. t['Cartier'] = true;
  17124. t['Caslon'] = true;
  17125. t['Catull'] = true;
  17126. t['Centaur'] = true;
  17127. t['Century Old Style'] = true;
  17128. t['Century Schoolbook'] = true;
  17129. t['Chaparral'] = true;
  17130. t['Charis SIL'] = true;
  17131. t['Cheltenham'] = true;
  17132. t['Cholla Slab'] = true;
  17133. t['Clarendon'] = true;
  17134. t['Clearface'] = true;
  17135. t['Cochin'] = true;
  17136. t['Colonna'] = true;
  17137. t['Computer Modern'] = true;
  17138. t['Concrete Roman'] = true;
  17139. t['Constantia'] = true;
  17140. t['Cooper Black'] = true;
  17141. t['Corona'] = true;
  17142. t['Ecotype'] = true;
  17143. t['Egyptienne'] = true;
  17144. t['Elephant'] = true;
  17145. t['Excelsior'] = true;
  17146. t['Fairfield'] = true;
  17147. t['FF Scala'] = true;
  17148. t['Folkard'] = true;
  17149. t['Footlight'] = true;
  17150. t['FreeSerif'] = true;
  17151. t['Friz Quadrata'] = true;
  17152. t['Garamond'] = true;
  17153. t['Gentium'] = true;
  17154. t['Georgia'] = true;
  17155. t['Gloucester'] = true;
  17156. t['Goudy Old Style'] = true;
  17157. t['Goudy Schoolbook'] = true;
  17158. t['Goudy Pro Font'] = true;
  17159. t['Granjon'] = true;
  17160. t['Guardian Egyptian'] = true;
  17161. t['Heather'] = true;
  17162. t['Hercules'] = true;
  17163. t['High Tower Text'] = true;
  17164. t['Hiroshige'] = true;
  17165. t['Hoefler Text'] = true;
  17166. t['Humana Serif'] = true;
  17167. t['Imprint'] = true;
  17168. t['Ionic No. 5'] = true;
  17169. t['Janson'] = true;
  17170. t['Joanna'] = true;
  17171. t['Korinna'] = true;
  17172. t['Lexicon'] = true;
  17173. t['Liberation Serif'] = true;
  17174. t['Linux Libertine'] = true;
  17175. t['Literaturnaya'] = true;
  17176. t['Lucida'] = true;
  17177. t['Lucida Bright'] = true;
  17178. t['Melior'] = true;
  17179. t['Memphis'] = true;
  17180. t['Miller'] = true;
  17181. t['Minion'] = true;
  17182. t['Modern'] = true;
  17183. t['Mona Lisa'] = true;
  17184. t['Mrs Eaves'] = true;
  17185. t['MS Serif'] = true;
  17186. t['Museo Slab'] = true;
  17187. t['New York'] = true;
  17188. t['Nimbus Roman'] = true;
  17189. t['NPS Rawlinson Roadway'] = true;
  17190. t['Palatino'] = true;
  17191. t['Perpetua'] = true;
  17192. t['Plantin'] = true;
  17193. t['Plantin Schoolbook'] = true;
  17194. t['Playbill'] = true;
  17195. t['Poor Richard'] = true;
  17196. t['Rawlinson Roadway'] = true;
  17197. t['Renault'] = true;
  17198. t['Requiem'] = true;
  17199. t['Rockwell'] = true;
  17200. t['Roman'] = true;
  17201. t['Rotis Serif'] = true;
  17202. t['Sabon'] = true;
  17203. t['Scala'] = true;
  17204. t['Seagull'] = true;
  17205. t['Sistina'] = true;
  17206. t['Souvenir'] = true;
  17207. t['STIX'] = true;
  17208. t['Stone Informal'] = true;
  17209. t['Stone Serif'] = true;
  17210. t['Sylfaen'] = true;
  17211. t['Times'] = true;
  17212. t['Trajan'] = true;
  17213. t['Trinité'] = true;
  17214. t['Trump Mediaeval'] = true;
  17215. t['Utopia'] = true;
  17216. t['Vale Type'] = true;
  17217. t['Bitstream Vera'] = true;
  17218. t['Vera Serif'] = true;
  17219. t['Versailles'] = true;
  17220. t['Wanted'] = true;
  17221. t['Weiss'] = true;
  17222. t['Wide Latin'] = true;
  17223. t['Windsor'] = true;
  17224. t['XITS'] = true;
  17225. });
  17226. var getSymbolsFonts = getLookupTableFactory(function (t) {
  17227. t['Dingbats'] = true;
  17228. t['Symbol'] = true;
  17229. t['ZapfDingbats'] = true;
  17230. });
  17231. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
  17232. // fonts, but does not embed the CID to GID mapping. The mapping is incomplete
  17233. // for all glyphs, but common for some set of the standard fonts.
  17234. var getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  17235. t[2] = 10; t[3] = 32; t[4] = 33; t[5] = 34; t[6] = 35; t[7] = 36; t[8] = 37;
  17236. t[9] = 38; t[10] = 39; t[11] = 40; t[12] = 41; t[13] = 42; t[14] = 43;
  17237. t[15] = 44; t[16] = 45; t[17] = 46; t[18] = 47; t[19] = 48; t[20] = 49;
  17238. t[21] = 50; t[22] = 51; t[23] = 52; t[24] = 53; t[25] = 54; t[26] = 55;
  17239. t[27] = 56; t[28] = 57; t[29] = 58; t[30] = 894; t[31] = 60; t[32] = 61;
  17240. t[33] = 62; t[34] = 63; t[35] = 64; t[36] = 65; t[37] = 66; t[38] = 67;
  17241. t[39] = 68; t[40] = 69; t[41] = 70; t[42] = 71; t[43] = 72; t[44] = 73;
  17242. t[45] = 74; t[46] = 75; t[47] = 76; t[48] = 77; t[49] = 78; t[50] = 79;
  17243. t[51] = 80; t[52] = 81; t[53] = 82; t[54] = 83; t[55] = 84; t[56] = 85;
  17244. t[57] = 86; t[58] = 87; t[59] = 88; t[60] = 89; t[61] = 90; t[62] = 91;
  17245. t[63] = 92; t[64] = 93; t[65] = 94; t[66] = 95; t[67] = 96; t[68] = 97;
  17246. t[69] = 98; t[70] = 99; t[71] = 100; t[72] = 101; t[73] = 102; t[74] = 103;
  17247. t[75] = 104; t[76] = 105; t[77] = 106; t[78] = 107; t[79] = 108;
  17248. t[80] = 109; t[81] = 110; t[82] = 111; t[83] = 112; t[84] = 113;
  17249. t[85] = 114; t[86] = 115; t[87] = 116; t[88] = 117; t[89] = 118;
  17250. t[90] = 119; t[91] = 120; t[92] = 121; t[93] = 122; t[94] = 123;
  17251. t[95] = 124; t[96] = 125; t[97] = 126; t[98] = 196; t[99] = 197;
  17252. t[100] = 199; t[101] = 201; t[102] = 209; t[103] = 214; t[104] = 220;
  17253. t[105] = 225; t[106] = 224; t[107] = 226; t[108] = 228; t[109] = 227;
  17254. t[110] = 229; t[111] = 231; t[112] = 233; t[113] = 232; t[114] = 234;
  17255. t[115] = 235; t[116] = 237; t[117] = 236; t[118] = 238; t[119] = 239;
  17256. t[120] = 241; t[121] = 243; t[122] = 242; t[123] = 244; t[124] = 246;
  17257. t[125] = 245; t[126] = 250; t[127] = 249; t[128] = 251; t[129] = 252;
  17258. t[130] = 8224; t[131] = 176; t[132] = 162; t[133] = 163; t[134] = 167;
  17259. t[135] = 8226; t[136] = 182; t[137] = 223; t[138] = 174; t[139] = 169;
  17260. t[140] = 8482; t[141] = 180; t[142] = 168; t[143] = 8800; t[144] = 198;
  17261. t[145] = 216; t[146] = 8734; t[147] = 177; t[148] = 8804; t[149] = 8805;
  17262. t[150] = 165; t[151] = 181; t[152] = 8706; t[153] = 8721; t[154] = 8719;
  17263. t[156] = 8747; t[157] = 170; t[158] = 186; t[159] = 8486; t[160] = 230;
  17264. t[161] = 248; t[162] = 191; t[163] = 161; t[164] = 172; t[165] = 8730;
  17265. t[166] = 402; t[167] = 8776; t[168] = 8710; t[169] = 171; t[170] = 187;
  17266. t[171] = 8230; t[210] = 218; t[223] = 711; t[224] = 321; t[225] = 322;
  17267. t[227] = 353; t[229] = 382; t[234] = 253; t[252] = 263; t[253] = 268;
  17268. t[254] = 269; t[258] = 258; t[260] = 260; t[261] = 261; t[265] = 280;
  17269. t[266] = 281; t[268] = 283; t[269] = 313; t[275] = 323; t[276] = 324;
  17270. t[278] = 328; t[284] = 345; t[285] = 346; t[286] = 347; t[292] = 367;
  17271. t[295] = 377; t[296] = 378; t[298] = 380; t[305] = 963; t[306] = 964;
  17272. t[307] = 966; t[308] = 8215; t[309] = 8252; t[310] = 8319; t[311] = 8359;
  17273. t[312] = 8592; t[313] = 8593; t[337] = 9552; t[493] = 1039;
  17274. t[494] = 1040; t[705] = 1524; t[706] = 8362; t[710] = 64288; t[711] = 64298;
  17275. t[759] = 1617; t[761] = 1776; t[763] = 1778; t[775] = 1652; t[777] = 1764;
  17276. t[778] = 1780; t[779] = 1781; t[780] = 1782; t[782] = 771; t[783] = 64726;
  17277. t[786] = 8363; t[788] = 8532; t[790] = 768; t[791] = 769; t[792] = 768;
  17278. t[795] = 803; t[797] = 64336; t[798] = 64337; t[799] = 64342;
  17279. t[800] = 64343; t[801] = 64344; t[802] = 64345; t[803] = 64362;
  17280. t[804] = 64363; t[805] = 64364; t[2424] = 7821; t[2425] = 7822;
  17281. t[2426] = 7823; t[2427] = 7824; t[2428] = 7825; t[2429] = 7826;
  17282. t[2430] = 7827; t[2433] = 7682; t[2678] = 8045; t[2679] = 8046;
  17283. t[2830] = 1552; t[2838] = 686; t[2840] = 751; t[2842] = 753; t[2843] = 754;
  17284. t[2844] = 755; t[2846] = 757; t[2856] = 767; t[2857] = 848; t[2858] = 849;
  17285. t[2862] = 853; t[2863] = 854; t[2864] = 855; t[2865] = 861; t[2866] = 862;
  17286. t[2906] = 7460; t[2908] = 7462; t[2909] = 7463; t[2910] = 7464;
  17287. t[2912] = 7466; t[2913] = 7467; t[2914] = 7468; t[2916] = 7470;
  17288. t[2917] = 7471; t[2918] = 7472; t[2920] = 7474; t[2921] = 7475;
  17289. t[2922] = 7476; t[2924] = 7478; t[2925] = 7479; t[2926] = 7480;
  17290. t[2928] = 7482; t[2929] = 7483; t[2930] = 7484; t[2932] = 7486;
  17291. t[2933] = 7487; t[2934] = 7488; t[2936] = 7490; t[2937] = 7491;
  17292. t[2938] = 7492; t[2940] = 7494; t[2941] = 7495; t[2942] = 7496;
  17293. t[2944] = 7498; t[2946] = 7500; t[2948] = 7502; t[2950] = 7504;
  17294. t[2951] = 7505; t[2952] = 7506; t[2954] = 7508; t[2955] = 7509;
  17295. t[2956] = 7510; t[2958] = 7512; t[2959] = 7513; t[2960] = 7514;
  17296. t[2962] = 7516; t[2963] = 7517; t[2964] = 7518; t[2966] = 7520;
  17297. t[2967] = 7521; t[2968] = 7522; t[2970] = 7524; t[2971] = 7525;
  17298. t[2972] = 7526; t[2974] = 7528; t[2975] = 7529; t[2976] = 7530;
  17299. t[2978] = 1537; t[2979] = 1538; t[2980] = 1539; t[2982] = 1549;
  17300. t[2983] = 1551; t[2984] = 1552; t[2986] = 1554; t[2987] = 1555;
  17301. t[2988] = 1556; t[2990] = 1623; t[2991] = 1624; t[2995] = 1775;
  17302. t[2999] = 1791; t[3002] = 64290; t[3003] = 64291; t[3004] = 64292;
  17303. t[3006] = 64294; t[3007] = 64295; t[3008] = 64296; t[3011] = 1900;
  17304. t[3014] = 8223; t[3015] = 8244; t[3017] = 7532; t[3018] = 7533;
  17305. t[3019] = 7534; t[3075] = 7590; t[3076] = 7591; t[3079] = 7594;
  17306. t[3080] = 7595; t[3083] = 7598; t[3084] = 7599; t[3087] = 7602;
  17307. t[3088] = 7603; t[3091] = 7606; t[3092] = 7607; t[3095] = 7610;
  17308. t[3096] = 7611; t[3099] = 7614; t[3100] = 7615; t[3103] = 7618;
  17309. t[3104] = 7619; t[3107] = 8337; t[3108] = 8338; t[3116] = 1884;
  17310. t[3119] = 1885; t[3120] = 1885; t[3123] = 1886; t[3124] = 1886;
  17311. t[3127] = 1887; t[3128] = 1887; t[3131] = 1888; t[3132] = 1888;
  17312. t[3135] = 1889; t[3136] = 1889; t[3139] = 1890; t[3140] = 1890;
  17313. t[3143] = 1891; t[3144] = 1891; t[3147] = 1892; t[3148] = 1892;
  17314. t[3153] = 580; t[3154] = 581; t[3157] = 584; t[3158] = 585; t[3161] = 588;
  17315. t[3162] = 589; t[3165] = 891; t[3166] = 892; t[3169] = 1274; t[3170] = 1275;
  17316. t[3173] = 1278; t[3174] = 1279; t[3181] = 7622; t[3182] = 7623;
  17317. t[3282] = 11799; t[3316] = 578; t[3379] = 42785; t[3393] = 1159;
  17318. t[3416] = 8377;
  17319. });
  17320. // The glyph map for ArialBlack differs slightly from the glyph map used for
  17321. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  17322. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  17323. var getSupplementalGlyphMapForArialBlack =
  17324. getLookupTableFactory(function (t) {
  17325. t[227] = 322; t[264] = 261; t[291] = 346;
  17326. });
  17327. exports.getStdFontMap = getStdFontMap;
  17328. exports.getNonStdFontMap = getNonStdFontMap;
  17329. exports.getSerifFonts = getSerifFonts;
  17330. exports.getSymbolsFonts = getSymbolsFonts;
  17331. exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts;
  17332. exports.getSupplementalGlyphMapForArialBlack =
  17333. getSupplementalGlyphMapForArialBlack;
  17334. }));
  17335. (function (root, factory) {
  17336. {
  17337. factory((root.pdfjsCoreUnicode = {}), root.pdfjsSharedUtil);
  17338. }
  17339. }(this, function (exports, sharedUtil) {
  17340. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  17341. // Some characters, e.g. copyrightserif, are mapped to the private use area
  17342. // and might not be displayed using standard fonts. Mapping/hacking well-known
  17343. // chars to the similar equivalents in the normal characters range.
  17344. var getSpecialPUASymbols = getLookupTableFactory(function (t) {
  17345. t[63721] = 0x00A9; // copyrightsans (0xF8E9) => copyright
  17346. t[63193] = 0x00A9; // copyrightserif (0xF6D9) => copyright
  17347. t[63720] = 0x00AE; // registersans (0xF8E8) => registered
  17348. t[63194] = 0x00AE; // registerserif (0xF6DA) => registered
  17349. t[63722] = 0x2122; // trademarksans (0xF8EA) => trademark
  17350. t[63195] = 0x2122; // trademarkserif (0xF6DB) => trademark
  17351. t[63729] = 0x23A7; // bracelefttp (0xF8F1)
  17352. t[63730] = 0x23A8; // braceleftmid (0xF8F2)
  17353. t[63731] = 0x23A9; // braceleftbt (0xF8F3)
  17354. t[63740] = 0x23AB; // bracerighttp (0xF8FC)
  17355. t[63741] = 0x23AC; // bracerightmid (0xF8FD)
  17356. t[63742] = 0x23AD; // bracerightbt (0xF8FE)
  17357. t[63726] = 0x23A1; // bracketlefttp (0xF8EE)
  17358. t[63727] = 0x23A2; // bracketleftex (0xF8EF)
  17359. t[63728] = 0x23A3; // bracketleftbt (0xF8F0)
  17360. t[63737] = 0x23A4; // bracketrighttp (0xF8F9)
  17361. t[63738] = 0x23A5; // bracketrightex (0xF8FA)
  17362. t[63739] = 0x23A6; // bracketrightbt (0xF8FB)
  17363. t[63723] = 0x239B; // parenlefttp (0xF8EB)
  17364. t[63724] = 0x239C; // parenleftex (0xF8EC)
  17365. t[63725] = 0x239D; // parenleftbt (0xF8ED)
  17366. t[63734] = 0x239E; // parenrighttp (0xF8F6)
  17367. t[63735] = 0x239F; // parenrightex (0xF8F7)
  17368. t[63736] = 0x23A0; // parenrightbt (0xF8F8)
  17369. });
  17370. function mapSpecialUnicodeValues(code) {
  17371. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  17372. return 0;
  17373. } else if (code >= 0xF600 && code <= 0xF8FF) {
  17374. return (getSpecialPUASymbols()[code] || code);
  17375. }
  17376. return code;
  17377. }
  17378. function getUnicodeForGlyph(name, glyphsUnicodeMap) {
  17379. var unicode = glyphsUnicodeMap[name];
  17380. if (unicode !== undefined) {
  17381. return unicode;
  17382. }
  17383. if (!name) {
  17384. return -1;
  17385. }
  17386. // Try to recover valid Unicode values from 'uniXXXX'/'uXXXX{XX}' glyphs.
  17387. if (name[0] === 'u') {
  17388. var nameLen = name.length, hexStr;
  17389. if (nameLen === 7 && name[1] === 'n' && name[2] === 'i') { // 'uniXXXX'
  17390. hexStr = name.substr(3);
  17391. } else if (nameLen >= 5 && nameLen <= 7) { // 'uXXXX{XX}'
  17392. hexStr = name.substr(1);
  17393. } else {
  17394. return -1;
  17395. }
  17396. // Check for upper-case hexadecimal characters, to avoid false positives.
  17397. if (hexStr === hexStr.toUpperCase()) {
  17398. unicode = parseInt(hexStr, 16);
  17399. if (unicode >= 0) {
  17400. return unicode;
  17401. }
  17402. }
  17403. }
  17404. return -1;
  17405. }
  17406. var UnicodeRanges = [
  17407. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  17408. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  17409. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  17410. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  17411. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  17412. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  17413. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  17414. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  17415. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  17416. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  17417. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  17418. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  17419. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  17420. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  17421. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  17422. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  17423. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  17424. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  17425. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  17426. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  17427. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  17428. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  17429. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  17430. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  17431. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  17432. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  17433. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  17434. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  17435. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  17436. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  17437. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  17438. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  17439. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  17440. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  17441. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks
  17442. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  17443. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  17444. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  17445. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  17446. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  17447. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  17448. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  17449. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  17450. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  17451. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  17452. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  17453. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  17454. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  17455. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  17456. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  17457. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  17458. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  17459. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  17460. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  17461. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  17462. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  17463. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  17464. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  17465. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  17466. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  17467. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  17468. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  17469. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  17470. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  17471. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  17472. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  17473. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  17474. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  17475. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  17476. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  17477. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  17478. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  17479. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  17480. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  17481. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  17482. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  17483. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  17484. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  17485. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  17486. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  17487. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  17488. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  17489. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  17490. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  17491. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  17492. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  17493. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  17494. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  17495. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  17496. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  17497. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  17498. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  17499. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  17500. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  17501. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  17502. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  17503. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  17504. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  17505. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  17506. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  17507. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  17508. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  17509. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  17510. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  17511. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  17512. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  17513. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  17514. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  17515. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  17516. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  17517. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  17518. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  17519. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  17520. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  17521. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  17522. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  17523. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  17524. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  17525. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  17526. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  17527. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  17528. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  17529. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  17530. ];
  17531. function getUnicodeRangeFor(value) {
  17532. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  17533. var range = UnicodeRanges[i];
  17534. if (value >= range.begin && value < range.end) {
  17535. return i;
  17536. }
  17537. }
  17538. return -1;
  17539. }
  17540. function isRTLRangeFor(value) {
  17541. var range = UnicodeRanges[13];
  17542. if (value >= range.begin && value < range.end) {
  17543. return true;
  17544. }
  17545. range = UnicodeRanges[11];
  17546. if (value >= range.begin && value < range.end) {
  17547. return true;
  17548. }
  17549. return false;
  17550. }
  17551. // The normalization table is obtained by filtering the Unicode characters
  17552. // database with <compat> entries.
  17553. var getNormalizedUnicodes = getLookupTableFactory(function (t) {
  17554. t['\u00A8'] = '\u0020\u0308';
  17555. t['\u00AF'] = '\u0020\u0304';
  17556. t['\u00B4'] = '\u0020\u0301';
  17557. t['\u00B5'] = '\u03BC';
  17558. t['\u00B8'] = '\u0020\u0327';
  17559. t['\u0132'] = '\u0049\u004A';
  17560. t['\u0133'] = '\u0069\u006A';
  17561. t['\u013F'] = '\u004C\u00B7';
  17562. t['\u0140'] = '\u006C\u00B7';
  17563. t['\u0149'] = '\u02BC\u006E';
  17564. t['\u017F'] = '\u0073';
  17565. t['\u01C4'] = '\u0044\u017D';
  17566. t['\u01C5'] = '\u0044\u017E';
  17567. t['\u01C6'] = '\u0064\u017E';
  17568. t['\u01C7'] = '\u004C\u004A';
  17569. t['\u01C8'] = '\u004C\u006A';
  17570. t['\u01C9'] = '\u006C\u006A';
  17571. t['\u01CA'] = '\u004E\u004A';
  17572. t['\u01CB'] = '\u004E\u006A';
  17573. t['\u01CC'] = '\u006E\u006A';
  17574. t['\u01F1'] = '\u0044\u005A';
  17575. t['\u01F2'] = '\u0044\u007A';
  17576. t['\u01F3'] = '\u0064\u007A';
  17577. t['\u02D8'] = '\u0020\u0306';
  17578. t['\u02D9'] = '\u0020\u0307';
  17579. t['\u02DA'] = '\u0020\u030A';
  17580. t['\u02DB'] = '\u0020\u0328';
  17581. t['\u02DC'] = '\u0020\u0303';
  17582. t['\u02DD'] = '\u0020\u030B';
  17583. t['\u037A'] = '\u0020\u0345';
  17584. t['\u0384'] = '\u0020\u0301';
  17585. t['\u03D0'] = '\u03B2';
  17586. t['\u03D1'] = '\u03B8';
  17587. t['\u03D2'] = '\u03A5';
  17588. t['\u03D5'] = '\u03C6';
  17589. t['\u03D6'] = '\u03C0';
  17590. t['\u03F0'] = '\u03BA';
  17591. t['\u03F1'] = '\u03C1';
  17592. t['\u03F2'] = '\u03C2';
  17593. t['\u03F4'] = '\u0398';
  17594. t['\u03F5'] = '\u03B5';
  17595. t['\u03F9'] = '\u03A3';
  17596. t['\u0587'] = '\u0565\u0582';
  17597. t['\u0675'] = '\u0627\u0674';
  17598. t['\u0676'] = '\u0648\u0674';
  17599. t['\u0677'] = '\u06C7\u0674';
  17600. t['\u0678'] = '\u064A\u0674';
  17601. t['\u0E33'] = '\u0E4D\u0E32';
  17602. t['\u0EB3'] = '\u0ECD\u0EB2';
  17603. t['\u0EDC'] = '\u0EAB\u0E99';
  17604. t['\u0EDD'] = '\u0EAB\u0EA1';
  17605. t['\u0F77'] = '\u0FB2\u0F81';
  17606. t['\u0F79'] = '\u0FB3\u0F81';
  17607. t['\u1E9A'] = '\u0061\u02BE';
  17608. t['\u1FBD'] = '\u0020\u0313';
  17609. t['\u1FBF'] = '\u0020\u0313';
  17610. t['\u1FC0'] = '\u0020\u0342';
  17611. t['\u1FFE'] = '\u0020\u0314';
  17612. t['\u2002'] = '\u0020';
  17613. t['\u2003'] = '\u0020';
  17614. t['\u2004'] = '\u0020';
  17615. t['\u2005'] = '\u0020';
  17616. t['\u2006'] = '\u0020';
  17617. t['\u2008'] = '\u0020';
  17618. t['\u2009'] = '\u0020';
  17619. t['\u200A'] = '\u0020';
  17620. t['\u2017'] = '\u0020\u0333';
  17621. t['\u2024'] = '\u002E';
  17622. t['\u2025'] = '\u002E\u002E';
  17623. t['\u2026'] = '\u002E\u002E\u002E';
  17624. t['\u2033'] = '\u2032\u2032';
  17625. t['\u2034'] = '\u2032\u2032\u2032';
  17626. t['\u2036'] = '\u2035\u2035';
  17627. t['\u2037'] = '\u2035\u2035\u2035';
  17628. t['\u203C'] = '\u0021\u0021';
  17629. t['\u203E'] = '\u0020\u0305';
  17630. t['\u2047'] = '\u003F\u003F';
  17631. t['\u2048'] = '\u003F\u0021';
  17632. t['\u2049'] = '\u0021\u003F';
  17633. t['\u2057'] = '\u2032\u2032\u2032\u2032';
  17634. t['\u205F'] = '\u0020';
  17635. t['\u20A8'] = '\u0052\u0073';
  17636. t['\u2100'] = '\u0061\u002F\u0063';
  17637. t['\u2101'] = '\u0061\u002F\u0073';
  17638. t['\u2103'] = '\u00B0\u0043';
  17639. t['\u2105'] = '\u0063\u002F\u006F';
  17640. t['\u2106'] = '\u0063\u002F\u0075';
  17641. t['\u2107'] = '\u0190';
  17642. t['\u2109'] = '\u00B0\u0046';
  17643. t['\u2116'] = '\u004E\u006F';
  17644. t['\u2121'] = '\u0054\u0045\u004C';
  17645. t['\u2135'] = '\u05D0';
  17646. t['\u2136'] = '\u05D1';
  17647. t['\u2137'] = '\u05D2';
  17648. t['\u2138'] = '\u05D3';
  17649. t['\u213B'] = '\u0046\u0041\u0058';
  17650. t['\u2160'] = '\u0049';
  17651. t['\u2161'] = '\u0049\u0049';
  17652. t['\u2162'] = '\u0049\u0049\u0049';
  17653. t['\u2163'] = '\u0049\u0056';
  17654. t['\u2164'] = '\u0056';
  17655. t['\u2165'] = '\u0056\u0049';
  17656. t['\u2166'] = '\u0056\u0049\u0049';
  17657. t['\u2167'] = '\u0056\u0049\u0049\u0049';
  17658. t['\u2168'] = '\u0049\u0058';
  17659. t['\u2169'] = '\u0058';
  17660. t['\u216A'] = '\u0058\u0049';
  17661. t['\u216B'] = '\u0058\u0049\u0049';
  17662. t['\u216C'] = '\u004C';
  17663. t['\u216D'] = '\u0043';
  17664. t['\u216E'] = '\u0044';
  17665. t['\u216F'] = '\u004D';
  17666. t['\u2170'] = '\u0069';
  17667. t['\u2171'] = '\u0069\u0069';
  17668. t['\u2172'] = '\u0069\u0069\u0069';
  17669. t['\u2173'] = '\u0069\u0076';
  17670. t['\u2174'] = '\u0076';
  17671. t['\u2175'] = '\u0076\u0069';
  17672. t['\u2176'] = '\u0076\u0069\u0069';
  17673. t['\u2177'] = '\u0076\u0069\u0069\u0069';
  17674. t['\u2178'] = '\u0069\u0078';
  17675. t['\u2179'] = '\u0078';
  17676. t['\u217A'] = '\u0078\u0069';
  17677. t['\u217B'] = '\u0078\u0069\u0069';
  17678. t['\u217C'] = '\u006C';
  17679. t['\u217D'] = '\u0063';
  17680. t['\u217E'] = '\u0064';
  17681. t['\u217F'] = '\u006D';
  17682. t['\u222C'] = '\u222B\u222B';
  17683. t['\u222D'] = '\u222B\u222B\u222B';
  17684. t['\u222F'] = '\u222E\u222E';
  17685. t['\u2230'] = '\u222E\u222E\u222E';
  17686. t['\u2474'] = '\u0028\u0031\u0029';
  17687. t['\u2475'] = '\u0028\u0032\u0029';
  17688. t['\u2476'] = '\u0028\u0033\u0029';
  17689. t['\u2477'] = '\u0028\u0034\u0029';
  17690. t['\u2478'] = '\u0028\u0035\u0029';
  17691. t['\u2479'] = '\u0028\u0036\u0029';
  17692. t['\u247A'] = '\u0028\u0037\u0029';
  17693. t['\u247B'] = '\u0028\u0038\u0029';
  17694. t['\u247C'] = '\u0028\u0039\u0029';
  17695. t['\u247D'] = '\u0028\u0031\u0030\u0029';
  17696. t['\u247E'] = '\u0028\u0031\u0031\u0029';
  17697. t['\u247F'] = '\u0028\u0031\u0032\u0029';
  17698. t['\u2480'] = '\u0028\u0031\u0033\u0029';
  17699. t['\u2481'] = '\u0028\u0031\u0034\u0029';
  17700. t['\u2482'] = '\u0028\u0031\u0035\u0029';
  17701. t['\u2483'] = '\u0028\u0031\u0036\u0029';
  17702. t['\u2484'] = '\u0028\u0031\u0037\u0029';
  17703. t['\u2485'] = '\u0028\u0031\u0038\u0029';
  17704. t['\u2486'] = '\u0028\u0031\u0039\u0029';
  17705. t['\u2487'] = '\u0028\u0032\u0030\u0029';
  17706. t['\u2488'] = '\u0031\u002E';
  17707. t['\u2489'] = '\u0032\u002E';
  17708. t['\u248A'] = '\u0033\u002E';
  17709. t['\u248B'] = '\u0034\u002E';
  17710. t['\u248C'] = '\u0035\u002E';
  17711. t['\u248D'] = '\u0036\u002E';
  17712. t['\u248E'] = '\u0037\u002E';
  17713. t['\u248F'] = '\u0038\u002E';
  17714. t['\u2490'] = '\u0039\u002E';
  17715. t['\u2491'] = '\u0031\u0030\u002E';
  17716. t['\u2492'] = '\u0031\u0031\u002E';
  17717. t['\u2493'] = '\u0031\u0032\u002E';
  17718. t['\u2494'] = '\u0031\u0033\u002E';
  17719. t['\u2495'] = '\u0031\u0034\u002E';
  17720. t['\u2496'] = '\u0031\u0035\u002E';
  17721. t['\u2497'] = '\u0031\u0036\u002E';
  17722. t['\u2498'] = '\u0031\u0037\u002E';
  17723. t['\u2499'] = '\u0031\u0038\u002E';
  17724. t['\u249A'] = '\u0031\u0039\u002E';
  17725. t['\u249B'] = '\u0032\u0030\u002E';
  17726. t['\u249C'] = '\u0028\u0061\u0029';
  17727. t['\u249D'] = '\u0028\u0062\u0029';
  17728. t['\u249E'] = '\u0028\u0063\u0029';
  17729. t['\u249F'] = '\u0028\u0064\u0029';
  17730. t['\u24A0'] = '\u0028\u0065\u0029';
  17731. t['\u24A1'] = '\u0028\u0066\u0029';
  17732. t['\u24A2'] = '\u0028\u0067\u0029';
  17733. t['\u24A3'] = '\u0028\u0068\u0029';
  17734. t['\u24A4'] = '\u0028\u0069\u0029';
  17735. t['\u24A5'] = '\u0028\u006A\u0029';
  17736. t['\u24A6'] = '\u0028\u006B\u0029';
  17737. t['\u24A7'] = '\u0028\u006C\u0029';
  17738. t['\u24A8'] = '\u0028\u006D\u0029';
  17739. t['\u24A9'] = '\u0028\u006E\u0029';
  17740. t['\u24AA'] = '\u0028\u006F\u0029';
  17741. t['\u24AB'] = '\u0028\u0070\u0029';
  17742. t['\u24AC'] = '\u0028\u0071\u0029';
  17743. t['\u24AD'] = '\u0028\u0072\u0029';
  17744. t['\u24AE'] = '\u0028\u0073\u0029';
  17745. t['\u24AF'] = '\u0028\u0074\u0029';
  17746. t['\u24B0'] = '\u0028\u0075\u0029';
  17747. t['\u24B1'] = '\u0028\u0076\u0029';
  17748. t['\u24B2'] = '\u0028\u0077\u0029';
  17749. t['\u24B3'] = '\u0028\u0078\u0029';
  17750. t['\u24B4'] = '\u0028\u0079\u0029';
  17751. t['\u24B5'] = '\u0028\u007A\u0029';
  17752. t['\u2A0C'] = '\u222B\u222B\u222B\u222B';
  17753. t['\u2A74'] = '\u003A\u003A\u003D';
  17754. t['\u2A75'] = '\u003D\u003D';
  17755. t['\u2A76'] = '\u003D\u003D\u003D';
  17756. t['\u2E9F'] = '\u6BCD';
  17757. t['\u2EF3'] = '\u9F9F';
  17758. t['\u2F00'] = '\u4E00';
  17759. t['\u2F01'] = '\u4E28';
  17760. t['\u2F02'] = '\u4E36';
  17761. t['\u2F03'] = '\u4E3F';
  17762. t['\u2F04'] = '\u4E59';
  17763. t['\u2F05'] = '\u4E85';
  17764. t['\u2F06'] = '\u4E8C';
  17765. t['\u2F07'] = '\u4EA0';
  17766. t['\u2F08'] = '\u4EBA';
  17767. t['\u2F09'] = '\u513F';
  17768. t['\u2F0A'] = '\u5165';
  17769. t['\u2F0B'] = '\u516B';
  17770. t['\u2F0C'] = '\u5182';
  17771. t['\u2F0D'] = '\u5196';
  17772. t['\u2F0E'] = '\u51AB';
  17773. t['\u2F0F'] = '\u51E0';
  17774. t['\u2F10'] = '\u51F5';
  17775. t['\u2F11'] = '\u5200';
  17776. t['\u2F12'] = '\u529B';
  17777. t['\u2F13'] = '\u52F9';
  17778. t['\u2F14'] = '\u5315';
  17779. t['\u2F15'] = '\u531A';
  17780. t['\u2F16'] = '\u5338';
  17781. t['\u2F17'] = '\u5341';
  17782. t['\u2F18'] = '\u535C';
  17783. t['\u2F19'] = '\u5369';
  17784. t['\u2F1A'] = '\u5382';
  17785. t['\u2F1B'] = '\u53B6';
  17786. t['\u2F1C'] = '\u53C8';
  17787. t['\u2F1D'] = '\u53E3';
  17788. t['\u2F1E'] = '\u56D7';
  17789. t['\u2F1F'] = '\u571F';
  17790. t['\u2F20'] = '\u58EB';
  17791. t['\u2F21'] = '\u5902';
  17792. t['\u2F22'] = '\u590A';
  17793. t['\u2F23'] = '\u5915';
  17794. t['\u2F24'] = '\u5927';
  17795. t['\u2F25'] = '\u5973';
  17796. t['\u2F26'] = '\u5B50';
  17797. t['\u2F27'] = '\u5B80';
  17798. t['\u2F28'] = '\u5BF8';
  17799. t['\u2F29'] = '\u5C0F';
  17800. t['\u2F2A'] = '\u5C22';
  17801. t['\u2F2B'] = '\u5C38';
  17802. t['\u2F2C'] = '\u5C6E';
  17803. t['\u2F2D'] = '\u5C71';
  17804. t['\u2F2E'] = '\u5DDB';
  17805. t['\u2F2F'] = '\u5DE5';
  17806. t['\u2F30'] = '\u5DF1';
  17807. t['\u2F31'] = '\u5DFE';
  17808. t['\u2F32'] = '\u5E72';
  17809. t['\u2F33'] = '\u5E7A';
  17810. t['\u2F34'] = '\u5E7F';
  17811. t['\u2F35'] = '\u5EF4';
  17812. t['\u2F36'] = '\u5EFE';
  17813. t['\u2F37'] = '\u5F0B';
  17814. t['\u2F38'] = '\u5F13';
  17815. t['\u2F39'] = '\u5F50';
  17816. t['\u2F3A'] = '\u5F61';
  17817. t['\u2F3B'] = '\u5F73';
  17818. t['\u2F3C'] = '\u5FC3';
  17819. t['\u2F3D'] = '\u6208';
  17820. t['\u2F3E'] = '\u6236';
  17821. t['\u2F3F'] = '\u624B';
  17822. t['\u2F40'] = '\u652F';
  17823. t['\u2F41'] = '\u6534';
  17824. t['\u2F42'] = '\u6587';
  17825. t['\u2F43'] = '\u6597';
  17826. t['\u2F44'] = '\u65A4';
  17827. t['\u2F45'] = '\u65B9';
  17828. t['\u2F46'] = '\u65E0';
  17829. t['\u2F47'] = '\u65E5';
  17830. t['\u2F48'] = '\u66F0';
  17831. t['\u2F49'] = '\u6708';
  17832. t['\u2F4A'] = '\u6728';
  17833. t['\u2F4B'] = '\u6B20';
  17834. t['\u2F4C'] = '\u6B62';
  17835. t['\u2F4D'] = '\u6B79';
  17836. t['\u2F4E'] = '\u6BB3';
  17837. t['\u2F4F'] = '\u6BCB';
  17838. t['\u2F50'] = '\u6BD4';
  17839. t['\u2F51'] = '\u6BDB';
  17840. t['\u2F52'] = '\u6C0F';
  17841. t['\u2F53'] = '\u6C14';
  17842. t['\u2F54'] = '\u6C34';
  17843. t['\u2F55'] = '\u706B';
  17844. t['\u2F56'] = '\u722A';
  17845. t['\u2F57'] = '\u7236';
  17846. t['\u2F58'] = '\u723B';
  17847. t['\u2F59'] = '\u723F';
  17848. t['\u2F5A'] = '\u7247';
  17849. t['\u2F5B'] = '\u7259';
  17850. t['\u2F5C'] = '\u725B';
  17851. t['\u2F5D'] = '\u72AC';
  17852. t['\u2F5E'] = '\u7384';
  17853. t['\u2F5F'] = '\u7389';
  17854. t['\u2F60'] = '\u74DC';
  17855. t['\u2F61'] = '\u74E6';
  17856. t['\u2F62'] = '\u7518';
  17857. t['\u2F63'] = '\u751F';
  17858. t['\u2F64'] = '\u7528';
  17859. t['\u2F65'] = '\u7530';
  17860. t['\u2F66'] = '\u758B';
  17861. t['\u2F67'] = '\u7592';
  17862. t['\u2F68'] = '\u7676';
  17863. t['\u2F69'] = '\u767D';
  17864. t['\u2F6A'] = '\u76AE';
  17865. t['\u2F6B'] = '\u76BF';
  17866. t['\u2F6C'] = '\u76EE';
  17867. t['\u2F6D'] = '\u77DB';
  17868. t['\u2F6E'] = '\u77E2';
  17869. t['\u2F6F'] = '\u77F3';
  17870. t['\u2F70'] = '\u793A';
  17871. t['\u2F71'] = '\u79B8';
  17872. t['\u2F72'] = '\u79BE';
  17873. t['\u2F73'] = '\u7A74';
  17874. t['\u2F74'] = '\u7ACB';
  17875. t['\u2F75'] = '\u7AF9';
  17876. t['\u2F76'] = '\u7C73';
  17877. t['\u2F77'] = '\u7CF8';
  17878. t['\u2F78'] = '\u7F36';
  17879. t['\u2F79'] = '\u7F51';
  17880. t['\u2F7A'] = '\u7F8A';
  17881. t['\u2F7B'] = '\u7FBD';
  17882. t['\u2F7C'] = '\u8001';
  17883. t['\u2F7D'] = '\u800C';
  17884. t['\u2F7E'] = '\u8012';
  17885. t['\u2F7F'] = '\u8033';
  17886. t['\u2F80'] = '\u807F';
  17887. t['\u2F81'] = '\u8089';
  17888. t['\u2F82'] = '\u81E3';
  17889. t['\u2F83'] = '\u81EA';
  17890. t['\u2F84'] = '\u81F3';
  17891. t['\u2F85'] = '\u81FC';
  17892. t['\u2F86'] = '\u820C';
  17893. t['\u2F87'] = '\u821B';
  17894. t['\u2F88'] = '\u821F';
  17895. t['\u2F89'] = '\u826E';
  17896. t['\u2F8A'] = '\u8272';
  17897. t['\u2F8B'] = '\u8278';
  17898. t['\u2F8C'] = '\u864D';
  17899. t['\u2F8D'] = '\u866B';
  17900. t['\u2F8E'] = '\u8840';
  17901. t['\u2F8F'] = '\u884C';
  17902. t['\u2F90'] = '\u8863';
  17903. t['\u2F91'] = '\u897E';
  17904. t['\u2F92'] = '\u898B';
  17905. t['\u2F93'] = '\u89D2';
  17906. t['\u2F94'] = '\u8A00';
  17907. t['\u2F95'] = '\u8C37';
  17908. t['\u2F96'] = '\u8C46';
  17909. t['\u2F97'] = '\u8C55';
  17910. t['\u2F98'] = '\u8C78';
  17911. t['\u2F99'] = '\u8C9D';
  17912. t['\u2F9A'] = '\u8D64';
  17913. t['\u2F9B'] = '\u8D70';
  17914. t['\u2F9C'] = '\u8DB3';
  17915. t['\u2F9D'] = '\u8EAB';
  17916. t['\u2F9E'] = '\u8ECA';
  17917. t['\u2F9F'] = '\u8F9B';
  17918. t['\u2FA0'] = '\u8FB0';
  17919. t['\u2FA1'] = '\u8FB5';
  17920. t['\u2FA2'] = '\u9091';
  17921. t['\u2FA3'] = '\u9149';
  17922. t['\u2FA4'] = '\u91C6';
  17923. t['\u2FA5'] = '\u91CC';
  17924. t['\u2FA6'] = '\u91D1';
  17925. t['\u2FA7'] = '\u9577';
  17926. t['\u2FA8'] = '\u9580';
  17927. t['\u2FA9'] = '\u961C';
  17928. t['\u2FAA'] = '\u96B6';
  17929. t['\u2FAB'] = '\u96B9';
  17930. t['\u2FAC'] = '\u96E8';
  17931. t['\u2FAD'] = '\u9751';
  17932. t['\u2FAE'] = '\u975E';
  17933. t['\u2FAF'] = '\u9762';
  17934. t['\u2FB0'] = '\u9769';
  17935. t['\u2FB1'] = '\u97CB';
  17936. t['\u2FB2'] = '\u97ED';
  17937. t['\u2FB3'] = '\u97F3';
  17938. t['\u2FB4'] = '\u9801';
  17939. t['\u2FB5'] = '\u98A8';
  17940. t['\u2FB6'] = '\u98DB';
  17941. t['\u2FB7'] = '\u98DF';
  17942. t['\u2FB8'] = '\u9996';
  17943. t['\u2FB9'] = '\u9999';
  17944. t['\u2FBA'] = '\u99AC';
  17945. t['\u2FBB'] = '\u9AA8';
  17946. t['\u2FBC'] = '\u9AD8';
  17947. t['\u2FBD'] = '\u9ADF';
  17948. t['\u2FBE'] = '\u9B25';
  17949. t['\u2FBF'] = '\u9B2F';
  17950. t['\u2FC0'] = '\u9B32';
  17951. t['\u2FC1'] = '\u9B3C';
  17952. t['\u2FC2'] = '\u9B5A';
  17953. t['\u2FC3'] = '\u9CE5';
  17954. t['\u2FC4'] = '\u9E75';
  17955. t['\u2FC5'] = '\u9E7F';
  17956. t['\u2FC6'] = '\u9EA5';
  17957. t['\u2FC7'] = '\u9EBB';
  17958. t['\u2FC8'] = '\u9EC3';
  17959. t['\u2FC9'] = '\u9ECD';
  17960. t['\u2FCA'] = '\u9ED1';
  17961. t['\u2FCB'] = '\u9EF9';
  17962. t['\u2FCC'] = '\u9EFD';
  17963. t['\u2FCD'] = '\u9F0E';
  17964. t['\u2FCE'] = '\u9F13';
  17965. t['\u2FCF'] = '\u9F20';
  17966. t['\u2FD0'] = '\u9F3B';
  17967. t['\u2FD1'] = '\u9F4A';
  17968. t['\u2FD2'] = '\u9F52';
  17969. t['\u2FD3'] = '\u9F8D';
  17970. t['\u2FD4'] = '\u9F9C';
  17971. t['\u2FD5'] = '\u9FA0';
  17972. t['\u3036'] = '\u3012';
  17973. t['\u3038'] = '\u5341';
  17974. t['\u3039'] = '\u5344';
  17975. t['\u303A'] = '\u5345';
  17976. t['\u309B'] = '\u0020\u3099';
  17977. t['\u309C'] = '\u0020\u309A';
  17978. t['\u3131'] = '\u1100';
  17979. t['\u3132'] = '\u1101';
  17980. t['\u3133'] = '\u11AA';
  17981. t['\u3134'] = '\u1102';
  17982. t['\u3135'] = '\u11AC';
  17983. t['\u3136'] = '\u11AD';
  17984. t['\u3137'] = '\u1103';
  17985. t['\u3138'] = '\u1104';
  17986. t['\u3139'] = '\u1105';
  17987. t['\u313A'] = '\u11B0';
  17988. t['\u313B'] = '\u11B1';
  17989. t['\u313C'] = '\u11B2';
  17990. t['\u313D'] = '\u11B3';
  17991. t['\u313E'] = '\u11B4';
  17992. t['\u313F'] = '\u11B5';
  17993. t['\u3140'] = '\u111A';
  17994. t['\u3141'] = '\u1106';
  17995. t['\u3142'] = '\u1107';
  17996. t['\u3143'] = '\u1108';
  17997. t['\u3144'] = '\u1121';
  17998. t['\u3145'] = '\u1109';
  17999. t['\u3146'] = '\u110A';
  18000. t['\u3147'] = '\u110B';
  18001. t['\u3148'] = '\u110C';
  18002. t['\u3149'] = '\u110D';
  18003. t['\u314A'] = '\u110E';
  18004. t['\u314B'] = '\u110F';
  18005. t['\u314C'] = '\u1110';
  18006. t['\u314D'] = '\u1111';
  18007. t['\u314E'] = '\u1112';
  18008. t['\u314F'] = '\u1161';
  18009. t['\u3150'] = '\u1162';
  18010. t['\u3151'] = '\u1163';
  18011. t['\u3152'] = '\u1164';
  18012. t['\u3153'] = '\u1165';
  18013. t['\u3154'] = '\u1166';
  18014. t['\u3155'] = '\u1167';
  18015. t['\u3156'] = '\u1168';
  18016. t['\u3157'] = '\u1169';
  18017. t['\u3158'] = '\u116A';
  18018. t['\u3159'] = '\u116B';
  18019. t['\u315A'] = '\u116C';
  18020. t['\u315B'] = '\u116D';
  18021. t['\u315C'] = '\u116E';
  18022. t['\u315D'] = '\u116F';
  18023. t['\u315E'] = '\u1170';
  18024. t['\u315F'] = '\u1171';
  18025. t['\u3160'] = '\u1172';
  18026. t['\u3161'] = '\u1173';
  18027. t['\u3162'] = '\u1174';
  18028. t['\u3163'] = '\u1175';
  18029. t['\u3164'] = '\u1160';
  18030. t['\u3165'] = '\u1114';
  18031. t['\u3166'] = '\u1115';
  18032. t['\u3167'] = '\u11C7';
  18033. t['\u3168'] = '\u11C8';
  18034. t['\u3169'] = '\u11CC';
  18035. t['\u316A'] = '\u11CE';
  18036. t['\u316B'] = '\u11D3';
  18037. t['\u316C'] = '\u11D7';
  18038. t['\u316D'] = '\u11D9';
  18039. t['\u316E'] = '\u111C';
  18040. t['\u316F'] = '\u11DD';
  18041. t['\u3170'] = '\u11DF';
  18042. t['\u3171'] = '\u111D';
  18043. t['\u3172'] = '\u111E';
  18044. t['\u3173'] = '\u1120';
  18045. t['\u3174'] = '\u1122';
  18046. t['\u3175'] = '\u1123';
  18047. t['\u3176'] = '\u1127';
  18048. t['\u3177'] = '\u1129';
  18049. t['\u3178'] = '\u112B';
  18050. t['\u3179'] = '\u112C';
  18051. t['\u317A'] = '\u112D';
  18052. t['\u317B'] = '\u112E';
  18053. t['\u317C'] = '\u112F';
  18054. t['\u317D'] = '\u1132';
  18055. t['\u317E'] = '\u1136';
  18056. t['\u317F'] = '\u1140';
  18057. t['\u3180'] = '\u1147';
  18058. t['\u3181'] = '\u114C';
  18059. t['\u3182'] = '\u11F1';
  18060. t['\u3183'] = '\u11F2';
  18061. t['\u3184'] = '\u1157';
  18062. t['\u3185'] = '\u1158';
  18063. t['\u3186'] = '\u1159';
  18064. t['\u3187'] = '\u1184';
  18065. t['\u3188'] = '\u1185';
  18066. t['\u3189'] = '\u1188';
  18067. t['\u318A'] = '\u1191';
  18068. t['\u318B'] = '\u1192';
  18069. t['\u318C'] = '\u1194';
  18070. t['\u318D'] = '\u119E';
  18071. t['\u318E'] = '\u11A1';
  18072. t['\u3200'] = '\u0028\u1100\u0029';
  18073. t['\u3201'] = '\u0028\u1102\u0029';
  18074. t['\u3202'] = '\u0028\u1103\u0029';
  18075. t['\u3203'] = '\u0028\u1105\u0029';
  18076. t['\u3204'] = '\u0028\u1106\u0029';
  18077. t['\u3205'] = '\u0028\u1107\u0029';
  18078. t['\u3206'] = '\u0028\u1109\u0029';
  18079. t['\u3207'] = '\u0028\u110B\u0029';
  18080. t['\u3208'] = '\u0028\u110C\u0029';
  18081. t['\u3209'] = '\u0028\u110E\u0029';
  18082. t['\u320A'] = '\u0028\u110F\u0029';
  18083. t['\u320B'] = '\u0028\u1110\u0029';
  18084. t['\u320C'] = '\u0028\u1111\u0029';
  18085. t['\u320D'] = '\u0028\u1112\u0029';
  18086. t['\u320E'] = '\u0028\u1100\u1161\u0029';
  18087. t['\u320F'] = '\u0028\u1102\u1161\u0029';
  18088. t['\u3210'] = '\u0028\u1103\u1161\u0029';
  18089. t['\u3211'] = '\u0028\u1105\u1161\u0029';
  18090. t['\u3212'] = '\u0028\u1106\u1161\u0029';
  18091. t['\u3213'] = '\u0028\u1107\u1161\u0029';
  18092. t['\u3214'] = '\u0028\u1109\u1161\u0029';
  18093. t['\u3215'] = '\u0028\u110B\u1161\u0029';
  18094. t['\u3216'] = '\u0028\u110C\u1161\u0029';
  18095. t['\u3217'] = '\u0028\u110E\u1161\u0029';
  18096. t['\u3218'] = '\u0028\u110F\u1161\u0029';
  18097. t['\u3219'] = '\u0028\u1110\u1161\u0029';
  18098. t['\u321A'] = '\u0028\u1111\u1161\u0029';
  18099. t['\u321B'] = '\u0028\u1112\u1161\u0029';
  18100. t['\u321C'] = '\u0028\u110C\u116E\u0029';
  18101. t['\u321D'] = '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029';
  18102. t['\u321E'] = '\u0028\u110B\u1169\u1112\u116E\u0029';
  18103. t['\u3220'] = '\u0028\u4E00\u0029';
  18104. t['\u3221'] = '\u0028\u4E8C\u0029';
  18105. t['\u3222'] = '\u0028\u4E09\u0029';
  18106. t['\u3223'] = '\u0028\u56DB\u0029';
  18107. t['\u3224'] = '\u0028\u4E94\u0029';
  18108. t['\u3225'] = '\u0028\u516D\u0029';
  18109. t['\u3226'] = '\u0028\u4E03\u0029';
  18110. t['\u3227'] = '\u0028\u516B\u0029';
  18111. t['\u3228'] = '\u0028\u4E5D\u0029';
  18112. t['\u3229'] = '\u0028\u5341\u0029';
  18113. t['\u322A'] = '\u0028\u6708\u0029';
  18114. t['\u322B'] = '\u0028\u706B\u0029';
  18115. t['\u322C'] = '\u0028\u6C34\u0029';
  18116. t['\u322D'] = '\u0028\u6728\u0029';
  18117. t['\u322E'] = '\u0028\u91D1\u0029';
  18118. t['\u322F'] = '\u0028\u571F\u0029';
  18119. t['\u3230'] = '\u0028\u65E5\u0029';
  18120. t['\u3231'] = '\u0028\u682A\u0029';
  18121. t['\u3232'] = '\u0028\u6709\u0029';
  18122. t['\u3233'] = '\u0028\u793E\u0029';
  18123. t['\u3234'] = '\u0028\u540D\u0029';
  18124. t['\u3235'] = '\u0028\u7279\u0029';
  18125. t['\u3236'] = '\u0028\u8CA1\u0029';
  18126. t['\u3237'] = '\u0028\u795D\u0029';
  18127. t['\u3238'] = '\u0028\u52B4\u0029';
  18128. t['\u3239'] = '\u0028\u4EE3\u0029';
  18129. t['\u323A'] = '\u0028\u547C\u0029';
  18130. t['\u323B'] = '\u0028\u5B66\u0029';
  18131. t['\u323C'] = '\u0028\u76E3\u0029';
  18132. t['\u323D'] = '\u0028\u4F01\u0029';
  18133. t['\u323E'] = '\u0028\u8CC7\u0029';
  18134. t['\u323F'] = '\u0028\u5354\u0029';
  18135. t['\u3240'] = '\u0028\u796D\u0029';
  18136. t['\u3241'] = '\u0028\u4F11\u0029';
  18137. t['\u3242'] = '\u0028\u81EA\u0029';
  18138. t['\u3243'] = '\u0028\u81F3\u0029';
  18139. t['\u32C0'] = '\u0031\u6708';
  18140. t['\u32C1'] = '\u0032\u6708';
  18141. t['\u32C2'] = '\u0033\u6708';
  18142. t['\u32C3'] = '\u0034\u6708';
  18143. t['\u32C4'] = '\u0035\u6708';
  18144. t['\u32C5'] = '\u0036\u6708';
  18145. t['\u32C6'] = '\u0037\u6708';
  18146. t['\u32C7'] = '\u0038\u6708';
  18147. t['\u32C8'] = '\u0039\u6708';
  18148. t['\u32C9'] = '\u0031\u0030\u6708';
  18149. t['\u32CA'] = '\u0031\u0031\u6708';
  18150. t['\u32CB'] = '\u0031\u0032\u6708';
  18151. t['\u3358'] = '\u0030\u70B9';
  18152. t['\u3359'] = '\u0031\u70B9';
  18153. t['\u335A'] = '\u0032\u70B9';
  18154. t['\u335B'] = '\u0033\u70B9';
  18155. t['\u335C'] = '\u0034\u70B9';
  18156. t['\u335D'] = '\u0035\u70B9';
  18157. t['\u335E'] = '\u0036\u70B9';
  18158. t['\u335F'] = '\u0037\u70B9';
  18159. t['\u3360'] = '\u0038\u70B9';
  18160. t['\u3361'] = '\u0039\u70B9';
  18161. t['\u3362'] = '\u0031\u0030\u70B9';
  18162. t['\u3363'] = '\u0031\u0031\u70B9';
  18163. t['\u3364'] = '\u0031\u0032\u70B9';
  18164. t['\u3365'] = '\u0031\u0033\u70B9';
  18165. t['\u3366'] = '\u0031\u0034\u70B9';
  18166. t['\u3367'] = '\u0031\u0035\u70B9';
  18167. t['\u3368'] = '\u0031\u0036\u70B9';
  18168. t['\u3369'] = '\u0031\u0037\u70B9';
  18169. t['\u336A'] = '\u0031\u0038\u70B9';
  18170. t['\u336B'] = '\u0031\u0039\u70B9';
  18171. t['\u336C'] = '\u0032\u0030\u70B9';
  18172. t['\u336D'] = '\u0032\u0031\u70B9';
  18173. t['\u336E'] = '\u0032\u0032\u70B9';
  18174. t['\u336F'] = '\u0032\u0033\u70B9';
  18175. t['\u3370'] = '\u0032\u0034\u70B9';
  18176. t['\u33E0'] = '\u0031\u65E5';
  18177. t['\u33E1'] = '\u0032\u65E5';
  18178. t['\u33E2'] = '\u0033\u65E5';
  18179. t['\u33E3'] = '\u0034\u65E5';
  18180. t['\u33E4'] = '\u0035\u65E5';
  18181. t['\u33E5'] = '\u0036\u65E5';
  18182. t['\u33E6'] = '\u0037\u65E5';
  18183. t['\u33E7'] = '\u0038\u65E5';
  18184. t['\u33E8'] = '\u0039\u65E5';
  18185. t['\u33E9'] = '\u0031\u0030\u65E5';
  18186. t['\u33EA'] = '\u0031\u0031\u65E5';
  18187. t['\u33EB'] = '\u0031\u0032\u65E5';
  18188. t['\u33EC'] = '\u0031\u0033\u65E5';
  18189. t['\u33ED'] = '\u0031\u0034\u65E5';
  18190. t['\u33EE'] = '\u0031\u0035\u65E5';
  18191. t['\u33EF'] = '\u0031\u0036\u65E5';
  18192. t['\u33F0'] = '\u0031\u0037\u65E5';
  18193. t['\u33F1'] = '\u0031\u0038\u65E5';
  18194. t['\u33F2'] = '\u0031\u0039\u65E5';
  18195. t['\u33F3'] = '\u0032\u0030\u65E5';
  18196. t['\u33F4'] = '\u0032\u0031\u65E5';
  18197. t['\u33F5'] = '\u0032\u0032\u65E5';
  18198. t['\u33F6'] = '\u0032\u0033\u65E5';
  18199. t['\u33F7'] = '\u0032\u0034\u65E5';
  18200. t['\u33F8'] = '\u0032\u0035\u65E5';
  18201. t['\u33F9'] = '\u0032\u0036\u65E5';
  18202. t['\u33FA'] = '\u0032\u0037\u65E5';
  18203. t['\u33FB'] = '\u0032\u0038\u65E5';
  18204. t['\u33FC'] = '\u0032\u0039\u65E5';
  18205. t['\u33FD'] = '\u0033\u0030\u65E5';
  18206. t['\u33FE'] = '\u0033\u0031\u65E5';
  18207. t['\uFB00'] = '\u0066\u0066';
  18208. t['\uFB01'] = '\u0066\u0069';
  18209. t['\uFB02'] = '\u0066\u006C';
  18210. t['\uFB03'] = '\u0066\u0066\u0069';
  18211. t['\uFB04'] = '\u0066\u0066\u006C';
  18212. t['\uFB05'] = '\u017F\u0074';
  18213. t['\uFB06'] = '\u0073\u0074';
  18214. t['\uFB13'] = '\u0574\u0576';
  18215. t['\uFB14'] = '\u0574\u0565';
  18216. t['\uFB15'] = '\u0574\u056B';
  18217. t['\uFB16'] = '\u057E\u0576';
  18218. t['\uFB17'] = '\u0574\u056D';
  18219. t['\uFB4F'] = '\u05D0\u05DC';
  18220. t['\uFB50'] = '\u0671';
  18221. t['\uFB51'] = '\u0671';
  18222. t['\uFB52'] = '\u067B';
  18223. t['\uFB53'] = '\u067B';
  18224. t['\uFB54'] = '\u067B';
  18225. t['\uFB55'] = '\u067B';
  18226. t['\uFB56'] = '\u067E';
  18227. t['\uFB57'] = '\u067E';
  18228. t['\uFB58'] = '\u067E';
  18229. t['\uFB59'] = '\u067E';
  18230. t['\uFB5A'] = '\u0680';
  18231. t['\uFB5B'] = '\u0680';
  18232. t['\uFB5C'] = '\u0680';
  18233. t['\uFB5D'] = '\u0680';
  18234. t['\uFB5E'] = '\u067A';
  18235. t['\uFB5F'] = '\u067A';
  18236. t['\uFB60'] = '\u067A';
  18237. t['\uFB61'] = '\u067A';
  18238. t['\uFB62'] = '\u067F';
  18239. t['\uFB63'] = '\u067F';
  18240. t['\uFB64'] = '\u067F';
  18241. t['\uFB65'] = '\u067F';
  18242. t['\uFB66'] = '\u0679';
  18243. t['\uFB67'] = '\u0679';
  18244. t['\uFB68'] = '\u0679';
  18245. t['\uFB69'] = '\u0679';
  18246. t['\uFB6A'] = '\u06A4';
  18247. t['\uFB6B'] = '\u06A4';
  18248. t['\uFB6C'] = '\u06A4';
  18249. t['\uFB6D'] = '\u06A4';
  18250. t['\uFB6E'] = '\u06A6';
  18251. t['\uFB6F'] = '\u06A6';
  18252. t['\uFB70'] = '\u06A6';
  18253. t['\uFB71'] = '\u06A6';
  18254. t['\uFB72'] = '\u0684';
  18255. t['\uFB73'] = '\u0684';
  18256. t['\uFB74'] = '\u0684';
  18257. t['\uFB75'] = '\u0684';
  18258. t['\uFB76'] = '\u0683';
  18259. t['\uFB77'] = '\u0683';
  18260. t['\uFB78'] = '\u0683';
  18261. t['\uFB79'] = '\u0683';
  18262. t['\uFB7A'] = '\u0686';
  18263. t['\uFB7B'] = '\u0686';
  18264. t['\uFB7C'] = '\u0686';
  18265. t['\uFB7D'] = '\u0686';
  18266. t['\uFB7E'] = '\u0687';
  18267. t['\uFB7F'] = '\u0687';
  18268. t['\uFB80'] = '\u0687';
  18269. t['\uFB81'] = '\u0687';
  18270. t['\uFB82'] = '\u068D';
  18271. t['\uFB83'] = '\u068D';
  18272. t['\uFB84'] = '\u068C';
  18273. t['\uFB85'] = '\u068C';
  18274. t['\uFB86'] = '\u068E';
  18275. t['\uFB87'] = '\u068E';
  18276. t['\uFB88'] = '\u0688';
  18277. t['\uFB89'] = '\u0688';
  18278. t['\uFB8A'] = '\u0698';
  18279. t['\uFB8B'] = '\u0698';
  18280. t['\uFB8C'] = '\u0691';
  18281. t['\uFB8D'] = '\u0691';
  18282. t['\uFB8E'] = '\u06A9';
  18283. t['\uFB8F'] = '\u06A9';
  18284. t['\uFB90'] = '\u06A9';
  18285. t['\uFB91'] = '\u06A9';
  18286. t['\uFB92'] = '\u06AF';
  18287. t['\uFB93'] = '\u06AF';
  18288. t['\uFB94'] = '\u06AF';
  18289. t['\uFB95'] = '\u06AF';
  18290. t['\uFB96'] = '\u06B3';
  18291. t['\uFB97'] = '\u06B3';
  18292. t['\uFB98'] = '\u06B3';
  18293. t['\uFB99'] = '\u06B3';
  18294. t['\uFB9A'] = '\u06B1';
  18295. t['\uFB9B'] = '\u06B1';
  18296. t['\uFB9C'] = '\u06B1';
  18297. t['\uFB9D'] = '\u06B1';
  18298. t['\uFB9E'] = '\u06BA';
  18299. t['\uFB9F'] = '\u06BA';
  18300. t['\uFBA0'] = '\u06BB';
  18301. t['\uFBA1'] = '\u06BB';
  18302. t['\uFBA2'] = '\u06BB';
  18303. t['\uFBA3'] = '\u06BB';
  18304. t['\uFBA4'] = '\u06C0';
  18305. t['\uFBA5'] = '\u06C0';
  18306. t['\uFBA6'] = '\u06C1';
  18307. t['\uFBA7'] = '\u06C1';
  18308. t['\uFBA8'] = '\u06C1';
  18309. t['\uFBA9'] = '\u06C1';
  18310. t['\uFBAA'] = '\u06BE';
  18311. t['\uFBAB'] = '\u06BE';
  18312. t['\uFBAC'] = '\u06BE';
  18313. t['\uFBAD'] = '\u06BE';
  18314. t['\uFBAE'] = '\u06D2';
  18315. t['\uFBAF'] = '\u06D2';
  18316. t['\uFBB0'] = '\u06D3';
  18317. t['\uFBB1'] = '\u06D3';
  18318. t['\uFBD3'] = '\u06AD';
  18319. t['\uFBD4'] = '\u06AD';
  18320. t['\uFBD5'] = '\u06AD';
  18321. t['\uFBD6'] = '\u06AD';
  18322. t['\uFBD7'] = '\u06C7';
  18323. t['\uFBD8'] = '\u06C7';
  18324. t['\uFBD9'] = '\u06C6';
  18325. t['\uFBDA'] = '\u06C6';
  18326. t['\uFBDB'] = '\u06C8';
  18327. t['\uFBDC'] = '\u06C8';
  18328. t['\uFBDD'] = '\u0677';
  18329. t['\uFBDE'] = '\u06CB';
  18330. t['\uFBDF'] = '\u06CB';
  18331. t['\uFBE0'] = '\u06C5';
  18332. t['\uFBE1'] = '\u06C5';
  18333. t['\uFBE2'] = '\u06C9';
  18334. t['\uFBE3'] = '\u06C9';
  18335. t['\uFBE4'] = '\u06D0';
  18336. t['\uFBE5'] = '\u06D0';
  18337. t['\uFBE6'] = '\u06D0';
  18338. t['\uFBE7'] = '\u06D0';
  18339. t['\uFBE8'] = '\u0649';
  18340. t['\uFBE9'] = '\u0649';
  18341. t['\uFBEA'] = '\u0626\u0627';
  18342. t['\uFBEB'] = '\u0626\u0627';
  18343. t['\uFBEC'] = '\u0626\u06D5';
  18344. t['\uFBED'] = '\u0626\u06D5';
  18345. t['\uFBEE'] = '\u0626\u0648';
  18346. t['\uFBEF'] = '\u0626\u0648';
  18347. t['\uFBF0'] = '\u0626\u06C7';
  18348. t['\uFBF1'] = '\u0626\u06C7';
  18349. t['\uFBF2'] = '\u0626\u06C6';
  18350. t['\uFBF3'] = '\u0626\u06C6';
  18351. t['\uFBF4'] = '\u0626\u06C8';
  18352. t['\uFBF5'] = '\u0626\u06C8';
  18353. t['\uFBF6'] = '\u0626\u06D0';
  18354. t['\uFBF7'] = '\u0626\u06D0';
  18355. t['\uFBF8'] = '\u0626\u06D0';
  18356. t['\uFBF9'] = '\u0626\u0649';
  18357. t['\uFBFA'] = '\u0626\u0649';
  18358. t['\uFBFB'] = '\u0626\u0649';
  18359. t['\uFBFC'] = '\u06CC';
  18360. t['\uFBFD'] = '\u06CC';
  18361. t['\uFBFE'] = '\u06CC';
  18362. t['\uFBFF'] = '\u06CC';
  18363. t['\uFC00'] = '\u0626\u062C';
  18364. t['\uFC01'] = '\u0626\u062D';
  18365. t['\uFC02'] = '\u0626\u0645';
  18366. t['\uFC03'] = '\u0626\u0649';
  18367. t['\uFC04'] = '\u0626\u064A';
  18368. t['\uFC05'] = '\u0628\u062C';
  18369. t['\uFC06'] = '\u0628\u062D';
  18370. t['\uFC07'] = '\u0628\u062E';
  18371. t['\uFC08'] = '\u0628\u0645';
  18372. t['\uFC09'] = '\u0628\u0649';
  18373. t['\uFC0A'] = '\u0628\u064A';
  18374. t['\uFC0B'] = '\u062A\u062C';
  18375. t['\uFC0C'] = '\u062A\u062D';
  18376. t['\uFC0D'] = '\u062A\u062E';
  18377. t['\uFC0E'] = '\u062A\u0645';
  18378. t['\uFC0F'] = '\u062A\u0649';
  18379. t['\uFC10'] = '\u062A\u064A';
  18380. t['\uFC11'] = '\u062B\u062C';
  18381. t['\uFC12'] = '\u062B\u0645';
  18382. t['\uFC13'] = '\u062B\u0649';
  18383. t['\uFC14'] = '\u062B\u064A';
  18384. t['\uFC15'] = '\u062C\u062D';
  18385. t['\uFC16'] = '\u062C\u0645';
  18386. t['\uFC17'] = '\u062D\u062C';
  18387. t['\uFC18'] = '\u062D\u0645';
  18388. t['\uFC19'] = '\u062E\u062C';
  18389. t['\uFC1A'] = '\u062E\u062D';
  18390. t['\uFC1B'] = '\u062E\u0645';
  18391. t['\uFC1C'] = '\u0633\u062C';
  18392. t['\uFC1D'] = '\u0633\u062D';
  18393. t['\uFC1E'] = '\u0633\u062E';
  18394. t['\uFC1F'] = '\u0633\u0645';
  18395. t['\uFC20'] = '\u0635\u062D';
  18396. t['\uFC21'] = '\u0635\u0645';
  18397. t['\uFC22'] = '\u0636\u062C';
  18398. t['\uFC23'] = '\u0636\u062D';
  18399. t['\uFC24'] = '\u0636\u062E';
  18400. t['\uFC25'] = '\u0636\u0645';
  18401. t['\uFC26'] = '\u0637\u062D';
  18402. t['\uFC27'] = '\u0637\u0645';
  18403. t['\uFC28'] = '\u0638\u0645';
  18404. t['\uFC29'] = '\u0639\u062C';
  18405. t['\uFC2A'] = '\u0639\u0645';
  18406. t['\uFC2B'] = '\u063A\u062C';
  18407. t['\uFC2C'] = '\u063A\u0645';
  18408. t['\uFC2D'] = '\u0641\u062C';
  18409. t['\uFC2E'] = '\u0641\u062D';
  18410. t['\uFC2F'] = '\u0641\u062E';
  18411. t['\uFC30'] = '\u0641\u0645';
  18412. t['\uFC31'] = '\u0641\u0649';
  18413. t['\uFC32'] = '\u0641\u064A';
  18414. t['\uFC33'] = '\u0642\u062D';
  18415. t['\uFC34'] = '\u0642\u0645';
  18416. t['\uFC35'] = '\u0642\u0649';
  18417. t['\uFC36'] = '\u0642\u064A';
  18418. t['\uFC37'] = '\u0643\u0627';
  18419. t['\uFC38'] = '\u0643\u062C';
  18420. t['\uFC39'] = '\u0643\u062D';
  18421. t['\uFC3A'] = '\u0643\u062E';
  18422. t['\uFC3B'] = '\u0643\u0644';
  18423. t['\uFC3C'] = '\u0643\u0645';
  18424. t['\uFC3D'] = '\u0643\u0649';
  18425. t['\uFC3E'] = '\u0643\u064A';
  18426. t['\uFC3F'] = '\u0644\u062C';
  18427. t['\uFC40'] = '\u0644\u062D';
  18428. t['\uFC41'] = '\u0644\u062E';
  18429. t['\uFC42'] = '\u0644\u0645';
  18430. t['\uFC43'] = '\u0644\u0649';
  18431. t['\uFC44'] = '\u0644\u064A';
  18432. t['\uFC45'] = '\u0645\u062C';
  18433. t['\uFC46'] = '\u0645\u062D';
  18434. t['\uFC47'] = '\u0645\u062E';
  18435. t['\uFC48'] = '\u0645\u0645';
  18436. t['\uFC49'] = '\u0645\u0649';
  18437. t['\uFC4A'] = '\u0645\u064A';
  18438. t['\uFC4B'] = '\u0646\u062C';
  18439. t['\uFC4C'] = '\u0646\u062D';
  18440. t['\uFC4D'] = '\u0646\u062E';
  18441. t['\uFC4E'] = '\u0646\u0645';
  18442. t['\uFC4F'] = '\u0646\u0649';
  18443. t['\uFC50'] = '\u0646\u064A';
  18444. t['\uFC51'] = '\u0647\u062C';
  18445. t['\uFC52'] = '\u0647\u0645';
  18446. t['\uFC53'] = '\u0647\u0649';
  18447. t['\uFC54'] = '\u0647\u064A';
  18448. t['\uFC55'] = '\u064A\u062C';
  18449. t['\uFC56'] = '\u064A\u062D';
  18450. t['\uFC57'] = '\u064A\u062E';
  18451. t['\uFC58'] = '\u064A\u0645';
  18452. t['\uFC59'] = '\u064A\u0649';
  18453. t['\uFC5A'] = '\u064A\u064A';
  18454. t['\uFC5B'] = '\u0630\u0670';
  18455. t['\uFC5C'] = '\u0631\u0670';
  18456. t['\uFC5D'] = '\u0649\u0670';
  18457. t['\uFC5E'] = '\u0020\u064C\u0651';
  18458. t['\uFC5F'] = '\u0020\u064D\u0651';
  18459. t['\uFC60'] = '\u0020\u064E\u0651';
  18460. t['\uFC61'] = '\u0020\u064F\u0651';
  18461. t['\uFC62'] = '\u0020\u0650\u0651';
  18462. t['\uFC63'] = '\u0020\u0651\u0670';
  18463. t['\uFC64'] = '\u0626\u0631';
  18464. t['\uFC65'] = '\u0626\u0632';
  18465. t['\uFC66'] = '\u0626\u0645';
  18466. t['\uFC67'] = '\u0626\u0646';
  18467. t['\uFC68'] = '\u0626\u0649';
  18468. t['\uFC69'] = '\u0626\u064A';
  18469. t['\uFC6A'] = '\u0628\u0631';
  18470. t['\uFC6B'] = '\u0628\u0632';
  18471. t['\uFC6C'] = '\u0628\u0645';
  18472. t['\uFC6D'] = '\u0628\u0646';
  18473. t['\uFC6E'] = '\u0628\u0649';
  18474. t['\uFC6F'] = '\u0628\u064A';
  18475. t['\uFC70'] = '\u062A\u0631';
  18476. t['\uFC71'] = '\u062A\u0632';
  18477. t['\uFC72'] = '\u062A\u0645';
  18478. t['\uFC73'] = '\u062A\u0646';
  18479. t['\uFC74'] = '\u062A\u0649';
  18480. t['\uFC75'] = '\u062A\u064A';
  18481. t['\uFC76'] = '\u062B\u0631';
  18482. t['\uFC77'] = '\u062B\u0632';
  18483. t['\uFC78'] = '\u062B\u0645';
  18484. t['\uFC79'] = '\u062B\u0646';
  18485. t['\uFC7A'] = '\u062B\u0649';
  18486. t['\uFC7B'] = '\u062B\u064A';
  18487. t['\uFC7C'] = '\u0641\u0649';
  18488. t['\uFC7D'] = '\u0641\u064A';
  18489. t['\uFC7E'] = '\u0642\u0649';
  18490. t['\uFC7F'] = '\u0642\u064A';
  18491. t['\uFC80'] = '\u0643\u0627';
  18492. t['\uFC81'] = '\u0643\u0644';
  18493. t['\uFC82'] = '\u0643\u0645';
  18494. t['\uFC83'] = '\u0643\u0649';
  18495. t['\uFC84'] = '\u0643\u064A';
  18496. t['\uFC85'] = '\u0644\u0645';
  18497. t['\uFC86'] = '\u0644\u0649';
  18498. t['\uFC87'] = '\u0644\u064A';
  18499. t['\uFC88'] = '\u0645\u0627';
  18500. t['\uFC89'] = '\u0645\u0645';
  18501. t['\uFC8A'] = '\u0646\u0631';
  18502. t['\uFC8B'] = '\u0646\u0632';
  18503. t['\uFC8C'] = '\u0646\u0645';
  18504. t['\uFC8D'] = '\u0646\u0646';
  18505. t['\uFC8E'] = '\u0646\u0649';
  18506. t['\uFC8F'] = '\u0646\u064A';
  18507. t['\uFC90'] = '\u0649\u0670';
  18508. t['\uFC91'] = '\u064A\u0631';
  18509. t['\uFC92'] = '\u064A\u0632';
  18510. t['\uFC93'] = '\u064A\u0645';
  18511. t['\uFC94'] = '\u064A\u0646';
  18512. t['\uFC95'] = '\u064A\u0649';
  18513. t['\uFC96'] = '\u064A\u064A';
  18514. t['\uFC97'] = '\u0626\u062C';
  18515. t['\uFC98'] = '\u0626\u062D';
  18516. t['\uFC99'] = '\u0626\u062E';
  18517. t['\uFC9A'] = '\u0626\u0645';
  18518. t['\uFC9B'] = '\u0626\u0647';
  18519. t['\uFC9C'] = '\u0628\u062C';
  18520. t['\uFC9D'] = '\u0628\u062D';
  18521. t['\uFC9E'] = '\u0628\u062E';
  18522. t['\uFC9F'] = '\u0628\u0645';
  18523. t['\uFCA0'] = '\u0628\u0647';
  18524. t['\uFCA1'] = '\u062A\u062C';
  18525. t['\uFCA2'] = '\u062A\u062D';
  18526. t['\uFCA3'] = '\u062A\u062E';
  18527. t['\uFCA4'] = '\u062A\u0645';
  18528. t['\uFCA5'] = '\u062A\u0647';
  18529. t['\uFCA6'] = '\u062B\u0645';
  18530. t['\uFCA7'] = '\u062C\u062D';
  18531. t['\uFCA8'] = '\u062C\u0645';
  18532. t['\uFCA9'] = '\u062D\u062C';
  18533. t['\uFCAA'] = '\u062D\u0645';
  18534. t['\uFCAB'] = '\u062E\u062C';
  18535. t['\uFCAC'] = '\u062E\u0645';
  18536. t['\uFCAD'] = '\u0633\u062C';
  18537. t['\uFCAE'] = '\u0633\u062D';
  18538. t['\uFCAF'] = '\u0633\u062E';
  18539. t['\uFCB0'] = '\u0633\u0645';
  18540. t['\uFCB1'] = '\u0635\u062D';
  18541. t['\uFCB2'] = '\u0635\u062E';
  18542. t['\uFCB3'] = '\u0635\u0645';
  18543. t['\uFCB4'] = '\u0636\u062C';
  18544. t['\uFCB5'] = '\u0636\u062D';
  18545. t['\uFCB6'] = '\u0636\u062E';
  18546. t['\uFCB7'] = '\u0636\u0645';
  18547. t['\uFCB8'] = '\u0637\u062D';
  18548. t['\uFCB9'] = '\u0638\u0645';
  18549. t['\uFCBA'] = '\u0639\u062C';
  18550. t['\uFCBB'] = '\u0639\u0645';
  18551. t['\uFCBC'] = '\u063A\u062C';
  18552. t['\uFCBD'] = '\u063A\u0645';
  18553. t['\uFCBE'] = '\u0641\u062C';
  18554. t['\uFCBF'] = '\u0641\u062D';
  18555. t['\uFCC0'] = '\u0641\u062E';
  18556. t['\uFCC1'] = '\u0641\u0645';
  18557. t['\uFCC2'] = '\u0642\u062D';
  18558. t['\uFCC3'] = '\u0642\u0645';
  18559. t['\uFCC4'] = '\u0643\u062C';
  18560. t['\uFCC5'] = '\u0643\u062D';
  18561. t['\uFCC6'] = '\u0643\u062E';
  18562. t['\uFCC7'] = '\u0643\u0644';
  18563. t['\uFCC8'] = '\u0643\u0645';
  18564. t['\uFCC9'] = '\u0644\u062C';
  18565. t['\uFCCA'] = '\u0644\u062D';
  18566. t['\uFCCB'] = '\u0644\u062E';
  18567. t['\uFCCC'] = '\u0644\u0645';
  18568. t['\uFCCD'] = '\u0644\u0647';
  18569. t['\uFCCE'] = '\u0645\u062C';
  18570. t['\uFCCF'] = '\u0645\u062D';
  18571. t['\uFCD0'] = '\u0645\u062E';
  18572. t['\uFCD1'] = '\u0645\u0645';
  18573. t['\uFCD2'] = '\u0646\u062C';
  18574. t['\uFCD3'] = '\u0646\u062D';
  18575. t['\uFCD4'] = '\u0646\u062E';
  18576. t['\uFCD5'] = '\u0646\u0645';
  18577. t['\uFCD6'] = '\u0646\u0647';
  18578. t['\uFCD7'] = '\u0647\u062C';
  18579. t['\uFCD8'] = '\u0647\u0645';
  18580. t['\uFCD9'] = '\u0647\u0670';
  18581. t['\uFCDA'] = '\u064A\u062C';
  18582. t['\uFCDB'] = '\u064A\u062D';
  18583. t['\uFCDC'] = '\u064A\u062E';
  18584. t['\uFCDD'] = '\u064A\u0645';
  18585. t['\uFCDE'] = '\u064A\u0647';
  18586. t['\uFCDF'] = '\u0626\u0645';
  18587. t['\uFCE0'] = '\u0626\u0647';
  18588. t['\uFCE1'] = '\u0628\u0645';
  18589. t['\uFCE2'] = '\u0628\u0647';
  18590. t['\uFCE3'] = '\u062A\u0645';
  18591. t['\uFCE4'] = '\u062A\u0647';
  18592. t['\uFCE5'] = '\u062B\u0645';
  18593. t['\uFCE6'] = '\u062B\u0647';
  18594. t['\uFCE7'] = '\u0633\u0645';
  18595. t['\uFCE8'] = '\u0633\u0647';
  18596. t['\uFCE9'] = '\u0634\u0645';
  18597. t['\uFCEA'] = '\u0634\u0647';
  18598. t['\uFCEB'] = '\u0643\u0644';
  18599. t['\uFCEC'] = '\u0643\u0645';
  18600. t['\uFCED'] = '\u0644\u0645';
  18601. t['\uFCEE'] = '\u0646\u0645';
  18602. t['\uFCEF'] = '\u0646\u0647';
  18603. t['\uFCF0'] = '\u064A\u0645';
  18604. t['\uFCF1'] = '\u064A\u0647';
  18605. t['\uFCF2'] = '\u0640\u064E\u0651';
  18606. t['\uFCF3'] = '\u0640\u064F\u0651';
  18607. t['\uFCF4'] = '\u0640\u0650\u0651';
  18608. t['\uFCF5'] = '\u0637\u0649';
  18609. t['\uFCF6'] = '\u0637\u064A';
  18610. t['\uFCF7'] = '\u0639\u0649';
  18611. t['\uFCF8'] = '\u0639\u064A';
  18612. t['\uFCF9'] = '\u063A\u0649';
  18613. t['\uFCFA'] = '\u063A\u064A';
  18614. t['\uFCFB'] = '\u0633\u0649';
  18615. t['\uFCFC'] = '\u0633\u064A';
  18616. t['\uFCFD'] = '\u0634\u0649';
  18617. t['\uFCFE'] = '\u0634\u064A';
  18618. t['\uFCFF'] = '\u062D\u0649';
  18619. t['\uFD00'] = '\u062D\u064A';
  18620. t['\uFD01'] = '\u062C\u0649';
  18621. t['\uFD02'] = '\u062C\u064A';
  18622. t['\uFD03'] = '\u062E\u0649';
  18623. t['\uFD04'] = '\u062E\u064A';
  18624. t['\uFD05'] = '\u0635\u0649';
  18625. t['\uFD06'] = '\u0635\u064A';
  18626. t['\uFD07'] = '\u0636\u0649';
  18627. t['\uFD08'] = '\u0636\u064A';
  18628. t['\uFD09'] = '\u0634\u062C';
  18629. t['\uFD0A'] = '\u0634\u062D';
  18630. t['\uFD0B'] = '\u0634\u062E';
  18631. t['\uFD0C'] = '\u0634\u0645';
  18632. t['\uFD0D'] = '\u0634\u0631';
  18633. t['\uFD0E'] = '\u0633\u0631';
  18634. t['\uFD0F'] = '\u0635\u0631';
  18635. t['\uFD10'] = '\u0636\u0631';
  18636. t['\uFD11'] = '\u0637\u0649';
  18637. t['\uFD12'] = '\u0637\u064A';
  18638. t['\uFD13'] = '\u0639\u0649';
  18639. t['\uFD14'] = '\u0639\u064A';
  18640. t['\uFD15'] = '\u063A\u0649';
  18641. t['\uFD16'] = '\u063A\u064A';
  18642. t['\uFD17'] = '\u0633\u0649';
  18643. t['\uFD18'] = '\u0633\u064A';
  18644. t['\uFD19'] = '\u0634\u0649';
  18645. t['\uFD1A'] = '\u0634\u064A';
  18646. t['\uFD1B'] = '\u062D\u0649';
  18647. t['\uFD1C'] = '\u062D\u064A';
  18648. t['\uFD1D'] = '\u062C\u0649';
  18649. t['\uFD1E'] = '\u062C\u064A';
  18650. t['\uFD1F'] = '\u062E\u0649';
  18651. t['\uFD20'] = '\u062E\u064A';
  18652. t['\uFD21'] = '\u0635\u0649';
  18653. t['\uFD22'] = '\u0635\u064A';
  18654. t['\uFD23'] = '\u0636\u0649';
  18655. t['\uFD24'] = '\u0636\u064A';
  18656. t['\uFD25'] = '\u0634\u062C';
  18657. t['\uFD26'] = '\u0634\u062D';
  18658. t['\uFD27'] = '\u0634\u062E';
  18659. t['\uFD28'] = '\u0634\u0645';
  18660. t['\uFD29'] = '\u0634\u0631';
  18661. t['\uFD2A'] = '\u0633\u0631';
  18662. t['\uFD2B'] = '\u0635\u0631';
  18663. t['\uFD2C'] = '\u0636\u0631';
  18664. t['\uFD2D'] = '\u0634\u062C';
  18665. t['\uFD2E'] = '\u0634\u062D';
  18666. t['\uFD2F'] = '\u0634\u062E';
  18667. t['\uFD30'] = '\u0634\u0645';
  18668. t['\uFD31'] = '\u0633\u0647';
  18669. t['\uFD32'] = '\u0634\u0647';
  18670. t['\uFD33'] = '\u0637\u0645';
  18671. t['\uFD34'] = '\u0633\u062C';
  18672. t['\uFD35'] = '\u0633\u062D';
  18673. t['\uFD36'] = '\u0633\u062E';
  18674. t['\uFD37'] = '\u0634\u062C';
  18675. t['\uFD38'] = '\u0634\u062D';
  18676. t['\uFD39'] = '\u0634\u062E';
  18677. t['\uFD3A'] = '\u0637\u0645';
  18678. t['\uFD3B'] = '\u0638\u0645';
  18679. t['\uFD3C'] = '\u0627\u064B';
  18680. t['\uFD3D'] = '\u0627\u064B';
  18681. t['\uFD50'] = '\u062A\u062C\u0645';
  18682. t['\uFD51'] = '\u062A\u062D\u062C';
  18683. t['\uFD52'] = '\u062A\u062D\u062C';
  18684. t['\uFD53'] = '\u062A\u062D\u0645';
  18685. t['\uFD54'] = '\u062A\u062E\u0645';
  18686. t['\uFD55'] = '\u062A\u0645\u062C';
  18687. t['\uFD56'] = '\u062A\u0645\u062D';
  18688. t['\uFD57'] = '\u062A\u0645\u062E';
  18689. t['\uFD58'] = '\u062C\u0645\u062D';
  18690. t['\uFD59'] = '\u062C\u0645\u062D';
  18691. t['\uFD5A'] = '\u062D\u0645\u064A';
  18692. t['\uFD5B'] = '\u062D\u0645\u0649';
  18693. t['\uFD5C'] = '\u0633\u062D\u062C';
  18694. t['\uFD5D'] = '\u0633\u062C\u062D';
  18695. t['\uFD5E'] = '\u0633\u062C\u0649';
  18696. t['\uFD5F'] = '\u0633\u0645\u062D';
  18697. t['\uFD60'] = '\u0633\u0645\u062D';
  18698. t['\uFD61'] = '\u0633\u0645\u062C';
  18699. t['\uFD62'] = '\u0633\u0645\u0645';
  18700. t['\uFD63'] = '\u0633\u0645\u0645';
  18701. t['\uFD64'] = '\u0635\u062D\u062D';
  18702. t['\uFD65'] = '\u0635\u062D\u062D';
  18703. t['\uFD66'] = '\u0635\u0645\u0645';
  18704. t['\uFD67'] = '\u0634\u062D\u0645';
  18705. t['\uFD68'] = '\u0634\u062D\u0645';
  18706. t['\uFD69'] = '\u0634\u062C\u064A';
  18707. t['\uFD6A'] = '\u0634\u0645\u062E';
  18708. t['\uFD6B'] = '\u0634\u0645\u062E';
  18709. t['\uFD6C'] = '\u0634\u0645\u0645';
  18710. t['\uFD6D'] = '\u0634\u0645\u0645';
  18711. t['\uFD6E'] = '\u0636\u062D\u0649';
  18712. t['\uFD6F'] = '\u0636\u062E\u0645';
  18713. t['\uFD70'] = '\u0636\u062E\u0645';
  18714. t['\uFD71'] = '\u0637\u0645\u062D';
  18715. t['\uFD72'] = '\u0637\u0645\u062D';
  18716. t['\uFD73'] = '\u0637\u0645\u0645';
  18717. t['\uFD74'] = '\u0637\u0645\u064A';
  18718. t['\uFD75'] = '\u0639\u062C\u0645';
  18719. t['\uFD76'] = '\u0639\u0645\u0645';
  18720. t['\uFD77'] = '\u0639\u0645\u0645';
  18721. t['\uFD78'] = '\u0639\u0645\u0649';
  18722. t['\uFD79'] = '\u063A\u0645\u0645';
  18723. t['\uFD7A'] = '\u063A\u0645\u064A';
  18724. t['\uFD7B'] = '\u063A\u0645\u0649';
  18725. t['\uFD7C'] = '\u0641\u062E\u0645';
  18726. t['\uFD7D'] = '\u0641\u062E\u0645';
  18727. t['\uFD7E'] = '\u0642\u0645\u062D';
  18728. t['\uFD7F'] = '\u0642\u0645\u0645';
  18729. t['\uFD80'] = '\u0644\u062D\u0645';
  18730. t['\uFD81'] = '\u0644\u062D\u064A';
  18731. t['\uFD82'] = '\u0644\u062D\u0649';
  18732. t['\uFD83'] = '\u0644\u062C\u062C';
  18733. t['\uFD84'] = '\u0644\u062C\u062C';
  18734. t['\uFD85'] = '\u0644\u062E\u0645';
  18735. t['\uFD86'] = '\u0644\u062E\u0645';
  18736. t['\uFD87'] = '\u0644\u0645\u062D';
  18737. t['\uFD88'] = '\u0644\u0645\u062D';
  18738. t['\uFD89'] = '\u0645\u062D\u062C';
  18739. t['\uFD8A'] = '\u0645\u062D\u0645';
  18740. t['\uFD8B'] = '\u0645\u062D\u064A';
  18741. t['\uFD8C'] = '\u0645\u062C\u062D';
  18742. t['\uFD8D'] = '\u0645\u062C\u0645';
  18743. t['\uFD8E'] = '\u0645\u062E\u062C';
  18744. t['\uFD8F'] = '\u0645\u062E\u0645';
  18745. t['\uFD92'] = '\u0645\u062C\u062E';
  18746. t['\uFD93'] = '\u0647\u0645\u062C';
  18747. t['\uFD94'] = '\u0647\u0645\u0645';
  18748. t['\uFD95'] = '\u0646\u062D\u0645';
  18749. t['\uFD96'] = '\u0646\u062D\u0649';
  18750. t['\uFD97'] = '\u0646\u062C\u0645';
  18751. t['\uFD98'] = '\u0646\u062C\u0645';
  18752. t['\uFD99'] = '\u0646\u062C\u0649';
  18753. t['\uFD9A'] = '\u0646\u0645\u064A';
  18754. t['\uFD9B'] = '\u0646\u0645\u0649';
  18755. t['\uFD9C'] = '\u064A\u0645\u0645';
  18756. t['\uFD9D'] = '\u064A\u0645\u0645';
  18757. t['\uFD9E'] = '\u0628\u062E\u064A';
  18758. t['\uFD9F'] = '\u062A\u062C\u064A';
  18759. t['\uFDA0'] = '\u062A\u062C\u0649';
  18760. t['\uFDA1'] = '\u062A\u062E\u064A';
  18761. t['\uFDA2'] = '\u062A\u062E\u0649';
  18762. t['\uFDA3'] = '\u062A\u0645\u064A';
  18763. t['\uFDA4'] = '\u062A\u0645\u0649';
  18764. t['\uFDA5'] = '\u062C\u0645\u064A';
  18765. t['\uFDA6'] = '\u062C\u062D\u0649';
  18766. t['\uFDA7'] = '\u062C\u0645\u0649';
  18767. t['\uFDA8'] = '\u0633\u062E\u0649';
  18768. t['\uFDA9'] = '\u0635\u062D\u064A';
  18769. t['\uFDAA'] = '\u0634\u062D\u064A';
  18770. t['\uFDAB'] = '\u0636\u062D\u064A';
  18771. t['\uFDAC'] = '\u0644\u062C\u064A';
  18772. t['\uFDAD'] = '\u0644\u0645\u064A';
  18773. t['\uFDAE'] = '\u064A\u062D\u064A';
  18774. t['\uFDAF'] = '\u064A\u062C\u064A';
  18775. t['\uFDB0'] = '\u064A\u0645\u064A';
  18776. t['\uFDB1'] = '\u0645\u0645\u064A';
  18777. t['\uFDB2'] = '\u0642\u0645\u064A';
  18778. t['\uFDB3'] = '\u0646\u062D\u064A';
  18779. t['\uFDB4'] = '\u0642\u0645\u062D';
  18780. t['\uFDB5'] = '\u0644\u062D\u0645';
  18781. t['\uFDB6'] = '\u0639\u0645\u064A';
  18782. t['\uFDB7'] = '\u0643\u0645\u064A';
  18783. t['\uFDB8'] = '\u0646\u062C\u062D';
  18784. t['\uFDB9'] = '\u0645\u062E\u064A';
  18785. t['\uFDBA'] = '\u0644\u062C\u0645';
  18786. t['\uFDBB'] = '\u0643\u0645\u0645';
  18787. t['\uFDBC'] = '\u0644\u062C\u0645';
  18788. t['\uFDBD'] = '\u0646\u062C\u062D';
  18789. t['\uFDBE'] = '\u062C\u062D\u064A';
  18790. t['\uFDBF'] = '\u062D\u062C\u064A';
  18791. t['\uFDC0'] = '\u0645\u062C\u064A';
  18792. t['\uFDC1'] = '\u0641\u0645\u064A';
  18793. t['\uFDC2'] = '\u0628\u062D\u064A';
  18794. t['\uFDC3'] = '\u0643\u0645\u0645';
  18795. t['\uFDC4'] = '\u0639\u062C\u0645';
  18796. t['\uFDC5'] = '\u0635\u0645\u0645';
  18797. t['\uFDC6'] = '\u0633\u062E\u064A';
  18798. t['\uFDC7'] = '\u0646\u062C\u064A';
  18799. t['\uFE49'] = '\u203E';
  18800. t['\uFE4A'] = '\u203E';
  18801. t['\uFE4B'] = '\u203E';
  18802. t['\uFE4C'] = '\u203E';
  18803. t['\uFE4D'] = '\u005F';
  18804. t['\uFE4E'] = '\u005F';
  18805. t['\uFE4F'] = '\u005F';
  18806. t['\uFE80'] = '\u0621';
  18807. t['\uFE81'] = '\u0622';
  18808. t['\uFE82'] = '\u0622';
  18809. t['\uFE83'] = '\u0623';
  18810. t['\uFE84'] = '\u0623';
  18811. t['\uFE85'] = '\u0624';
  18812. t['\uFE86'] = '\u0624';
  18813. t['\uFE87'] = '\u0625';
  18814. t['\uFE88'] = '\u0625';
  18815. t['\uFE89'] = '\u0626';
  18816. t['\uFE8A'] = '\u0626';
  18817. t['\uFE8B'] = '\u0626';
  18818. t['\uFE8C'] = '\u0626';
  18819. t['\uFE8D'] = '\u0627';
  18820. t['\uFE8E'] = '\u0627';
  18821. t['\uFE8F'] = '\u0628';
  18822. t['\uFE90'] = '\u0628';
  18823. t['\uFE91'] = '\u0628';
  18824. t['\uFE92'] = '\u0628';
  18825. t['\uFE93'] = '\u0629';
  18826. t['\uFE94'] = '\u0629';
  18827. t['\uFE95'] = '\u062A';
  18828. t['\uFE96'] = '\u062A';
  18829. t['\uFE97'] = '\u062A';
  18830. t['\uFE98'] = '\u062A';
  18831. t['\uFE99'] = '\u062B';
  18832. t['\uFE9A'] = '\u062B';
  18833. t['\uFE9B'] = '\u062B';
  18834. t['\uFE9C'] = '\u062B';
  18835. t['\uFE9D'] = '\u062C';
  18836. t['\uFE9E'] = '\u062C';
  18837. t['\uFE9F'] = '\u062C';
  18838. t['\uFEA0'] = '\u062C';
  18839. t['\uFEA1'] = '\u062D';
  18840. t['\uFEA2'] = '\u062D';
  18841. t['\uFEA3'] = '\u062D';
  18842. t['\uFEA4'] = '\u062D';
  18843. t['\uFEA5'] = '\u062E';
  18844. t['\uFEA6'] = '\u062E';
  18845. t['\uFEA7'] = '\u062E';
  18846. t['\uFEA8'] = '\u062E';
  18847. t['\uFEA9'] = '\u062F';
  18848. t['\uFEAA'] = '\u062F';
  18849. t['\uFEAB'] = '\u0630';
  18850. t['\uFEAC'] = '\u0630';
  18851. t['\uFEAD'] = '\u0631';
  18852. t['\uFEAE'] = '\u0631';
  18853. t['\uFEAF'] = '\u0632';
  18854. t['\uFEB0'] = '\u0632';
  18855. t['\uFEB1'] = '\u0633';
  18856. t['\uFEB2'] = '\u0633';
  18857. t['\uFEB3'] = '\u0633';
  18858. t['\uFEB4'] = '\u0633';
  18859. t['\uFEB5'] = '\u0634';
  18860. t['\uFEB6'] = '\u0634';
  18861. t['\uFEB7'] = '\u0634';
  18862. t['\uFEB8'] = '\u0634';
  18863. t['\uFEB9'] = '\u0635';
  18864. t['\uFEBA'] = '\u0635';
  18865. t['\uFEBB'] = '\u0635';
  18866. t['\uFEBC'] = '\u0635';
  18867. t['\uFEBD'] = '\u0636';
  18868. t['\uFEBE'] = '\u0636';
  18869. t['\uFEBF'] = '\u0636';
  18870. t['\uFEC0'] = '\u0636';
  18871. t['\uFEC1'] = '\u0637';
  18872. t['\uFEC2'] = '\u0637';
  18873. t['\uFEC3'] = '\u0637';
  18874. t['\uFEC4'] = '\u0637';
  18875. t['\uFEC5'] = '\u0638';
  18876. t['\uFEC6'] = '\u0638';
  18877. t['\uFEC7'] = '\u0638';
  18878. t['\uFEC8'] = '\u0638';
  18879. t['\uFEC9'] = '\u0639';
  18880. t['\uFECA'] = '\u0639';
  18881. t['\uFECB'] = '\u0639';
  18882. t['\uFECC'] = '\u0639';
  18883. t['\uFECD'] = '\u063A';
  18884. t['\uFECE'] = '\u063A';
  18885. t['\uFECF'] = '\u063A';
  18886. t['\uFED0'] = '\u063A';
  18887. t['\uFED1'] = '\u0641';
  18888. t['\uFED2'] = '\u0641';
  18889. t['\uFED3'] = '\u0641';
  18890. t['\uFED4'] = '\u0641';
  18891. t['\uFED5'] = '\u0642';
  18892. t['\uFED6'] = '\u0642';
  18893. t['\uFED7'] = '\u0642';
  18894. t['\uFED8'] = '\u0642';
  18895. t['\uFED9'] = '\u0643';
  18896. t['\uFEDA'] = '\u0643';
  18897. t['\uFEDB'] = '\u0643';
  18898. t['\uFEDC'] = '\u0643';
  18899. t['\uFEDD'] = '\u0644';
  18900. t['\uFEDE'] = '\u0644';
  18901. t['\uFEDF'] = '\u0644';
  18902. t['\uFEE0'] = '\u0644';
  18903. t['\uFEE1'] = '\u0645';
  18904. t['\uFEE2'] = '\u0645';
  18905. t['\uFEE3'] = '\u0645';
  18906. t['\uFEE4'] = '\u0645';
  18907. t['\uFEE5'] = '\u0646';
  18908. t['\uFEE6'] = '\u0646';
  18909. t['\uFEE7'] = '\u0646';
  18910. t['\uFEE8'] = '\u0646';
  18911. t['\uFEE9'] = '\u0647';
  18912. t['\uFEEA'] = '\u0647';
  18913. t['\uFEEB'] = '\u0647';
  18914. t['\uFEEC'] = '\u0647';
  18915. t['\uFEED'] = '\u0648';
  18916. t['\uFEEE'] = '\u0648';
  18917. t['\uFEEF'] = '\u0649';
  18918. t['\uFEF0'] = '\u0649';
  18919. t['\uFEF1'] = '\u064A';
  18920. t['\uFEF2'] = '\u064A';
  18921. t['\uFEF3'] = '\u064A';
  18922. t['\uFEF4'] = '\u064A';
  18923. t['\uFEF5'] = '\u0644\u0622';
  18924. t['\uFEF6'] = '\u0644\u0622';
  18925. t['\uFEF7'] = '\u0644\u0623';
  18926. t['\uFEF8'] = '\u0644\u0623';
  18927. t['\uFEF9'] = '\u0644\u0625';
  18928. t['\uFEFA'] = '\u0644\u0625';
  18929. t['\uFEFB'] = '\u0644\u0627';
  18930. t['\uFEFC'] = '\u0644\u0627';
  18931. });
  18932. function reverseIfRtl(chars) {
  18933. var charsLength = chars.length;
  18934. //reverse an arabic ligature
  18935. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  18936. return chars;
  18937. }
  18938. var s = '';
  18939. for (var ii = charsLength - 1; ii >= 0; ii--) {
  18940. s += chars[ii];
  18941. }
  18942. return s;
  18943. }
  18944. exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues;
  18945. exports.reverseIfRtl = reverseIfRtl;
  18946. exports.getUnicodeRangeFor = getUnicodeRangeFor;
  18947. exports.getNormalizedUnicodes = getNormalizedUnicodes;
  18948. exports.getUnicodeForGlyph = getUnicodeForGlyph;
  18949. }));
  18950. (function (root, factory) {
  18951. {
  18952. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  18953. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  18954. root.pdfjsCoreJpx);
  18955. }
  18956. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  18957. coreJpx) {
  18958. var Util = sharedUtil.Util;
  18959. var error = sharedUtil.error;
  18960. var info = sharedUtil.info;
  18961. var isArray = sharedUtil.isArray;
  18962. var createObjectURL = sharedUtil.createObjectURL;
  18963. var shadow = sharedUtil.shadow;
  18964. var warn = sharedUtil.warn;
  18965. var isSpace = sharedUtil.isSpace;
  18966. var Dict = corePrimitives.Dict;
  18967. var isDict = corePrimitives.isDict;
  18968. var Jbig2Image = coreJbig2.Jbig2Image;
  18969. var JpegImage = coreJpg.JpegImage;
  18970. var JpxImage = coreJpx.JpxImage;
  18971. var Stream = (function StreamClosure() {
  18972. function Stream(arrayBuffer, start, length, dict) {
  18973. this.bytes = (arrayBuffer instanceof Uint8Array ?
  18974. arrayBuffer : new Uint8Array(arrayBuffer));
  18975. this.start = start || 0;
  18976. this.pos = this.start;
  18977. this.end = (start + length) || this.bytes.length;
  18978. this.dict = dict;
  18979. }
  18980. // required methods for a stream. if a particular stream does not
  18981. // implement these, an error should be thrown
  18982. Stream.prototype = {
  18983. get length() {
  18984. return this.end - this.start;
  18985. },
  18986. get isEmpty() {
  18987. return this.length === 0;
  18988. },
  18989. getByte: function Stream_getByte() {
  18990. if (this.pos >= this.end) {
  18991. return -1;
  18992. }
  18993. return this.bytes[this.pos++];
  18994. },
  18995. getUint16: function Stream_getUint16() {
  18996. var b0 = this.getByte();
  18997. var b1 = this.getByte();
  18998. if (b0 === -1 || b1 === -1) {
  18999. return -1;
  19000. }
  19001. return (b0 << 8) + b1;
  19002. },
  19003. getInt32: function Stream_getInt32() {
  19004. var b0 = this.getByte();
  19005. var b1 = this.getByte();
  19006. var b2 = this.getByte();
  19007. var b3 = this.getByte();
  19008. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  19009. },
  19010. // returns subarray of original buffer
  19011. // should only be read
  19012. getBytes: function Stream_getBytes(length) {
  19013. var bytes = this.bytes;
  19014. var pos = this.pos;
  19015. var strEnd = this.end;
  19016. if (!length) {
  19017. return bytes.subarray(pos, strEnd);
  19018. }
  19019. var end = pos + length;
  19020. if (end > strEnd) {
  19021. end = strEnd;
  19022. }
  19023. this.pos = end;
  19024. return bytes.subarray(pos, end);
  19025. },
  19026. peekByte: function Stream_peekByte() {
  19027. var peekedByte = this.getByte();
  19028. this.pos--;
  19029. return peekedByte;
  19030. },
  19031. peekBytes: function Stream_peekBytes(length) {
  19032. var bytes = this.getBytes(length);
  19033. this.pos -= bytes.length;
  19034. return bytes;
  19035. },
  19036. skip: function Stream_skip(n) {
  19037. if (!n) {
  19038. n = 1;
  19039. }
  19040. this.pos += n;
  19041. },
  19042. reset: function Stream_reset() {
  19043. this.pos = this.start;
  19044. },
  19045. moveStart: function Stream_moveStart() {
  19046. this.start = this.pos;
  19047. },
  19048. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  19049. return new Stream(this.bytes.buffer, start, length, dict);
  19050. },
  19051. isStream: true
  19052. };
  19053. return Stream;
  19054. })();
  19055. var StringStream = (function StringStreamClosure() {
  19056. function StringStream(str) {
  19057. var length = str.length;
  19058. var bytes = new Uint8Array(length);
  19059. for (var n = 0; n < length; ++n) {
  19060. bytes[n] = str.charCodeAt(n);
  19061. }
  19062. Stream.call(this, bytes);
  19063. }
  19064. StringStream.prototype = Stream.prototype;
  19065. return StringStream;
  19066. })();
  19067. // super class for the decoding streams
  19068. var DecodeStream = (function DecodeStreamClosure() {
  19069. // Lots of DecodeStreams are created whose buffers are never used. For these
  19070. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  19071. // having special cases that would be required if we used |null| for an empty
  19072. // buffer.
  19073. var emptyBuffer = new Uint8Array(0);
  19074. function DecodeStream(maybeMinBufferLength) {
  19075. this.pos = 0;
  19076. this.bufferLength = 0;
  19077. this.eof = false;
  19078. this.buffer = emptyBuffer;
  19079. this.minBufferLength = 512;
  19080. if (maybeMinBufferLength) {
  19081. // Compute the first power of two that is as big as maybeMinBufferLength.
  19082. while (this.minBufferLength < maybeMinBufferLength) {
  19083. this.minBufferLength *= 2;
  19084. }
  19085. }
  19086. }
  19087. DecodeStream.prototype = {
  19088. get isEmpty() {
  19089. while (!this.eof && this.bufferLength === 0) {
  19090. this.readBlock();
  19091. }
  19092. return this.bufferLength === 0;
  19093. },
  19094. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  19095. var buffer = this.buffer;
  19096. if (requested <= buffer.byteLength) {
  19097. return buffer;
  19098. }
  19099. var size = this.minBufferLength;
  19100. while (size < requested) {
  19101. size *= 2;
  19102. }
  19103. var buffer2 = new Uint8Array(size);
  19104. buffer2.set(buffer);
  19105. return (this.buffer = buffer2);
  19106. },
  19107. getByte: function DecodeStream_getByte() {
  19108. var pos = this.pos;
  19109. while (this.bufferLength <= pos) {
  19110. if (this.eof) {
  19111. return -1;
  19112. }
  19113. this.readBlock();
  19114. }
  19115. return this.buffer[this.pos++];
  19116. },
  19117. getUint16: function DecodeStream_getUint16() {
  19118. var b0 = this.getByte();
  19119. var b1 = this.getByte();
  19120. if (b0 === -1 || b1 === -1) {
  19121. return -1;
  19122. }
  19123. return (b0 << 8) + b1;
  19124. },
  19125. getInt32: function DecodeStream_getInt32() {
  19126. var b0 = this.getByte();
  19127. var b1 = this.getByte();
  19128. var b2 = this.getByte();
  19129. var b3 = this.getByte();
  19130. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  19131. },
  19132. getBytes: function DecodeStream_getBytes(length) {
  19133. var end, pos = this.pos;
  19134. if (length) {
  19135. this.ensureBuffer(pos + length);
  19136. end = pos + length;
  19137. while (!this.eof && this.bufferLength < end) {
  19138. this.readBlock();
  19139. }
  19140. var bufEnd = this.bufferLength;
  19141. if (end > bufEnd) {
  19142. end = bufEnd;
  19143. }
  19144. } else {
  19145. while (!this.eof) {
  19146. this.readBlock();
  19147. }
  19148. end = this.bufferLength;
  19149. }
  19150. this.pos = end;
  19151. return this.buffer.subarray(pos, end);
  19152. },
  19153. peekByte: function DecodeStream_peekByte() {
  19154. var peekedByte = this.getByte();
  19155. this.pos--;
  19156. return peekedByte;
  19157. },
  19158. peekBytes: function DecodeStream_peekBytes(length) {
  19159. var bytes = this.getBytes(length);
  19160. this.pos -= bytes.length;
  19161. return bytes;
  19162. },
  19163. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  19164. var end = start + length;
  19165. while (this.bufferLength <= end && !this.eof) {
  19166. this.readBlock();
  19167. }
  19168. return new Stream(this.buffer, start, length, dict);
  19169. },
  19170. skip: function DecodeStream_skip(n) {
  19171. if (!n) {
  19172. n = 1;
  19173. }
  19174. this.pos += n;
  19175. },
  19176. reset: function DecodeStream_reset() {
  19177. this.pos = 0;
  19178. },
  19179. getBaseStreams: function DecodeStream_getBaseStreams() {
  19180. if (this.str && this.str.getBaseStreams) {
  19181. return this.str.getBaseStreams();
  19182. }
  19183. return [];
  19184. }
  19185. };
  19186. return DecodeStream;
  19187. })();
  19188. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  19189. function StreamsSequenceStream(streams) {
  19190. this.streams = streams;
  19191. DecodeStream.call(this, /* maybeLength = */ null);
  19192. }
  19193. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  19194. StreamsSequenceStream.prototype.readBlock =
  19195. function streamSequenceStreamReadBlock() {
  19196. var streams = this.streams;
  19197. if (streams.length === 0) {
  19198. this.eof = true;
  19199. return;
  19200. }
  19201. var stream = streams.shift();
  19202. var chunk = stream.getBytes();
  19203. var bufferLength = this.bufferLength;
  19204. var newLength = bufferLength + chunk.length;
  19205. var buffer = this.ensureBuffer(newLength);
  19206. buffer.set(chunk, bufferLength);
  19207. this.bufferLength = newLength;
  19208. };
  19209. StreamsSequenceStream.prototype.getBaseStreams =
  19210. function StreamsSequenceStream_getBaseStreams() {
  19211. var baseStreams = [];
  19212. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  19213. var stream = this.streams[i];
  19214. if (stream.getBaseStreams) {
  19215. Util.appendToArray(baseStreams, stream.getBaseStreams());
  19216. }
  19217. }
  19218. return baseStreams;
  19219. };
  19220. return StreamsSequenceStream;
  19221. })();
  19222. var FlateStream = (function FlateStreamClosure() {
  19223. var codeLenCodeMap = new Int32Array([
  19224. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  19225. ]);
  19226. var lengthDecode = new Int32Array([
  19227. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  19228. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  19229. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  19230. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  19231. ]);
  19232. var distDecode = new Int32Array([
  19233. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  19234. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  19235. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  19236. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  19237. ]);
  19238. var fixedLitCodeTab = [new Int32Array([
  19239. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  19240. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  19241. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  19242. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  19243. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  19244. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  19245. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  19246. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  19247. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  19248. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  19249. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  19250. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  19251. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  19252. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  19253. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  19254. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  19255. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  19256. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  19257. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  19258. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  19259. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  19260. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  19261. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  19262. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  19263. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  19264. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  19265. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  19266. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  19267. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  19268. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  19269. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  19270. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  19271. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  19272. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  19273. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  19274. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  19275. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  19276. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  19277. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  19278. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  19279. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  19280. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  19281. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  19282. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  19283. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  19284. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  19285. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  19286. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  19287. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  19288. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  19289. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  19290. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  19291. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  19292. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  19293. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  19294. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  19295. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  19296. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  19297. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  19298. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  19299. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  19300. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  19301. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  19302. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  19303. ]), 9];
  19304. var fixedDistCodeTab = [new Int32Array([
  19305. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  19306. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  19307. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  19308. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  19309. ]), 5];
  19310. function FlateStream(str, maybeLength) {
  19311. this.str = str;
  19312. this.dict = str.dict;
  19313. var cmf = str.getByte();
  19314. var flg = str.getByte();
  19315. if (cmf === -1 || flg === -1) {
  19316. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  19317. }
  19318. if ((cmf & 0x0f) !== 0x08) {
  19319. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  19320. }
  19321. if ((((cmf << 8) + flg) % 31) !== 0) {
  19322. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  19323. }
  19324. if (flg & 0x20) {
  19325. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  19326. }
  19327. this.codeSize = 0;
  19328. this.codeBuf = 0;
  19329. DecodeStream.call(this, maybeLength);
  19330. }
  19331. FlateStream.prototype = Object.create(DecodeStream.prototype);
  19332. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  19333. var str = this.str;
  19334. var codeSize = this.codeSize;
  19335. var codeBuf = this.codeBuf;
  19336. var b;
  19337. while (codeSize < bits) {
  19338. if ((b = str.getByte()) === -1) {
  19339. error('Bad encoding in flate stream');
  19340. }
  19341. codeBuf |= b << codeSize;
  19342. codeSize += 8;
  19343. }
  19344. b = codeBuf & ((1 << bits) - 1);
  19345. this.codeBuf = codeBuf >> bits;
  19346. this.codeSize = codeSize -= bits;
  19347. return b;
  19348. };
  19349. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  19350. var str = this.str;
  19351. var codes = table[0];
  19352. var maxLen = table[1];
  19353. var codeSize = this.codeSize;
  19354. var codeBuf = this.codeBuf;
  19355. var b;
  19356. while (codeSize < maxLen) {
  19357. if ((b = str.getByte()) === -1) {
  19358. // premature end of stream. code might however still be valid.
  19359. // codeSize < codeLen check below guards against incomplete codeVal.
  19360. break;
  19361. }
  19362. codeBuf |= (b << codeSize);
  19363. codeSize += 8;
  19364. }
  19365. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  19366. var codeLen = code >> 16;
  19367. var codeVal = code & 0xffff;
  19368. if (codeLen < 1 || codeSize < codeLen) {
  19369. error('Bad encoding in flate stream');
  19370. }
  19371. this.codeBuf = (codeBuf >> codeLen);
  19372. this.codeSize = (codeSize - codeLen);
  19373. return codeVal;
  19374. };
  19375. FlateStream.prototype.generateHuffmanTable =
  19376. function flateStreamGenerateHuffmanTable(lengths) {
  19377. var n = lengths.length;
  19378. // find max code length
  19379. var maxLen = 0;
  19380. var i;
  19381. for (i = 0; i < n; ++i) {
  19382. if (lengths[i] > maxLen) {
  19383. maxLen = lengths[i];
  19384. }
  19385. }
  19386. // build the table
  19387. var size = 1 << maxLen;
  19388. var codes = new Int32Array(size);
  19389. for (var len = 1, code = 0, skip = 2;
  19390. len <= maxLen;
  19391. ++len, code <<= 1, skip <<= 1) {
  19392. for (var val = 0; val < n; ++val) {
  19393. if (lengths[val] === len) {
  19394. // bit-reverse the code
  19395. var code2 = 0;
  19396. var t = code;
  19397. for (i = 0; i < len; ++i) {
  19398. code2 = (code2 << 1) | (t & 1);
  19399. t >>= 1;
  19400. }
  19401. // fill the table entries
  19402. for (i = code2; i < size; i += skip) {
  19403. codes[i] = (len << 16) | val;
  19404. }
  19405. ++code;
  19406. }
  19407. }
  19408. }
  19409. return [codes, maxLen];
  19410. };
  19411. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  19412. var buffer, len;
  19413. var str = this.str;
  19414. // read block header
  19415. var hdr = this.getBits(3);
  19416. if (hdr & 1) {
  19417. this.eof = true;
  19418. }
  19419. hdr >>= 1;
  19420. if (hdr === 0) { // uncompressed block
  19421. var b;
  19422. if ((b = str.getByte()) === -1) {
  19423. error('Bad block header in flate stream');
  19424. }
  19425. var blockLen = b;
  19426. if ((b = str.getByte()) === -1) {
  19427. error('Bad block header in flate stream');
  19428. }
  19429. blockLen |= (b << 8);
  19430. if ((b = str.getByte()) === -1) {
  19431. error('Bad block header in flate stream');
  19432. }
  19433. var check = b;
  19434. if ((b = str.getByte()) === -1) {
  19435. error('Bad block header in flate stream');
  19436. }
  19437. check |= (b << 8);
  19438. if (check !== (~blockLen & 0xffff) &&
  19439. (blockLen !== 0 || check !== 0)) {
  19440. // Ignoring error for bad "empty" block (see issue 1277)
  19441. error('Bad uncompressed block length in flate stream');
  19442. }
  19443. this.codeBuf = 0;
  19444. this.codeSize = 0;
  19445. var bufferLength = this.bufferLength;
  19446. buffer = this.ensureBuffer(bufferLength + blockLen);
  19447. var end = bufferLength + blockLen;
  19448. this.bufferLength = end;
  19449. if (blockLen === 0) {
  19450. if (str.peekByte() === -1) {
  19451. this.eof = true;
  19452. }
  19453. } else {
  19454. for (var n = bufferLength; n < end; ++n) {
  19455. if ((b = str.getByte()) === -1) {
  19456. this.eof = true;
  19457. break;
  19458. }
  19459. buffer[n] = b;
  19460. }
  19461. }
  19462. return;
  19463. }
  19464. var litCodeTable;
  19465. var distCodeTable;
  19466. if (hdr === 1) { // compressed block, fixed codes
  19467. litCodeTable = fixedLitCodeTab;
  19468. distCodeTable = fixedDistCodeTab;
  19469. } else if (hdr === 2) { // compressed block, dynamic codes
  19470. var numLitCodes = this.getBits(5) + 257;
  19471. var numDistCodes = this.getBits(5) + 1;
  19472. var numCodeLenCodes = this.getBits(4) + 4;
  19473. // build the code lengths code table
  19474. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  19475. var i;
  19476. for (i = 0; i < numCodeLenCodes; ++i) {
  19477. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  19478. }
  19479. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  19480. // build the literal and distance code tables
  19481. len = 0;
  19482. i = 0;
  19483. var codes = numLitCodes + numDistCodes;
  19484. var codeLengths = new Uint8Array(codes);
  19485. var bitsLength, bitsOffset, what;
  19486. while (i < codes) {
  19487. var code = this.getCode(codeLenCodeTab);
  19488. if (code === 16) {
  19489. bitsLength = 2; bitsOffset = 3; what = len;
  19490. } else if (code === 17) {
  19491. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  19492. } else if (code === 18) {
  19493. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  19494. } else {
  19495. codeLengths[i++] = len = code;
  19496. continue;
  19497. }
  19498. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  19499. while (repeatLength-- > 0) {
  19500. codeLengths[i++] = what;
  19501. }
  19502. }
  19503. litCodeTable =
  19504. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  19505. distCodeTable =
  19506. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  19507. } else {
  19508. error('Unknown block type in flate stream');
  19509. }
  19510. buffer = this.buffer;
  19511. var limit = buffer ? buffer.length : 0;
  19512. var pos = this.bufferLength;
  19513. while (true) {
  19514. var code1 = this.getCode(litCodeTable);
  19515. if (code1 < 256) {
  19516. if (pos + 1 >= limit) {
  19517. buffer = this.ensureBuffer(pos + 1);
  19518. limit = buffer.length;
  19519. }
  19520. buffer[pos++] = code1;
  19521. continue;
  19522. }
  19523. if (code1 === 256) {
  19524. this.bufferLength = pos;
  19525. return;
  19526. }
  19527. code1 -= 257;
  19528. code1 = lengthDecode[code1];
  19529. var code2 = code1 >> 16;
  19530. if (code2 > 0) {
  19531. code2 = this.getBits(code2);
  19532. }
  19533. len = (code1 & 0xffff) + code2;
  19534. code1 = this.getCode(distCodeTable);
  19535. code1 = distDecode[code1];
  19536. code2 = code1 >> 16;
  19537. if (code2 > 0) {
  19538. code2 = this.getBits(code2);
  19539. }
  19540. var dist = (code1 & 0xffff) + code2;
  19541. if (pos + len >= limit) {
  19542. buffer = this.ensureBuffer(pos + len);
  19543. limit = buffer.length;
  19544. }
  19545. for (var k = 0; k < len; ++k, ++pos) {
  19546. buffer[pos] = buffer[pos - dist];
  19547. }
  19548. }
  19549. };
  19550. return FlateStream;
  19551. })();
  19552. var PredictorStream = (function PredictorStreamClosure() {
  19553. function PredictorStream(str, maybeLength, params) {
  19554. if (!isDict(params)) {
  19555. return str; // no prediction
  19556. }
  19557. var predictor = this.predictor = params.get('Predictor') || 1;
  19558. if (predictor <= 1) {
  19559. return str; // no prediction
  19560. }
  19561. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  19562. error('Unsupported predictor: ' + predictor);
  19563. }
  19564. if (predictor === 2) {
  19565. this.readBlock = this.readBlockTiff;
  19566. } else {
  19567. this.readBlock = this.readBlockPng;
  19568. }
  19569. this.str = str;
  19570. this.dict = str.dict;
  19571. var colors = this.colors = params.get('Colors') || 1;
  19572. var bits = this.bits = params.get('BitsPerComponent') || 8;
  19573. var columns = this.columns = params.get('Columns') || 1;
  19574. this.pixBytes = (colors * bits + 7) >> 3;
  19575. this.rowBytes = (columns * colors * bits + 7) >> 3;
  19576. DecodeStream.call(this, maybeLength);
  19577. return this;
  19578. }
  19579. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  19580. PredictorStream.prototype.readBlockTiff =
  19581. function predictorStreamReadBlockTiff() {
  19582. var rowBytes = this.rowBytes;
  19583. var bufferLength = this.bufferLength;
  19584. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  19585. var bits = this.bits;
  19586. var colors = this.colors;
  19587. var rawBytes = this.str.getBytes(rowBytes);
  19588. this.eof = !rawBytes.length;
  19589. if (this.eof) {
  19590. return;
  19591. }
  19592. var inbuf = 0, outbuf = 0;
  19593. var inbits = 0, outbits = 0;
  19594. var pos = bufferLength;
  19595. var i;
  19596. if (bits === 1) {
  19597. for (i = 0; i < rowBytes; ++i) {
  19598. var c = rawBytes[i];
  19599. inbuf = (inbuf << 8) | c;
  19600. // bitwise addition is exclusive or
  19601. // first shift inbuf and then add
  19602. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  19603. // truncate inbuf (assumes colors < 16)
  19604. inbuf &= 0xFFFF;
  19605. }
  19606. } else if (bits === 8) {
  19607. for (i = 0; i < colors; ++i) {
  19608. buffer[pos++] = rawBytes[i];
  19609. }
  19610. for (; i < rowBytes; ++i) {
  19611. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  19612. pos++;
  19613. }
  19614. } else {
  19615. var compArray = new Uint8Array(colors + 1);
  19616. var bitMask = (1 << bits) - 1;
  19617. var j = 0, k = bufferLength;
  19618. var columns = this.columns;
  19619. for (i = 0; i < columns; ++i) {
  19620. for (var kk = 0; kk < colors; ++kk) {
  19621. if (inbits < bits) {
  19622. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  19623. inbits += 8;
  19624. }
  19625. compArray[kk] = (compArray[kk] +
  19626. (inbuf >> (inbits - bits))) & bitMask;
  19627. inbits -= bits;
  19628. outbuf = (outbuf << bits) | compArray[kk];
  19629. outbits += bits;
  19630. if (outbits >= 8) {
  19631. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  19632. outbits -= 8;
  19633. }
  19634. }
  19635. }
  19636. if (outbits > 0) {
  19637. buffer[k++] = (outbuf << (8 - outbits)) +
  19638. (inbuf & ((1 << (8 - outbits)) - 1));
  19639. }
  19640. }
  19641. this.bufferLength += rowBytes;
  19642. };
  19643. PredictorStream.prototype.readBlockPng =
  19644. function predictorStreamReadBlockPng() {
  19645. var rowBytes = this.rowBytes;
  19646. var pixBytes = this.pixBytes;
  19647. var predictor = this.str.getByte();
  19648. var rawBytes = this.str.getBytes(rowBytes);
  19649. this.eof = !rawBytes.length;
  19650. if (this.eof) {
  19651. return;
  19652. }
  19653. var bufferLength = this.bufferLength;
  19654. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  19655. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  19656. if (prevRow.length === 0) {
  19657. prevRow = new Uint8Array(rowBytes);
  19658. }
  19659. var i, j = bufferLength, up, c;
  19660. switch (predictor) {
  19661. case 0:
  19662. for (i = 0; i < rowBytes; ++i) {
  19663. buffer[j++] = rawBytes[i];
  19664. }
  19665. break;
  19666. case 1:
  19667. for (i = 0; i < pixBytes; ++i) {
  19668. buffer[j++] = rawBytes[i];
  19669. }
  19670. for (; i < rowBytes; ++i) {
  19671. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  19672. j++;
  19673. }
  19674. break;
  19675. case 2:
  19676. for (i = 0; i < rowBytes; ++i) {
  19677. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  19678. }
  19679. break;
  19680. case 3:
  19681. for (i = 0; i < pixBytes; ++i) {
  19682. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  19683. }
  19684. for (; i < rowBytes; ++i) {
  19685. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  19686. rawBytes[i]) & 0xFF;
  19687. j++;
  19688. }
  19689. break;
  19690. case 4:
  19691. // we need to save the up left pixels values. the simplest way
  19692. // is to create a new buffer
  19693. for (i = 0; i < pixBytes; ++i) {
  19694. up = prevRow[i];
  19695. c = rawBytes[i];
  19696. buffer[j++] = up + c;
  19697. }
  19698. for (; i < rowBytes; ++i) {
  19699. up = prevRow[i];
  19700. var upLeft = prevRow[i - pixBytes];
  19701. var left = buffer[j - pixBytes];
  19702. var p = left + up - upLeft;
  19703. var pa = p - left;
  19704. if (pa < 0) {
  19705. pa = -pa;
  19706. }
  19707. var pb = p - up;
  19708. if (pb < 0) {
  19709. pb = -pb;
  19710. }
  19711. var pc = p - upLeft;
  19712. if (pc < 0) {
  19713. pc = -pc;
  19714. }
  19715. c = rawBytes[i];
  19716. if (pa <= pb && pa <= pc) {
  19717. buffer[j++] = left + c;
  19718. } else if (pb <= pc) {
  19719. buffer[j++] = up + c;
  19720. } else {
  19721. buffer[j++] = upLeft + c;
  19722. }
  19723. }
  19724. break;
  19725. default:
  19726. error('Unsupported predictor: ' + predictor);
  19727. }
  19728. this.bufferLength += rowBytes;
  19729. };
  19730. return PredictorStream;
  19731. })();
  19732. /**
  19733. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  19734. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  19735. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  19736. * a library to decode these images and the stream behaves like all the other
  19737. * DecodeStreams.
  19738. */
  19739. var JpegStream = (function JpegStreamClosure() {
  19740. function JpegStream(stream, maybeLength, dict, xref) {
  19741. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  19742. // Note: this seems to mainly affect inline images.
  19743. var ch;
  19744. while ((ch = stream.getByte()) !== -1) {
  19745. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  19746. stream.skip(-1); // Reset the stream position to the SOI.
  19747. break;
  19748. }
  19749. }
  19750. this.stream = stream;
  19751. this.maybeLength = maybeLength;
  19752. this.dict = dict;
  19753. DecodeStream.call(this, maybeLength);
  19754. }
  19755. JpegStream.prototype = Object.create(DecodeStream.prototype);
  19756. Object.defineProperty(JpegStream.prototype, 'bytes', {
  19757. get: function JpegStream_bytes() {
  19758. // If this.maybeLength is null, we'll get the entire stream.
  19759. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  19760. },
  19761. configurable: true
  19762. });
  19763. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  19764. if (this.bufferLength) {
  19765. return;
  19766. }
  19767. var jpegImage = new JpegImage();
  19768. // Checking if values need to be transformed before conversion.
  19769. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  19770. var decodeArr = this.dict.getArray('Decode');
  19771. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  19772. var decodeArrLength = decodeArr.length;
  19773. var transform = new Int32Array(decodeArrLength);
  19774. var transformNeeded = false;
  19775. var maxValue = (1 << bitsPerComponent) - 1;
  19776. for (var i = 0; i < decodeArrLength; i += 2) {
  19777. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  19778. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  19779. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  19780. transformNeeded = true;
  19781. }
  19782. }
  19783. if (transformNeeded) {
  19784. jpegImage.decodeTransform = transform;
  19785. }
  19786. }
  19787. jpegImage.parse(this.bytes);
  19788. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  19789. this.forceRGB);
  19790. this.buffer = data;
  19791. this.bufferLength = data.length;
  19792. this.eof = true;
  19793. };
  19794. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  19795. this.ensureBuffer();
  19796. return this.buffer;
  19797. };
  19798. JpegStream.prototype.getIR = function JpegStream_getIR(forceDataSchema) {
  19799. return createObjectURL(this.bytes, 'image/jpeg', forceDataSchema);
  19800. };
  19801. return JpegStream;
  19802. })();
  19803. /**
  19804. * For JPEG 2000's we use a library to decode these images and
  19805. * the stream behaves like all the other DecodeStreams.
  19806. */
  19807. var JpxStream = (function JpxStreamClosure() {
  19808. function JpxStream(stream, maybeLength, dict) {
  19809. this.stream = stream;
  19810. this.maybeLength = maybeLength;
  19811. this.dict = dict;
  19812. DecodeStream.call(this, maybeLength);
  19813. }
  19814. JpxStream.prototype = Object.create(DecodeStream.prototype);
  19815. Object.defineProperty(JpxStream.prototype, 'bytes', {
  19816. get: function JpxStream_bytes() {
  19817. // If this.maybeLength is null, we'll get the entire stream.
  19818. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  19819. },
  19820. configurable: true
  19821. });
  19822. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  19823. if (this.bufferLength) {
  19824. return;
  19825. }
  19826. var jpxImage = new JpxImage();
  19827. jpxImage.parse(this.bytes);
  19828. var width = jpxImage.width;
  19829. var height = jpxImage.height;
  19830. var componentsCount = jpxImage.componentsCount;
  19831. var tileCount = jpxImage.tiles.length;
  19832. if (tileCount === 1) {
  19833. this.buffer = jpxImage.tiles[0].items;
  19834. } else {
  19835. var data = new Uint8Array(width * height * componentsCount);
  19836. for (var k = 0; k < tileCount; k++) {
  19837. var tileComponents = jpxImage.tiles[k];
  19838. var tileWidth = tileComponents.width;
  19839. var tileHeight = tileComponents.height;
  19840. var tileLeft = tileComponents.left;
  19841. var tileTop = tileComponents.top;
  19842. var src = tileComponents.items;
  19843. var srcPosition = 0;
  19844. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  19845. var imgRowSize = width * componentsCount;
  19846. var tileRowSize = tileWidth * componentsCount;
  19847. for (var j = 0; j < tileHeight; j++) {
  19848. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  19849. data.set(rowBytes, dataPosition);
  19850. srcPosition += tileRowSize;
  19851. dataPosition += imgRowSize;
  19852. }
  19853. }
  19854. this.buffer = data;
  19855. }
  19856. this.bufferLength = this.buffer.length;
  19857. this.eof = true;
  19858. };
  19859. return JpxStream;
  19860. })();
  19861. /**
  19862. * For JBIG2's we use a library to decode these images and
  19863. * the stream behaves like all the other DecodeStreams.
  19864. */
  19865. var Jbig2Stream = (function Jbig2StreamClosure() {
  19866. function Jbig2Stream(stream, maybeLength, dict) {
  19867. this.stream = stream;
  19868. this.maybeLength = maybeLength;
  19869. this.dict = dict;
  19870. DecodeStream.call(this, maybeLength);
  19871. }
  19872. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  19873. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  19874. get: function Jbig2Stream_bytes() {
  19875. // If this.maybeLength is null, we'll get the entire stream.
  19876. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  19877. },
  19878. configurable: true
  19879. });
  19880. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  19881. if (this.bufferLength) {
  19882. return;
  19883. }
  19884. var jbig2Image = new Jbig2Image();
  19885. var chunks = [];
  19886. var decodeParams = this.dict.getArray('DecodeParms');
  19887. // According to the PDF specification, DecodeParms can be either
  19888. // a dictionary, or an array whose elements are dictionaries.
  19889. if (isArray(decodeParams)) {
  19890. if (decodeParams.length > 1) {
  19891. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  19892. 'not supported.');
  19893. }
  19894. decodeParams = decodeParams[0];
  19895. }
  19896. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  19897. var globalsStream = decodeParams.get('JBIG2Globals');
  19898. var globals = globalsStream.getBytes();
  19899. chunks.push({data: globals, start: 0, end: globals.length});
  19900. }
  19901. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  19902. var data = jbig2Image.parseChunks(chunks);
  19903. var dataLength = data.length;
  19904. // JBIG2 had black as 1 and white as 0, inverting the colors
  19905. for (var i = 0; i < dataLength; i++) {
  19906. data[i] ^= 0xFF;
  19907. }
  19908. this.buffer = data;
  19909. this.bufferLength = dataLength;
  19910. this.eof = true;
  19911. };
  19912. return Jbig2Stream;
  19913. })();
  19914. var DecryptStream = (function DecryptStreamClosure() {
  19915. function DecryptStream(str, maybeLength, decrypt) {
  19916. this.str = str;
  19917. this.dict = str.dict;
  19918. this.decrypt = decrypt;
  19919. this.nextChunk = null;
  19920. this.initialized = false;
  19921. DecodeStream.call(this, maybeLength);
  19922. }
  19923. var chunkSize = 512;
  19924. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  19925. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  19926. var chunk;
  19927. if (this.initialized) {
  19928. chunk = this.nextChunk;
  19929. } else {
  19930. chunk = this.str.getBytes(chunkSize);
  19931. this.initialized = true;
  19932. }
  19933. if (!chunk || chunk.length === 0) {
  19934. this.eof = true;
  19935. return;
  19936. }
  19937. this.nextChunk = this.str.getBytes(chunkSize);
  19938. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  19939. var decrypt = this.decrypt;
  19940. chunk = decrypt(chunk, !hasMoreData);
  19941. var bufferLength = this.bufferLength;
  19942. var i, n = chunk.length;
  19943. var buffer = this.ensureBuffer(bufferLength + n);
  19944. for (i = 0; i < n; i++) {
  19945. buffer[bufferLength++] = chunk[i];
  19946. }
  19947. this.bufferLength = bufferLength;
  19948. };
  19949. return DecryptStream;
  19950. })();
  19951. var Ascii85Stream = (function Ascii85StreamClosure() {
  19952. function Ascii85Stream(str, maybeLength) {
  19953. this.str = str;
  19954. this.dict = str.dict;
  19955. this.input = new Uint8Array(5);
  19956. // Most streams increase in size when decoded, but Ascii85 streams
  19957. // typically shrink by ~20%.
  19958. if (maybeLength) {
  19959. maybeLength = 0.8 * maybeLength;
  19960. }
  19961. DecodeStream.call(this, maybeLength);
  19962. }
  19963. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  19964. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  19965. var TILDA_CHAR = 0x7E; // '~'
  19966. var Z_LOWER_CHAR = 0x7A; // 'z'
  19967. var EOF = -1;
  19968. var str = this.str;
  19969. var c = str.getByte();
  19970. while (isSpace(c)) {
  19971. c = str.getByte();
  19972. }
  19973. if (c === EOF || c === TILDA_CHAR) {
  19974. this.eof = true;
  19975. return;
  19976. }
  19977. var bufferLength = this.bufferLength, buffer;
  19978. var i;
  19979. // special code for z
  19980. if (c === Z_LOWER_CHAR) {
  19981. buffer = this.ensureBuffer(bufferLength + 4);
  19982. for (i = 0; i < 4; ++i) {
  19983. buffer[bufferLength + i] = 0;
  19984. }
  19985. this.bufferLength += 4;
  19986. } else {
  19987. var input = this.input;
  19988. input[0] = c;
  19989. for (i = 1; i < 5; ++i) {
  19990. c = str.getByte();
  19991. while (isSpace(c)) {
  19992. c = str.getByte();
  19993. }
  19994. input[i] = c;
  19995. if (c === EOF || c === TILDA_CHAR) {
  19996. break;
  19997. }
  19998. }
  19999. buffer = this.ensureBuffer(bufferLength + i - 1);
  20000. this.bufferLength += i - 1;
  20001. // partial ending;
  20002. if (i < 5) {
  20003. for (; i < 5; ++i) {
  20004. input[i] = 0x21 + 84;
  20005. }
  20006. this.eof = true;
  20007. }
  20008. var t = 0;
  20009. for (i = 0; i < 5; ++i) {
  20010. t = t * 85 + (input[i] - 0x21);
  20011. }
  20012. for (i = 3; i >= 0; --i) {
  20013. buffer[bufferLength + i] = t & 0xFF;
  20014. t >>= 8;
  20015. }
  20016. }
  20017. };
  20018. return Ascii85Stream;
  20019. })();
  20020. var AsciiHexStream = (function AsciiHexStreamClosure() {
  20021. function AsciiHexStream(str, maybeLength) {
  20022. this.str = str;
  20023. this.dict = str.dict;
  20024. this.firstDigit = -1;
  20025. // Most streams increase in size when decoded, but AsciiHex streams shrink
  20026. // by 50%.
  20027. if (maybeLength) {
  20028. maybeLength = 0.5 * maybeLength;
  20029. }
  20030. DecodeStream.call(this, maybeLength);
  20031. }
  20032. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  20033. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  20034. var UPSTREAM_BLOCK_SIZE = 8000;
  20035. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  20036. if (!bytes.length) {
  20037. this.eof = true;
  20038. return;
  20039. }
  20040. var maxDecodeLength = (bytes.length + 1) >> 1;
  20041. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  20042. var bufferLength = this.bufferLength;
  20043. var firstDigit = this.firstDigit;
  20044. for (var i = 0, ii = bytes.length; i < ii; i++) {
  20045. var ch = bytes[i], digit;
  20046. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  20047. digit = ch & 0x0F;
  20048. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  20049. // 'A'-'Z', 'a'-'z'
  20050. digit = (ch & 0x0F) + 9;
  20051. } else if (ch === 0x3E) { // '>'
  20052. this.eof = true;
  20053. break;
  20054. } else { // probably whitespace
  20055. continue; // ignoring
  20056. }
  20057. if (firstDigit < 0) {
  20058. firstDigit = digit;
  20059. } else {
  20060. buffer[bufferLength++] = (firstDigit << 4) | digit;
  20061. firstDigit = -1;
  20062. }
  20063. }
  20064. if (firstDigit >= 0 && this.eof) {
  20065. // incomplete byte
  20066. buffer[bufferLength++] = (firstDigit << 4);
  20067. firstDigit = -1;
  20068. }
  20069. this.firstDigit = firstDigit;
  20070. this.bufferLength = bufferLength;
  20071. };
  20072. return AsciiHexStream;
  20073. })();
  20074. var RunLengthStream = (function RunLengthStreamClosure() {
  20075. function RunLengthStream(str, maybeLength) {
  20076. this.str = str;
  20077. this.dict = str.dict;
  20078. DecodeStream.call(this, maybeLength);
  20079. }
  20080. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  20081. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  20082. // The repeatHeader has following format. The first byte defines type of run
  20083. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  20084. // (in addition to the second byte from the header), n = 129 through 255 -
  20085. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  20086. var repeatHeader = this.str.getBytes(2);
  20087. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  20088. this.eof = true;
  20089. return;
  20090. }
  20091. var buffer;
  20092. var bufferLength = this.bufferLength;
  20093. var n = repeatHeader[0];
  20094. if (n < 128) {
  20095. // copy n bytes
  20096. buffer = this.ensureBuffer(bufferLength + n + 1);
  20097. buffer[bufferLength++] = repeatHeader[1];
  20098. if (n > 0) {
  20099. var source = this.str.getBytes(n);
  20100. buffer.set(source, bufferLength);
  20101. bufferLength += n;
  20102. }
  20103. } else {
  20104. n = 257 - n;
  20105. var b = repeatHeader[1];
  20106. buffer = this.ensureBuffer(bufferLength + n + 1);
  20107. for (var i = 0; i < n; i++) {
  20108. buffer[bufferLength++] = b;
  20109. }
  20110. }
  20111. this.bufferLength = bufferLength;
  20112. };
  20113. return RunLengthStream;
  20114. })();
  20115. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  20116. var ccittEOL = -2;
  20117. var ccittEOF = -1;
  20118. var twoDimPass = 0;
  20119. var twoDimHoriz = 1;
  20120. var twoDimVert0 = 2;
  20121. var twoDimVertR1 = 3;
  20122. var twoDimVertL1 = 4;
  20123. var twoDimVertR2 = 5;
  20124. var twoDimVertL2 = 6;
  20125. var twoDimVertR3 = 7;
  20126. var twoDimVertL3 = 8;
  20127. var twoDimTable = [
  20128. [-1, -1], [-1, -1], // 000000x
  20129. [7, twoDimVertL3], // 0000010
  20130. [7, twoDimVertR3], // 0000011
  20131. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  20132. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  20133. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  20134. [4, twoDimPass], [4, twoDimPass],
  20135. [4, twoDimPass], [4, twoDimPass],
  20136. [4, twoDimPass], [4, twoDimPass],
  20137. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  20138. [3, twoDimHoriz], [3, twoDimHoriz],
  20139. [3, twoDimHoriz], [3, twoDimHoriz],
  20140. [3, twoDimHoriz], [3, twoDimHoriz],
  20141. [3, twoDimHoriz], [3, twoDimHoriz],
  20142. [3, twoDimHoriz], [3, twoDimHoriz],
  20143. [3, twoDimHoriz], [3, twoDimHoriz],
  20144. [3, twoDimHoriz], [3, twoDimHoriz],
  20145. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  20146. [3, twoDimVertL1], [3, twoDimVertL1],
  20147. [3, twoDimVertL1], [3, twoDimVertL1],
  20148. [3, twoDimVertL1], [3, twoDimVertL1],
  20149. [3, twoDimVertL1], [3, twoDimVertL1],
  20150. [3, twoDimVertL1], [3, twoDimVertL1],
  20151. [3, twoDimVertL1], [3, twoDimVertL1],
  20152. [3, twoDimVertL1], [3, twoDimVertL1],
  20153. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  20154. [3, twoDimVertR1], [3, twoDimVertR1],
  20155. [3, twoDimVertR1], [3, twoDimVertR1],
  20156. [3, twoDimVertR1], [3, twoDimVertR1],
  20157. [3, twoDimVertR1], [3, twoDimVertR1],
  20158. [3, twoDimVertR1], [3, twoDimVertR1],
  20159. [3, twoDimVertR1], [3, twoDimVertR1],
  20160. [3, twoDimVertR1], [3, twoDimVertR1],
  20161. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  20162. [1, twoDimVert0], [1, twoDimVert0],
  20163. [1, twoDimVert0], [1, twoDimVert0],
  20164. [1, twoDimVert0], [1, twoDimVert0],
  20165. [1, twoDimVert0], [1, twoDimVert0],
  20166. [1, twoDimVert0], [1, twoDimVert0],
  20167. [1, twoDimVert0], [1, twoDimVert0],
  20168. [1, twoDimVert0], [1, twoDimVert0],
  20169. [1, twoDimVert0], [1, twoDimVert0],
  20170. [1, twoDimVert0], [1, twoDimVert0],
  20171. [1, twoDimVert0], [1, twoDimVert0],
  20172. [1, twoDimVert0], [1, twoDimVert0],
  20173. [1, twoDimVert0], [1, twoDimVert0],
  20174. [1, twoDimVert0], [1, twoDimVert0],
  20175. [1, twoDimVert0], [1, twoDimVert0],
  20176. [1, twoDimVert0], [1, twoDimVert0],
  20177. [1, twoDimVert0], [1, twoDimVert0],
  20178. [1, twoDimVert0], [1, twoDimVert0],
  20179. [1, twoDimVert0], [1, twoDimVert0],
  20180. [1, twoDimVert0], [1, twoDimVert0],
  20181. [1, twoDimVert0], [1, twoDimVert0],
  20182. [1, twoDimVert0], [1, twoDimVert0],
  20183. [1, twoDimVert0], [1, twoDimVert0],
  20184. [1, twoDimVert0], [1, twoDimVert0],
  20185. [1, twoDimVert0], [1, twoDimVert0],
  20186. [1, twoDimVert0], [1, twoDimVert0],
  20187. [1, twoDimVert0], [1, twoDimVert0],
  20188. [1, twoDimVert0], [1, twoDimVert0],
  20189. [1, twoDimVert0], [1, twoDimVert0],
  20190. [1, twoDimVert0], [1, twoDimVert0],
  20191. [1, twoDimVert0], [1, twoDimVert0],
  20192. [1, twoDimVert0], [1, twoDimVert0]
  20193. ];
  20194. var whiteTable1 = [
  20195. [-1, -1], // 00000
  20196. [12, ccittEOL], // 00001
  20197. [-1, -1], [-1, -1], // 0001x
  20198. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  20199. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  20200. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  20201. [11, 1792], [11, 1792], // 1000x
  20202. [12, 1984], // 10010
  20203. [12, 2048], // 10011
  20204. [12, 2112], // 10100
  20205. [12, 2176], // 10101
  20206. [12, 2240], // 10110
  20207. [12, 2304], // 10111
  20208. [11, 1856], [11, 1856], // 1100x
  20209. [11, 1920], [11, 1920], // 1101x
  20210. [12, 2368], // 11100
  20211. [12, 2432], // 11101
  20212. [12, 2496], // 11110
  20213. [12, 2560] // 11111
  20214. ];
  20215. var whiteTable2 = [
  20216. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  20217. [8, 29], [8, 29], // 00000010x
  20218. [8, 30], [8, 30], // 00000011x
  20219. [8, 45], [8, 45], // 00000100x
  20220. [8, 46], [8, 46], // 00000101x
  20221. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  20222. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  20223. [8, 47], [8, 47], // 00001010x
  20224. [8, 48], [8, 48], // 00001011x
  20225. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  20226. [6, 13], [6, 13], [6, 13], [6, 13],
  20227. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  20228. [8, 33], [8, 33], // 00010010x
  20229. [8, 34], [8, 34], // 00010011x
  20230. [8, 35], [8, 35], // 00010100x
  20231. [8, 36], [8, 36], // 00010101x
  20232. [8, 37], [8, 37], // 00010110x
  20233. [8, 38], [8, 38], // 00010111x
  20234. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  20235. [8, 31], [8, 31], // 00011010x
  20236. [8, 32], [8, 32], // 00011011x
  20237. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  20238. [6, 1], [6, 1], [6, 1], [6, 1],
  20239. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  20240. [6, 12], [6, 12], [6, 12], [6, 12],
  20241. [8, 53], [8, 53], // 00100100x
  20242. [8, 54], [8, 54], // 00100101x
  20243. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  20244. [8, 39], [8, 39], // 00101000x
  20245. [8, 40], [8, 40], // 00101001x
  20246. [8, 41], [8, 41], // 00101010x
  20247. [8, 42], [8, 42], // 00101011x
  20248. [8, 43], [8, 43], // 00101100x
  20249. [8, 44], [8, 44], // 00101101x
  20250. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  20251. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  20252. [8, 61], [8, 61], // 00110010x
  20253. [8, 62], [8, 62], // 00110011x
  20254. [8, 63], [8, 63], // 00110100x
  20255. [8, 0], [8, 0], // 00110101x
  20256. [8, 320], [8, 320], // 00110110x
  20257. [8, 384], [8, 384], // 00110111x
  20258. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  20259. [5, 10], [5, 10], [5, 10], [5, 10],
  20260. [5, 10], [5, 10], [5, 10], [5, 10],
  20261. [5, 10], [5, 10], [5, 10], [5, 10],
  20262. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  20263. [5, 11], [5, 11], [5, 11], [5, 11],
  20264. [5, 11], [5, 11], [5, 11], [5, 11],
  20265. [5, 11], [5, 11], [5, 11], [5, 11],
  20266. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  20267. [8, 59], [8, 59], // 01001010x
  20268. [8, 60], [8, 60], // 01001011x
  20269. [9, 1472], // 010011000
  20270. [9, 1536], // 010011001
  20271. [9, 1600], // 010011010
  20272. [9, 1728], // 010011011
  20273. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  20274. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  20275. [8, 49], [8, 49], // 01010010x
  20276. [8, 50], [8, 50], // 01010011x
  20277. [8, 51], [8, 51], // 01010100x
  20278. [8, 52], [8, 52], // 01010101x
  20279. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  20280. [8, 55], [8, 55], // 01011000x
  20281. [8, 56], [8, 56], // 01011001x
  20282. [8, 57], [8, 57], // 01011010x
  20283. [8, 58], [8, 58], // 01011011x
  20284. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  20285. [6, 192], [6, 192], [6, 192], [6, 192],
  20286. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  20287. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  20288. [8, 448], [8, 448], // 01100100x
  20289. [8, 512], [8, 512], // 01100101x
  20290. [9, 704], // 011001100
  20291. [9, 768], // 011001101
  20292. [8, 640], [8, 640], // 01100111x
  20293. [8, 576], [8, 576], // 01101000x
  20294. [9, 832], // 011010010
  20295. [9, 896], // 011010011
  20296. [9, 960], // 011010100
  20297. [9, 1024], // 011010101
  20298. [9, 1088], // 011010110
  20299. [9, 1152], // 011010111
  20300. [9, 1216], // 011011000
  20301. [9, 1280], // 011011001
  20302. [9, 1344], // 011011010
  20303. [9, 1408], // 011011011
  20304. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  20305. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  20306. [4, 2], [4, 2], [4, 2], [4, 2],
  20307. [4, 2], [4, 2], [4, 2], [4, 2],
  20308. [4, 2], [4, 2], [4, 2], [4, 2],
  20309. [4, 2], [4, 2], [4, 2], [4, 2],
  20310. [4, 2], [4, 2], [4, 2], [4, 2],
  20311. [4, 2], [4, 2], [4, 2], [4, 2],
  20312. [4, 2], [4, 2], [4, 2], [4, 2],
  20313. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  20314. [4, 3], [4, 3], [4, 3], [4, 3],
  20315. [4, 3], [4, 3], [4, 3], [4, 3],
  20316. [4, 3], [4, 3], [4, 3], [4, 3],
  20317. [4, 3], [4, 3], [4, 3], [4, 3],
  20318. [4, 3], [4, 3], [4, 3], [4, 3],
  20319. [4, 3], [4, 3], [4, 3], [4, 3],
  20320. [4, 3], [4, 3], [4, 3], [4, 3],
  20321. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  20322. [5, 128], [5, 128], [5, 128], [5, 128],
  20323. [5, 128], [5, 128], [5, 128], [5, 128],
  20324. [5, 128], [5, 128], [5, 128], [5, 128],
  20325. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  20326. [5, 8], [5, 8], [5, 8], [5, 8],
  20327. [5, 8], [5, 8], [5, 8], [5, 8],
  20328. [5, 8], [5, 8], [5, 8], [5, 8],
  20329. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  20330. [5, 9], [5, 9], [5, 9], [5, 9],
  20331. [5, 9], [5, 9], [5, 9], [5, 9],
  20332. [5, 9], [5, 9], [5, 9], [5, 9],
  20333. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  20334. [6, 16], [6, 16], [6, 16], [6, 16],
  20335. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  20336. [6, 17], [6, 17], [6, 17], [6, 17],
  20337. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  20338. [4, 4], [4, 4], [4, 4], [4, 4],
  20339. [4, 4], [4, 4], [4, 4], [4, 4],
  20340. [4, 4], [4, 4], [4, 4], [4, 4],
  20341. [4, 4], [4, 4], [4, 4], [4, 4],
  20342. [4, 4], [4, 4], [4, 4], [4, 4],
  20343. [4, 4], [4, 4], [4, 4], [4, 4],
  20344. [4, 4], [4, 4], [4, 4], [4, 4],
  20345. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  20346. [4, 5], [4, 5], [4, 5], [4, 5],
  20347. [4, 5], [4, 5], [4, 5], [4, 5],
  20348. [4, 5], [4, 5], [4, 5], [4, 5],
  20349. [4, 5], [4, 5], [4, 5], [4, 5],
  20350. [4, 5], [4, 5], [4, 5], [4, 5],
  20351. [4, 5], [4, 5], [4, 5], [4, 5],
  20352. [4, 5], [4, 5], [4, 5], [4, 5],
  20353. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  20354. [6, 14], [6, 14], [6, 14], [6, 14],
  20355. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  20356. [6, 15], [6, 15], [6, 15], [6, 15],
  20357. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  20358. [5, 64], [5, 64], [5, 64], [5, 64],
  20359. [5, 64], [5, 64], [5, 64], [5, 64],
  20360. [5, 64], [5, 64], [5, 64], [5, 64],
  20361. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  20362. [4, 6], [4, 6], [4, 6], [4, 6],
  20363. [4, 6], [4, 6], [4, 6], [4, 6],
  20364. [4, 6], [4, 6], [4, 6], [4, 6],
  20365. [4, 6], [4, 6], [4, 6], [4, 6],
  20366. [4, 6], [4, 6], [4, 6], [4, 6],
  20367. [4, 6], [4, 6], [4, 6], [4, 6],
  20368. [4, 6], [4, 6], [4, 6], [4, 6],
  20369. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  20370. [4, 7], [4, 7], [4, 7], [4, 7],
  20371. [4, 7], [4, 7], [4, 7], [4, 7],
  20372. [4, 7], [4, 7], [4, 7], [4, 7],
  20373. [4, 7], [4, 7], [4, 7], [4, 7],
  20374. [4, 7], [4, 7], [4, 7], [4, 7],
  20375. [4, 7], [4, 7], [4, 7], [4, 7],
  20376. [4, 7], [4, 7], [4, 7], [4, 7]
  20377. ];
  20378. var blackTable1 = [
  20379. [-1, -1], [-1, -1], // 000000000000x
  20380. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  20381. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  20382. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  20383. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  20384. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  20385. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  20386. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  20387. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  20388. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  20389. [12, 1984], [12, 1984], // 000000010010x
  20390. [12, 2048], [12, 2048], // 000000010011x
  20391. [12, 2112], [12, 2112], // 000000010100x
  20392. [12, 2176], [12, 2176], // 000000010101x
  20393. [12, 2240], [12, 2240], // 000000010110x
  20394. [12, 2304], [12, 2304], // 000000010111x
  20395. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  20396. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  20397. [12, 2368], [12, 2368], // 000000011100x
  20398. [12, 2432], [12, 2432], // 000000011101x
  20399. [12, 2496], [12, 2496], // 000000011110x
  20400. [12, 2560], [12, 2560], // 000000011111x
  20401. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  20402. [10, 18], [10, 18], [10, 18], [10, 18],
  20403. [12, 52], [12, 52], // 000000100100x
  20404. [13, 640], // 0000001001010
  20405. [13, 704], // 0000001001011
  20406. [13, 768], // 0000001001100
  20407. [13, 832], // 0000001001101
  20408. [12, 55], [12, 55], // 000000100111x
  20409. [12, 56], [12, 56], // 000000101000x
  20410. [13, 1280], // 0000001010010
  20411. [13, 1344], // 0000001010011
  20412. [13, 1408], // 0000001010100
  20413. [13, 1472], // 0000001010101
  20414. [12, 59], [12, 59], // 000000101011x
  20415. [12, 60], [12, 60], // 000000101100x
  20416. [13, 1536], // 0000001011010
  20417. [13, 1600], // 0000001011011
  20418. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  20419. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  20420. [13, 1664], // 0000001100100
  20421. [13, 1728], // 0000001100101
  20422. [12, 320], [12, 320], // 000000110011x
  20423. [12, 384], [12, 384], // 000000110100x
  20424. [12, 448], [12, 448], // 000000110101x
  20425. [13, 512], // 0000001101100
  20426. [13, 576], // 0000001101101
  20427. [12, 53], [12, 53], // 000000110111x
  20428. [12, 54], [12, 54], // 000000111000x
  20429. [13, 896], // 0000001110010
  20430. [13, 960], // 0000001110011
  20431. [13, 1024], // 0000001110100
  20432. [13, 1088], // 0000001110101
  20433. [13, 1152], // 0000001110110
  20434. [13, 1216], // 0000001110111
  20435. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  20436. [10, 64], [10, 64], [10, 64], [10, 64]
  20437. ];
  20438. var blackTable2 = [
  20439. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  20440. [8, 13], [8, 13], [8, 13], [8, 13],
  20441. [8, 13], [8, 13], [8, 13], [8, 13],
  20442. [8, 13], [8, 13], [8, 13], [8, 13],
  20443. [11, 23], [11, 23], // 00000101000x
  20444. [12, 50], // 000001010010
  20445. [12, 51], // 000001010011
  20446. [12, 44], // 000001010100
  20447. [12, 45], // 000001010101
  20448. [12, 46], // 000001010110
  20449. [12, 47], // 000001010111
  20450. [12, 57], // 000001011000
  20451. [12, 58], // 000001011001
  20452. [12, 61], // 000001011010
  20453. [12, 256], // 000001011011
  20454. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  20455. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  20456. [12, 48], // 000001100100
  20457. [12, 49], // 000001100101
  20458. [12, 62], // 000001100110
  20459. [12, 63], // 000001100111
  20460. [12, 30], // 000001101000
  20461. [12, 31], // 000001101001
  20462. [12, 32], // 000001101010
  20463. [12, 33], // 000001101011
  20464. [12, 40], // 000001101100
  20465. [12, 41], // 000001101101
  20466. [11, 22], [11, 22], // 00000110111x
  20467. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  20468. [8, 14], [8, 14], [8, 14], [8, 14],
  20469. [8, 14], [8, 14], [8, 14], [8, 14],
  20470. [8, 14], [8, 14], [8, 14], [8, 14],
  20471. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  20472. [7, 10], [7, 10], [7, 10], [7, 10],
  20473. [7, 10], [7, 10], [7, 10], [7, 10],
  20474. [7, 10], [7, 10], [7, 10], [7, 10],
  20475. [7, 10], [7, 10], [7, 10], [7, 10],
  20476. [7, 10], [7, 10], [7, 10], [7, 10],
  20477. [7, 10], [7, 10], [7, 10], [7, 10],
  20478. [7, 10], [7, 10], [7, 10], [7, 10],
  20479. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  20480. [7, 11], [7, 11], [7, 11], [7, 11],
  20481. [7, 11], [7, 11], [7, 11], [7, 11],
  20482. [7, 11], [7, 11], [7, 11], [7, 11],
  20483. [7, 11], [7, 11], [7, 11], [7, 11],
  20484. [7, 11], [7, 11], [7, 11], [7, 11],
  20485. [7, 11], [7, 11], [7, 11], [7, 11],
  20486. [7, 11], [7, 11], [7, 11], [7, 11],
  20487. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  20488. [9, 15], [9, 15], [9, 15], [9, 15],
  20489. [12, 128], // 000011001000
  20490. [12, 192], // 000011001001
  20491. [12, 26], // 000011001010
  20492. [12, 27], // 000011001011
  20493. [12, 28], // 000011001100
  20494. [12, 29], // 000011001101
  20495. [11, 19], [11, 19], // 00001100111x
  20496. [11, 20], [11, 20], // 00001101000x
  20497. [12, 34], // 000011010010
  20498. [12, 35], // 000011010011
  20499. [12, 36], // 000011010100
  20500. [12, 37], // 000011010101
  20501. [12, 38], // 000011010110
  20502. [12, 39], // 000011010111
  20503. [11, 21], [11, 21], // 00001101100x
  20504. [12, 42], // 000011011010
  20505. [12, 43], // 000011011011
  20506. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  20507. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  20508. [7, 12], [7, 12], [7, 12], [7, 12],
  20509. [7, 12], [7, 12], [7, 12], [7, 12],
  20510. [7, 12], [7, 12], [7, 12], [7, 12],
  20511. [7, 12], [7, 12], [7, 12], [7, 12],
  20512. [7, 12], [7, 12], [7, 12], [7, 12],
  20513. [7, 12], [7, 12], [7, 12], [7, 12],
  20514. [7, 12], [7, 12], [7, 12], [7, 12]
  20515. ];
  20516. var blackTable3 = [
  20517. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  20518. [6, 9], // 000100
  20519. [6, 8], // 000101
  20520. [5, 7], [5, 7], // 00011x
  20521. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  20522. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  20523. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  20524. [3, 1], [3, 1], [3, 1], [3, 1],
  20525. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  20526. [3, 4], [3, 4], [3, 4], [3, 4],
  20527. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  20528. [2, 3], [2, 3], [2, 3], [2, 3],
  20529. [2, 3], [2, 3], [2, 3], [2, 3],
  20530. [2, 3], [2, 3], [2, 3], [2, 3],
  20531. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  20532. [2, 2], [2, 2], [2, 2], [2, 2],
  20533. [2, 2], [2, 2], [2, 2], [2, 2],
  20534. [2, 2], [2, 2], [2, 2], [2, 2]
  20535. ];
  20536. function CCITTFaxStream(str, maybeLength, params) {
  20537. this.str = str;
  20538. this.dict = str.dict;
  20539. params = params || Dict.empty;
  20540. this.encoding = params.get('K') || 0;
  20541. this.eoline = params.get('EndOfLine') || false;
  20542. this.byteAlign = params.get('EncodedByteAlign') || false;
  20543. this.columns = params.get('Columns') || 1728;
  20544. this.rows = params.get('Rows') || 0;
  20545. var eoblock = params.get('EndOfBlock');
  20546. if (eoblock === null || eoblock === undefined) {
  20547. eoblock = true;
  20548. }
  20549. this.eoblock = eoblock;
  20550. this.black = params.get('BlackIs1') || false;
  20551. this.codingLine = new Uint32Array(this.columns + 1);
  20552. this.refLine = new Uint32Array(this.columns + 2);
  20553. this.codingLine[0] = this.columns;
  20554. this.codingPos = 0;
  20555. this.row = 0;
  20556. this.nextLine2D = this.encoding < 0;
  20557. this.inputBits = 0;
  20558. this.inputBuf = 0;
  20559. this.outputBits = 0;
  20560. var code1;
  20561. while ((code1 = this.lookBits(12)) === 0) {
  20562. this.eatBits(1);
  20563. }
  20564. if (code1 === 1) {
  20565. this.eatBits(12);
  20566. }
  20567. if (this.encoding > 0) {
  20568. this.nextLine2D = !this.lookBits(1);
  20569. this.eatBits(1);
  20570. }
  20571. DecodeStream.call(this, maybeLength);
  20572. }
  20573. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  20574. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  20575. while (!this.eof) {
  20576. var c = this.lookChar();
  20577. this.ensureBuffer(this.bufferLength + 1);
  20578. this.buffer[this.bufferLength++] = c;
  20579. }
  20580. };
  20581. CCITTFaxStream.prototype.addPixels =
  20582. function ccittFaxStreamAddPixels(a1, blackPixels) {
  20583. var codingLine = this.codingLine;
  20584. var codingPos = this.codingPos;
  20585. if (a1 > codingLine[codingPos]) {
  20586. if (a1 > this.columns) {
  20587. info('row is wrong length');
  20588. this.err = true;
  20589. a1 = this.columns;
  20590. }
  20591. if ((codingPos & 1) ^ blackPixels) {
  20592. ++codingPos;
  20593. }
  20594. codingLine[codingPos] = a1;
  20595. }
  20596. this.codingPos = codingPos;
  20597. };
  20598. CCITTFaxStream.prototype.addPixelsNeg =
  20599. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  20600. var codingLine = this.codingLine;
  20601. var codingPos = this.codingPos;
  20602. if (a1 > codingLine[codingPos]) {
  20603. if (a1 > this.columns) {
  20604. info('row is wrong length');
  20605. this.err = true;
  20606. a1 = this.columns;
  20607. }
  20608. if ((codingPos & 1) ^ blackPixels) {
  20609. ++codingPos;
  20610. }
  20611. codingLine[codingPos] = a1;
  20612. } else if (a1 < codingLine[codingPos]) {
  20613. if (a1 < 0) {
  20614. info('invalid code');
  20615. this.err = true;
  20616. a1 = 0;
  20617. }
  20618. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  20619. --codingPos;
  20620. }
  20621. codingLine[codingPos] = a1;
  20622. }
  20623. this.codingPos = codingPos;
  20624. };
  20625. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  20626. var refLine = this.refLine;
  20627. var codingLine = this.codingLine;
  20628. var columns = this.columns;
  20629. var refPos, blackPixels, bits, i;
  20630. if (this.outputBits === 0) {
  20631. if (this.eof) {
  20632. return null;
  20633. }
  20634. this.err = false;
  20635. var code1, code2, code3;
  20636. if (this.nextLine2D) {
  20637. for (i = 0; codingLine[i] < columns; ++i) {
  20638. refLine[i] = codingLine[i];
  20639. }
  20640. refLine[i++] = columns;
  20641. refLine[i] = columns;
  20642. codingLine[0] = 0;
  20643. this.codingPos = 0;
  20644. refPos = 0;
  20645. blackPixels = 0;
  20646. while (codingLine[this.codingPos] < columns) {
  20647. code1 = this.getTwoDimCode();
  20648. switch (code1) {
  20649. case twoDimPass:
  20650. this.addPixels(refLine[refPos + 1], blackPixels);
  20651. if (refLine[refPos + 1] < columns) {
  20652. refPos += 2;
  20653. }
  20654. break;
  20655. case twoDimHoriz:
  20656. code1 = code2 = 0;
  20657. if (blackPixels) {
  20658. do {
  20659. code1 += (code3 = this.getBlackCode());
  20660. } while (code3 >= 64);
  20661. do {
  20662. code2 += (code3 = this.getWhiteCode());
  20663. } while (code3 >= 64);
  20664. } else {
  20665. do {
  20666. code1 += (code3 = this.getWhiteCode());
  20667. } while (code3 >= 64);
  20668. do {
  20669. code2 += (code3 = this.getBlackCode());
  20670. } while (code3 >= 64);
  20671. }
  20672. this.addPixels(codingLine[this.codingPos] +
  20673. code1, blackPixels);
  20674. if (codingLine[this.codingPos] < columns) {
  20675. this.addPixels(codingLine[this.codingPos] + code2,
  20676. blackPixels ^ 1);
  20677. }
  20678. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20679. refLine[refPos] < columns) {
  20680. refPos += 2;
  20681. }
  20682. break;
  20683. case twoDimVertR3:
  20684. this.addPixels(refLine[refPos] + 3, blackPixels);
  20685. blackPixels ^= 1;
  20686. if (codingLine[this.codingPos] < columns) {
  20687. ++refPos;
  20688. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20689. refLine[refPos] < columns) {
  20690. refPos += 2;
  20691. }
  20692. }
  20693. break;
  20694. case twoDimVertR2:
  20695. this.addPixels(refLine[refPos] + 2, blackPixels);
  20696. blackPixels ^= 1;
  20697. if (codingLine[this.codingPos] < columns) {
  20698. ++refPos;
  20699. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20700. refLine[refPos] < columns) {
  20701. refPos += 2;
  20702. }
  20703. }
  20704. break;
  20705. case twoDimVertR1:
  20706. this.addPixels(refLine[refPos] + 1, blackPixels);
  20707. blackPixels ^= 1;
  20708. if (codingLine[this.codingPos] < columns) {
  20709. ++refPos;
  20710. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20711. refLine[refPos] < columns) {
  20712. refPos += 2;
  20713. }
  20714. }
  20715. break;
  20716. case twoDimVert0:
  20717. this.addPixels(refLine[refPos], blackPixels);
  20718. blackPixels ^= 1;
  20719. if (codingLine[this.codingPos] < columns) {
  20720. ++refPos;
  20721. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20722. refLine[refPos] < columns) {
  20723. refPos += 2;
  20724. }
  20725. }
  20726. break;
  20727. case twoDimVertL3:
  20728. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  20729. blackPixels ^= 1;
  20730. if (codingLine[this.codingPos] < columns) {
  20731. if (refPos > 0) {
  20732. --refPos;
  20733. } else {
  20734. ++refPos;
  20735. }
  20736. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20737. refLine[refPos] < columns) {
  20738. refPos += 2;
  20739. }
  20740. }
  20741. break;
  20742. case twoDimVertL2:
  20743. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  20744. blackPixels ^= 1;
  20745. if (codingLine[this.codingPos] < columns) {
  20746. if (refPos > 0) {
  20747. --refPos;
  20748. } else {
  20749. ++refPos;
  20750. }
  20751. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20752. refLine[refPos] < columns) {
  20753. refPos += 2;
  20754. }
  20755. }
  20756. break;
  20757. case twoDimVertL1:
  20758. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  20759. blackPixels ^= 1;
  20760. if (codingLine[this.codingPos] < columns) {
  20761. if (refPos > 0) {
  20762. --refPos;
  20763. } else {
  20764. ++refPos;
  20765. }
  20766. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20767. refLine[refPos] < columns) {
  20768. refPos += 2;
  20769. }
  20770. }
  20771. break;
  20772. case ccittEOF:
  20773. this.addPixels(columns, 0);
  20774. this.eof = true;
  20775. break;
  20776. default:
  20777. info('bad 2d code');
  20778. this.addPixels(columns, 0);
  20779. this.err = true;
  20780. }
  20781. }
  20782. } else {
  20783. codingLine[0] = 0;
  20784. this.codingPos = 0;
  20785. blackPixels = 0;
  20786. while (codingLine[this.codingPos] < columns) {
  20787. code1 = 0;
  20788. if (blackPixels) {
  20789. do {
  20790. code1 += (code3 = this.getBlackCode());
  20791. } while (code3 >= 64);
  20792. } else {
  20793. do {
  20794. code1 += (code3 = this.getWhiteCode());
  20795. } while (code3 >= 64);
  20796. }
  20797. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  20798. blackPixels ^= 1;
  20799. }
  20800. }
  20801. var gotEOL = false;
  20802. if (this.byteAlign) {
  20803. this.inputBits &= ~7;
  20804. }
  20805. if (!this.eoblock && this.row === this.rows - 1) {
  20806. this.eof = true;
  20807. } else {
  20808. code1 = this.lookBits(12);
  20809. if (this.eoline) {
  20810. while (code1 !== ccittEOF && code1 !== 1) {
  20811. this.eatBits(1);
  20812. code1 = this.lookBits(12);
  20813. }
  20814. } else {
  20815. while (code1 === 0) {
  20816. this.eatBits(1);
  20817. code1 = this.lookBits(12);
  20818. }
  20819. }
  20820. if (code1 === 1) {
  20821. this.eatBits(12);
  20822. gotEOL = true;
  20823. } else if (code1 === ccittEOF) {
  20824. this.eof = true;
  20825. }
  20826. }
  20827. if (!this.eof && this.encoding > 0) {
  20828. this.nextLine2D = !this.lookBits(1);
  20829. this.eatBits(1);
  20830. }
  20831. if (this.eoblock && gotEOL && this.byteAlign) {
  20832. code1 = this.lookBits(12);
  20833. if (code1 === 1) {
  20834. this.eatBits(12);
  20835. if (this.encoding > 0) {
  20836. this.lookBits(1);
  20837. this.eatBits(1);
  20838. }
  20839. if (this.encoding >= 0) {
  20840. for (i = 0; i < 4; ++i) {
  20841. code1 = this.lookBits(12);
  20842. if (code1 !== 1) {
  20843. info('bad rtc code: ' + code1);
  20844. }
  20845. this.eatBits(12);
  20846. if (this.encoding > 0) {
  20847. this.lookBits(1);
  20848. this.eatBits(1);
  20849. }
  20850. }
  20851. }
  20852. this.eof = true;
  20853. }
  20854. } else if (this.err && this.eoline) {
  20855. while (true) {
  20856. code1 = this.lookBits(13);
  20857. if (code1 === ccittEOF) {
  20858. this.eof = true;
  20859. return null;
  20860. }
  20861. if ((code1 >> 1) === 1) {
  20862. break;
  20863. }
  20864. this.eatBits(1);
  20865. }
  20866. this.eatBits(12);
  20867. if (this.encoding > 0) {
  20868. this.eatBits(1);
  20869. this.nextLine2D = !(code1 & 1);
  20870. }
  20871. }
  20872. if (codingLine[0] > 0) {
  20873. this.outputBits = codingLine[this.codingPos = 0];
  20874. } else {
  20875. this.outputBits = codingLine[this.codingPos = 1];
  20876. }
  20877. this.row++;
  20878. }
  20879. var c;
  20880. if (this.outputBits >= 8) {
  20881. c = (this.codingPos & 1) ? 0 : 0xFF;
  20882. this.outputBits -= 8;
  20883. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  20884. this.codingPos++;
  20885. this.outputBits = (codingLine[this.codingPos] -
  20886. codingLine[this.codingPos - 1]);
  20887. }
  20888. } else {
  20889. bits = 8;
  20890. c = 0;
  20891. do {
  20892. if (this.outputBits > bits) {
  20893. c <<= bits;
  20894. if (!(this.codingPos & 1)) {
  20895. c |= 0xFF >> (8 - bits);
  20896. }
  20897. this.outputBits -= bits;
  20898. bits = 0;
  20899. } else {
  20900. c <<= this.outputBits;
  20901. if (!(this.codingPos & 1)) {
  20902. c |= 0xFF >> (8 - this.outputBits);
  20903. }
  20904. bits -= this.outputBits;
  20905. this.outputBits = 0;
  20906. if (codingLine[this.codingPos] < columns) {
  20907. this.codingPos++;
  20908. this.outputBits = (codingLine[this.codingPos] -
  20909. codingLine[this.codingPos - 1]);
  20910. } else if (bits > 0) {
  20911. c <<= bits;
  20912. bits = 0;
  20913. }
  20914. }
  20915. } while (bits);
  20916. }
  20917. if (this.black) {
  20918. c ^= 0xFF;
  20919. }
  20920. return c;
  20921. };
  20922. // This functions returns the code found from the table.
  20923. // The start and end parameters set the boundaries for searching the table.
  20924. // The limit parameter is optional. Function returns an array with three
  20925. // values. The first array element indicates whether a valid code is being
  20926. // returned. The second array element is the actual code. The third array
  20927. // element indicates whether EOF was reached.
  20928. CCITTFaxStream.prototype.findTableCode =
  20929. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  20930. var limitValue = limit || 0;
  20931. for (var i = start; i <= end; ++i) {
  20932. var code = this.lookBits(i);
  20933. if (code === ccittEOF) {
  20934. return [true, 1, false];
  20935. }
  20936. if (i < end) {
  20937. code <<= end - i;
  20938. }
  20939. if (!limitValue || code >= limitValue) {
  20940. var p = table[code - limitValue];
  20941. if (p[0] === i) {
  20942. this.eatBits(i);
  20943. return [true, p[1], true];
  20944. }
  20945. }
  20946. }
  20947. return [false, 0, false];
  20948. };
  20949. CCITTFaxStream.prototype.getTwoDimCode =
  20950. function ccittFaxStreamGetTwoDimCode() {
  20951. var code = 0;
  20952. var p;
  20953. if (this.eoblock) {
  20954. code = this.lookBits(7);
  20955. p = twoDimTable[code];
  20956. if (p && p[0] > 0) {
  20957. this.eatBits(p[0]);
  20958. return p[1];
  20959. }
  20960. } else {
  20961. var result = this.findTableCode(1, 7, twoDimTable);
  20962. if (result[0] && result[2]) {
  20963. return result[1];
  20964. }
  20965. }
  20966. info('Bad two dim code');
  20967. return ccittEOF;
  20968. };
  20969. CCITTFaxStream.prototype.getWhiteCode =
  20970. function ccittFaxStreamGetWhiteCode() {
  20971. var code = 0;
  20972. var p;
  20973. if (this.eoblock) {
  20974. code = this.lookBits(12);
  20975. if (code === ccittEOF) {
  20976. return 1;
  20977. }
  20978. if ((code >> 5) === 0) {
  20979. p = whiteTable1[code];
  20980. } else {
  20981. p = whiteTable2[code >> 3];
  20982. }
  20983. if (p[0] > 0) {
  20984. this.eatBits(p[0]);
  20985. return p[1];
  20986. }
  20987. } else {
  20988. var result = this.findTableCode(1, 9, whiteTable2);
  20989. if (result[0]) {
  20990. return result[1];
  20991. }
  20992. result = this.findTableCode(11, 12, whiteTable1);
  20993. if (result[0]) {
  20994. return result[1];
  20995. }
  20996. }
  20997. info('bad white code');
  20998. this.eatBits(1);
  20999. return 1;
  21000. };
  21001. CCITTFaxStream.prototype.getBlackCode =
  21002. function ccittFaxStreamGetBlackCode() {
  21003. var code, p;
  21004. if (this.eoblock) {
  21005. code = this.lookBits(13);
  21006. if (code === ccittEOF) {
  21007. return 1;
  21008. }
  21009. if ((code >> 7) === 0) {
  21010. p = blackTable1[code];
  21011. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  21012. p = blackTable2[(code >> 1) - 64];
  21013. } else {
  21014. p = blackTable3[code >> 7];
  21015. }
  21016. if (p[0] > 0) {
  21017. this.eatBits(p[0]);
  21018. return p[1];
  21019. }
  21020. } else {
  21021. var result = this.findTableCode(2, 6, blackTable3);
  21022. if (result[0]) {
  21023. return result[1];
  21024. }
  21025. result = this.findTableCode(7, 12, blackTable2, 64);
  21026. if (result[0]) {
  21027. return result[1];
  21028. }
  21029. result = this.findTableCode(10, 13, blackTable1);
  21030. if (result[0]) {
  21031. return result[1];
  21032. }
  21033. }
  21034. info('bad black code');
  21035. this.eatBits(1);
  21036. return 1;
  21037. };
  21038. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  21039. var c;
  21040. while (this.inputBits < n) {
  21041. if ((c = this.str.getByte()) === -1) {
  21042. if (this.inputBits === 0) {
  21043. return ccittEOF;
  21044. }
  21045. return ((this.inputBuf << (n - this.inputBits)) &
  21046. (0xFFFF >> (16 - n)));
  21047. }
  21048. this.inputBuf = (this.inputBuf << 8) | c;
  21049. this.inputBits += 8;
  21050. }
  21051. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  21052. };
  21053. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  21054. if ((this.inputBits -= n) < 0) {
  21055. this.inputBits = 0;
  21056. }
  21057. };
  21058. return CCITTFaxStream;
  21059. })();
  21060. var LZWStream = (function LZWStreamClosure() {
  21061. function LZWStream(str, maybeLength, earlyChange) {
  21062. this.str = str;
  21063. this.dict = str.dict;
  21064. this.cachedData = 0;
  21065. this.bitsCached = 0;
  21066. var maxLzwDictionarySize = 4096;
  21067. var lzwState = {
  21068. earlyChange: earlyChange,
  21069. codeLength: 9,
  21070. nextCode: 258,
  21071. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  21072. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  21073. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  21074. currentSequence: new Uint8Array(maxLzwDictionarySize),
  21075. currentSequenceLength: 0
  21076. };
  21077. for (var i = 0; i < 256; ++i) {
  21078. lzwState.dictionaryValues[i] = i;
  21079. lzwState.dictionaryLengths[i] = 1;
  21080. }
  21081. this.lzwState = lzwState;
  21082. DecodeStream.call(this, maybeLength);
  21083. }
  21084. LZWStream.prototype = Object.create(DecodeStream.prototype);
  21085. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  21086. var bitsCached = this.bitsCached;
  21087. var cachedData = this.cachedData;
  21088. while (bitsCached < n) {
  21089. var c = this.str.getByte();
  21090. if (c === -1) {
  21091. this.eof = true;
  21092. return null;
  21093. }
  21094. cachedData = (cachedData << 8) | c;
  21095. bitsCached += 8;
  21096. }
  21097. this.bitsCached = (bitsCached -= n);
  21098. this.cachedData = cachedData;
  21099. this.lastCode = null;
  21100. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  21101. };
  21102. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  21103. var blockSize = 512;
  21104. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  21105. var i, j, q;
  21106. var lzwState = this.lzwState;
  21107. if (!lzwState) {
  21108. return; // eof was found
  21109. }
  21110. var earlyChange = lzwState.earlyChange;
  21111. var nextCode = lzwState.nextCode;
  21112. var dictionaryValues = lzwState.dictionaryValues;
  21113. var dictionaryLengths = lzwState.dictionaryLengths;
  21114. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  21115. var codeLength = lzwState.codeLength;
  21116. var prevCode = lzwState.prevCode;
  21117. var currentSequence = lzwState.currentSequence;
  21118. var currentSequenceLength = lzwState.currentSequenceLength;
  21119. var decodedLength = 0;
  21120. var currentBufferLength = this.bufferLength;
  21121. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  21122. for (i = 0; i < blockSize; i++) {
  21123. var code = this.readBits(codeLength);
  21124. var hasPrev = currentSequenceLength > 0;
  21125. if (code < 256) {
  21126. currentSequence[0] = code;
  21127. currentSequenceLength = 1;
  21128. } else if (code >= 258) {
  21129. if (code < nextCode) {
  21130. currentSequenceLength = dictionaryLengths[code];
  21131. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  21132. currentSequence[j] = dictionaryValues[q];
  21133. q = dictionaryPrevCodes[q];
  21134. }
  21135. } else {
  21136. currentSequence[currentSequenceLength++] = currentSequence[0];
  21137. }
  21138. } else if (code === 256) {
  21139. codeLength = 9;
  21140. nextCode = 258;
  21141. currentSequenceLength = 0;
  21142. continue;
  21143. } else {
  21144. this.eof = true;
  21145. delete this.lzwState;
  21146. break;
  21147. }
  21148. if (hasPrev) {
  21149. dictionaryPrevCodes[nextCode] = prevCode;
  21150. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  21151. dictionaryValues[nextCode] = currentSequence[0];
  21152. nextCode++;
  21153. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  21154. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  21155. 0.6931471805599453 + 1, 12) | 0;
  21156. }
  21157. prevCode = code;
  21158. decodedLength += currentSequenceLength;
  21159. if (estimatedDecodedSize < decodedLength) {
  21160. do {
  21161. estimatedDecodedSize += decodedSizeDelta;
  21162. } while (estimatedDecodedSize < decodedLength);
  21163. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  21164. }
  21165. for (j = 0; j < currentSequenceLength; j++) {
  21166. buffer[currentBufferLength++] = currentSequence[j];
  21167. }
  21168. }
  21169. lzwState.nextCode = nextCode;
  21170. lzwState.codeLength = codeLength;
  21171. lzwState.prevCode = prevCode;
  21172. lzwState.currentSequenceLength = currentSequenceLength;
  21173. this.bufferLength = currentBufferLength;
  21174. };
  21175. return LZWStream;
  21176. })();
  21177. var NullStream = (function NullStreamClosure() {
  21178. function NullStream() {
  21179. Stream.call(this, new Uint8Array(0));
  21180. }
  21181. NullStream.prototype = Stream.prototype;
  21182. return NullStream;
  21183. })();
  21184. exports.Ascii85Stream = Ascii85Stream;
  21185. exports.AsciiHexStream = AsciiHexStream;
  21186. exports.CCITTFaxStream = CCITTFaxStream;
  21187. exports.DecryptStream = DecryptStream;
  21188. exports.DecodeStream = DecodeStream;
  21189. exports.FlateStream = FlateStream;
  21190. exports.Jbig2Stream = Jbig2Stream;
  21191. exports.JpegStream = JpegStream;
  21192. exports.JpxStream = JpxStream;
  21193. exports.NullStream = NullStream;
  21194. exports.PredictorStream = PredictorStream;
  21195. exports.RunLengthStream = RunLengthStream;
  21196. exports.Stream = Stream;
  21197. exports.StreamsSequenceStream = StreamsSequenceStream;
  21198. exports.StringStream = StringStream;
  21199. exports.LZWStream = LZWStream;
  21200. }));
  21201. (function (root, factory) {
  21202. {
  21203. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  21204. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  21205. }
  21206. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  21207. var PasswordException = sharedUtil.PasswordException;
  21208. var PasswordResponses = sharedUtil.PasswordResponses;
  21209. var bytesToString = sharedUtil.bytesToString;
  21210. var error = sharedUtil.error;
  21211. var isInt = sharedUtil.isInt;
  21212. var stringToBytes = sharedUtil.stringToBytes;
  21213. var utf8StringToString = sharedUtil.utf8StringToString;
  21214. var warn = sharedUtil.warn;
  21215. var Name = corePrimitives.Name;
  21216. var isName = corePrimitives.isName;
  21217. var isDict = corePrimitives.isDict;
  21218. var DecryptStream = coreStream.DecryptStream;
  21219. var ARCFourCipher = (function ARCFourCipherClosure() {
  21220. function ARCFourCipher(key) {
  21221. this.a = 0;
  21222. this.b = 0;
  21223. var s = new Uint8Array(256);
  21224. var i, j = 0, tmp, keyLength = key.length;
  21225. for (i = 0; i < 256; ++i) {
  21226. s[i] = i;
  21227. }
  21228. for (i = 0; i < 256; ++i) {
  21229. tmp = s[i];
  21230. j = (j + tmp + key[i % keyLength]) & 0xFF;
  21231. s[i] = s[j];
  21232. s[j] = tmp;
  21233. }
  21234. this.s = s;
  21235. }
  21236. ARCFourCipher.prototype = {
  21237. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  21238. var i, n = data.length, tmp, tmp2;
  21239. var a = this.a, b = this.b, s = this.s;
  21240. var output = new Uint8Array(n);
  21241. for (i = 0; i < n; ++i) {
  21242. a = (a + 1) & 0xFF;
  21243. tmp = s[a];
  21244. b = (b + tmp) & 0xFF;
  21245. tmp2 = s[b];
  21246. s[a] = tmp2;
  21247. s[b] = tmp;
  21248. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  21249. }
  21250. this.a = a;
  21251. this.b = b;
  21252. return output;
  21253. }
  21254. };
  21255. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  21256. return ARCFourCipher;
  21257. })();
  21258. var calculateMD5 = (function calculateMD5Closure() {
  21259. var r = new Uint8Array([
  21260. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  21261. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  21262. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  21263. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  21264. var k = new Int32Array([
  21265. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  21266. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  21267. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  21268. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  21269. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  21270. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  21271. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  21272. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  21273. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  21274. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  21275. -145523070, -1120210379, 718787259, -343485551]);
  21276. function hash(data, offset, length) {
  21277. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  21278. // pre-processing
  21279. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  21280. var padded = new Uint8Array(paddedLength);
  21281. var i, j, n;
  21282. for (i = 0; i < length; ++i) {
  21283. padded[i] = data[offset++];
  21284. }
  21285. padded[i++] = 0x80;
  21286. n = paddedLength - 8;
  21287. while (i < n) {
  21288. padded[i++] = 0;
  21289. }
  21290. padded[i++] = (length << 3) & 0xFF;
  21291. padded[i++] = (length >> 5) & 0xFF;
  21292. padded[i++] = (length >> 13) & 0xFF;
  21293. padded[i++] = (length >> 21) & 0xFF;
  21294. padded[i++] = (length >>> 29) & 0xFF;
  21295. padded[i++] = 0;
  21296. padded[i++] = 0;
  21297. padded[i++] = 0;
  21298. var w = new Int32Array(16);
  21299. for (i = 0; i < paddedLength;) {
  21300. for (j = 0; j < 16; ++j, i += 4) {
  21301. w[j] = (padded[i] | (padded[i + 1] << 8) |
  21302. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  21303. }
  21304. var a = h0, b = h1, c = h2, d = h3, f, g;
  21305. for (j = 0; j < 64; ++j) {
  21306. if (j < 16) {
  21307. f = (b & c) | ((~b) & d);
  21308. g = j;
  21309. } else if (j < 32) {
  21310. f = (d & b) | ((~d) & c);
  21311. g = (5 * j + 1) & 15;
  21312. } else if (j < 48) {
  21313. f = b ^ c ^ d;
  21314. g = (3 * j + 5) & 15;
  21315. } else {
  21316. f = c ^ (b | (~d));
  21317. g = (7 * j) & 15;
  21318. }
  21319. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  21320. d = c;
  21321. c = b;
  21322. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  21323. a = tmp;
  21324. }
  21325. h0 = (h0 + a) | 0;
  21326. h1 = (h1 + b) | 0;
  21327. h2 = (h2 + c) | 0;
  21328. h3 = (h3 + d) | 0;
  21329. }
  21330. return new Uint8Array([
  21331. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  21332. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  21333. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  21334. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  21335. ]);
  21336. }
  21337. return hash;
  21338. })();
  21339. var Word64 = (function Word64Closure() {
  21340. function Word64(highInteger, lowInteger) {
  21341. this.high = highInteger | 0;
  21342. this.low = lowInteger | 0;
  21343. }
  21344. Word64.prototype = {
  21345. and: function Word64_and(word) {
  21346. this.high &= word.high;
  21347. this.low &= word.low;
  21348. },
  21349. xor: function Word64_xor(word) {
  21350. this.high ^= word.high;
  21351. this.low ^= word.low;
  21352. },
  21353. or: function Word64_or(word) {
  21354. this.high |= word.high;
  21355. this.low |= word.low;
  21356. },
  21357. shiftRight: function Word64_shiftRight(places) {
  21358. if (places >= 32) {
  21359. this.low = (this.high >>> (places - 32)) | 0;
  21360. this.high = 0;
  21361. } else {
  21362. this.low = (this.low >>> places) | (this.high << (32 - places));
  21363. this.high = (this.high >>> places) | 0;
  21364. }
  21365. },
  21366. shiftLeft: function Word64_shiftLeft(places) {
  21367. if (places >= 32) {
  21368. this.high = this.low << (places - 32);
  21369. this.low = 0;
  21370. } else {
  21371. this.high = (this.high << places) | (this.low >>> (32 - places));
  21372. this.low = this.low << places;
  21373. }
  21374. },
  21375. rotateRight: function Word64_rotateRight(places) {
  21376. var low, high;
  21377. if (places & 32) {
  21378. high = this.low;
  21379. low = this.high;
  21380. } else {
  21381. low = this.low;
  21382. high = this.high;
  21383. }
  21384. places &= 31;
  21385. this.low = (low >>> places) | (high << (32 - places));
  21386. this.high = (high >>> places) | (low << (32 - places));
  21387. },
  21388. not: function Word64_not() {
  21389. this.high = ~this.high;
  21390. this.low = ~this.low;
  21391. },
  21392. add: function Word64_add(word) {
  21393. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  21394. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  21395. if (lowAdd > 0xFFFFFFFF) {
  21396. highAdd += 1;
  21397. }
  21398. this.low = lowAdd | 0;
  21399. this.high = highAdd | 0;
  21400. },
  21401. copyTo: function Word64_copyTo(bytes, offset) {
  21402. bytes[offset] = (this.high >>> 24) & 0xFF;
  21403. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  21404. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  21405. bytes[offset + 3] = this.high & 0xFF;
  21406. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  21407. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  21408. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  21409. bytes[offset + 7] = this.low & 0xFF;
  21410. },
  21411. assign: function Word64_assign(word) {
  21412. this.high = word.high;
  21413. this.low = word.low;
  21414. }
  21415. };
  21416. return Word64;
  21417. })();
  21418. var calculateSHA256 = (function calculateSHA256Closure() {
  21419. function rotr(x, n) {
  21420. return (x >>> n) | (x << 32 - n);
  21421. }
  21422. function ch(x, y, z) {
  21423. return (x & y) ^ (~x & z);
  21424. }
  21425. function maj(x, y, z) {
  21426. return (x & y) ^ (x & z) ^ (y & z);
  21427. }
  21428. function sigma(x) {
  21429. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  21430. }
  21431. function sigmaPrime(x) {
  21432. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  21433. }
  21434. function littleSigma(x) {
  21435. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  21436. }
  21437. function littleSigmaPrime(x) {
  21438. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  21439. }
  21440. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  21441. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  21442. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  21443. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  21444. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  21445. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  21446. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  21447. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  21448. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  21449. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  21450. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  21451. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  21452. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  21453. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  21454. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  21455. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  21456. function hash(data, offset, length) {
  21457. // initial hash values
  21458. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  21459. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  21460. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  21461. // pre-processing
  21462. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  21463. var padded = new Uint8Array(paddedLength);
  21464. var i, j, n;
  21465. for (i = 0; i < length; ++i) {
  21466. padded[i] = data[offset++];
  21467. }
  21468. padded[i++] = 0x80;
  21469. n = paddedLength - 8;
  21470. while (i < n) {
  21471. padded[i++] = 0;
  21472. }
  21473. padded[i++] = 0;
  21474. padded[i++] = 0;
  21475. padded[i++] = 0;
  21476. padded[i++] = (length >>> 29) & 0xFF;
  21477. padded[i++] = (length >> 21) & 0xFF;
  21478. padded[i++] = (length >> 13) & 0xFF;
  21479. padded[i++] = (length >> 5) & 0xFF;
  21480. padded[i++] = (length << 3) & 0xFF;
  21481. var w = new Uint32Array(64);
  21482. // for each 512 bit block
  21483. for (i = 0; i < paddedLength;) {
  21484. for (j = 0; j < 16; ++j) {
  21485. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  21486. (padded[i + 2] << 8) | (padded[i + 3]));
  21487. i += 4;
  21488. }
  21489. for (j = 16; j < 64; ++j) {
  21490. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  21491. littleSigma(w[j - 15]) + w[j - 16] | 0;
  21492. }
  21493. var a = h0, b = h1, c = h2, d = h3, e = h4,
  21494. f = h5, g = h6, h = h7, t1, t2;
  21495. for (j = 0; j < 64; ++j) {
  21496. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  21497. t2 = sigma(a) + maj(a, b, c);
  21498. h = g;
  21499. g = f;
  21500. f = e;
  21501. e = (d + t1) | 0;
  21502. d = c;
  21503. c = b;
  21504. b = a;
  21505. a = (t1 + t2) | 0;
  21506. }
  21507. h0 = (h0 + a) | 0;
  21508. h1 = (h1 + b) | 0;
  21509. h2 = (h2 + c) | 0;
  21510. h3 = (h3 + d) | 0;
  21511. h4 = (h4 + e) | 0;
  21512. h5 = (h5 + f) | 0;
  21513. h6 = (h6 + g) | 0;
  21514. h7 = (h7 + h) | 0;
  21515. }
  21516. return new Uint8Array([
  21517. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  21518. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  21519. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  21520. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  21521. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  21522. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  21523. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  21524. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  21525. ]);
  21526. }
  21527. return hash;
  21528. })();
  21529. var calculateSHA512 = (function calculateSHA512Closure() {
  21530. function ch(result, x, y, z, tmp) {
  21531. result.assign(x);
  21532. result.and(y);
  21533. tmp.assign(x);
  21534. tmp.not();
  21535. tmp.and(z);
  21536. result.xor(tmp);
  21537. }
  21538. function maj(result, x, y, z, tmp) {
  21539. result.assign(x);
  21540. result.and(y);
  21541. tmp.assign(x);
  21542. tmp.and(z);
  21543. result.xor(tmp);
  21544. tmp.assign(y);
  21545. tmp.and(z);
  21546. result.xor(tmp);
  21547. }
  21548. function sigma(result, x, tmp) {
  21549. result.assign(x);
  21550. result.rotateRight(28);
  21551. tmp.assign(x);
  21552. tmp.rotateRight(34);
  21553. result.xor(tmp);
  21554. tmp.assign(x);
  21555. tmp.rotateRight(39);
  21556. result.xor(tmp);
  21557. }
  21558. function sigmaPrime(result, x, tmp) {
  21559. result.assign(x);
  21560. result.rotateRight(14);
  21561. tmp.assign(x);
  21562. tmp.rotateRight(18);
  21563. result.xor(tmp);
  21564. tmp.assign(x);
  21565. tmp.rotateRight(41);
  21566. result.xor(tmp);
  21567. }
  21568. function littleSigma(result, x, tmp) {
  21569. result.assign(x);
  21570. result.rotateRight(1);
  21571. tmp.assign(x);
  21572. tmp.rotateRight(8);
  21573. result.xor(tmp);
  21574. tmp.assign(x);
  21575. tmp.shiftRight(7);
  21576. result.xor(tmp);
  21577. }
  21578. function littleSigmaPrime(result, x, tmp) {
  21579. result.assign(x);
  21580. result.rotateRight(19);
  21581. tmp.assign(x);
  21582. tmp.rotateRight(61);
  21583. result.xor(tmp);
  21584. tmp.assign(x);
  21585. tmp.shiftRight(6);
  21586. result.xor(tmp);
  21587. }
  21588. var k = [
  21589. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  21590. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  21591. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  21592. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  21593. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  21594. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  21595. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  21596. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  21597. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  21598. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  21599. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  21600. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  21601. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  21602. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  21603. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  21604. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  21605. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  21606. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  21607. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  21608. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  21609. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  21610. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  21611. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  21612. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  21613. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  21614. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  21615. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  21616. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  21617. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  21618. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  21619. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  21620. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  21621. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  21622. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  21623. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  21624. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  21625. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  21626. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  21627. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  21628. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  21629. function hash(data, offset, length, mode384) {
  21630. mode384 = !!mode384;
  21631. // initial hash values
  21632. var h0, h1, h2, h3, h4, h5, h6, h7;
  21633. if (!mode384) {
  21634. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  21635. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  21636. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  21637. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  21638. h4 = new Word64(0x510e527f, 0xade682d1);
  21639. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  21640. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  21641. h7 = new Word64(0x5be0cd19, 0x137e2179);
  21642. }
  21643. else {
  21644. // SHA384 is exactly the same
  21645. // except with different starting values and a trimmed result
  21646. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  21647. h1 = new Word64(0x629a292a, 0x367cd507);
  21648. h2 = new Word64(0x9159015a, 0x3070dd17);
  21649. h3 = new Word64(0x152fecd8, 0xf70e5939);
  21650. h4 = new Word64(0x67332667, 0xffc00b31);
  21651. h5 = new Word64(0x8eb44a87, 0x68581511);
  21652. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  21653. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  21654. }
  21655. // pre-processing
  21656. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  21657. var padded = new Uint8Array(paddedLength);
  21658. var i, j, n;
  21659. for (i = 0; i < length; ++i) {
  21660. padded[i] = data[offset++];
  21661. }
  21662. padded[i++] = 0x80;
  21663. n = paddedLength - 16;
  21664. while (i < n) {
  21665. padded[i++] = 0;
  21666. }
  21667. padded[i++] = 0;
  21668. padded[i++] = 0;
  21669. padded[i++] = 0;
  21670. padded[i++] = 0;
  21671. padded[i++] = 0;
  21672. padded[i++] = 0;
  21673. padded[i++] = 0;
  21674. padded[i++] = 0;
  21675. padded[i++] = 0;
  21676. padded[i++] = 0;
  21677. padded[i++] = 0;
  21678. padded[i++] = (length >>> 29) & 0xFF;
  21679. padded[i++] = (length >> 21) & 0xFF;
  21680. padded[i++] = (length >> 13) & 0xFF;
  21681. padded[i++] = (length >> 5) & 0xFF;
  21682. padded[i++] = (length << 3) & 0xFF;
  21683. var w = new Array(80);
  21684. for (i = 0; i < 80; i++) {
  21685. w[i] = new Word64(0, 0);
  21686. }
  21687. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  21688. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  21689. var g = new Word64(0, 0), h = new Word64(0, 0);
  21690. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  21691. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  21692. // for each 1024 bit block
  21693. for (i = 0; i < paddedLength;) {
  21694. for (j = 0; j < 16; ++j) {
  21695. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  21696. (padded[i + 2] << 8) | (padded[i + 3]);
  21697. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  21698. (padded[i + 6]) << 8 | (padded[i + 7]);
  21699. i += 8;
  21700. }
  21701. for (j = 16; j < 80; ++j) {
  21702. tmp3 = w[j];
  21703. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  21704. tmp3.add(w[j - 7]);
  21705. littleSigma(tmp1, w[j - 15], tmp2);
  21706. tmp3.add(tmp1);
  21707. tmp3.add(w[j - 16]);
  21708. }
  21709. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  21710. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  21711. for (j = 0; j < 80; ++j) {
  21712. t1.assign(h);
  21713. sigmaPrime(tmp1, e, tmp2);
  21714. t1.add(tmp1);
  21715. ch(tmp1, e, f, g, tmp2);
  21716. t1.add(tmp1);
  21717. t1.add(k[j]);
  21718. t1.add(w[j]);
  21719. sigma(t2, a, tmp2);
  21720. maj(tmp1, a, b, c, tmp2);
  21721. t2.add(tmp1);
  21722. tmp3 = h;
  21723. h = g;
  21724. g = f;
  21725. f = e;
  21726. d.add(t1);
  21727. e = d;
  21728. d = c;
  21729. c = b;
  21730. b = a;
  21731. tmp3.assign(t1);
  21732. tmp3.add(t2);
  21733. a = tmp3;
  21734. }
  21735. h0.add(a);
  21736. h1.add(b);
  21737. h2.add(c);
  21738. h3.add(d);
  21739. h4.add(e);
  21740. h5.add(f);
  21741. h6.add(g);
  21742. h7.add(h);
  21743. }
  21744. var result;
  21745. if (!mode384) {
  21746. result = new Uint8Array(64);
  21747. h0.copyTo(result,0);
  21748. h1.copyTo(result,8);
  21749. h2.copyTo(result,16);
  21750. h3.copyTo(result,24);
  21751. h4.copyTo(result,32);
  21752. h5.copyTo(result,40);
  21753. h6.copyTo(result,48);
  21754. h7.copyTo(result,56);
  21755. }
  21756. else {
  21757. result = new Uint8Array(48);
  21758. h0.copyTo(result,0);
  21759. h1.copyTo(result,8);
  21760. h2.copyTo(result,16);
  21761. h3.copyTo(result,24);
  21762. h4.copyTo(result,32);
  21763. h5.copyTo(result,40);
  21764. }
  21765. return result;
  21766. }
  21767. return hash;
  21768. })();
  21769. var calculateSHA384 = (function calculateSHA384Closure() {
  21770. function hash(data, offset, length) {
  21771. return calculateSHA512(data, offset, length, true);
  21772. }
  21773. return hash;
  21774. })();
  21775. var NullCipher = (function NullCipherClosure() {
  21776. function NullCipher() {
  21777. }
  21778. NullCipher.prototype = {
  21779. decryptBlock: function NullCipher_decryptBlock(data) {
  21780. return data;
  21781. }
  21782. };
  21783. return NullCipher;
  21784. })();
  21785. var AES128Cipher = (function AES128CipherClosure() {
  21786. var rcon = new Uint8Array([
  21787. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  21788. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  21789. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  21790. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  21791. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  21792. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  21793. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  21794. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  21795. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  21796. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  21797. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  21798. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  21799. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  21800. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  21801. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  21802. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  21803. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  21804. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  21805. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  21806. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  21807. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  21808. 0x74, 0xe8, 0xcb, 0x8d]);
  21809. var s = new Uint8Array([
  21810. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  21811. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  21812. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  21813. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  21814. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  21815. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  21816. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  21817. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  21818. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  21819. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  21820. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  21821. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  21822. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  21823. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  21824. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  21825. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  21826. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  21827. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  21828. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  21829. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  21830. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  21831. 0xb0, 0x54, 0xbb, 0x16]);
  21832. var inv_s = new Uint8Array([
  21833. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  21834. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  21835. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  21836. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  21837. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  21838. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  21839. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  21840. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  21841. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  21842. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  21843. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  21844. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  21845. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  21846. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  21847. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  21848. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  21849. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  21850. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  21851. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  21852. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  21853. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  21854. 0x55, 0x21, 0x0c, 0x7d]);
  21855. var mixCol = new Uint8Array(256);
  21856. for (var i = 0; i < 256; i++) {
  21857. if (i < 128) {
  21858. mixCol[i] = i << 1;
  21859. } else {
  21860. mixCol[i] = (i << 1) ^ 0x1b;
  21861. }
  21862. }
  21863. var mix = new Uint32Array([
  21864. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  21865. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  21866. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  21867. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  21868. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  21869. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  21870. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  21871. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  21872. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  21873. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  21874. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  21875. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  21876. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  21877. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  21878. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  21879. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  21880. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  21881. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  21882. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  21883. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  21884. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  21885. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  21886. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  21887. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  21888. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  21889. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  21890. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  21891. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  21892. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  21893. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  21894. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  21895. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  21896. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  21897. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  21898. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  21899. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  21900. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  21901. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  21902. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  21903. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  21904. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  21905. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  21906. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  21907. function expandKey128(cipherKey) {
  21908. var b = 176, result = new Uint8Array(b);
  21909. result.set(cipherKey);
  21910. for (var j = 16, i = 1; j < b; ++i) {
  21911. // RotWord
  21912. var t1 = result[j - 3], t2 = result[j - 2],
  21913. t3 = result[j - 1], t4 = result[j - 4];
  21914. // SubWord
  21915. t1 = s[t1];
  21916. t2 = s[t2];
  21917. t3 = s[t3];
  21918. t4 = s[t4];
  21919. // Rcon
  21920. t1 = t1 ^ rcon[i];
  21921. for (var n = 0; n < 4; ++n) {
  21922. result[j] = (t1 ^= result[j - 16]);
  21923. j++;
  21924. result[j] = (t2 ^= result[j - 16]);
  21925. j++;
  21926. result[j] = (t3 ^= result[j - 16]);
  21927. j++;
  21928. result[j] = (t4 ^= result[j - 16]);
  21929. j++;
  21930. }
  21931. }
  21932. return result;
  21933. }
  21934. function decrypt128(input, key) {
  21935. var state = new Uint8Array(16);
  21936. state.set(input);
  21937. var i, j, k;
  21938. var t, u, v;
  21939. // AddRoundKey
  21940. for (j = 0, k = 160; j < 16; ++j, ++k) {
  21941. state[j] ^= key[k];
  21942. }
  21943. for (i = 9; i >= 1; --i) {
  21944. // InvShiftRows
  21945. t = state[13];
  21946. state[13] = state[9];
  21947. state[9] = state[5];
  21948. state[5] = state[1];
  21949. state[1] = t;
  21950. t = state[14];
  21951. u = state[10];
  21952. state[14] = state[6];
  21953. state[10] = state[2];
  21954. state[6] = t;
  21955. state[2] = u;
  21956. t = state[15];
  21957. u = state[11];
  21958. v = state[7];
  21959. state[15] = state[3];
  21960. state[11] = t;
  21961. state[7] = u;
  21962. state[3] = v;
  21963. // InvSubBytes
  21964. for (j = 0; j < 16; ++j) {
  21965. state[j] = inv_s[state[j]];
  21966. }
  21967. // AddRoundKey
  21968. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  21969. state[j] ^= key[k];
  21970. }
  21971. // InvMixColumns
  21972. for (j = 0; j < 16; j += 4) {
  21973. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  21974. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  21975. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  21976. (s3 >>> 24) ^ (s3 << 8));
  21977. state[j] = (t >>> 24) & 0xFF;
  21978. state[j + 1] = (t >> 16) & 0xFF;
  21979. state[j + 2] = (t >> 8) & 0xFF;
  21980. state[j + 3] = t & 0xFF;
  21981. }
  21982. }
  21983. // InvShiftRows
  21984. t = state[13];
  21985. state[13] = state[9];
  21986. state[9] = state[5];
  21987. state[5] = state[1];
  21988. state[1] = t;
  21989. t = state[14];
  21990. u = state[10];
  21991. state[14] = state[6];
  21992. state[10] = state[2];
  21993. state[6] = t;
  21994. state[2] = u;
  21995. t = state[15];
  21996. u = state[11];
  21997. v = state[7];
  21998. state[15] = state[3];
  21999. state[11] = t;
  22000. state[7] = u;
  22001. state[3] = v;
  22002. for (j = 0; j < 16; ++j) {
  22003. // InvSubBytes
  22004. state[j] = inv_s[state[j]];
  22005. // AddRoundKey
  22006. state[j] ^= key[j];
  22007. }
  22008. return state;
  22009. }
  22010. function encrypt128(input, key) {
  22011. var t, u, v, k;
  22012. var state = new Uint8Array(16);
  22013. state.set(input);
  22014. for (j = 0; j < 16; ++j) {
  22015. // AddRoundKey
  22016. state[j] ^= key[j];
  22017. }
  22018. for (i = 1; i < 10; i++) {
  22019. //SubBytes
  22020. for (j = 0; j < 16; ++j) {
  22021. state[j] = s[state[j]];
  22022. }
  22023. //ShiftRows
  22024. v = state[1];
  22025. state[1] = state[5];
  22026. state[5] = state[9];
  22027. state[9] = state[13];
  22028. state[13] = v;
  22029. v = state[2];
  22030. u = state[6];
  22031. state[2] = state[10];
  22032. state[6] = state[14];
  22033. state[10] = v;
  22034. state[14] = u;
  22035. v = state[3];
  22036. u = state[7];
  22037. t = state[11];
  22038. state[3] = state[15];
  22039. state[7] = v;
  22040. state[11] = u;
  22041. state[15] = t;
  22042. //MixColumns
  22043. for (var j = 0; j < 16; j += 4) {
  22044. var s0 = state[j + 0], s1 = state[j + 1];
  22045. var s2 = state[j + 2], s3 = state[j + 3];
  22046. t = s0 ^ s1 ^ s2 ^ s3;
  22047. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  22048. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  22049. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  22050. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  22051. }
  22052. //AddRoundKey
  22053. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  22054. state[j] ^= key[k];
  22055. }
  22056. }
  22057. //SubBytes
  22058. for (j = 0; j < 16; ++j) {
  22059. state[j] = s[state[j]];
  22060. }
  22061. //ShiftRows
  22062. v = state[1];
  22063. state[1] = state[5];
  22064. state[5] = state[9];
  22065. state[9] = state[13];
  22066. state[13] = v;
  22067. v = state[2];
  22068. u = state[6];
  22069. state[2] = state[10];
  22070. state[6] = state[14];
  22071. state[10] = v;
  22072. state[14] = u;
  22073. v = state[3];
  22074. u = state[7];
  22075. t = state[11];
  22076. state[3] = state[15];
  22077. state[7] = v;
  22078. state[11] = u;
  22079. state[15] = t;
  22080. //AddRoundKey
  22081. for (j = 0, k = 160; j < 16; ++j, ++k) {
  22082. state[j] ^= key[k];
  22083. }
  22084. return state;
  22085. }
  22086. function AES128Cipher(key) {
  22087. this.key = expandKey128(key);
  22088. this.buffer = new Uint8Array(16);
  22089. this.bufferPosition = 0;
  22090. }
  22091. function decryptBlock2(data, finalize) {
  22092. var i, j, ii, sourceLength = data.length,
  22093. buffer = this.buffer, bufferLength = this.bufferPosition,
  22094. result = [], iv = this.iv;
  22095. for (i = 0; i < sourceLength; ++i) {
  22096. buffer[bufferLength] = data[i];
  22097. ++bufferLength;
  22098. if (bufferLength < 16) {
  22099. continue;
  22100. }
  22101. // buffer is full, decrypting
  22102. var plain = decrypt128(buffer, this.key);
  22103. // xor-ing the IV vector to get plain text
  22104. for (j = 0; j < 16; ++j) {
  22105. plain[j] ^= iv[j];
  22106. }
  22107. iv = buffer;
  22108. result.push(plain);
  22109. buffer = new Uint8Array(16);
  22110. bufferLength = 0;
  22111. }
  22112. // saving incomplete buffer
  22113. this.buffer = buffer;
  22114. this.bufferLength = bufferLength;
  22115. this.iv = iv;
  22116. if (result.length === 0) {
  22117. return new Uint8Array([]);
  22118. }
  22119. // combining plain text blocks into one
  22120. var outputLength = 16 * result.length;
  22121. if (finalize) {
  22122. // undo a padding that is described in RFC 2898
  22123. var lastBlock = result[result.length - 1];
  22124. var psLen = lastBlock[15];
  22125. if (psLen <= 16) {
  22126. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  22127. if (lastBlock[i] !== psLen) {
  22128. // Invalid padding, assume that the block has no padding.
  22129. psLen = 0;
  22130. break;
  22131. }
  22132. }
  22133. outputLength -= psLen;
  22134. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  22135. }
  22136. }
  22137. var output = new Uint8Array(outputLength);
  22138. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  22139. output.set(result[i], j);
  22140. }
  22141. return output;
  22142. }
  22143. AES128Cipher.prototype = {
  22144. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  22145. var i, sourceLength = data.length;
  22146. var buffer = this.buffer, bufferLength = this.bufferPosition;
  22147. // waiting for IV values -- they are at the start of the stream
  22148. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  22149. buffer[bufferLength] = data[i];
  22150. }
  22151. if (bufferLength < 16) {
  22152. // need more data
  22153. this.bufferLength = bufferLength;
  22154. return new Uint8Array([]);
  22155. }
  22156. this.iv = buffer;
  22157. this.buffer = new Uint8Array(16);
  22158. this.bufferLength = 0;
  22159. // starting decryption
  22160. this.decryptBlock = decryptBlock2;
  22161. return this.decryptBlock(data.subarray(16), finalize);
  22162. },
  22163. encrypt: function AES128Cipher_encrypt(data, iv) {
  22164. var i, j, ii, sourceLength = data.length,
  22165. buffer = this.buffer, bufferLength = this.bufferPosition,
  22166. result = [];
  22167. if (!iv) {
  22168. iv = new Uint8Array(16);
  22169. }
  22170. for (i = 0; i < sourceLength; ++i) {
  22171. buffer[bufferLength] = data[i];
  22172. ++bufferLength;
  22173. if (bufferLength < 16) {
  22174. continue;
  22175. }
  22176. for (j = 0; j < 16; ++j) {
  22177. buffer[j] ^= iv[j];
  22178. }
  22179. // buffer is full, encrypting
  22180. var cipher = encrypt128(buffer, this.key);
  22181. iv = cipher;
  22182. result.push(cipher);
  22183. buffer = new Uint8Array(16);
  22184. bufferLength = 0;
  22185. }
  22186. // saving incomplete buffer
  22187. this.buffer = buffer;
  22188. this.bufferLength = bufferLength;
  22189. this.iv = iv;
  22190. if (result.length === 0) {
  22191. return new Uint8Array([]);
  22192. }
  22193. // combining plain text blocks into one
  22194. var outputLength = 16 * result.length;
  22195. var output = new Uint8Array(outputLength);
  22196. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  22197. output.set(result[i], j);
  22198. }
  22199. return output;
  22200. }
  22201. };
  22202. return AES128Cipher;
  22203. })();
  22204. var AES256Cipher = (function AES256CipherClosure() {
  22205. var rcon = new Uint8Array([
  22206. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  22207. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  22208. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  22209. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  22210. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  22211. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  22212. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  22213. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  22214. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  22215. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  22216. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  22217. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  22218. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  22219. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  22220. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  22221. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  22222. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  22223. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  22224. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  22225. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  22226. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  22227. 0x74, 0xe8, 0xcb, 0x8d]);
  22228. var s = new Uint8Array([
  22229. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  22230. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  22231. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  22232. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  22233. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  22234. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  22235. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  22236. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  22237. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  22238. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  22239. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  22240. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  22241. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  22242. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  22243. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  22244. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  22245. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  22246. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  22247. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  22248. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  22249. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  22250. 0xb0, 0x54, 0xbb, 0x16]);
  22251. var inv_s = new Uint8Array([
  22252. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  22253. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  22254. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  22255. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  22256. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  22257. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  22258. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  22259. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  22260. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  22261. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  22262. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  22263. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  22264. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  22265. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  22266. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  22267. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  22268. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  22269. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  22270. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  22271. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  22272. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  22273. 0x55, 0x21, 0x0c, 0x7d]);
  22274. var mixCol = new Uint8Array(256);
  22275. for (var i = 0; i < 256; i++) {
  22276. if (i < 128) {
  22277. mixCol[i] = i << 1;
  22278. } else {
  22279. mixCol[i] = (i << 1) ^ 0x1b;
  22280. }
  22281. }
  22282. var mix = new Uint32Array([
  22283. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  22284. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  22285. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  22286. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  22287. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  22288. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  22289. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  22290. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  22291. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  22292. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  22293. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  22294. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  22295. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  22296. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  22297. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  22298. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  22299. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  22300. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  22301. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  22302. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  22303. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  22304. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  22305. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  22306. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  22307. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  22308. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  22309. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  22310. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  22311. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  22312. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  22313. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  22314. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  22315. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  22316. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  22317. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  22318. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  22319. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  22320. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  22321. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  22322. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  22323. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  22324. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  22325. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  22326. function expandKey256(cipherKey) {
  22327. var b = 240, result = new Uint8Array(b);
  22328. var r = 1;
  22329. result.set(cipherKey);
  22330. for (var j = 32, i = 1; j < b; ++i) {
  22331. if (j % 32 === 16) {
  22332. t1 = s[t1];
  22333. t2 = s[t2];
  22334. t3 = s[t3];
  22335. t4 = s[t4];
  22336. } else if (j % 32 === 0) {
  22337. // RotWord
  22338. var t1 = result[j - 3], t2 = result[j - 2],
  22339. t3 = result[j - 1], t4 = result[j - 4];
  22340. // SubWord
  22341. t1 = s[t1];
  22342. t2 = s[t2];
  22343. t3 = s[t3];
  22344. t4 = s[t4];
  22345. // Rcon
  22346. t1 = t1 ^ r;
  22347. if ((r <<= 1) >= 256) {
  22348. r = (r ^ 0x1b) & 0xFF;
  22349. }
  22350. }
  22351. for (var n = 0; n < 4; ++n) {
  22352. result[j] = (t1 ^= result[j - 32]);
  22353. j++;
  22354. result[j] = (t2 ^= result[j - 32]);
  22355. j++;
  22356. result[j] = (t3 ^= result[j - 32]);
  22357. j++;
  22358. result[j] = (t4 ^= result[j - 32]);
  22359. j++;
  22360. }
  22361. }
  22362. return result;
  22363. }
  22364. function decrypt256(input, key) {
  22365. var state = new Uint8Array(16);
  22366. state.set(input);
  22367. var i, j, k;
  22368. var t, u, v;
  22369. // AddRoundKey
  22370. for (j = 0, k = 224; j < 16; ++j, ++k) {
  22371. state[j] ^= key[k];
  22372. }
  22373. for (i = 13; i >= 1; --i) {
  22374. // InvShiftRows
  22375. t = state[13];
  22376. state[13] = state[9];
  22377. state[9] = state[5];
  22378. state[5] = state[1];
  22379. state[1] = t;
  22380. t = state[14];
  22381. u = state[10];
  22382. state[14] = state[6];
  22383. state[10] = state[2];
  22384. state[6] = t;
  22385. state[2] = u;
  22386. t = state[15];
  22387. u = state[11];
  22388. v = state[7];
  22389. state[15] = state[3];
  22390. state[11] = t;
  22391. state[7] = u;
  22392. state[3] = v;
  22393. // InvSubBytes
  22394. for (j = 0; j < 16; ++j) {
  22395. state[j] = inv_s[state[j]];
  22396. }
  22397. // AddRoundKey
  22398. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  22399. state[j] ^= key[k];
  22400. }
  22401. // InvMixColumns
  22402. for (j = 0; j < 16; j += 4) {
  22403. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  22404. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  22405. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  22406. (s3 >>> 24) ^ (s3 << 8));
  22407. state[j] = (t >>> 24) & 0xFF;
  22408. state[j + 1] = (t >> 16) & 0xFF;
  22409. state[j + 2] = (t >> 8) & 0xFF;
  22410. state[j + 3] = t & 0xFF;
  22411. }
  22412. }
  22413. // InvShiftRows
  22414. t = state[13];
  22415. state[13] = state[9];
  22416. state[9] = state[5];
  22417. state[5] = state[1];
  22418. state[1] = t;
  22419. t = state[14];
  22420. u = state[10];
  22421. state[14] = state[6];
  22422. state[10] = state[2];
  22423. state[6] = t;
  22424. state[2] = u;
  22425. t = state[15];
  22426. u = state[11];
  22427. v = state[7];
  22428. state[15] = state[3];
  22429. state[11] = t;
  22430. state[7] = u;
  22431. state[3] = v;
  22432. for (j = 0; j < 16; ++j) {
  22433. // InvSubBytes
  22434. state[j] = inv_s[state[j]];
  22435. // AddRoundKey
  22436. state[j] ^= key[j];
  22437. }
  22438. return state;
  22439. }
  22440. function encrypt256(input, key) {
  22441. var t, u, v, k;
  22442. var state = new Uint8Array(16);
  22443. state.set(input);
  22444. for (j = 0; j < 16; ++j) {
  22445. // AddRoundKey
  22446. state[j] ^= key[j];
  22447. }
  22448. for (i = 1; i < 14; i++) {
  22449. //SubBytes
  22450. for (j = 0; j < 16; ++j) {
  22451. state[j] = s[state[j]];
  22452. }
  22453. //ShiftRows
  22454. v = state[1];
  22455. state[1] = state[5];
  22456. state[5] = state[9];
  22457. state[9] = state[13];
  22458. state[13] = v;
  22459. v = state[2];
  22460. u = state[6];
  22461. state[2] = state[10];
  22462. state[6] = state[14];
  22463. state[10] = v;
  22464. state[14] = u;
  22465. v = state[3];
  22466. u = state[7];
  22467. t = state[11];
  22468. state[3] = state[15];
  22469. state[7] = v;
  22470. state[11] = u;
  22471. state[15] = t;
  22472. //MixColumns
  22473. for (var j = 0; j < 16; j += 4) {
  22474. var s0 = state[j + 0], s1 = state[j + 1];
  22475. var s2 = state[j + 2], s3 = state[j + 3];
  22476. t = s0 ^ s1 ^ s2 ^ s3;
  22477. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  22478. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  22479. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  22480. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  22481. }
  22482. //AddRoundKey
  22483. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  22484. state[j] ^= key[k];
  22485. }
  22486. }
  22487. //SubBytes
  22488. for (j = 0; j < 16; ++j) {
  22489. state[j] = s[state[j]];
  22490. }
  22491. //ShiftRows
  22492. v = state[1];
  22493. state[1] = state[5];
  22494. state[5] = state[9];
  22495. state[9] = state[13];
  22496. state[13] = v;
  22497. v = state[2];
  22498. u = state[6];
  22499. state[2] = state[10];
  22500. state[6] = state[14];
  22501. state[10] = v;
  22502. state[14] = u;
  22503. v = state[3];
  22504. u = state[7];
  22505. t = state[11];
  22506. state[3] = state[15];
  22507. state[7] = v;
  22508. state[11] = u;
  22509. state[15] = t;
  22510. //AddRoundKey
  22511. for (j = 0, k = 224; j < 16; ++j, ++k) {
  22512. state[j] ^= key[k];
  22513. }
  22514. return state;
  22515. }
  22516. function AES256Cipher(key) {
  22517. this.key = expandKey256(key);
  22518. this.buffer = new Uint8Array(16);
  22519. this.bufferPosition = 0;
  22520. }
  22521. function decryptBlock2(data, finalize) {
  22522. var i, j, ii, sourceLength = data.length,
  22523. buffer = this.buffer, bufferLength = this.bufferPosition,
  22524. result = [], iv = this.iv;
  22525. for (i = 0; i < sourceLength; ++i) {
  22526. buffer[bufferLength] = data[i];
  22527. ++bufferLength;
  22528. if (bufferLength < 16) {
  22529. continue;
  22530. }
  22531. // buffer is full, decrypting
  22532. var plain = decrypt256(buffer, this.key);
  22533. // xor-ing the IV vector to get plain text
  22534. for (j = 0; j < 16; ++j) {
  22535. plain[j] ^= iv[j];
  22536. }
  22537. iv = buffer;
  22538. result.push(plain);
  22539. buffer = new Uint8Array(16);
  22540. bufferLength = 0;
  22541. }
  22542. // saving incomplete buffer
  22543. this.buffer = buffer;
  22544. this.bufferLength = bufferLength;
  22545. this.iv = iv;
  22546. if (result.length === 0) {
  22547. return new Uint8Array([]);
  22548. }
  22549. // combining plain text blocks into one
  22550. var outputLength = 16 * result.length;
  22551. if (finalize) {
  22552. // undo a padding that is described in RFC 2898
  22553. var lastBlock = result[result.length - 1];
  22554. var psLen = lastBlock[15];
  22555. if (psLen <= 16) {
  22556. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  22557. if (lastBlock[i] !== psLen) {
  22558. // Invalid padding, assume that the block has no padding.
  22559. psLen = 0;
  22560. break;
  22561. }
  22562. }
  22563. outputLength -= psLen;
  22564. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  22565. }
  22566. }
  22567. var output = new Uint8Array(outputLength);
  22568. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  22569. output.set(result[i], j);
  22570. }
  22571. return output;
  22572. }
  22573. AES256Cipher.prototype = {
  22574. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  22575. var i, sourceLength = data.length;
  22576. var buffer = this.buffer, bufferLength = this.bufferPosition;
  22577. // if not supplied an IV wait for IV values
  22578. // they are at the start of the stream
  22579. if (iv) {
  22580. this.iv = iv;
  22581. } else {
  22582. for (i = 0; bufferLength < 16 &&
  22583. i < sourceLength; ++i, ++bufferLength) {
  22584. buffer[bufferLength] = data[i];
  22585. }
  22586. if (bufferLength < 16) {
  22587. //need more data
  22588. this.bufferLength = bufferLength;
  22589. return new Uint8Array([]);
  22590. }
  22591. this.iv = buffer;
  22592. data = data.subarray(16);
  22593. }
  22594. this.buffer = new Uint8Array(16);
  22595. this.bufferLength = 0;
  22596. // starting decryption
  22597. this.decryptBlock = decryptBlock2;
  22598. return this.decryptBlock(data, finalize);
  22599. },
  22600. encrypt: function AES256Cipher_encrypt(data, iv) {
  22601. var i, j, ii, sourceLength = data.length,
  22602. buffer = this.buffer, bufferLength = this.bufferPosition,
  22603. result = [];
  22604. if (!iv) {
  22605. iv = new Uint8Array(16);
  22606. }
  22607. for (i = 0; i < sourceLength; ++i) {
  22608. buffer[bufferLength] = data[i];
  22609. ++bufferLength;
  22610. if (bufferLength < 16) {
  22611. continue;
  22612. }
  22613. for (j = 0; j < 16; ++j) {
  22614. buffer[j] ^= iv[j];
  22615. }
  22616. // buffer is full, encrypting
  22617. var cipher = encrypt256(buffer, this.key);
  22618. this.iv = cipher;
  22619. result.push(cipher);
  22620. buffer = new Uint8Array(16);
  22621. bufferLength = 0;
  22622. }
  22623. // saving incomplete buffer
  22624. this.buffer = buffer;
  22625. this.bufferLength = bufferLength;
  22626. this.iv = iv;
  22627. if (result.length === 0) {
  22628. return new Uint8Array([]);
  22629. }
  22630. // combining plain text blocks into one
  22631. var outputLength = 16 * result.length;
  22632. var output = new Uint8Array(outputLength);
  22633. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  22634. output.set(result[i], j);
  22635. }
  22636. return output;
  22637. }
  22638. };
  22639. return AES256Cipher;
  22640. })();
  22641. var PDF17 = (function PDF17Closure() {
  22642. function compareByteArrays(array1, array2) {
  22643. if (array1.length !== array2.length) {
  22644. return false;
  22645. }
  22646. for (var i = 0; i < array1.length; i++) {
  22647. if (array1[i] !== array2[i]) {
  22648. return false;
  22649. }
  22650. }
  22651. return true;
  22652. }
  22653. function PDF17() {
  22654. }
  22655. PDF17.prototype = {
  22656. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  22657. ownerValidationSalt,
  22658. userBytes,
  22659. ownerPassword) {
  22660. var hashData = new Uint8Array(password.length + 56);
  22661. hashData.set(password, 0);
  22662. hashData.set(ownerValidationSalt, password.length);
  22663. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  22664. var result = calculateSHA256(hashData, 0, hashData.length);
  22665. return compareByteArrays(result, ownerPassword);
  22666. },
  22667. checkUserPassword: function PDF17_checkUserPassword(password,
  22668. userValidationSalt,
  22669. userPassword) {
  22670. var hashData = new Uint8Array(password.length + 8);
  22671. hashData.set(password, 0);
  22672. hashData.set(userValidationSalt, password.length);
  22673. var result = calculateSHA256(hashData, 0, hashData.length);
  22674. return compareByteArrays(result, userPassword);
  22675. },
  22676. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  22677. ownerEncryption) {
  22678. var hashData = new Uint8Array(password.length + 56);
  22679. hashData.set(password, 0);
  22680. hashData.set(ownerKeySalt, password.length);
  22681. hashData.set(userBytes, password.length + ownerKeySalt.length);
  22682. var key = calculateSHA256(hashData, 0, hashData.length);
  22683. var cipher = new AES256Cipher(key);
  22684. return cipher.decryptBlock(ownerEncryption,
  22685. false,
  22686. new Uint8Array(16));
  22687. },
  22688. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  22689. userEncryption) {
  22690. var hashData = new Uint8Array(password.length + 8);
  22691. hashData.set(password, 0);
  22692. hashData.set(userKeySalt, password.length);
  22693. //key is the decryption key for the UE string
  22694. var key = calculateSHA256(hashData, 0, hashData.length);
  22695. var cipher = new AES256Cipher(key);
  22696. return cipher.decryptBlock(userEncryption,
  22697. false,
  22698. new Uint8Array(16));
  22699. }
  22700. };
  22701. return PDF17;
  22702. })();
  22703. var PDF20 = (function PDF20Closure() {
  22704. function concatArrays(array1, array2) {
  22705. var t = new Uint8Array(array1.length + array2.length);
  22706. t.set(array1, 0);
  22707. t.set(array2, array1.length);
  22708. return t;
  22709. }
  22710. function calculatePDF20Hash(password, input, userBytes) {
  22711. //This refers to Algorithm 2.B as defined in ISO 32000-2
  22712. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  22713. var e = [0];
  22714. var i = 0;
  22715. while (i < 64 || e[e.length - 1] > i - 32) {
  22716. var arrayLength = password.length + k.length + userBytes.length;
  22717. var k1 = new Uint8Array(arrayLength * 64);
  22718. var array = concatArrays(password, k);
  22719. array = concatArrays(array, userBytes);
  22720. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  22721. k1.set(array, pos);
  22722. }
  22723. //AES128 CBC NO PADDING with
  22724. //first 16 bytes of k as the key and the second 16 as the iv.
  22725. var cipher = new AES128Cipher(k.subarray(0, 16));
  22726. e = cipher.encrypt(k1, k.subarray(16, 32));
  22727. //Now we have to take the first 16 bytes of an unsigned
  22728. //big endian integer... and compute the remainder
  22729. //modulo 3.... That is a fairly large number and
  22730. //JavaScript isn't going to handle that well...
  22731. //So we're using a trick that allows us to perform
  22732. //modulo math byte by byte
  22733. var remainder = 0;
  22734. for (var z = 0; z < 16; z++) {
  22735. remainder *= (256 % 3);
  22736. remainder %= 3;
  22737. remainder += ((e[z] >>> 0) % 3);
  22738. remainder %= 3;
  22739. }
  22740. if (remainder === 0) {
  22741. k = calculateSHA256(e, 0, e.length);
  22742. }
  22743. else if (remainder === 1) {
  22744. k = calculateSHA384(e, 0, e.length);
  22745. }
  22746. else if (remainder === 2) {
  22747. k = calculateSHA512(e, 0, e.length);
  22748. }
  22749. i++;
  22750. }
  22751. return k.subarray(0, 32);
  22752. }
  22753. function PDF20() {
  22754. }
  22755. function compareByteArrays(array1, array2) {
  22756. if (array1.length !== array2.length) {
  22757. return false;
  22758. }
  22759. for (var i = 0; i < array1.length; i++) {
  22760. if (array1[i] !== array2[i]) {
  22761. return false;
  22762. }
  22763. }
  22764. return true;
  22765. }
  22766. PDF20.prototype = {
  22767. hash: function PDF20_hash(password, concatBytes, userBytes) {
  22768. return calculatePDF20Hash(password, concatBytes, userBytes);
  22769. },
  22770. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  22771. ownerValidationSalt,
  22772. userBytes,
  22773. ownerPassword) {
  22774. var hashData = new Uint8Array(password.length + 56);
  22775. hashData.set(password, 0);
  22776. hashData.set(ownerValidationSalt, password.length);
  22777. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  22778. var result = calculatePDF20Hash(password, hashData, userBytes);
  22779. return compareByteArrays(result, ownerPassword);
  22780. },
  22781. checkUserPassword: function PDF20_checkUserPassword(password,
  22782. userValidationSalt,
  22783. userPassword) {
  22784. var hashData = new Uint8Array(password.length + 8);
  22785. hashData.set(password, 0);
  22786. hashData.set(userValidationSalt, password.length);
  22787. var result = calculatePDF20Hash(password, hashData, []);
  22788. return compareByteArrays(result, userPassword);
  22789. },
  22790. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  22791. ownerEncryption) {
  22792. var hashData = new Uint8Array(password.length + 56);
  22793. hashData.set(password, 0);
  22794. hashData.set(ownerKeySalt, password.length);
  22795. hashData.set(userBytes, password.length + ownerKeySalt.length);
  22796. var key = calculatePDF20Hash(password, hashData, userBytes);
  22797. var cipher = new AES256Cipher(key);
  22798. return cipher.decryptBlock(ownerEncryption,
  22799. false,
  22800. new Uint8Array(16));
  22801. },
  22802. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  22803. userEncryption) {
  22804. var hashData = new Uint8Array(password.length + 8);
  22805. hashData.set(password, 0);
  22806. hashData.set(userKeySalt, password.length);
  22807. //key is the decryption key for the UE string
  22808. var key = calculatePDF20Hash(password, hashData, []);
  22809. var cipher = new AES256Cipher(key);
  22810. return cipher.decryptBlock(userEncryption,
  22811. false,
  22812. new Uint8Array(16));
  22813. }
  22814. };
  22815. return PDF20;
  22816. })();
  22817. var CipherTransform = (function CipherTransformClosure() {
  22818. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  22819. this.stringCipherConstructor = stringCipherConstructor;
  22820. this.streamCipherConstructor = streamCipherConstructor;
  22821. }
  22822. CipherTransform.prototype = {
  22823. createStream: function CipherTransform_createStream(stream, length) {
  22824. var cipher = new this.streamCipherConstructor();
  22825. return new DecryptStream(stream, length,
  22826. function cipherTransformDecryptStream(data, finalize) {
  22827. return cipher.decryptBlock(data, finalize);
  22828. }
  22829. );
  22830. },
  22831. decryptString: function CipherTransform_decryptString(s) {
  22832. var cipher = new this.stringCipherConstructor();
  22833. var data = stringToBytes(s);
  22834. data = cipher.decryptBlock(data, true);
  22835. return bytesToString(data);
  22836. }
  22837. };
  22838. return CipherTransform;
  22839. })();
  22840. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  22841. var defaultPasswordBytes = new Uint8Array([
  22842. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  22843. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  22844. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  22845. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  22846. function createEncryptionKey20(revision, password, ownerPassword,
  22847. ownerValidationSalt, ownerKeySalt, uBytes,
  22848. userPassword, userValidationSalt, userKeySalt,
  22849. ownerEncryption, userEncryption, perms) {
  22850. if (password) {
  22851. var passwordLength = Math.min(127, password.length);
  22852. password = password.subarray(0, passwordLength);
  22853. } else {
  22854. password = [];
  22855. }
  22856. var pdfAlgorithm;
  22857. if (revision === 6) {
  22858. pdfAlgorithm = new PDF20();
  22859. } else {
  22860. pdfAlgorithm = new PDF17();
  22861. }
  22862. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  22863. userPassword)) {
  22864. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  22865. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  22866. ownerValidationSalt,
  22867. uBytes,
  22868. ownerPassword)) {
  22869. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  22870. ownerEncryption);
  22871. }
  22872. return null;
  22873. }
  22874. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  22875. flags, revision, keyLength, encryptMetadata) {
  22876. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  22877. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  22878. if (password) {
  22879. n = Math.min(32, password.length);
  22880. for (; i < n; ++i) {
  22881. hashData[i] = password[i];
  22882. }
  22883. }
  22884. j = 0;
  22885. while (i < 32) {
  22886. hashData[i++] = defaultPasswordBytes[j++];
  22887. }
  22888. // as now the padded password in the hashData[0..i]
  22889. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  22890. hashData[i++] = ownerPassword[j];
  22891. }
  22892. hashData[i++] = flags & 0xFF;
  22893. hashData[i++] = (flags >> 8) & 0xFF;
  22894. hashData[i++] = (flags >> 16) & 0xFF;
  22895. hashData[i++] = (flags >>> 24) & 0xFF;
  22896. for (j = 0, n = fileId.length; j < n; ++j) {
  22897. hashData[i++] = fileId[j];
  22898. }
  22899. if (revision >= 4 && !encryptMetadata) {
  22900. hashData[i++] = 0xFF;
  22901. hashData[i++] = 0xFF;
  22902. hashData[i++] = 0xFF;
  22903. hashData[i++] = 0xFF;
  22904. }
  22905. var hash = calculateMD5(hashData, 0, i);
  22906. var keyLengthInBytes = keyLength >> 3;
  22907. if (revision >= 3) {
  22908. for (j = 0; j < 50; ++j) {
  22909. hash = calculateMD5(hash, 0, keyLengthInBytes);
  22910. }
  22911. }
  22912. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  22913. var cipher, checkData;
  22914. if (revision >= 3) {
  22915. for (i = 0; i < 32; ++i) {
  22916. hashData[i] = defaultPasswordBytes[i];
  22917. }
  22918. for (j = 0, n = fileId.length; j < n; ++j) {
  22919. hashData[i++] = fileId[j];
  22920. }
  22921. cipher = new ARCFourCipher(encryptionKey);
  22922. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  22923. n = encryptionKey.length;
  22924. var derivedKey = new Uint8Array(n), k;
  22925. for (j = 1; j <= 19; ++j) {
  22926. for (k = 0; k < n; ++k) {
  22927. derivedKey[k] = encryptionKey[k] ^ j;
  22928. }
  22929. cipher = new ARCFourCipher(derivedKey);
  22930. checkData = cipher.encryptBlock(checkData);
  22931. }
  22932. for (j = 0, n = checkData.length; j < n; ++j) {
  22933. if (userPassword[j] !== checkData[j]) {
  22934. return null;
  22935. }
  22936. }
  22937. } else {
  22938. cipher = new ARCFourCipher(encryptionKey);
  22939. checkData = cipher.encryptBlock(defaultPasswordBytes);
  22940. for (j = 0, n = checkData.length; j < n; ++j) {
  22941. if (userPassword[j] !== checkData[j]) {
  22942. return null;
  22943. }
  22944. }
  22945. }
  22946. return encryptionKey;
  22947. }
  22948. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  22949. var hashData = new Uint8Array(32), i = 0, j, n;
  22950. n = Math.min(32, password.length);
  22951. for (; i < n; ++i) {
  22952. hashData[i] = password[i];
  22953. }
  22954. j = 0;
  22955. while (i < 32) {
  22956. hashData[i++] = defaultPasswordBytes[j++];
  22957. }
  22958. var hash = calculateMD5(hashData, 0, i);
  22959. var keyLengthInBytes = keyLength >> 3;
  22960. if (revision >= 3) {
  22961. for (j = 0; j < 50; ++j) {
  22962. hash = calculateMD5(hash, 0, hash.length);
  22963. }
  22964. }
  22965. var cipher, userPassword;
  22966. if (revision >= 3) {
  22967. userPassword = ownerPassword;
  22968. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  22969. for (j = 19; j >= 0; j--) {
  22970. for (k = 0; k < keyLengthInBytes; ++k) {
  22971. derivedKey[k] = hash[k] ^ j;
  22972. }
  22973. cipher = new ARCFourCipher(derivedKey);
  22974. userPassword = cipher.encryptBlock(userPassword);
  22975. }
  22976. } else {
  22977. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  22978. userPassword = cipher.encryptBlock(ownerPassword);
  22979. }
  22980. return userPassword;
  22981. }
  22982. var identityName = Name.get('Identity');
  22983. function CipherTransformFactory(dict, fileId, password) {
  22984. var filter = dict.get('Filter');
  22985. if (!isName(filter, 'Standard')) {
  22986. error('unknown encryption method');
  22987. }
  22988. this.dict = dict;
  22989. var algorithm = dict.get('V');
  22990. if (!isInt(algorithm) ||
  22991. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  22992. algorithm !== 5)) {
  22993. error('unsupported encryption algorithm');
  22994. }
  22995. this.algorithm = algorithm;
  22996. var keyLength = dict.get('Length');
  22997. if (!keyLength) {
  22998. // Spec asks to rely on encryption dictionary's Length entry, however
  22999. // some PDFs don't have it. Trying to recover.
  23000. if (algorithm <= 3) {
  23001. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  23002. keyLength = 40;
  23003. } else {
  23004. // Trying to find default handler -- it usually has Length.
  23005. var cfDict = dict.get('CF');
  23006. var streamCryptoName = dict.get('StmF');
  23007. if (isDict(cfDict) && isName(streamCryptoName)) {
  23008. var handlerDict = cfDict.get(streamCryptoName.name);
  23009. keyLength = (handlerDict && handlerDict.get('Length')) || 128;
  23010. if (keyLength < 40) {
  23011. // Sometimes it's incorrect value of bits, generators specify bytes.
  23012. keyLength <<= 3;
  23013. }
  23014. }
  23015. }
  23016. }
  23017. if (!isInt(keyLength) ||
  23018. keyLength < 40 || (keyLength % 8) !== 0) {
  23019. error('invalid key length');
  23020. }
  23021. // prepare keys
  23022. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  23023. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  23024. var flags = dict.get('P');
  23025. var revision = dict.get('R');
  23026. // meaningful when V is 4 or 5
  23027. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  23028. dict.get('EncryptMetadata') !== false);
  23029. this.encryptMetadata = encryptMetadata;
  23030. var fileIdBytes = stringToBytes(fileId);
  23031. var passwordBytes;
  23032. if (password) {
  23033. if (revision === 6) {
  23034. try {
  23035. password = utf8StringToString(password);
  23036. } catch (ex) {
  23037. warn('CipherTransformFactory: ' +
  23038. 'Unable to convert UTF8 encoded password.');
  23039. }
  23040. }
  23041. passwordBytes = stringToBytes(password);
  23042. }
  23043. var encryptionKey;
  23044. if (algorithm !== 5) {
  23045. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  23046. ownerPassword, userPassword, flags,
  23047. revision, keyLength, encryptMetadata);
  23048. }
  23049. else {
  23050. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  23051. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  23052. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  23053. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  23054. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  23055. var ownerEncryption = stringToBytes(dict.get('OE'));
  23056. var userEncryption = stringToBytes(dict.get('UE'));
  23057. var perms = stringToBytes(dict.get('Perms'));
  23058. encryptionKey =
  23059. createEncryptionKey20(revision, passwordBytes,
  23060. ownerPassword, ownerValidationSalt,
  23061. ownerKeySalt, uBytes,
  23062. userPassword, userValidationSalt,
  23063. userKeySalt, ownerEncryption,
  23064. userEncryption, perms);
  23065. }
  23066. if (!encryptionKey && !password) {
  23067. throw new PasswordException('No password given',
  23068. PasswordResponses.NEED_PASSWORD);
  23069. } else if (!encryptionKey && password) {
  23070. // Attempting use the password as an owner password
  23071. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  23072. revision, keyLength);
  23073. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  23074. ownerPassword, userPassword, flags,
  23075. revision, keyLength, encryptMetadata);
  23076. }
  23077. if (!encryptionKey) {
  23078. throw new PasswordException('Incorrect Password',
  23079. PasswordResponses.INCORRECT_PASSWORD);
  23080. }
  23081. this.encryptionKey = encryptionKey;
  23082. if (algorithm >= 4) {
  23083. this.cf = dict.get('CF');
  23084. this.stmf = dict.get('StmF') || identityName;
  23085. this.strf = dict.get('StrF') || identityName;
  23086. this.eff = dict.get('EFF') || this.stmf;
  23087. }
  23088. }
  23089. function buildObjectKey(num, gen, encryptionKey, isAes) {
  23090. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  23091. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  23092. key[i] = encryptionKey[i];
  23093. }
  23094. key[i++] = num & 0xFF;
  23095. key[i++] = (num >> 8) & 0xFF;
  23096. key[i++] = (num >> 16) & 0xFF;
  23097. key[i++] = gen & 0xFF;
  23098. key[i++] = (gen >> 8) & 0xFF;
  23099. if (isAes) {
  23100. key[i++] = 0x73;
  23101. key[i++] = 0x41;
  23102. key[i++] = 0x6C;
  23103. key[i++] = 0x54;
  23104. }
  23105. var hash = calculateMD5(key, 0, i);
  23106. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  23107. }
  23108. function buildCipherConstructor(cf, name, num, gen, key) {
  23109. var cryptFilter = cf.get(name.name);
  23110. var cfm;
  23111. if (cryptFilter !== null && cryptFilter !== undefined) {
  23112. cfm = cryptFilter.get('CFM');
  23113. }
  23114. if (!cfm || cfm.name === 'None') {
  23115. return function cipherTransformFactoryBuildCipherConstructorNone() {
  23116. return new NullCipher();
  23117. };
  23118. }
  23119. if ('V2' === cfm.name) {
  23120. return function cipherTransformFactoryBuildCipherConstructorV2() {
  23121. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  23122. };
  23123. }
  23124. if ('AESV2' === cfm.name) {
  23125. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  23126. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  23127. };
  23128. }
  23129. if ('AESV3' === cfm.name) {
  23130. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  23131. return new AES256Cipher(key);
  23132. };
  23133. }
  23134. error('Unknown crypto method');
  23135. }
  23136. CipherTransformFactory.prototype = {
  23137. createCipherTransform:
  23138. function CipherTransformFactory_createCipherTransform(num, gen) {
  23139. if (this.algorithm === 4 || this.algorithm === 5) {
  23140. return new CipherTransform(
  23141. buildCipherConstructor(this.cf, this.stmf,
  23142. num, gen, this.encryptionKey),
  23143. buildCipherConstructor(this.cf, this.strf,
  23144. num, gen, this.encryptionKey));
  23145. }
  23146. // algorithms 1 and 2
  23147. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  23148. var cipherConstructor = function buildCipherCipherConstructor() {
  23149. return new ARCFourCipher(key);
  23150. };
  23151. return new CipherTransform(cipherConstructor, cipherConstructor);
  23152. }
  23153. };
  23154. return CipherTransformFactory;
  23155. })();
  23156. exports.AES128Cipher = AES128Cipher;
  23157. exports.AES256Cipher = AES256Cipher;
  23158. exports.ARCFourCipher = ARCFourCipher;
  23159. exports.CipherTransformFactory = CipherTransformFactory;
  23160. exports.PDF17 = PDF17;
  23161. exports.PDF20 = PDF20;
  23162. exports.calculateMD5 = calculateMD5;
  23163. exports.calculateSHA256 = calculateSHA256;
  23164. exports.calculateSHA384 = calculateSHA384;
  23165. exports.calculateSHA512 = calculateSHA512;
  23166. }));
  23167. (function (root, factory) {
  23168. {
  23169. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  23170. root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings,
  23171. root.pdfjsCoreCFFParser);
  23172. }
  23173. }(this, function (exports, sharedUtil, coreStream, coreGlyphList,
  23174. coreEncodings, coreCFFParser) {
  23175. var Util = sharedUtil.Util;
  23176. var bytesToString = sharedUtil.bytesToString;
  23177. var error = sharedUtil.error;
  23178. var Stream = coreStream.Stream;
  23179. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  23180. var StandardEncoding = coreEncodings.StandardEncoding;
  23181. var CFFParser = coreCFFParser.CFFParser;
  23182. var FontRendererFactory = (function FontRendererFactoryClosure() {
  23183. function getLong(data, offset) {
  23184. return (data[offset] << 24) | (data[offset + 1] << 16) |
  23185. (data[offset + 2] << 8) | data[offset + 3];
  23186. }
  23187. function getUshort(data, offset) {
  23188. return (data[offset] << 8) | data[offset + 1];
  23189. }
  23190. function parseCmap(data, start, end) {
  23191. var offset = (getUshort(data, start + 2) === 1 ?
  23192. getLong(data, start + 8) : getLong(data, start + 16));
  23193. var format = getUshort(data, start + offset);
  23194. var length, ranges, p, i;
  23195. if (format === 4) {
  23196. length = getUshort(data, start + offset + 2);
  23197. var segCount = getUshort(data, start + offset + 6) >> 1;
  23198. p = start + offset + 14;
  23199. ranges = [];
  23200. for (i = 0; i < segCount; i++, p += 2) {
  23201. ranges[i] = {end: getUshort(data, p)};
  23202. }
  23203. p += 2;
  23204. for (i = 0; i < segCount; i++, p += 2) {
  23205. ranges[i].start = getUshort(data, p);
  23206. }
  23207. for (i = 0; i < segCount; i++, p += 2) {
  23208. ranges[i].idDelta = getUshort(data, p);
  23209. }
  23210. for (i = 0; i < segCount; i++, p += 2) {
  23211. var idOffset = getUshort(data, p);
  23212. if (idOffset === 0) {
  23213. continue;
  23214. }
  23215. ranges[i].ids = [];
  23216. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  23217. ranges[i].ids[j] = getUshort(data, p + idOffset);
  23218. idOffset += 2;
  23219. }
  23220. }
  23221. return ranges;
  23222. } else if (format === 12) {
  23223. length = getLong(data, start + offset + 4);
  23224. var groups = getLong(data, start + offset + 12);
  23225. p = start + offset + 16;
  23226. ranges = [];
  23227. for (i = 0; i < groups; i++) {
  23228. ranges.push({
  23229. start: getLong(data, p),
  23230. end: getLong(data, p + 4),
  23231. idDelta: getLong(data, p + 8) - getLong(data, p)
  23232. });
  23233. p += 12;
  23234. }
  23235. return ranges;
  23236. }
  23237. error('not supported cmap: ' + format);
  23238. }
  23239. function parseCff(data, start, end, seacAnalysisEnabled) {
  23240. var properties = {};
  23241. var parser = new CFFParser(new Stream(data, start, end - start),
  23242. properties, seacAnalysisEnabled);
  23243. var cff = parser.parse();
  23244. return {
  23245. glyphs: cff.charStrings.objects,
  23246. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  23247. cff.topDict.privateDict.subrsIndex.objects),
  23248. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  23249. };
  23250. }
  23251. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  23252. var itemSize, itemDecode;
  23253. if (isGlyphLocationsLong) {
  23254. itemSize = 4;
  23255. itemDecode = function fontItemDecodeLong(data, offset) {
  23256. return (data[offset] << 24) | (data[offset + 1] << 16) |
  23257. (data[offset + 2] << 8) | data[offset + 3];
  23258. };
  23259. } else {
  23260. itemSize = 2;
  23261. itemDecode = function fontItemDecode(data, offset) {
  23262. return (data[offset] << 9) | (data[offset + 1] << 1);
  23263. };
  23264. }
  23265. var glyphs = [];
  23266. var startOffset = itemDecode(loca, 0);
  23267. for (var j = itemSize; j < loca.length; j += itemSize) {
  23268. var endOffset = itemDecode(loca, j);
  23269. glyphs.push(glyf.subarray(startOffset, endOffset));
  23270. startOffset = endOffset;
  23271. }
  23272. return glyphs;
  23273. }
  23274. function lookupCmap(ranges, unicode) {
  23275. var code = unicode.charCodeAt(0), gid = 0;
  23276. var l = 0, r = ranges.length - 1;
  23277. while (l < r) {
  23278. var c = (l + r + 1) >> 1;
  23279. if (code < ranges[c].start) {
  23280. r = c - 1;
  23281. } else {
  23282. l = c;
  23283. }
  23284. }
  23285. if (ranges[l].start <= code && code <= ranges[l].end) {
  23286. gid = (ranges[l].idDelta + (ranges[l].ids ?
  23287. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  23288. }
  23289. return {
  23290. charCode: code,
  23291. glyphId: gid,
  23292. };
  23293. }
  23294. function compileGlyf(code, cmds, font) {
  23295. function moveTo(x, y) {
  23296. cmds.push({cmd: 'moveTo', args: [x, y]});
  23297. }
  23298. function lineTo(x, y) {
  23299. cmds.push({cmd: 'lineTo', args: [x, y]});
  23300. }
  23301. function quadraticCurveTo(xa, ya, x, y) {
  23302. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  23303. }
  23304. var i = 0;
  23305. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23306. var flags;
  23307. var x = 0, y = 0;
  23308. i += 10;
  23309. if (numberOfContours < 0) {
  23310. // composite glyph
  23311. do {
  23312. flags = (code[i] << 8) | code[i + 1];
  23313. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  23314. i += 4;
  23315. var arg1, arg2;
  23316. if ((flags & 0x01)) {
  23317. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23318. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  23319. i += 4;
  23320. } else {
  23321. arg1 = code[i++]; arg2 = code[i++];
  23322. }
  23323. if ((flags & 0x02)) {
  23324. x = arg1;
  23325. y = arg2;
  23326. } else {
  23327. x = 0; y = 0; // TODO "they are points" ?
  23328. }
  23329. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  23330. if ((flags & 0x08)) {
  23331. scaleX =
  23332. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  23333. i += 2;
  23334. } else if ((flags & 0x40)) {
  23335. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  23336. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  23337. i += 4;
  23338. } else if ((flags & 0x80)) {
  23339. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  23340. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  23341. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  23342. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  23343. i += 8;
  23344. }
  23345. var subglyph = font.glyphs[glyphIndex];
  23346. if (subglyph) {
  23347. cmds.push({cmd: 'save'});
  23348. cmds.push({cmd: 'transform',
  23349. args: [scaleX, scale01, scale10, scaleY, x, y]});
  23350. compileGlyf(subglyph, cmds, font);
  23351. cmds.push({cmd: 'restore'});
  23352. }
  23353. } while ((flags & 0x20));
  23354. } else {
  23355. // simple glyph
  23356. var endPtsOfContours = [];
  23357. var j, jj;
  23358. for (j = 0; j < numberOfContours; j++) {
  23359. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  23360. i += 2;
  23361. }
  23362. var instructionLength = (code[i] << 8) | code[i + 1];
  23363. i += 2 + instructionLength; // skipping the instructions
  23364. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  23365. var points = [];
  23366. while (points.length < numberOfPoints) {
  23367. flags = code[i++];
  23368. var repeat = 1;
  23369. if ((flags & 0x08)) {
  23370. repeat += code[i++];
  23371. }
  23372. while (repeat-- > 0) {
  23373. points.push({flags: flags});
  23374. }
  23375. }
  23376. for (j = 0; j < numberOfPoints; j++) {
  23377. switch (points[j].flags & 0x12) {
  23378. case 0x00:
  23379. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23380. i += 2;
  23381. break;
  23382. case 0x02:
  23383. x -= code[i++];
  23384. break;
  23385. case 0x12:
  23386. x += code[i++];
  23387. break;
  23388. }
  23389. points[j].x = x;
  23390. }
  23391. for (j = 0; j < numberOfPoints; j++) {
  23392. switch (points[j].flags & 0x24) {
  23393. case 0x00:
  23394. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23395. i += 2;
  23396. break;
  23397. case 0x04:
  23398. y -= code[i++];
  23399. break;
  23400. case 0x24:
  23401. y += code[i++];
  23402. break;
  23403. }
  23404. points[j].y = y;
  23405. }
  23406. var startPoint = 0;
  23407. for (i = 0; i < numberOfContours; i++) {
  23408. var endPoint = endPtsOfContours[i];
  23409. // contours might have implicit points, which is located in the middle
  23410. // between two neighboring off-curve points
  23411. var contour = points.slice(startPoint, endPoint + 1);
  23412. if ((contour[0].flags & 1)) {
  23413. contour.push(contour[0]); // using start point at the contour end
  23414. } else if ((contour[contour.length - 1].flags & 1)) {
  23415. // first is off-curve point, trying to use one from the end
  23416. contour.unshift(contour[contour.length - 1]);
  23417. } else {
  23418. // start and end are off-curve points, creating implicit one
  23419. var p = {
  23420. flags: 1,
  23421. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  23422. y: (contour[0].y + contour[contour.length - 1].y) / 2
  23423. };
  23424. contour.unshift(p);
  23425. contour.push(p);
  23426. }
  23427. moveTo(contour[0].x, contour[0].y);
  23428. for (j = 1, jj = contour.length; j < jj; j++) {
  23429. if ((contour[j].flags & 1)) {
  23430. lineTo(contour[j].x, contour[j].y);
  23431. } else if ((contour[j + 1].flags & 1)){
  23432. quadraticCurveTo(contour[j].x, contour[j].y,
  23433. contour[j + 1].x, contour[j + 1].y);
  23434. j++;
  23435. } else {
  23436. quadraticCurveTo(contour[j].x, contour[j].y,
  23437. (contour[j].x + contour[j + 1].x) / 2,
  23438. (contour[j].y + contour[j + 1].y) / 2);
  23439. }
  23440. }
  23441. startPoint = endPoint + 1;
  23442. }
  23443. }
  23444. }
  23445. function compileCharString(code, cmds, font) {
  23446. var stack = [];
  23447. var x = 0, y = 0;
  23448. var stems = 0;
  23449. function moveTo(x, y) {
  23450. cmds.push({cmd: 'moveTo', args: [x, y]});
  23451. }
  23452. function lineTo(x, y) {
  23453. cmds.push({cmd: 'lineTo', args: [x, y]});
  23454. }
  23455. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  23456. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  23457. }
  23458. function parse(code) {
  23459. var i = 0;
  23460. while (i < code.length) {
  23461. var stackClean = false;
  23462. var v = code[i++];
  23463. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  23464. switch (v) {
  23465. case 1: // hstem
  23466. stems += stack.length >> 1;
  23467. stackClean = true;
  23468. break;
  23469. case 3: // vstem
  23470. stems += stack.length >> 1;
  23471. stackClean = true;
  23472. break;
  23473. case 4: // vmoveto
  23474. y += stack.pop();
  23475. moveTo(x, y);
  23476. stackClean = true;
  23477. break;
  23478. case 5: // rlineto
  23479. while (stack.length > 0) {
  23480. x += stack.shift();
  23481. y += stack.shift();
  23482. lineTo(x, y);
  23483. }
  23484. break;
  23485. case 6: // hlineto
  23486. while (stack.length > 0) {
  23487. x += stack.shift();
  23488. lineTo(x, y);
  23489. if (stack.length === 0) {
  23490. break;
  23491. }
  23492. y += stack.shift();
  23493. lineTo(x, y);
  23494. }
  23495. break;
  23496. case 7: // vlineto
  23497. while (stack.length > 0) {
  23498. y += stack.shift();
  23499. lineTo(x, y);
  23500. if (stack.length === 0) {
  23501. break;
  23502. }
  23503. x += stack.shift();
  23504. lineTo(x, y);
  23505. }
  23506. break;
  23507. case 8: // rrcurveto
  23508. while (stack.length > 0) {
  23509. xa = x + stack.shift(); ya = y + stack.shift();
  23510. xb = xa + stack.shift(); yb = ya + stack.shift();
  23511. x = xb + stack.shift(); y = yb + stack.shift();
  23512. bezierCurveTo(xa, ya, xb, yb, x, y);
  23513. }
  23514. break;
  23515. case 10: // callsubr
  23516. n = stack.pop() + font.subrsBias;
  23517. subrCode = font.subrs[n];
  23518. if (subrCode) {
  23519. parse(subrCode);
  23520. }
  23521. break;
  23522. case 11: // return
  23523. return;
  23524. case 12:
  23525. v = code[i++];
  23526. switch (v) {
  23527. case 34: // flex
  23528. xa = x + stack.shift();
  23529. xb = xa + stack.shift(); y1 = y + stack.shift();
  23530. x = xb + stack.shift();
  23531. bezierCurveTo(xa, y, xb, y1, x, y1);
  23532. xa = x + stack.shift();
  23533. xb = xa + stack.shift();
  23534. x = xb + stack.shift();
  23535. bezierCurveTo(xa, y1, xb, y, x, y);
  23536. break;
  23537. case 35: // flex
  23538. xa = x + stack.shift(); ya = y + stack.shift();
  23539. xb = xa + stack.shift(); yb = ya + stack.shift();
  23540. x = xb + stack.shift(); y = yb + stack.shift();
  23541. bezierCurveTo(xa, ya, xb, yb, x, y);
  23542. xa = x + stack.shift(); ya = y + stack.shift();
  23543. xb = xa + stack.shift(); yb = ya + stack.shift();
  23544. x = xb + stack.shift(); y = yb + stack.shift();
  23545. bezierCurveTo(xa, ya, xb, yb, x, y);
  23546. stack.pop(); // fd
  23547. break;
  23548. case 36: // hflex1
  23549. xa = x + stack.shift(); y1 = y + stack.shift();
  23550. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  23551. x = xb + stack.shift();
  23552. bezierCurveTo(xa, y1, xb, y2, x, y2);
  23553. xa = x + stack.shift();
  23554. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  23555. x = xb + stack.shift();
  23556. bezierCurveTo(xa, y2, xb, y3, x, y);
  23557. break;
  23558. case 37: // flex1
  23559. var x0 = x, y0 = y;
  23560. xa = x + stack.shift(); ya = y + stack.shift();
  23561. xb = xa + stack.shift(); yb = ya + stack.shift();
  23562. x = xb + stack.shift(); y = yb + stack.shift();
  23563. bezierCurveTo(xa, ya, xb, yb, x, y);
  23564. xa = x + stack.shift(); ya = y + stack.shift();
  23565. xb = xa + stack.shift(); yb = ya + stack.shift();
  23566. x = xb; y = yb;
  23567. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  23568. x += stack.shift();
  23569. } else {
  23570. y += stack.shift();
  23571. }
  23572. bezierCurveTo(xa, ya, xb, yb, x, y);
  23573. break;
  23574. default:
  23575. error('unknown operator: 12 ' + v);
  23576. }
  23577. break;
  23578. case 14: // endchar
  23579. if (stack.length >= 4) {
  23580. var achar = stack.pop();
  23581. var bchar = stack.pop();
  23582. y = stack.pop();
  23583. x = stack.pop();
  23584. cmds.push({cmd: 'save'});
  23585. cmds.push({cmd: 'translate', args: [x, y]});
  23586. var cmap = lookupCmap(font.cmap, String.fromCharCode(
  23587. font.glyphNameMap[StandardEncoding[achar]]));
  23588. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  23589. cmds.push({cmd: 'restore'});
  23590. cmap = lookupCmap(font.cmap, String.fromCharCode(
  23591. font.glyphNameMap[StandardEncoding[bchar]]));
  23592. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  23593. }
  23594. return;
  23595. case 18: // hstemhm
  23596. stems += stack.length >> 1;
  23597. stackClean = true;
  23598. break;
  23599. case 19: // hintmask
  23600. stems += stack.length >> 1;
  23601. i += (stems + 7) >> 3;
  23602. stackClean = true;
  23603. break;
  23604. case 20: // cntrmask
  23605. stems += stack.length >> 1;
  23606. i += (stems + 7) >> 3;
  23607. stackClean = true;
  23608. break;
  23609. case 21: // rmoveto
  23610. y += stack.pop();
  23611. x += stack.pop();
  23612. moveTo(x, y);
  23613. stackClean = true;
  23614. break;
  23615. case 22: // hmoveto
  23616. x += stack.pop();
  23617. moveTo(x, y);
  23618. stackClean = true;
  23619. break;
  23620. case 23: // vstemhm
  23621. stems += stack.length >> 1;
  23622. stackClean = true;
  23623. break;
  23624. case 24: // rcurveline
  23625. while (stack.length > 2) {
  23626. xa = x + stack.shift(); ya = y + stack.shift();
  23627. xb = xa + stack.shift(); yb = ya + stack.shift();
  23628. x = xb + stack.shift(); y = yb + stack.shift();
  23629. bezierCurveTo(xa, ya, xb, yb, x, y);
  23630. }
  23631. x += stack.shift();
  23632. y += stack.shift();
  23633. lineTo(x, y);
  23634. break;
  23635. case 25: // rlinecurve
  23636. while (stack.length > 6) {
  23637. x += stack.shift();
  23638. y += stack.shift();
  23639. lineTo(x, y);
  23640. }
  23641. xa = x + stack.shift(); ya = y + stack.shift();
  23642. xb = xa + stack.shift(); yb = ya + stack.shift();
  23643. x = xb + stack.shift(); y = yb + stack.shift();
  23644. bezierCurveTo(xa, ya, xb, yb, x, y);
  23645. break;
  23646. case 26: // vvcurveto
  23647. if (stack.length % 2) {
  23648. x += stack.shift();
  23649. }
  23650. while (stack.length > 0) {
  23651. xa = x; ya = y + stack.shift();
  23652. xb = xa + stack.shift(); yb = ya + stack.shift();
  23653. x = xb; y = yb + stack.shift();
  23654. bezierCurveTo(xa, ya, xb, yb, x, y);
  23655. }
  23656. break;
  23657. case 27: // hhcurveto
  23658. if (stack.length % 2) {
  23659. y += stack.shift();
  23660. }
  23661. while (stack.length > 0) {
  23662. xa = x + stack.shift(); ya = y;
  23663. xb = xa + stack.shift(); yb = ya + stack.shift();
  23664. x = xb + stack.shift(); y = yb;
  23665. bezierCurveTo(xa, ya, xb, yb, x, y);
  23666. }
  23667. break;
  23668. case 28:
  23669. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  23670. i += 2;
  23671. break;
  23672. case 29: // callgsubr
  23673. n = stack.pop() + font.gsubrsBias;
  23674. subrCode = font.gsubrs[n];
  23675. if (subrCode) {
  23676. parse(subrCode);
  23677. }
  23678. break;
  23679. case 30: // vhcurveto
  23680. while (stack.length > 0) {
  23681. xa = x; ya = y + stack.shift();
  23682. xb = xa + stack.shift(); yb = ya + stack.shift();
  23683. x = xb + stack.shift();
  23684. y = yb + (stack.length === 1 ? stack.shift() : 0);
  23685. bezierCurveTo(xa, ya, xb, yb, x, y);
  23686. if (stack.length === 0) {
  23687. break;
  23688. }
  23689. xa = x + stack.shift(); ya = y;
  23690. xb = xa + stack.shift(); yb = ya + stack.shift();
  23691. y = yb + stack.shift();
  23692. x = xb + (stack.length === 1 ? stack.shift() : 0);
  23693. bezierCurveTo(xa, ya, xb, yb, x, y);
  23694. }
  23695. break;
  23696. case 31: // hvcurveto
  23697. while (stack.length > 0) {
  23698. xa = x + stack.shift(); ya = y;
  23699. xb = xa + stack.shift(); yb = ya + stack.shift();
  23700. y = yb + stack.shift();
  23701. x = xb + (stack.length === 1 ? stack.shift() : 0);
  23702. bezierCurveTo(xa, ya, xb, yb, x, y);
  23703. if (stack.length === 0) {
  23704. break;
  23705. }
  23706. xa = x; ya = y + stack.shift();
  23707. xb = xa + stack.shift(); yb = ya + stack.shift();
  23708. x = xb + stack.shift();
  23709. y = yb + (stack.length === 1 ? stack.shift() : 0);
  23710. bezierCurveTo(xa, ya, xb, yb, x, y);
  23711. }
  23712. break;
  23713. default:
  23714. if (v < 32) {
  23715. error('unknown operator: ' + v);
  23716. }
  23717. if (v < 247) {
  23718. stack.push(v - 139);
  23719. } else if (v < 251) {
  23720. stack.push((v - 247) * 256 + code[i++] + 108);
  23721. } else if (v < 255) {
  23722. stack.push(-(v - 251) * 256 - code[i++] - 108);
  23723. } else {
  23724. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  23725. (code[i + 2] << 8) | code[i + 3]) / 65536);
  23726. i += 4;
  23727. }
  23728. break;
  23729. }
  23730. if (stackClean) {
  23731. stack.length = 0;
  23732. }
  23733. }
  23734. }
  23735. parse(code);
  23736. }
  23737. var noop = '';
  23738. function CompiledFont(fontMatrix) {
  23739. this.compiledGlyphs = Object.create(null);
  23740. this.compiledCharCodeToGlyphId = Object.create(null);
  23741. this.fontMatrix = fontMatrix;
  23742. }
  23743. CompiledFont.prototype = {
  23744. getPathJs: function (unicode) {
  23745. var cmap = lookupCmap(this.cmap, unicode);
  23746. var fn = this.compiledGlyphs[cmap.glyphId];
  23747. if (!fn) {
  23748. fn = this.compileGlyph(this.glyphs[cmap.glyphId]);
  23749. this.compiledGlyphs[cmap.glyphId] = fn;
  23750. }
  23751. if (this.compiledCharCodeToGlyphId[cmap.charCode] === undefined) {
  23752. this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
  23753. }
  23754. return fn;
  23755. },
  23756. compileGlyph: function (code) {
  23757. if (!code || code.length === 0 || code[0] === 14) {
  23758. return noop;
  23759. }
  23760. var cmds = [];
  23761. cmds.push({cmd: 'save'});
  23762. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  23763. cmds.push({cmd: 'scale', args: ['size', '-size']});
  23764. this.compileGlyphImpl(code, cmds);
  23765. cmds.push({cmd: 'restore'});
  23766. return cmds;
  23767. },
  23768. compileGlyphImpl: function () {
  23769. error('Children classes should implement this.');
  23770. },
  23771. hasBuiltPath: function (unicode) {
  23772. var cmap = lookupCmap(this.cmap, unicode);
  23773. return (this.compiledGlyphs[cmap.glyphId] !== undefined &&
  23774. this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined);
  23775. }
  23776. };
  23777. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  23778. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  23779. CompiledFont.call(this, fontMatrix);
  23780. this.glyphs = glyphs;
  23781. this.cmap = cmap;
  23782. }
  23783. Util.inherit(TrueTypeCompiled, CompiledFont, {
  23784. compileGlyphImpl: function (code, cmds) {
  23785. compileGlyf(code, cmds, this);
  23786. }
  23787. });
  23788. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  23789. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  23790. CompiledFont.call(this, fontMatrix);
  23791. this.glyphs = cffInfo.glyphs;
  23792. this.gsubrs = cffInfo.gsubrs || [];
  23793. this.subrs = cffInfo.subrs || [];
  23794. this.cmap = cmap;
  23795. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  23796. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  23797. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  23798. this.subrsBias = (this.subrs.length < 1240 ?
  23799. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  23800. }
  23801. Util.inherit(Type2Compiled, CompiledFont, {
  23802. compileGlyphImpl: function (code, cmds) {
  23803. compileCharString(code, cmds, this);
  23804. }
  23805. });
  23806. return {
  23807. create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
  23808. var data = new Uint8Array(font.data);
  23809. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  23810. var numTables = getUshort(data, 4);
  23811. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  23812. var tag = bytesToString(data.subarray(p, p + 4));
  23813. var offset = getLong(data, p + 8);
  23814. var length = getLong(data, p + 12);
  23815. switch (tag) {
  23816. case 'cmap':
  23817. cmap = parseCmap(data, offset, offset + length);
  23818. break;
  23819. case 'glyf':
  23820. glyf = data.subarray(offset, offset + length);
  23821. break;
  23822. case 'loca':
  23823. loca = data.subarray(offset, offset + length);
  23824. break;
  23825. case 'head':
  23826. unitsPerEm = getUshort(data, offset + 18);
  23827. indexToLocFormat = getUshort(data, offset + 50);
  23828. break;
  23829. case 'CFF ':
  23830. cff = parseCff(data, offset, offset + length, seacAnalysisEnabled);
  23831. break;
  23832. }
  23833. }
  23834. if (glyf) {
  23835. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  23836. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  23837. return new TrueTypeCompiled(
  23838. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  23839. } else {
  23840. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  23841. }
  23842. }
  23843. };
  23844. })();
  23845. exports.FontRendererFactory = FontRendererFactory;
  23846. }));
  23847. (function (root, factory) {
  23848. {
  23849. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  23850. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  23851. }
  23852. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  23853. var MissingDataException = sharedUtil.MissingDataException;
  23854. var StreamType = sharedUtil.StreamType;
  23855. var assert = sharedUtil.assert;
  23856. var error = sharedUtil.error;
  23857. var info = sharedUtil.info;
  23858. var isArray = sharedUtil.isArray;
  23859. var isInt = sharedUtil.isInt;
  23860. var isNum = sharedUtil.isNum;
  23861. var isString = sharedUtil.isString;
  23862. var warn = sharedUtil.warn;
  23863. var Cmd = corePrimitives.Cmd;
  23864. var Dict = corePrimitives.Dict;
  23865. var Name = corePrimitives.Name;
  23866. var Ref = corePrimitives.Ref;
  23867. var isCmd = corePrimitives.isCmd;
  23868. var isDict = corePrimitives.isDict;
  23869. var isName = corePrimitives.isName;
  23870. var Ascii85Stream = coreStream.Ascii85Stream;
  23871. var AsciiHexStream = coreStream.AsciiHexStream;
  23872. var CCITTFaxStream = coreStream.CCITTFaxStream;
  23873. var FlateStream = coreStream.FlateStream;
  23874. var Jbig2Stream = coreStream.Jbig2Stream;
  23875. var JpegStream = coreStream.JpegStream;
  23876. var JpxStream = coreStream.JpxStream;
  23877. var LZWStream = coreStream.LZWStream;
  23878. var NullStream = coreStream.NullStream;
  23879. var PredictorStream = coreStream.PredictorStream;
  23880. var RunLengthStream = coreStream.RunLengthStream;
  23881. var EOF = {};
  23882. function isEOF(v) {
  23883. return (v === EOF);
  23884. }
  23885. var MAX_LENGTH_TO_CACHE = 1000;
  23886. var Parser = (function ParserClosure() {
  23887. function Parser(lexer, allowStreams, xref, recoveryMode) {
  23888. this.lexer = lexer;
  23889. this.allowStreams = allowStreams;
  23890. this.xref = xref;
  23891. this.recoveryMode = recoveryMode || false;
  23892. this.imageCache = Object.create(null);
  23893. this.refill();
  23894. }
  23895. Parser.prototype = {
  23896. refill: function Parser_refill() {
  23897. this.buf1 = this.lexer.getObj();
  23898. this.buf2 = this.lexer.getObj();
  23899. },
  23900. shift: function Parser_shift() {
  23901. if (isCmd(this.buf2, 'ID')) {
  23902. this.buf1 = this.buf2;
  23903. this.buf2 = null;
  23904. } else {
  23905. this.buf1 = this.buf2;
  23906. this.buf2 = this.lexer.getObj();
  23907. }
  23908. },
  23909. tryShift: function Parser_tryShift() {
  23910. try {
  23911. this.shift();
  23912. return true;
  23913. } catch (e) {
  23914. if (e instanceof MissingDataException) {
  23915. throw e;
  23916. }
  23917. // Upon failure, the caller should reset this.lexer.pos to a known good
  23918. // state and call this.shift() twice to reset the buffers.
  23919. return false;
  23920. }
  23921. },
  23922. getObj: function Parser_getObj(cipherTransform) {
  23923. var buf1 = this.buf1;
  23924. this.shift();
  23925. if (buf1 instanceof Cmd) {
  23926. switch (buf1.cmd) {
  23927. case 'BI': // inline image
  23928. return this.makeInlineImage(cipherTransform);
  23929. case '[': // array
  23930. var array = [];
  23931. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  23932. array.push(this.getObj(cipherTransform));
  23933. }
  23934. if (isEOF(this.buf1)) {
  23935. if (!this.recoveryMode) {
  23936. error('End of file inside array');
  23937. }
  23938. return array;
  23939. }
  23940. this.shift();
  23941. return array;
  23942. case '<<': // dictionary or stream
  23943. var dict = new Dict(this.xref);
  23944. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  23945. if (!isName(this.buf1)) {
  23946. info('Malformed dictionary: key must be a name object');
  23947. this.shift();
  23948. continue;
  23949. }
  23950. var key = this.buf1.name;
  23951. this.shift();
  23952. if (isEOF(this.buf1)) {
  23953. break;
  23954. }
  23955. dict.set(key, this.getObj(cipherTransform));
  23956. }
  23957. if (isEOF(this.buf1)) {
  23958. if (!this.recoveryMode) {
  23959. error('End of file inside dictionary');
  23960. }
  23961. return dict;
  23962. }
  23963. // Stream objects are not allowed inside content streams or
  23964. // object streams.
  23965. if (isCmd(this.buf2, 'stream')) {
  23966. return (this.allowStreams ?
  23967. this.makeStream(dict, cipherTransform) : dict);
  23968. }
  23969. this.shift();
  23970. return dict;
  23971. default: // simple object
  23972. return buf1;
  23973. }
  23974. }
  23975. if (isInt(buf1)) { // indirect reference or integer
  23976. var num = buf1;
  23977. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  23978. var ref = new Ref(num, this.buf1);
  23979. this.shift();
  23980. this.shift();
  23981. return ref;
  23982. }
  23983. return num;
  23984. }
  23985. if (isString(buf1)) { // string
  23986. var str = buf1;
  23987. if (cipherTransform) {
  23988. str = cipherTransform.decryptString(str);
  23989. }
  23990. return str;
  23991. }
  23992. // simple object
  23993. return buf1;
  23994. },
  23995. /**
  23996. * Find the end of the stream by searching for the /EI\s/.
  23997. * @returns {number} The inline stream length.
  23998. */
  23999. findDefaultInlineStreamEnd:
  24000. function Parser_findDefaultInlineStreamEnd(stream) {
  24001. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  24002. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  24003. while ((ch = stream.getByte()) !== -1) {
  24004. if (state === 0) {
  24005. state = (ch === E) ? 1 : 0;
  24006. } else if (state === 1) {
  24007. state = (ch === I) ? 2 : 0;
  24008. } else {
  24009. assert(state === 2);
  24010. if (ch === SPACE || ch === LF || ch === CR) {
  24011. // Let's check the next five bytes are ASCII... just be sure.
  24012. n = 5;
  24013. followingBytes = stream.peekBytes(n);
  24014. for (i = 0; i < n; i++) {
  24015. ch = followingBytes[i];
  24016. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  24017. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  24018. // it's binary stuff. Resetting the state.
  24019. state = 0;
  24020. break;
  24021. }
  24022. }
  24023. if (state === 2) {
  24024. break; // Finished!
  24025. }
  24026. } else {
  24027. state = 0;
  24028. }
  24029. }
  24030. }
  24031. return ((stream.pos - 4) - startPos);
  24032. },
  24033. /**
  24034. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  24035. * @returns {number} The inline stream length.
  24036. */
  24037. findDCTDecodeInlineStreamEnd:
  24038. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  24039. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  24040. while ((b = stream.getByte()) !== -1) {
  24041. if (b !== 0xFF) { // Not a valid marker.
  24042. continue;
  24043. }
  24044. switch (stream.getByte()) {
  24045. case 0x00: // Byte stuffing.
  24046. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  24047. break;
  24048. case 0xFF: // Fill byte.
  24049. // Avoid skipping a valid marker, resetting the stream position.
  24050. stream.skip(-1);
  24051. break;
  24052. case 0xD9: // EOI
  24053. foundEOI = true;
  24054. break;
  24055. case 0xC0: // SOF0
  24056. case 0xC1: // SOF1
  24057. case 0xC2: // SOF2
  24058. case 0xC3: // SOF3
  24059. case 0xC5: // SOF5
  24060. case 0xC6: // SOF6
  24061. case 0xC7: // SOF7
  24062. case 0xC9: // SOF9
  24063. case 0xCA: // SOF10
  24064. case 0xCB: // SOF11
  24065. case 0xCD: // SOF13
  24066. case 0xCE: // SOF14
  24067. case 0xCF: // SOF15
  24068. case 0xC4: // DHT
  24069. case 0xCC: // DAC
  24070. case 0xDA: // SOS
  24071. case 0xDB: // DQT
  24072. case 0xDC: // DNL
  24073. case 0xDD: // DRI
  24074. case 0xDE: // DHP
  24075. case 0xDF: // EXP
  24076. case 0xE0: // APP0
  24077. case 0xE1: // APP1
  24078. case 0xE2: // APP2
  24079. case 0xE3: // APP3
  24080. case 0xE4: // APP4
  24081. case 0xE5: // APP5
  24082. case 0xE6: // APP6
  24083. case 0xE7: // APP7
  24084. case 0xE8: // APP8
  24085. case 0xE9: // APP9
  24086. case 0xEA: // APP10
  24087. case 0xEB: // APP11
  24088. case 0xEC: // APP12
  24089. case 0xED: // APP13
  24090. case 0xEE: // APP14
  24091. case 0xEF: // APP15
  24092. case 0xFE: // COM
  24093. // The marker should be followed by the length of the segment.
  24094. markerLength = stream.getUint16();
  24095. if (markerLength > 2) {
  24096. // |markerLength| contains the byte length of the marker segment,
  24097. // including its own length (2 bytes) and excluding the marker.
  24098. stream.skip(markerLength - 2); // Jump to the next marker.
  24099. } else {
  24100. // The marker length is invalid, resetting the stream position.
  24101. stream.skip(-2);
  24102. }
  24103. break;
  24104. }
  24105. if (foundEOI) {
  24106. break;
  24107. }
  24108. }
  24109. length = stream.pos - startPos;
  24110. if (b === -1) {
  24111. warn('Inline DCTDecode image stream: ' +
  24112. 'EOI marker not found, searching for /EI/ instead.');
  24113. stream.skip(-length); // Reset the stream position.
  24114. return this.findDefaultInlineStreamEnd(stream);
  24115. }
  24116. this.inlineStreamSkipEI(stream);
  24117. return length;
  24118. },
  24119. /**
  24120. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  24121. * @returns {number} The inline stream length.
  24122. */
  24123. findASCII85DecodeInlineStreamEnd:
  24124. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  24125. var TILDE = 0x7E, GT = 0x3E;
  24126. var startPos = stream.pos, ch, length;
  24127. while ((ch = stream.getByte()) !== -1) {
  24128. if (ch === TILDE && stream.peekByte() === GT) {
  24129. stream.skip();
  24130. break;
  24131. }
  24132. }
  24133. length = stream.pos - startPos;
  24134. if (ch === -1) {
  24135. warn('Inline ASCII85Decode image stream: ' +
  24136. 'EOD marker not found, searching for /EI/ instead.');
  24137. stream.skip(-length); // Reset the stream position.
  24138. return this.findDefaultInlineStreamEnd(stream);
  24139. }
  24140. this.inlineStreamSkipEI(stream);
  24141. return length;
  24142. },
  24143. /**
  24144. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  24145. * @returns {number} The inline stream length.
  24146. */
  24147. findASCIIHexDecodeInlineStreamEnd:
  24148. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  24149. var GT = 0x3E;
  24150. var startPos = stream.pos, ch, length;
  24151. while ((ch = stream.getByte()) !== -1) {
  24152. if (ch === GT) {
  24153. break;
  24154. }
  24155. }
  24156. length = stream.pos - startPos;
  24157. if (ch === -1) {
  24158. warn('Inline ASCIIHexDecode image stream: ' +
  24159. 'EOD marker not found, searching for /EI/ instead.');
  24160. stream.skip(-length); // Reset the stream position.
  24161. return this.findDefaultInlineStreamEnd(stream);
  24162. }
  24163. this.inlineStreamSkipEI(stream);
  24164. return length;
  24165. },
  24166. /**
  24167. * Skip over the /EI/ for streams where we search for an EOD marker.
  24168. */
  24169. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  24170. var E = 0x45, I = 0x49;
  24171. var state = 0, ch;
  24172. while ((ch = stream.getByte()) !== -1) {
  24173. if (state === 0) {
  24174. state = (ch === E) ? 1 : 0;
  24175. } else if (state === 1) {
  24176. state = (ch === I) ? 2 : 0;
  24177. } else if (state === 2) {
  24178. break;
  24179. }
  24180. }
  24181. },
  24182. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  24183. var lexer = this.lexer;
  24184. var stream = lexer.stream;
  24185. // Parse dictionary.
  24186. var dict = new Dict(this.xref);
  24187. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  24188. if (!isName(this.buf1)) {
  24189. error('Dictionary key must be a name object');
  24190. }
  24191. var key = this.buf1.name;
  24192. this.shift();
  24193. if (isEOF(this.buf1)) {
  24194. break;
  24195. }
  24196. dict.set(key, this.getObj(cipherTransform));
  24197. }
  24198. // Extract the name of the first (i.e. the current) image filter.
  24199. var filter = dict.get('Filter', 'F'), filterName;
  24200. if (isName(filter)) {
  24201. filterName = filter.name;
  24202. } else if (isArray(filter) && isName(filter[0])) {
  24203. filterName = filter[0].name;
  24204. }
  24205. // Parse image stream.
  24206. var startPos = stream.pos, length, i, ii;
  24207. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  24208. length = this.findDCTDecodeInlineStreamEnd(stream);
  24209. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  24210. length = this.findASCII85DecodeInlineStreamEnd(stream);
  24211. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  24212. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  24213. } else {
  24214. length = this.findDefaultInlineStreamEnd(stream);
  24215. }
  24216. var imageStream = stream.makeSubStream(startPos, length, dict);
  24217. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  24218. // adler32 checksum.
  24219. var adler32;
  24220. if (length < MAX_LENGTH_TO_CACHE) {
  24221. var imageBytes = imageStream.getBytes();
  24222. imageStream.reset();
  24223. var a = 1;
  24224. var b = 0;
  24225. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  24226. // No modulo required in the loop if imageBytes.length < 5552.
  24227. a += imageBytes[i] & 0xff;
  24228. b += a;
  24229. }
  24230. adler32 = ((b % 65521) << 16) | (a % 65521);
  24231. if (this.imageCache.adler32 === adler32) {
  24232. this.buf2 = Cmd.get('EI');
  24233. this.shift();
  24234. this.imageCache[adler32].reset();
  24235. return this.imageCache[adler32];
  24236. }
  24237. }
  24238. if (cipherTransform) {
  24239. imageStream = cipherTransform.createStream(imageStream, length);
  24240. }
  24241. imageStream = this.filter(imageStream, dict, length);
  24242. imageStream.dict = dict;
  24243. if (adler32 !== undefined) {
  24244. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  24245. this.imageCache[adler32] = imageStream;
  24246. }
  24247. this.buf2 = Cmd.get('EI');
  24248. this.shift();
  24249. return imageStream;
  24250. },
  24251. makeStream: function Parser_makeStream(dict, cipherTransform) {
  24252. var lexer = this.lexer;
  24253. var stream = lexer.stream;
  24254. // get stream start position
  24255. lexer.skipToNextLine();
  24256. var pos = stream.pos - 1;
  24257. // get length
  24258. var length = dict.get('Length');
  24259. if (!isInt(length)) {
  24260. info('Bad ' + length + ' attribute in stream');
  24261. length = 0;
  24262. }
  24263. // skip over the stream data
  24264. stream.pos = pos + length;
  24265. lexer.nextChar();
  24266. // Shift '>>' and check whether the new object marks the end of the stream
  24267. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  24268. this.shift(); // 'stream'
  24269. } else {
  24270. // bad stream length, scanning for endstream
  24271. stream.pos = pos;
  24272. var SCAN_BLOCK_SIZE = 2048;
  24273. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  24274. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  24275. 0x61, 0x6D];
  24276. var skipped = 0, found = false, i, j;
  24277. while (stream.pos < stream.end) {
  24278. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  24279. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  24280. if (scanLength <= 0) {
  24281. break;
  24282. }
  24283. found = false;
  24284. i = 0;
  24285. while (i < scanLength) {
  24286. j = 0;
  24287. while (j < ENDSTREAM_SIGNATURE_LENGTH &&
  24288. scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  24289. j++;
  24290. }
  24291. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  24292. found = true;
  24293. break;
  24294. }
  24295. i++;
  24296. }
  24297. if (found) {
  24298. skipped += i;
  24299. stream.pos += i;
  24300. break;
  24301. }
  24302. skipped += scanLength;
  24303. stream.pos += scanLength;
  24304. }
  24305. if (!found) {
  24306. error('Missing endstream');
  24307. }
  24308. length = skipped;
  24309. lexer.nextChar();
  24310. this.shift();
  24311. this.shift();
  24312. }
  24313. this.shift(); // 'endstream'
  24314. stream = stream.makeSubStream(pos, length, dict);
  24315. if (cipherTransform) {
  24316. stream = cipherTransform.createStream(stream, length);
  24317. }
  24318. stream = this.filter(stream, dict, length);
  24319. stream.dict = dict;
  24320. return stream;
  24321. },
  24322. filter: function Parser_filter(stream, dict, length) {
  24323. var filter = dict.get('Filter', 'F');
  24324. var params = dict.get('DecodeParms', 'DP');
  24325. if (isName(filter)) {
  24326. return this.makeFilter(stream, filter.name, length, params);
  24327. }
  24328. var maybeLength = length;
  24329. if (isArray(filter)) {
  24330. var filterArray = filter;
  24331. var paramsArray = params;
  24332. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  24333. filter = filterArray[i];
  24334. if (!isName(filter)) {
  24335. error('Bad filter name: ' + filter);
  24336. }
  24337. params = null;
  24338. if (isArray(paramsArray) && (i in paramsArray)) {
  24339. params = paramsArray[i];
  24340. }
  24341. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  24342. // after the first stream the length variable is invalid
  24343. maybeLength = null;
  24344. }
  24345. }
  24346. return stream;
  24347. },
  24348. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  24349. if (stream.dict.get('Length') === 0 && !maybeLength) {
  24350. warn('Empty "' + name + '" stream.');
  24351. return new NullStream(stream);
  24352. }
  24353. try {
  24354. if (params && this.xref) {
  24355. params = this.xref.fetchIfRef(params);
  24356. }
  24357. var xrefStreamStats = this.xref.stats.streamTypes;
  24358. if (name === 'FlateDecode' || name === 'Fl') {
  24359. xrefStreamStats[StreamType.FLATE] = true;
  24360. if (params) {
  24361. return new PredictorStream(new FlateStream(stream, maybeLength),
  24362. maybeLength, params);
  24363. }
  24364. return new FlateStream(stream, maybeLength);
  24365. }
  24366. if (name === 'LZWDecode' || name === 'LZW') {
  24367. xrefStreamStats[StreamType.LZW] = true;
  24368. var earlyChange = 1;
  24369. if (params) {
  24370. if (params.has('EarlyChange')) {
  24371. earlyChange = params.get('EarlyChange');
  24372. }
  24373. return new PredictorStream(
  24374. new LZWStream(stream, maybeLength, earlyChange),
  24375. maybeLength, params);
  24376. }
  24377. return new LZWStream(stream, maybeLength, earlyChange);
  24378. }
  24379. if (name === 'DCTDecode' || name === 'DCT') {
  24380. xrefStreamStats[StreamType.DCT] = true;
  24381. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  24382. }
  24383. if (name === 'JPXDecode' || name === 'JPX') {
  24384. xrefStreamStats[StreamType.JPX] = true;
  24385. return new JpxStream(stream, maybeLength, stream.dict);
  24386. }
  24387. if (name === 'ASCII85Decode' || name === 'A85') {
  24388. xrefStreamStats[StreamType.A85] = true;
  24389. return new Ascii85Stream(stream, maybeLength);
  24390. }
  24391. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  24392. xrefStreamStats[StreamType.AHX] = true;
  24393. return new AsciiHexStream(stream, maybeLength);
  24394. }
  24395. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  24396. xrefStreamStats[StreamType.CCF] = true;
  24397. return new CCITTFaxStream(stream, maybeLength, params);
  24398. }
  24399. if (name === 'RunLengthDecode' || name === 'RL') {
  24400. xrefStreamStats[StreamType.RL] = true;
  24401. return new RunLengthStream(stream, maybeLength);
  24402. }
  24403. if (name === 'JBIG2Decode') {
  24404. xrefStreamStats[StreamType.JBIG] = true;
  24405. return new Jbig2Stream(stream, maybeLength, stream.dict);
  24406. }
  24407. warn('filter "' + name + '" not supported yet');
  24408. return stream;
  24409. } catch (ex) {
  24410. if (ex instanceof MissingDataException) {
  24411. throw ex;
  24412. }
  24413. warn('Invalid stream: \"' + ex + '\"');
  24414. return new NullStream(stream);
  24415. }
  24416. }
  24417. };
  24418. return Parser;
  24419. })();
  24420. var Lexer = (function LexerClosure() {
  24421. function Lexer(stream, knownCommands) {
  24422. this.stream = stream;
  24423. this.nextChar();
  24424. // While lexing, we build up many strings one char at a time. Using += for
  24425. // this can result in lots of garbage strings. It's better to build an
  24426. // array of single-char strings and then join() them together at the end.
  24427. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  24428. // purpose uses less memory than using a new array for each string.
  24429. this.strBuf = [];
  24430. // The PDFs might have "glued" commands with other commands, operands or
  24431. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  24432. // commands and their prefixes. The prefixes are built the following way:
  24433. // if there a command that is a prefix of the other valid command or
  24434. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  24435. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  24436. // other commands or literals as a prefix. The knowCommands is optional.
  24437. this.knownCommands = knownCommands;
  24438. }
  24439. // A '1' in this array means the character is white space. A '1' or
  24440. // '2' means the character ends a name or command.
  24441. var specialChars = [
  24442. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  24443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  24444. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  24445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  24446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  24447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  24448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  24449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  24450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  24451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  24452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  24453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  24454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  24455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  24456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  24457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  24458. ];
  24459. function toHexDigit(ch) {
  24460. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  24461. return ch & 0x0F;
  24462. }
  24463. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  24464. // 'A'-'F', 'a'-'f'
  24465. return (ch & 0x0F) + 9;
  24466. }
  24467. return -1;
  24468. }
  24469. Lexer.prototype = {
  24470. nextChar: function Lexer_nextChar() {
  24471. return (this.currentChar = this.stream.getByte());
  24472. },
  24473. peekChar: function Lexer_peekChar() {
  24474. return this.stream.peekByte();
  24475. },
  24476. getNumber: function Lexer_getNumber() {
  24477. var ch = this.currentChar;
  24478. var eNotation = false;
  24479. var divideBy = 0; // different from 0 if it's a floating point value
  24480. var sign = 1;
  24481. if (ch === 0x2D) { // '-'
  24482. sign = -1;
  24483. ch = this.nextChar();
  24484. if (ch === 0x2D) { // '-'
  24485. // Ignore double negative (this is consistent with Adobe Reader).
  24486. ch = this.nextChar();
  24487. }
  24488. } else if (ch === 0x2B) { // '+'
  24489. ch = this.nextChar();
  24490. }
  24491. if (ch === 0x2E) { // '.'
  24492. divideBy = 10;
  24493. ch = this.nextChar();
  24494. }
  24495. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  24496. error('Invalid number: ' + String.fromCharCode(ch));
  24497. return 0;
  24498. }
  24499. var baseValue = ch - 0x30; // '0'
  24500. var powerValue = 0;
  24501. var powerValueSign = 1;
  24502. while ((ch = this.nextChar()) >= 0) {
  24503. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  24504. var currentDigit = ch - 0x30; // '0'
  24505. if (eNotation) { // We are after an 'e' or 'E'
  24506. powerValue = powerValue * 10 + currentDigit;
  24507. } else {
  24508. if (divideBy !== 0) { // We are after a point
  24509. divideBy *= 10;
  24510. }
  24511. baseValue = baseValue * 10 + currentDigit;
  24512. }
  24513. } else if (ch === 0x2E) { // '.'
  24514. if (divideBy === 0) {
  24515. divideBy = 1;
  24516. } else {
  24517. // A number can have only one '.'
  24518. break;
  24519. }
  24520. } else if (ch === 0x2D) { // '-'
  24521. // ignore minus signs in the middle of numbers to match
  24522. // Adobe's behavior
  24523. warn('Badly formatted number');
  24524. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  24525. // 'E' can be either a scientific notation or the beginning of a new
  24526. // operator
  24527. ch = this.peekChar();
  24528. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  24529. powerValueSign = (ch === 0x2D) ? -1 : 1;
  24530. this.nextChar(); // Consume the sign character
  24531. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  24532. // The 'E' must be the beginning of a new operator
  24533. break;
  24534. }
  24535. eNotation = true;
  24536. } else {
  24537. // the last character doesn't belong to us
  24538. break;
  24539. }
  24540. }
  24541. if (divideBy !== 0) {
  24542. baseValue /= divideBy;
  24543. }
  24544. if (eNotation) {
  24545. baseValue *= Math.pow(10, powerValueSign * powerValue);
  24546. }
  24547. return sign * baseValue;
  24548. },
  24549. getString: function Lexer_getString() {
  24550. var numParen = 1;
  24551. var done = false;
  24552. var strBuf = this.strBuf;
  24553. strBuf.length = 0;
  24554. var ch = this.nextChar();
  24555. while (true) {
  24556. var charBuffered = false;
  24557. switch (ch | 0) {
  24558. case -1:
  24559. warn('Unterminated string');
  24560. done = true;
  24561. break;
  24562. case 0x28: // '('
  24563. ++numParen;
  24564. strBuf.push('(');
  24565. break;
  24566. case 0x29: // ')'
  24567. if (--numParen === 0) {
  24568. this.nextChar(); // consume strings ')'
  24569. done = true;
  24570. } else {
  24571. strBuf.push(')');
  24572. }
  24573. break;
  24574. case 0x5C: // '\\'
  24575. ch = this.nextChar();
  24576. switch (ch) {
  24577. case -1:
  24578. warn('Unterminated string');
  24579. done = true;
  24580. break;
  24581. case 0x6E: // 'n'
  24582. strBuf.push('\n');
  24583. break;
  24584. case 0x72: // 'r'
  24585. strBuf.push('\r');
  24586. break;
  24587. case 0x74: // 't'
  24588. strBuf.push('\t');
  24589. break;
  24590. case 0x62: // 'b'
  24591. strBuf.push('\b');
  24592. break;
  24593. case 0x66: // 'f'
  24594. strBuf.push('\f');
  24595. break;
  24596. case 0x5C: // '\'
  24597. case 0x28: // '('
  24598. case 0x29: // ')'
  24599. strBuf.push(String.fromCharCode(ch));
  24600. break;
  24601. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  24602. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  24603. var x = ch & 0x0F;
  24604. ch = this.nextChar();
  24605. charBuffered = true;
  24606. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  24607. x = (x << 3) + (ch & 0x0F);
  24608. ch = this.nextChar();
  24609. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  24610. charBuffered = false;
  24611. x = (x << 3) + (ch & 0x0F);
  24612. }
  24613. }
  24614. strBuf.push(String.fromCharCode(x));
  24615. break;
  24616. case 0x0D: // CR
  24617. if (this.peekChar() === 0x0A) { // LF
  24618. this.nextChar();
  24619. }
  24620. break;
  24621. case 0x0A: // LF
  24622. break;
  24623. default:
  24624. strBuf.push(String.fromCharCode(ch));
  24625. break;
  24626. }
  24627. break;
  24628. default:
  24629. strBuf.push(String.fromCharCode(ch));
  24630. break;
  24631. }
  24632. if (done) {
  24633. break;
  24634. }
  24635. if (!charBuffered) {
  24636. ch = this.nextChar();
  24637. }
  24638. }
  24639. return strBuf.join('');
  24640. },
  24641. getName: function Lexer_getName() {
  24642. var ch, previousCh;
  24643. var strBuf = this.strBuf;
  24644. strBuf.length = 0;
  24645. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  24646. if (ch === 0x23) { // '#'
  24647. ch = this.nextChar();
  24648. if (specialChars[ch]) {
  24649. warn('Lexer_getName: ' +
  24650. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  24651. strBuf.push('#');
  24652. break;
  24653. }
  24654. var x = toHexDigit(ch);
  24655. if (x !== -1) {
  24656. previousCh = ch;
  24657. ch = this.nextChar();
  24658. var x2 = toHexDigit(ch);
  24659. if (x2 === -1) {
  24660. warn('Lexer_getName: Illegal digit (' +
  24661. String.fromCharCode(ch) +') in hexadecimal number.');
  24662. strBuf.push('#', String.fromCharCode(previousCh));
  24663. if (specialChars[ch]) {
  24664. break;
  24665. }
  24666. strBuf.push(String.fromCharCode(ch));
  24667. continue;
  24668. }
  24669. strBuf.push(String.fromCharCode((x << 4) | x2));
  24670. } else {
  24671. strBuf.push('#', String.fromCharCode(ch));
  24672. }
  24673. } else {
  24674. strBuf.push(String.fromCharCode(ch));
  24675. }
  24676. }
  24677. if (strBuf.length > 127) {
  24678. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  24679. }
  24680. return Name.get(strBuf.join(''));
  24681. },
  24682. getHexString: function Lexer_getHexString() {
  24683. var strBuf = this.strBuf;
  24684. strBuf.length = 0;
  24685. var ch = this.currentChar;
  24686. var isFirstHex = true;
  24687. var firstDigit;
  24688. var secondDigit;
  24689. while (true) {
  24690. if (ch < 0) {
  24691. warn('Unterminated hex string');
  24692. break;
  24693. } else if (ch === 0x3E) { // '>'
  24694. this.nextChar();
  24695. break;
  24696. } else if (specialChars[ch] === 1) {
  24697. ch = this.nextChar();
  24698. continue;
  24699. } else {
  24700. if (isFirstHex) {
  24701. firstDigit = toHexDigit(ch);
  24702. if (firstDigit === -1) {
  24703. warn('Ignoring invalid character "' + ch + '" in hex string');
  24704. ch = this.nextChar();
  24705. continue;
  24706. }
  24707. } else {
  24708. secondDigit = toHexDigit(ch);
  24709. if (secondDigit === -1) {
  24710. warn('Ignoring invalid character "' + ch + '" in hex string');
  24711. ch = this.nextChar();
  24712. continue;
  24713. }
  24714. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  24715. }
  24716. isFirstHex = !isFirstHex;
  24717. ch = this.nextChar();
  24718. }
  24719. }
  24720. return strBuf.join('');
  24721. },
  24722. getObj: function Lexer_getObj() {
  24723. // skip whitespace and comments
  24724. var comment = false;
  24725. var ch = this.currentChar;
  24726. while (true) {
  24727. if (ch < 0) {
  24728. return EOF;
  24729. }
  24730. if (comment) {
  24731. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  24732. comment = false;
  24733. }
  24734. } else if (ch === 0x25) { // '%'
  24735. comment = true;
  24736. } else if (specialChars[ch] !== 1) {
  24737. break;
  24738. }
  24739. ch = this.nextChar();
  24740. }
  24741. // start reading token
  24742. switch (ch | 0) {
  24743. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  24744. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  24745. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  24746. return this.getNumber();
  24747. case 0x28: // '('
  24748. return this.getString();
  24749. case 0x2F: // '/'
  24750. return this.getName();
  24751. // array punctuation
  24752. case 0x5B: // '['
  24753. this.nextChar();
  24754. return Cmd.get('[');
  24755. case 0x5D: // ']'
  24756. this.nextChar();
  24757. return Cmd.get(']');
  24758. // hex string or dict punctuation
  24759. case 0x3C: // '<'
  24760. ch = this.nextChar();
  24761. if (ch === 0x3C) {
  24762. // dict punctuation
  24763. this.nextChar();
  24764. return Cmd.get('<<');
  24765. }
  24766. return this.getHexString();
  24767. // dict punctuation
  24768. case 0x3E: // '>'
  24769. ch = this.nextChar();
  24770. if (ch === 0x3E) {
  24771. this.nextChar();
  24772. return Cmd.get('>>');
  24773. }
  24774. return Cmd.get('>');
  24775. case 0x7B: // '{'
  24776. this.nextChar();
  24777. return Cmd.get('{');
  24778. case 0x7D: // '}'
  24779. this.nextChar();
  24780. return Cmd.get('}');
  24781. case 0x29: // ')'
  24782. error('Illegal character: ' + ch);
  24783. break;
  24784. }
  24785. // command
  24786. var str = String.fromCharCode(ch);
  24787. var knownCommands = this.knownCommands;
  24788. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  24789. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  24790. // stop if known command is found and next character does not make
  24791. // the str a command
  24792. var possibleCommand = str + String.fromCharCode(ch);
  24793. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  24794. break;
  24795. }
  24796. if (str.length === 128) {
  24797. error('Command token too long: ' + str.length);
  24798. }
  24799. str = possibleCommand;
  24800. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  24801. }
  24802. if (str === 'true') {
  24803. return true;
  24804. }
  24805. if (str === 'false') {
  24806. return false;
  24807. }
  24808. if (str === 'null') {
  24809. return null;
  24810. }
  24811. return Cmd.get(str);
  24812. },
  24813. skipToNextLine: function Lexer_skipToNextLine() {
  24814. var ch = this.currentChar;
  24815. while (ch >= 0) {
  24816. if (ch === 0x0D) { // CR
  24817. ch = this.nextChar();
  24818. if (ch === 0x0A) { // LF
  24819. this.nextChar();
  24820. }
  24821. break;
  24822. } else if (ch === 0x0A) { // LF
  24823. this.nextChar();
  24824. break;
  24825. }
  24826. ch = this.nextChar();
  24827. }
  24828. }
  24829. };
  24830. return Lexer;
  24831. })();
  24832. var Linearization = {
  24833. create: function LinearizationCreate(stream) {
  24834. function getInt(name, allowZeroValue) {
  24835. var obj = linDict.get(name);
  24836. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  24837. return obj;
  24838. }
  24839. throw new Error('The "' + name + '" parameter in the linearization ' +
  24840. 'dictionary is invalid.');
  24841. }
  24842. function getHints() {
  24843. var hints = linDict.get('H'), hintsLength, item;
  24844. if (isArray(hints) &&
  24845. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  24846. for (var index = 0; index < hintsLength; index++) {
  24847. if (!(isInt(item = hints[index]) && item > 0)) {
  24848. throw new Error('Hint (' + index +
  24849. ') in the linearization dictionary is invalid.');
  24850. }
  24851. }
  24852. return hints;
  24853. }
  24854. throw new Error('Hint array in the linearization dictionary is invalid.');
  24855. }
  24856. var parser = new Parser(new Lexer(stream), false, null);
  24857. var obj1 = parser.getObj();
  24858. var obj2 = parser.getObj();
  24859. var obj3 = parser.getObj();
  24860. var linDict = parser.getObj();
  24861. var obj, length;
  24862. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  24863. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  24864. return null; // No valid linearization dictionary found.
  24865. } else if ((length = getInt('L')) !== stream.length) {
  24866. throw new Error('The "L" parameter in the linearization dictionary ' +
  24867. 'does not equal the stream length.');
  24868. }
  24869. return {
  24870. length: length,
  24871. hints: getHints(),
  24872. objectNumberFirst: getInt('O'),
  24873. endFirst: getInt('E'),
  24874. numPages: getInt('N'),
  24875. mainXRefEntriesOffset: getInt('T'),
  24876. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  24877. };
  24878. }
  24879. };
  24880. exports.EOF = EOF;
  24881. exports.Lexer = Lexer;
  24882. exports.Linearization = Linearization;
  24883. exports.Parser = Parser;
  24884. exports.isEOF = isEOF;
  24885. }));
  24886. (function (root, factory) {
  24887. {
  24888. factory((root.pdfjsCoreType1Parser = {}), root.pdfjsSharedUtil,
  24889. root.pdfjsCoreStream, root.pdfjsCoreEncodings);
  24890. }
  24891. }(this, function (exports, sharedUtil, coreStream, coreEncodings) {
  24892. var warn = sharedUtil.warn;
  24893. var isSpace = sharedUtil.isSpace;
  24894. var Stream = coreStream.Stream;
  24895. var getEncoding = coreEncodings.getEncoding;
  24896. // Hinting is currently disabled due to unknown problems on windows
  24897. // in tracemonkey and various other pdfs with type1 fonts.
  24898. var HINTING_ENABLED = false;
  24899. /*
  24900. * CharStrings are encoded following the the CharString Encoding sequence
  24901. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  24902. * The value in a byte indicates a command, a number, or subsequent bytes
  24903. * that are to be interpreted in a special way.
  24904. *
  24905. * CharString Number Encoding:
  24906. * A CharString byte containing the values from 32 through 255 inclusive
  24907. * indicate an integer. These values are decoded in four ranges.
  24908. *
  24909. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  24910. * indicate the integer v - 139. Thus, the integer values from -107 through
  24911. * 107 inclusive may be encoded in single byte.
  24912. *
  24913. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  24914. * indicates an integer involving the next byte, w, according to the formula:
  24915. * [(v - 247) x 256] + w + 108
  24916. *
  24917. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  24918. * indicates an integer involving the next byte, w, according to the formula:
  24919. * -[(v - 251) * 256] - w - 108
  24920. *
  24921. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  24922. * are a two complement signed integer. The first of these bytes contains the
  24923. * highest order bits, the second byte contains the next higher order bits
  24924. * and the fourth byte contain the lowest order bits.
  24925. *
  24926. *
  24927. * CharString Command Encoding:
  24928. * CharStrings commands are encoded in 1 or 2 bytes.
  24929. *
  24930. * Single byte commands are encoded in 1 byte that contains a value between
  24931. * 0 and 31 inclusive.
  24932. * If a command byte contains the value 12, then the value in the next byte
  24933. * indicates a command. This "escape" mechanism allows many extra commands
  24934. * to be encoded and this encoding technique helps to minimize the length of
  24935. * the charStrings.
  24936. */
  24937. var Type1CharString = (function Type1CharStringClosure() {
  24938. var COMMAND_MAP = {
  24939. 'hstem': [1],
  24940. 'vstem': [3],
  24941. 'vmoveto': [4],
  24942. 'rlineto': [5],
  24943. 'hlineto': [6],
  24944. 'vlineto': [7],
  24945. 'rrcurveto': [8],
  24946. 'callsubr': [10],
  24947. 'flex': [12, 35],
  24948. 'drop' : [12, 18],
  24949. 'endchar': [14],
  24950. 'rmoveto': [21],
  24951. 'hmoveto': [22],
  24952. 'vhcurveto': [30],
  24953. 'hvcurveto': [31]
  24954. };
  24955. function Type1CharString() {
  24956. this.width = 0;
  24957. this.lsb = 0;
  24958. this.flexing = false;
  24959. this.output = [];
  24960. this.stack = [];
  24961. }
  24962. Type1CharString.prototype = {
  24963. convert: function Type1CharString_convert(encoded, subrs,
  24964. seacAnalysisEnabled) {
  24965. var count = encoded.length;
  24966. var error = false;
  24967. var wx, sbx, subrNumber;
  24968. for (var i = 0; i < count; i++) {
  24969. var value = encoded[i];
  24970. if (value < 32) {
  24971. if (value === 12) {
  24972. value = (value << 8) + encoded[++i];
  24973. }
  24974. switch (value) {
  24975. case 1: // hstem
  24976. if (!HINTING_ENABLED) {
  24977. this.stack = [];
  24978. break;
  24979. }
  24980. error = this.executeCommand(2, COMMAND_MAP.hstem);
  24981. break;
  24982. case 3: // vstem
  24983. if (!HINTING_ENABLED) {
  24984. this.stack = [];
  24985. break;
  24986. }
  24987. error = this.executeCommand(2, COMMAND_MAP.vstem);
  24988. break;
  24989. case 4: // vmoveto
  24990. if (this.flexing) {
  24991. if (this.stack.length < 1) {
  24992. error = true;
  24993. break;
  24994. }
  24995. // Add the dx for flex and but also swap the values so they are
  24996. // the right order.
  24997. var dy = this.stack.pop();
  24998. this.stack.push(0, dy);
  24999. break;
  25000. }
  25001. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  25002. break;
  25003. case 5: // rlineto
  25004. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  25005. break;
  25006. case 6: // hlineto
  25007. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  25008. break;
  25009. case 7: // vlineto
  25010. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  25011. break;
  25012. case 8: // rrcurveto
  25013. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  25014. break;
  25015. case 9: // closepath
  25016. // closepath is a Type1 command that does not take argument and is
  25017. // useless in Type2 and it can simply be ignored.
  25018. this.stack = [];
  25019. break;
  25020. case 10: // callsubr
  25021. if (this.stack.length < 1) {
  25022. error = true;
  25023. break;
  25024. }
  25025. subrNumber = this.stack.pop();
  25026. error = this.convert(subrs[subrNumber], subrs,
  25027. seacAnalysisEnabled);
  25028. break;
  25029. case 11: // return
  25030. return error;
  25031. case 13: // hsbw
  25032. if (this.stack.length < 2) {
  25033. error = true;
  25034. break;
  25035. }
  25036. // To convert to type2 we have to move the width value to the
  25037. // first part of the charstring and then use hmoveto with lsb.
  25038. wx = this.stack.pop();
  25039. sbx = this.stack.pop();
  25040. this.lsb = sbx;
  25041. this.width = wx;
  25042. this.stack.push(wx, sbx);
  25043. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  25044. break;
  25045. case 14: // endchar
  25046. this.output.push(COMMAND_MAP.endchar[0]);
  25047. break;
  25048. case 21: // rmoveto
  25049. if (this.flexing) {
  25050. break;
  25051. }
  25052. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  25053. break;
  25054. case 22: // hmoveto
  25055. if (this.flexing) {
  25056. // Add the dy for flex.
  25057. this.stack.push(0);
  25058. break;
  25059. }
  25060. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  25061. break;
  25062. case 30: // vhcurveto
  25063. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  25064. break;
  25065. case 31: // hvcurveto
  25066. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  25067. break;
  25068. case (12 << 8) + 0: // dotsection
  25069. // dotsection is a Type1 command to specify some hinting feature
  25070. // for dots that do not take a parameter and it can safely be
  25071. // ignored for Type2.
  25072. this.stack = [];
  25073. break;
  25074. case (12 << 8) + 1: // vstem3
  25075. if (!HINTING_ENABLED) {
  25076. this.stack = [];
  25077. break;
  25078. }
  25079. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  25080. // multiple parameters, so instead of returning [vh]stem3 take a
  25081. // shortcut and return [vhstem] instead.
  25082. error = this.executeCommand(2, COMMAND_MAP.vstem);
  25083. break;
  25084. case (12 << 8) + 2: // hstem3
  25085. if (!HINTING_ENABLED) {
  25086. this.stack = [];
  25087. break;
  25088. }
  25089. // See vstem3.
  25090. error = this.executeCommand(2, COMMAND_MAP.hstem);
  25091. break;
  25092. case (12 << 8) + 6: // seac
  25093. // seac is like type 2's special endchar but it doesn't use the
  25094. // first argument asb, so remove it.
  25095. if (seacAnalysisEnabled) {
  25096. this.seac = this.stack.splice(-4, 4);
  25097. error = this.executeCommand(0, COMMAND_MAP.endchar);
  25098. } else {
  25099. error = this.executeCommand(4, COMMAND_MAP.endchar);
  25100. }
  25101. break;
  25102. case (12 << 8) + 7: // sbw
  25103. if (this.stack.length < 4) {
  25104. error = true;
  25105. break;
  25106. }
  25107. // To convert to type2 we have to move the width value to the
  25108. // first part of the charstring and then use rmoveto with
  25109. // (dx, dy). The height argument will not be used for vmtx and
  25110. // vhea tables reconstruction -- ignoring it.
  25111. var wy = this.stack.pop();
  25112. wx = this.stack.pop();
  25113. var sby = this.stack.pop();
  25114. sbx = this.stack.pop();
  25115. this.lsb = sbx;
  25116. this.width = wx;
  25117. this.stack.push(wx, sbx, sby);
  25118. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  25119. break;
  25120. case (12 << 8) + 12: // div
  25121. if (this.stack.length < 2) {
  25122. error = true;
  25123. break;
  25124. }
  25125. var num2 = this.stack.pop();
  25126. var num1 = this.stack.pop();
  25127. this.stack.push(num1 / num2);
  25128. break;
  25129. case (12 << 8) + 16: // callothersubr
  25130. if (this.stack.length < 2) {
  25131. error = true;
  25132. break;
  25133. }
  25134. subrNumber = this.stack.pop();
  25135. var numArgs = this.stack.pop();
  25136. if (subrNumber === 0 && numArgs === 3) {
  25137. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  25138. this.stack.push(
  25139. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  25140. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  25141. flexArgs[4], // bcp2x
  25142. flexArgs[5], // bcp2y
  25143. flexArgs[6], // p2x
  25144. flexArgs[7], // p2y
  25145. flexArgs[8], // bcp3x
  25146. flexArgs[9], // bcp3y
  25147. flexArgs[10], // bcp4x
  25148. flexArgs[11], // bcp4y
  25149. flexArgs[12], // p3x
  25150. flexArgs[13], // p3y
  25151. flexArgs[14] // flexDepth
  25152. // 15 = finalx unused by flex
  25153. // 16 = finaly unused by flex
  25154. );
  25155. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  25156. this.flexing = false;
  25157. this.stack.push(flexArgs[15], flexArgs[16]);
  25158. } else if (subrNumber === 1 && numArgs === 0) {
  25159. this.flexing = true;
  25160. }
  25161. break;
  25162. case (12 << 8) + 17: // pop
  25163. // Ignore this since it is only used with othersubr.
  25164. break;
  25165. case (12 << 8) + 33: // setcurrentpoint
  25166. // Ignore for now.
  25167. this.stack = [];
  25168. break;
  25169. default:
  25170. warn('Unknown type 1 charstring command of "' + value + '"');
  25171. break;
  25172. }
  25173. if (error) {
  25174. break;
  25175. }
  25176. continue;
  25177. } else if (value <= 246) {
  25178. value = value - 139;
  25179. } else if (value <= 250) {
  25180. value = ((value - 247) * 256) + encoded[++i] + 108;
  25181. } else if (value <= 254) {
  25182. value = -((value - 251) * 256) - encoded[++i] - 108;
  25183. } else {
  25184. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  25185. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  25186. }
  25187. this.stack.push(value);
  25188. }
  25189. return error;
  25190. },
  25191. executeCommand: function(howManyArgs, command, keepStack) {
  25192. var stackLength = this.stack.length;
  25193. if (howManyArgs > stackLength) {
  25194. return true;
  25195. }
  25196. var start = stackLength - howManyArgs;
  25197. for (var i = start; i < stackLength; i++) {
  25198. var value = this.stack[i];
  25199. if (value === (value | 0)) { // int
  25200. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  25201. } else { // fixed point
  25202. value = (65536 * value) | 0;
  25203. this.output.push(255,
  25204. (value >> 24) & 0xFF,
  25205. (value >> 16) & 0xFF,
  25206. (value >> 8) & 0xFF,
  25207. value & 0xFF);
  25208. }
  25209. }
  25210. this.output.push.apply(this.output, command);
  25211. if (keepStack) {
  25212. this.stack.splice(start, howManyArgs);
  25213. } else {
  25214. this.stack.length = 0;
  25215. }
  25216. return false;
  25217. }
  25218. };
  25219. return Type1CharString;
  25220. })();
  25221. /*
  25222. * Type1Parser encapsulate the needed code for parsing a Type1 font
  25223. * program. Some of its logic depends on the Type2 charstrings
  25224. * structure.
  25225. * Note: this doesn't really parse the font since that would require evaluation
  25226. * of PostScript, but it is possible in most cases to extract what we need
  25227. * without a full parse.
  25228. */
  25229. var Type1Parser = (function Type1ParserClosure() {
  25230. /*
  25231. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  25232. * of Plaintext Bytes. The function took a key as a parameter which can be
  25233. * for decrypting the eexec block of for decoding charStrings.
  25234. */
  25235. var EEXEC_ENCRYPT_KEY = 55665;
  25236. var CHAR_STRS_ENCRYPT_KEY = 4330;
  25237. function isHexDigit(code) {
  25238. return code >= 48 && code <= 57 || // '0'-'9'
  25239. code >= 65 && code <= 70 || // 'A'-'F'
  25240. code >= 97 && code <= 102; // 'a'-'f'
  25241. }
  25242. function decrypt(data, key, discardNumber) {
  25243. if (discardNumber >= data.length) {
  25244. return new Uint8Array(0);
  25245. }
  25246. var r = key | 0, c1 = 52845, c2 = 22719, i, j;
  25247. for (i = 0; i < discardNumber; i++) {
  25248. r = ((data[i] + r) * c1 + c2) & ((1 << 16) - 1);
  25249. }
  25250. var count = data.length - discardNumber;
  25251. var decrypted = new Uint8Array(count);
  25252. for (i = discardNumber, j = 0; j < count; i++, j++) {
  25253. var value = data[i];
  25254. decrypted[j] = value ^ (r >> 8);
  25255. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  25256. }
  25257. return decrypted;
  25258. }
  25259. function decryptAscii(data, key, discardNumber) {
  25260. var r = key | 0, c1 = 52845, c2 = 22719;
  25261. var count = data.length, maybeLength = count >>> 1;
  25262. var decrypted = new Uint8Array(maybeLength);
  25263. var i, j;
  25264. for (i = 0, j = 0; i < count; i++) {
  25265. var digit1 = data[i];
  25266. if (!isHexDigit(digit1)) {
  25267. continue;
  25268. }
  25269. i++;
  25270. var digit2;
  25271. while (i < count && !isHexDigit(digit2 = data[i])) {
  25272. i++;
  25273. }
  25274. if (i < count) {
  25275. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  25276. decrypted[j++] = value ^ (r >> 8);
  25277. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  25278. }
  25279. }
  25280. return Array.prototype.slice.call(decrypted, discardNumber, j);
  25281. }
  25282. function isSpecial(c) {
  25283. return c === 0x2F || // '/'
  25284. c === 0x5B || c === 0x5D || // '[', ']'
  25285. c === 0x7B || c === 0x7D || // '{', '}'
  25286. c === 0x28 || c === 0x29; // '(', ')'
  25287. }
  25288. function Type1Parser(stream, encrypted, seacAnalysisEnabled) {
  25289. if (encrypted) {
  25290. var data = stream.getBytes();
  25291. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  25292. isHexDigit(data[2]) && isHexDigit(data[3]));
  25293. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  25294. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  25295. }
  25296. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  25297. this.stream = stream;
  25298. this.nextChar();
  25299. }
  25300. Type1Parser.prototype = {
  25301. readNumberArray: function Type1Parser_readNumberArray() {
  25302. this.getToken(); // read '[' or '{' (arrays can start with either)
  25303. var array = [];
  25304. while (true) {
  25305. var token = this.getToken();
  25306. if (token === null || token === ']' || token === '}') {
  25307. break;
  25308. }
  25309. array.push(parseFloat(token || 0));
  25310. }
  25311. return array;
  25312. },
  25313. readNumber: function Type1Parser_readNumber() {
  25314. var token = this.getToken();
  25315. return parseFloat(token || 0);
  25316. },
  25317. readInt: function Type1Parser_readInt() {
  25318. // Use '| 0' to prevent setting a double into length such as the double
  25319. // does not flow into the loop variable.
  25320. var token = this.getToken();
  25321. return parseInt(token || 0, 10) | 0;
  25322. },
  25323. readBoolean: function Type1Parser_readBoolean() {
  25324. var token = this.getToken();
  25325. // Use 1 and 0 since that's what type2 charstrings use.
  25326. return token === 'true' ? 1 : 0;
  25327. },
  25328. nextChar : function Type1_nextChar() {
  25329. return (this.currentChar = this.stream.getByte());
  25330. },
  25331. getToken: function Type1Parser_getToken() {
  25332. // Eat whitespace and comments.
  25333. var comment = false;
  25334. var ch = this.currentChar;
  25335. while (true) {
  25336. if (ch === -1) {
  25337. return null;
  25338. }
  25339. if (comment) {
  25340. if (ch === 0x0A || ch === 0x0D) {
  25341. comment = false;
  25342. }
  25343. } else if (ch === 0x25) { // '%'
  25344. comment = true;
  25345. } else if (!isSpace(ch)) {
  25346. break;
  25347. }
  25348. ch = this.nextChar();
  25349. }
  25350. if (isSpecial(ch)) {
  25351. this.nextChar();
  25352. return String.fromCharCode(ch);
  25353. }
  25354. var token = '';
  25355. do {
  25356. token += String.fromCharCode(ch);
  25357. ch = this.nextChar();
  25358. } while (ch >= 0 && !isSpace(ch) && !isSpecial(ch));
  25359. return token;
  25360. },
  25361. /*
  25362. * Returns an object containing a Subrs array and a CharStrings
  25363. * array extracted from and eexec encrypted block of data
  25364. */
  25365. extractFontProgram: function Type1Parser_extractFontProgram() {
  25366. var stream = this.stream;
  25367. var subrs = [], charstrings = [];
  25368. var privateData = Object.create(null);
  25369. privateData['lenIV'] = 4;
  25370. var program = {
  25371. subrs: [],
  25372. charstrings: [],
  25373. properties: {
  25374. 'privateData': privateData
  25375. }
  25376. };
  25377. var token, length, data, lenIV, encoded;
  25378. while ((token = this.getToken()) !== null) {
  25379. if (token !== '/') {
  25380. continue;
  25381. }
  25382. token = this.getToken();
  25383. switch (token) {
  25384. case 'CharStrings':
  25385. // The number immediately following CharStrings must be greater or
  25386. // equal to the number of CharStrings.
  25387. this.getToken();
  25388. this.getToken(); // read in 'dict'
  25389. this.getToken(); // read in 'dup'
  25390. this.getToken(); // read in 'begin'
  25391. while(true) {
  25392. token = this.getToken();
  25393. if (token === null || token === 'end') {
  25394. break;
  25395. }
  25396. if (token !== '/') {
  25397. continue;
  25398. }
  25399. var glyph = this.getToken();
  25400. length = this.readInt();
  25401. this.getToken(); // read in 'RD' or '-|'
  25402. data = stream.makeSubStream(stream.pos, length);
  25403. lenIV = program.properties.privateData['lenIV'];
  25404. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  25405. // Skip past the required space and binary data.
  25406. stream.skip(length);
  25407. this.nextChar();
  25408. token = this.getToken(); // read in 'ND' or '|-'
  25409. if (token === 'noaccess') {
  25410. this.getToken(); // read in 'def'
  25411. }
  25412. charstrings.push({
  25413. glyph: glyph,
  25414. encoded: encoded
  25415. });
  25416. }
  25417. break;
  25418. case 'Subrs':
  25419. var num = this.readInt();
  25420. this.getToken(); // read in 'array'
  25421. while ((token = this.getToken()) === 'dup') {
  25422. var index = this.readInt();
  25423. length = this.readInt();
  25424. this.getToken(); // read in 'RD' or '-|'
  25425. data = stream.makeSubStream(stream.pos, length);
  25426. lenIV = program.properties.privateData['lenIV'];
  25427. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  25428. // Skip past the required space and binary data.
  25429. stream.skip(length);
  25430. this.nextChar();
  25431. token = this.getToken(); // read in 'NP' or '|'
  25432. if (token === 'noaccess') {
  25433. this.getToken(); // read in 'put'
  25434. }
  25435. subrs[index] = encoded;
  25436. }
  25437. break;
  25438. case 'BlueValues':
  25439. case 'OtherBlues':
  25440. case 'FamilyBlues':
  25441. case 'FamilyOtherBlues':
  25442. var blueArray = this.readNumberArray();
  25443. // *Blue* values may contain invalid data: disables reading of
  25444. // those values when hinting is disabled.
  25445. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  25446. HINTING_ENABLED) {
  25447. program.properties.privateData[token] = blueArray;
  25448. }
  25449. break;
  25450. case 'StemSnapH':
  25451. case 'StemSnapV':
  25452. program.properties.privateData[token] = this.readNumberArray();
  25453. break;
  25454. case 'StdHW':
  25455. case 'StdVW':
  25456. program.properties.privateData[token] =
  25457. this.readNumberArray()[0];
  25458. break;
  25459. case 'BlueShift':
  25460. case 'lenIV':
  25461. case 'BlueFuzz':
  25462. case 'BlueScale':
  25463. case 'LanguageGroup':
  25464. case 'ExpansionFactor':
  25465. program.properties.privateData[token] = this.readNumber();
  25466. break;
  25467. case 'ForceBold':
  25468. program.properties.privateData[token] = this.readBoolean();
  25469. break;
  25470. }
  25471. }
  25472. for (var i = 0; i < charstrings.length; i++) {
  25473. glyph = charstrings[i].glyph;
  25474. encoded = charstrings[i].encoded;
  25475. var charString = new Type1CharString();
  25476. var error = charString.convert(encoded, subrs,
  25477. this.seacAnalysisEnabled);
  25478. var output = charString.output;
  25479. if (error) {
  25480. // It seems when FreeType encounters an error while evaluating a glyph
  25481. // that it completely ignores the glyph so we'll mimic that behaviour
  25482. // here and put an endchar to make the validator happy.
  25483. output = [14];
  25484. }
  25485. program.charstrings.push({
  25486. glyphName: glyph,
  25487. charstring: output,
  25488. width: charString.width,
  25489. lsb: charString.lsb,
  25490. seac: charString.seac
  25491. });
  25492. }
  25493. return program;
  25494. },
  25495. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  25496. var token;
  25497. while ((token = this.getToken()) !== null) {
  25498. if (token !== '/') {
  25499. continue;
  25500. }
  25501. token = this.getToken();
  25502. switch (token) {
  25503. case 'FontMatrix':
  25504. var matrix = this.readNumberArray();
  25505. properties.fontMatrix = matrix;
  25506. break;
  25507. case 'Encoding':
  25508. var encodingArg = this.getToken();
  25509. var encoding;
  25510. if (!/^\d+$/.test(encodingArg)) {
  25511. // encoding name is specified
  25512. encoding = getEncoding(encodingArg);
  25513. } else {
  25514. encoding = [];
  25515. var size = parseInt(encodingArg, 10) | 0;
  25516. this.getToken(); // read in 'array'
  25517. for (var j = 0; j < size; j++) {
  25518. token = this.getToken();
  25519. // skipping till first dup or def (e.g. ignoring for statement)
  25520. while (token !== 'dup' && token !== 'def') {
  25521. token = this.getToken();
  25522. if (token === null) {
  25523. return; // invalid header
  25524. }
  25525. }
  25526. if (token === 'def') {
  25527. break; // read all array data
  25528. }
  25529. var index = this.readInt();
  25530. this.getToken(); // read in '/'
  25531. var glyph = this.getToken();
  25532. encoding[index] = glyph;
  25533. this.getToken(); // read the in 'put'
  25534. }
  25535. }
  25536. properties.builtInEncoding = encoding;
  25537. break;
  25538. case 'FontBBox':
  25539. var fontBBox = this.readNumberArray();
  25540. // adjusting ascent/descent
  25541. properties.ascent = fontBBox[3];
  25542. properties.descent = fontBBox[1];
  25543. properties.ascentScaled = true;
  25544. break;
  25545. }
  25546. }
  25547. }
  25548. };
  25549. return Type1Parser;
  25550. })();
  25551. exports.Type1Parser = Type1Parser;
  25552. }));
  25553. (function (root, factory) {
  25554. {
  25555. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  25556. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  25557. }
  25558. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  25559. var Util = sharedUtil.Util;
  25560. var assert = sharedUtil.assert;
  25561. var warn = sharedUtil.warn;
  25562. var error = sharedUtil.error;
  25563. var isInt = sharedUtil.isInt;
  25564. var isString = sharedUtil.isString;
  25565. var MissingDataException = sharedUtil.MissingDataException;
  25566. var isName = corePrimitives.isName;
  25567. var isCmd = corePrimitives.isCmd;
  25568. var isStream = corePrimitives.isStream;
  25569. var StringStream = coreStream.StringStream;
  25570. var Lexer = coreParser.Lexer;
  25571. var isEOF = coreParser.isEOF;
  25572. var BUILT_IN_CMAPS = [
  25573. // << Start unicode maps.
  25574. 'Adobe-GB1-UCS2',
  25575. 'Adobe-CNS1-UCS2',
  25576. 'Adobe-Japan1-UCS2',
  25577. 'Adobe-Korea1-UCS2',
  25578. // >> End unicode maps.
  25579. '78-EUC-H',
  25580. '78-EUC-V',
  25581. '78-H',
  25582. '78-RKSJ-H',
  25583. '78-RKSJ-V',
  25584. '78-V',
  25585. '78ms-RKSJ-H',
  25586. '78ms-RKSJ-V',
  25587. '83pv-RKSJ-H',
  25588. '90ms-RKSJ-H',
  25589. '90ms-RKSJ-V',
  25590. '90msp-RKSJ-H',
  25591. '90msp-RKSJ-V',
  25592. '90pv-RKSJ-H',
  25593. '90pv-RKSJ-V',
  25594. 'Add-H',
  25595. 'Add-RKSJ-H',
  25596. 'Add-RKSJ-V',
  25597. 'Add-V',
  25598. 'Adobe-CNS1-0',
  25599. 'Adobe-CNS1-1',
  25600. 'Adobe-CNS1-2',
  25601. 'Adobe-CNS1-3',
  25602. 'Adobe-CNS1-4',
  25603. 'Adobe-CNS1-5',
  25604. 'Adobe-CNS1-6',
  25605. 'Adobe-GB1-0',
  25606. 'Adobe-GB1-1',
  25607. 'Adobe-GB1-2',
  25608. 'Adobe-GB1-3',
  25609. 'Adobe-GB1-4',
  25610. 'Adobe-GB1-5',
  25611. 'Adobe-Japan1-0',
  25612. 'Adobe-Japan1-1',
  25613. 'Adobe-Japan1-2',
  25614. 'Adobe-Japan1-3',
  25615. 'Adobe-Japan1-4',
  25616. 'Adobe-Japan1-5',
  25617. 'Adobe-Japan1-6',
  25618. 'Adobe-Korea1-0',
  25619. 'Adobe-Korea1-1',
  25620. 'Adobe-Korea1-2',
  25621. 'B5-H',
  25622. 'B5-V',
  25623. 'B5pc-H',
  25624. 'B5pc-V',
  25625. 'CNS-EUC-H',
  25626. 'CNS-EUC-V',
  25627. 'CNS1-H',
  25628. 'CNS1-V',
  25629. 'CNS2-H',
  25630. 'CNS2-V',
  25631. 'ETHK-B5-H',
  25632. 'ETHK-B5-V',
  25633. 'ETen-B5-H',
  25634. 'ETen-B5-V',
  25635. 'ETenms-B5-H',
  25636. 'ETenms-B5-V',
  25637. 'EUC-H',
  25638. 'EUC-V',
  25639. 'Ext-H',
  25640. 'Ext-RKSJ-H',
  25641. 'Ext-RKSJ-V',
  25642. 'Ext-V',
  25643. 'GB-EUC-H',
  25644. 'GB-EUC-V',
  25645. 'GB-H',
  25646. 'GB-V',
  25647. 'GBK-EUC-H',
  25648. 'GBK-EUC-V',
  25649. 'GBK2K-H',
  25650. 'GBK2K-V',
  25651. 'GBKp-EUC-H',
  25652. 'GBKp-EUC-V',
  25653. 'GBT-EUC-H',
  25654. 'GBT-EUC-V',
  25655. 'GBT-H',
  25656. 'GBT-V',
  25657. 'GBTpc-EUC-H',
  25658. 'GBTpc-EUC-V',
  25659. 'GBpc-EUC-H',
  25660. 'GBpc-EUC-V',
  25661. 'H',
  25662. 'HKdla-B5-H',
  25663. 'HKdla-B5-V',
  25664. 'HKdlb-B5-H',
  25665. 'HKdlb-B5-V',
  25666. 'HKgccs-B5-H',
  25667. 'HKgccs-B5-V',
  25668. 'HKm314-B5-H',
  25669. 'HKm314-B5-V',
  25670. 'HKm471-B5-H',
  25671. 'HKm471-B5-V',
  25672. 'HKscs-B5-H',
  25673. 'HKscs-B5-V',
  25674. 'Hankaku',
  25675. 'Hiragana',
  25676. 'KSC-EUC-H',
  25677. 'KSC-EUC-V',
  25678. 'KSC-H',
  25679. 'KSC-Johab-H',
  25680. 'KSC-Johab-V',
  25681. 'KSC-V',
  25682. 'KSCms-UHC-H',
  25683. 'KSCms-UHC-HW-H',
  25684. 'KSCms-UHC-HW-V',
  25685. 'KSCms-UHC-V',
  25686. 'KSCpc-EUC-H',
  25687. 'KSCpc-EUC-V',
  25688. 'Katakana',
  25689. 'NWP-H',
  25690. 'NWP-V',
  25691. 'RKSJ-H',
  25692. 'RKSJ-V',
  25693. 'Roman',
  25694. 'UniCNS-UCS2-H',
  25695. 'UniCNS-UCS2-V',
  25696. 'UniCNS-UTF16-H',
  25697. 'UniCNS-UTF16-V',
  25698. 'UniCNS-UTF32-H',
  25699. 'UniCNS-UTF32-V',
  25700. 'UniCNS-UTF8-H',
  25701. 'UniCNS-UTF8-V',
  25702. 'UniGB-UCS2-H',
  25703. 'UniGB-UCS2-V',
  25704. 'UniGB-UTF16-H',
  25705. 'UniGB-UTF16-V',
  25706. 'UniGB-UTF32-H',
  25707. 'UniGB-UTF32-V',
  25708. 'UniGB-UTF8-H',
  25709. 'UniGB-UTF8-V',
  25710. 'UniJIS-UCS2-H',
  25711. 'UniJIS-UCS2-HW-H',
  25712. 'UniJIS-UCS2-HW-V',
  25713. 'UniJIS-UCS2-V',
  25714. 'UniJIS-UTF16-H',
  25715. 'UniJIS-UTF16-V',
  25716. 'UniJIS-UTF32-H',
  25717. 'UniJIS-UTF32-V',
  25718. 'UniJIS-UTF8-H',
  25719. 'UniJIS-UTF8-V',
  25720. 'UniJIS2004-UTF16-H',
  25721. 'UniJIS2004-UTF16-V',
  25722. 'UniJIS2004-UTF32-H',
  25723. 'UniJIS2004-UTF32-V',
  25724. 'UniJIS2004-UTF8-H',
  25725. 'UniJIS2004-UTF8-V',
  25726. 'UniJISPro-UCS2-HW-V',
  25727. 'UniJISPro-UCS2-V',
  25728. 'UniJISPro-UTF8-V',
  25729. 'UniJISX0213-UTF32-H',
  25730. 'UniJISX0213-UTF32-V',
  25731. 'UniJISX02132004-UTF32-H',
  25732. 'UniJISX02132004-UTF32-V',
  25733. 'UniKS-UCS2-H',
  25734. 'UniKS-UCS2-V',
  25735. 'UniKS-UTF16-H',
  25736. 'UniKS-UTF16-V',
  25737. 'UniKS-UTF32-H',
  25738. 'UniKS-UTF32-V',
  25739. 'UniKS-UTF8-H',
  25740. 'UniKS-UTF8-V',
  25741. 'V',
  25742. 'WP-Symbol'];
  25743. // CMap, not to be confused with TrueType's cmap.
  25744. var CMap = (function CMapClosure() {
  25745. function CMap(builtInCMap) {
  25746. // Codespace ranges are stored as follows:
  25747. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  25748. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  25749. this.codespaceRanges = [[], [], [], []];
  25750. this.numCodespaceRanges = 0;
  25751. // Map entries have one of two forms.
  25752. // - cid chars are 16-bit unsigned integers, stored as integers.
  25753. // - bf chars are variable-length byte sequences, stored as strings, with
  25754. // one byte per character.
  25755. this._map = [];
  25756. this.name = '';
  25757. this.vertical = false;
  25758. this.useCMap = null;
  25759. this.builtInCMap = builtInCMap;
  25760. }
  25761. CMap.prototype = {
  25762. addCodespaceRange: function(n, low, high) {
  25763. this.codespaceRanges[n - 1].push(low, high);
  25764. this.numCodespaceRanges++;
  25765. },
  25766. mapCidRange: function(low, high, dstLow) {
  25767. while (low <= high) {
  25768. this._map[low++] = dstLow++;
  25769. }
  25770. },
  25771. mapBfRange: function(low, high, dstLow) {
  25772. var lastByte = dstLow.length - 1;
  25773. while (low <= high) {
  25774. this._map[low++] = dstLow;
  25775. // Only the last byte has to be incremented.
  25776. dstLow = dstLow.substr(0, lastByte) +
  25777. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  25778. }
  25779. },
  25780. mapBfRangeToArray: function(low, high, array) {
  25781. var i = 0, ii = array.length;
  25782. while (low <= high && i < ii) {
  25783. this._map[low] = array[i++];
  25784. ++low;
  25785. }
  25786. },
  25787. // This is used for both bf and cid chars.
  25788. mapOne: function(src, dst) {
  25789. this._map[src] = dst;
  25790. },
  25791. lookup: function(code) {
  25792. return this._map[code];
  25793. },
  25794. contains: function(code) {
  25795. return this._map[code] !== undefined;
  25796. },
  25797. forEach: function(callback) {
  25798. // Most maps have fewer than 65536 entries, and for those we use normal
  25799. // array iteration. But really sparse tables are possible -- e.g. with
  25800. // indices in the *billions*. For such tables we use for..in, which isn't
  25801. // ideal because it stringifies the indices for all present elements, but
  25802. // it does avoid iterating over every undefined entry.
  25803. var map = this._map;
  25804. var length = map.length;
  25805. var i;
  25806. if (length <= 0x10000) {
  25807. for (i = 0; i < length; i++) {
  25808. if (map[i] !== undefined) {
  25809. callback(i, map[i]);
  25810. }
  25811. }
  25812. } else {
  25813. for (i in this._map) {
  25814. callback(i, map[i]);
  25815. }
  25816. }
  25817. },
  25818. charCodeOf: function(value) {
  25819. return this._map.indexOf(value);
  25820. },
  25821. getMap: function() {
  25822. return this._map;
  25823. },
  25824. readCharCode: function(str, offset, out) {
  25825. var c = 0;
  25826. var codespaceRanges = this.codespaceRanges;
  25827. var codespaceRangesLen = this.codespaceRanges.length;
  25828. // 9.7.6.2 CMap Mapping
  25829. // The code length is at most 4.
  25830. for (var n = 0; n < codespaceRangesLen; n++) {
  25831. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  25832. // Check each codespace range to see if it falls within.
  25833. var codespaceRange = codespaceRanges[n];
  25834. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  25835. var low = codespaceRange[k++];
  25836. var high = codespaceRange[k++];
  25837. if (c >= low && c <= high) {
  25838. out.charcode = c;
  25839. out.length = n + 1;
  25840. return;
  25841. }
  25842. }
  25843. }
  25844. out.charcode = 0;
  25845. out.length = 1;
  25846. },
  25847. get length() {
  25848. return this._map.length;
  25849. },
  25850. get isIdentityCMap() {
  25851. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  25852. return false;
  25853. }
  25854. if (this._map.length !== 0x10000) {
  25855. return false;
  25856. }
  25857. for (var i = 0; i < 0x10000; i++) {
  25858. if (this._map[i] !== i) {
  25859. return false;
  25860. }
  25861. }
  25862. return true;
  25863. }
  25864. };
  25865. return CMap;
  25866. })();
  25867. // A special case of CMap, where the _map array implicitly has a length of
  25868. // 65536 and each element is equal to its index.
  25869. var IdentityCMap = (function IdentityCMapClosure() {
  25870. function IdentityCMap(vertical, n) {
  25871. CMap.call(this);
  25872. this.vertical = vertical;
  25873. this.addCodespaceRange(n, 0, 0xffff);
  25874. }
  25875. Util.inherit(IdentityCMap, CMap, {});
  25876. IdentityCMap.prototype = {
  25877. addCodespaceRange: CMap.prototype.addCodespaceRange,
  25878. mapCidRange: function(low, high, dstLow) {
  25879. error('should not call mapCidRange');
  25880. },
  25881. mapBfRange: function(low, high, dstLow) {
  25882. error('should not call mapBfRange');
  25883. },
  25884. mapBfRangeToArray: function(low, high, array) {
  25885. error('should not call mapBfRangeToArray');
  25886. },
  25887. mapOne: function(src, dst) {
  25888. error('should not call mapCidOne');
  25889. },
  25890. lookup: function(code) {
  25891. return (isInt(code) && code <= 0xffff) ? code : undefined;
  25892. },
  25893. contains: function(code) {
  25894. return isInt(code) && code <= 0xffff;
  25895. },
  25896. forEach: function(callback) {
  25897. for (var i = 0; i <= 0xffff; i++) {
  25898. callback(i, i);
  25899. }
  25900. },
  25901. charCodeOf: function(value) {
  25902. return (isInt(value) && value <= 0xffff) ? value : -1;
  25903. },
  25904. getMap: function() {
  25905. // Sometimes identity maps must be instantiated, but it's rare.
  25906. var map = new Array(0x10000);
  25907. for (var i = 0; i <= 0xffff; i++) {
  25908. map[i] = i;
  25909. }
  25910. return map;
  25911. },
  25912. readCharCode: CMap.prototype.readCharCode,
  25913. get length() {
  25914. return 0x10000;
  25915. },
  25916. get isIdentityCMap() {
  25917. error('should not access .isIdentityCMap');
  25918. }
  25919. };
  25920. return IdentityCMap;
  25921. })();
  25922. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  25923. function fetchBinaryData(url) {
  25924. return new Promise(function (resolve, reject) {
  25925. var request = new XMLHttpRequest();
  25926. request.open('GET', url, true);
  25927. request.responseType = 'arraybuffer';
  25928. request.onreadystatechange = function () {
  25929. if (request.readyState === XMLHttpRequest.DONE) {
  25930. if (!request.response || request.status !== 200 &&
  25931. request.status !== 0) {
  25932. reject(new Error('Unable to get binary cMap at: ' + url));
  25933. } else {
  25934. resolve(new Uint8Array(request.response));
  25935. }
  25936. }
  25937. };
  25938. request.send(null);
  25939. });
  25940. }
  25941. function hexToInt(a, size) {
  25942. var n = 0;
  25943. for (var i = 0; i <= size; i++) {
  25944. n = (n << 8) | a[i];
  25945. }
  25946. return n >>> 0;
  25947. }
  25948. function hexToStr(a, size) {
  25949. // This code is hot. Special-case some common values to avoid creating an
  25950. // object with subarray().
  25951. if (size === 1) {
  25952. return String.fromCharCode(a[0], a[1]);
  25953. }
  25954. if (size === 3) {
  25955. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  25956. }
  25957. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  25958. }
  25959. function addHex(a, b, size) {
  25960. var c = 0;
  25961. for (var i = size; i >= 0; i--) {
  25962. c += a[i] + b[i];
  25963. a[i] = c & 255;
  25964. c >>= 8;
  25965. }
  25966. }
  25967. function incHex(a, size) {
  25968. var c = 1;
  25969. for (var i = size; i >= 0 && c > 0; i--) {
  25970. c += a[i];
  25971. a[i] = c & 255;
  25972. c >>= 8;
  25973. }
  25974. }
  25975. var MAX_NUM_SIZE = 16;
  25976. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  25977. function BinaryCMapStream(data) {
  25978. this.buffer = data;
  25979. this.pos = 0;
  25980. this.end = data.length;
  25981. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  25982. }
  25983. BinaryCMapStream.prototype = {
  25984. readByte: function () {
  25985. if (this.pos >= this.end) {
  25986. return -1;
  25987. }
  25988. return this.buffer[this.pos++];
  25989. },
  25990. readNumber: function () {
  25991. var n = 0;
  25992. var last;
  25993. do {
  25994. var b = this.readByte();
  25995. if (b < 0) {
  25996. error('unexpected EOF in bcmap');
  25997. }
  25998. last = !(b & 0x80);
  25999. n = (n << 7) | (b & 0x7F);
  26000. } while (!last);
  26001. return n;
  26002. },
  26003. readSigned: function () {
  26004. var n = this.readNumber();
  26005. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  26006. },
  26007. readHex: function (num, size) {
  26008. num.set(this.buffer.subarray(this.pos,
  26009. this.pos + size + 1));
  26010. this.pos += size + 1;
  26011. },
  26012. readHexNumber: function (num, size) {
  26013. var last;
  26014. var stack = this.tmpBuf, sp = 0;
  26015. do {
  26016. var b = this.readByte();
  26017. if (b < 0) {
  26018. error('unexpected EOF in bcmap');
  26019. }
  26020. last = !(b & 0x80);
  26021. stack[sp++] = b & 0x7F;
  26022. } while (!last);
  26023. var i = size, buffer = 0, bufferSize = 0;
  26024. while (i >= 0) {
  26025. while (bufferSize < 8 && stack.length > 0) {
  26026. buffer = (stack[--sp] << bufferSize) | buffer;
  26027. bufferSize += 7;
  26028. }
  26029. num[i] = buffer & 255;
  26030. i--;
  26031. buffer >>= 8;
  26032. bufferSize -= 8;
  26033. }
  26034. },
  26035. readHexSigned: function (num, size) {
  26036. this.readHexNumber(num, size);
  26037. var sign = num[size] & 1 ? 255 : 0;
  26038. var c = 0;
  26039. for (var i = 0; i <= size; i++) {
  26040. c = ((c & 1) << 8) | num[i];
  26041. num[i] = (c >> 1) ^ sign;
  26042. }
  26043. },
  26044. readString: function () {
  26045. var len = this.readNumber();
  26046. var s = '';
  26047. for (var i = 0; i < len; i++) {
  26048. s += String.fromCharCode(this.readNumber());
  26049. }
  26050. return s;
  26051. }
  26052. };
  26053. function processBinaryCMap(url, cMap, extend) {
  26054. return fetchBinaryData(url).then(function (data) {
  26055. var stream = new BinaryCMapStream(data);
  26056. var header = stream.readByte();
  26057. cMap.vertical = !!(header & 1);
  26058. var useCMap = null;
  26059. var start = new Uint8Array(MAX_NUM_SIZE);
  26060. var end = new Uint8Array(MAX_NUM_SIZE);
  26061. var char = new Uint8Array(MAX_NUM_SIZE);
  26062. var charCode = new Uint8Array(MAX_NUM_SIZE);
  26063. var tmp = new Uint8Array(MAX_NUM_SIZE);
  26064. var code;
  26065. var b;
  26066. while ((b = stream.readByte()) >= 0) {
  26067. var type = b >> 5;
  26068. if (type === 7) { // metadata, e.g. comment or usecmap
  26069. switch (b & 0x1F) {
  26070. case 0:
  26071. stream.readString(); // skipping comment
  26072. break;
  26073. case 1:
  26074. useCMap = stream.readString();
  26075. break;
  26076. }
  26077. continue;
  26078. }
  26079. var sequence = !!(b & 0x10);
  26080. var dataSize = b & 15;
  26081. assert(dataSize + 1 <= MAX_NUM_SIZE);
  26082. var ucs2DataSize = 1;
  26083. var subitemsCount = stream.readNumber();
  26084. var i;
  26085. switch (type) {
  26086. case 0: // codespacerange
  26087. stream.readHex(start, dataSize);
  26088. stream.readHexNumber(end, dataSize);
  26089. addHex(end, start, dataSize);
  26090. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  26091. hexToInt(end, dataSize));
  26092. for (i = 1; i < subitemsCount; i++) {
  26093. incHex(end, dataSize);
  26094. stream.readHexNumber(start, dataSize);
  26095. addHex(start, end, dataSize);
  26096. stream.readHexNumber(end, dataSize);
  26097. addHex(end, start, dataSize);
  26098. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  26099. hexToInt(end, dataSize));
  26100. }
  26101. break;
  26102. case 1: // notdefrange
  26103. stream.readHex(start, dataSize);
  26104. stream.readHexNumber(end, dataSize);
  26105. addHex(end, start, dataSize);
  26106. code = stream.readNumber();
  26107. // undefined range, skipping
  26108. for (i = 1; i < subitemsCount; i++) {
  26109. incHex(end, dataSize);
  26110. stream.readHexNumber(start, dataSize);
  26111. addHex(start, end, dataSize);
  26112. stream.readHexNumber(end, dataSize);
  26113. addHex(end, start, dataSize);
  26114. code = stream.readNumber();
  26115. // nop
  26116. }
  26117. break;
  26118. case 2: // cidchar
  26119. stream.readHex(char, dataSize);
  26120. code = stream.readNumber();
  26121. cMap.mapOne(hexToInt(char, dataSize), code);
  26122. for (i = 1; i < subitemsCount; i++) {
  26123. incHex(char, dataSize);
  26124. if (!sequence) {
  26125. stream.readHexNumber(tmp, dataSize);
  26126. addHex(char, tmp, dataSize);
  26127. }
  26128. code = stream.readSigned() + (code + 1);
  26129. cMap.mapOne(hexToInt(char, dataSize), code);
  26130. }
  26131. break;
  26132. case 3: // cidrange
  26133. stream.readHex(start, dataSize);
  26134. stream.readHexNumber(end, dataSize);
  26135. addHex(end, start, dataSize);
  26136. code = stream.readNumber();
  26137. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  26138. code);
  26139. for (i = 1; i < subitemsCount; i++) {
  26140. incHex(end, dataSize);
  26141. if (!sequence) {
  26142. stream.readHexNumber(start, dataSize);
  26143. addHex(start, end, dataSize);
  26144. } else {
  26145. start.set(end);
  26146. }
  26147. stream.readHexNumber(end, dataSize);
  26148. addHex(end, start, dataSize);
  26149. code = stream.readNumber();
  26150. cMap.mapCidRange(hexToInt(start, dataSize),
  26151. hexToInt(end, dataSize), code);
  26152. }
  26153. break;
  26154. case 4: // bfchar
  26155. stream.readHex(char, ucs2DataSize);
  26156. stream.readHex(charCode, dataSize);
  26157. cMap.mapOne(hexToInt(char, ucs2DataSize),
  26158. hexToStr(charCode, dataSize));
  26159. for (i = 1; i < subitemsCount; i++) {
  26160. incHex(char, ucs2DataSize);
  26161. if (!sequence) {
  26162. stream.readHexNumber(tmp, ucs2DataSize);
  26163. addHex(char, tmp, ucs2DataSize);
  26164. }
  26165. incHex(charCode, dataSize);
  26166. stream.readHexSigned(tmp, dataSize);
  26167. addHex(charCode, tmp, dataSize);
  26168. cMap.mapOne(hexToInt(char, ucs2DataSize),
  26169. hexToStr(charCode, dataSize));
  26170. }
  26171. break;
  26172. case 5: // bfrange
  26173. stream.readHex(start, ucs2DataSize);
  26174. stream.readHexNumber(end, ucs2DataSize);
  26175. addHex(end, start, ucs2DataSize);
  26176. stream.readHex(charCode, dataSize);
  26177. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  26178. hexToInt(end, ucs2DataSize),
  26179. hexToStr(charCode, dataSize));
  26180. for (i = 1; i < subitemsCount; i++) {
  26181. incHex(end, ucs2DataSize);
  26182. if (!sequence) {
  26183. stream.readHexNumber(start, ucs2DataSize);
  26184. addHex(start, end, ucs2DataSize);
  26185. } else {
  26186. start.set(end);
  26187. }
  26188. stream.readHexNumber(end, ucs2DataSize);
  26189. addHex(end, start, ucs2DataSize);
  26190. stream.readHex(charCode, dataSize);
  26191. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  26192. hexToInt(end, ucs2DataSize),
  26193. hexToStr(charCode, dataSize));
  26194. }
  26195. break;
  26196. default:
  26197. error('Unknown type: ' + type);
  26198. break;
  26199. }
  26200. }
  26201. if (useCMap) {
  26202. return extend(useCMap);
  26203. }
  26204. return cMap;
  26205. });
  26206. }
  26207. function BinaryCMapReader() {}
  26208. BinaryCMapReader.prototype = {
  26209. read: processBinaryCMap
  26210. };
  26211. return BinaryCMapReader;
  26212. })();
  26213. var CMapFactory = (function CMapFactoryClosure() {
  26214. function strToInt(str) {
  26215. var a = 0;
  26216. for (var i = 0; i < str.length; i++) {
  26217. a = (a << 8) | str.charCodeAt(i);
  26218. }
  26219. return a >>> 0;
  26220. }
  26221. function expectString(obj) {
  26222. if (!isString(obj)) {
  26223. error('Malformed CMap: expected string.');
  26224. }
  26225. }
  26226. function expectInt(obj) {
  26227. if (!isInt(obj)) {
  26228. error('Malformed CMap: expected int.');
  26229. }
  26230. }
  26231. function parseBfChar(cMap, lexer) {
  26232. while (true) {
  26233. var obj = lexer.getObj();
  26234. if (isEOF(obj)) {
  26235. break;
  26236. }
  26237. if (isCmd(obj, 'endbfchar')) {
  26238. return;
  26239. }
  26240. expectString(obj);
  26241. var src = strToInt(obj);
  26242. obj = lexer.getObj();
  26243. // TODO are /dstName used?
  26244. expectString(obj);
  26245. var dst = obj;
  26246. cMap.mapOne(src, dst);
  26247. }
  26248. }
  26249. function parseBfRange(cMap, lexer) {
  26250. while (true) {
  26251. var obj = lexer.getObj();
  26252. if (isEOF(obj)) {
  26253. break;
  26254. }
  26255. if (isCmd(obj, 'endbfrange')) {
  26256. return;
  26257. }
  26258. expectString(obj);
  26259. var low = strToInt(obj);
  26260. obj = lexer.getObj();
  26261. expectString(obj);
  26262. var high = strToInt(obj);
  26263. obj = lexer.getObj();
  26264. if (isInt(obj) || isString(obj)) {
  26265. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  26266. cMap.mapBfRange(low, high, dstLow);
  26267. } else if (isCmd(obj, '[')) {
  26268. obj = lexer.getObj();
  26269. var array = [];
  26270. while (!isCmd(obj, ']') && !isEOF(obj)) {
  26271. array.push(obj);
  26272. obj = lexer.getObj();
  26273. }
  26274. cMap.mapBfRangeToArray(low, high, array);
  26275. } else {
  26276. break;
  26277. }
  26278. }
  26279. error('Invalid bf range.');
  26280. }
  26281. function parseCidChar(cMap, lexer) {
  26282. while (true) {
  26283. var obj = lexer.getObj();
  26284. if (isEOF(obj)) {
  26285. break;
  26286. }
  26287. if (isCmd(obj, 'endcidchar')) {
  26288. return;
  26289. }
  26290. expectString(obj);
  26291. var src = strToInt(obj);
  26292. obj = lexer.getObj();
  26293. expectInt(obj);
  26294. var dst = obj;
  26295. cMap.mapOne(src, dst);
  26296. }
  26297. }
  26298. function parseCidRange(cMap, lexer) {
  26299. while (true) {
  26300. var obj = lexer.getObj();
  26301. if (isEOF(obj)) {
  26302. break;
  26303. }
  26304. if (isCmd(obj, 'endcidrange')) {
  26305. return;
  26306. }
  26307. expectString(obj);
  26308. var low = strToInt(obj);
  26309. obj = lexer.getObj();
  26310. expectString(obj);
  26311. var high = strToInt(obj);
  26312. obj = lexer.getObj();
  26313. expectInt(obj);
  26314. var dstLow = obj;
  26315. cMap.mapCidRange(low, high, dstLow);
  26316. }
  26317. }
  26318. function parseCodespaceRange(cMap, lexer) {
  26319. while (true) {
  26320. var obj = lexer.getObj();
  26321. if (isEOF(obj)) {
  26322. break;
  26323. }
  26324. if (isCmd(obj, 'endcodespacerange')) {
  26325. return;
  26326. }
  26327. if (!isString(obj)) {
  26328. break;
  26329. }
  26330. var low = strToInt(obj);
  26331. obj = lexer.getObj();
  26332. if (!isString(obj)) {
  26333. break;
  26334. }
  26335. var high = strToInt(obj);
  26336. cMap.addCodespaceRange(obj.length, low, high);
  26337. }
  26338. error('Invalid codespace range.');
  26339. }
  26340. function parseWMode(cMap, lexer) {
  26341. var obj = lexer.getObj();
  26342. if (isInt(obj)) {
  26343. cMap.vertical = !!obj;
  26344. }
  26345. }
  26346. function parseCMapName(cMap, lexer) {
  26347. var obj = lexer.getObj();
  26348. if (isName(obj) && isString(obj.name)) {
  26349. cMap.name = obj.name;
  26350. }
  26351. }
  26352. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  26353. var previous;
  26354. var embededUseCMap;
  26355. objLoop: while (true) {
  26356. try {
  26357. var obj = lexer.getObj();
  26358. if (isEOF(obj)) {
  26359. break;
  26360. } else if (isName(obj)) {
  26361. if (obj.name === 'WMode') {
  26362. parseWMode(cMap, lexer);
  26363. } else if (obj.name === 'CMapName') {
  26364. parseCMapName(cMap, lexer);
  26365. }
  26366. previous = obj;
  26367. } else if (isCmd(obj)) {
  26368. switch (obj.cmd) {
  26369. case 'endcmap':
  26370. break objLoop;
  26371. case 'usecmap':
  26372. if (isName(previous)) {
  26373. embededUseCMap = previous.name;
  26374. }
  26375. break;
  26376. case 'begincodespacerange':
  26377. parseCodespaceRange(cMap, lexer);
  26378. break;
  26379. case 'beginbfchar':
  26380. parseBfChar(cMap, lexer);
  26381. break;
  26382. case 'begincidchar':
  26383. parseCidChar(cMap, lexer);
  26384. break;
  26385. case 'beginbfrange':
  26386. parseBfRange(cMap, lexer);
  26387. break;
  26388. case 'begincidrange':
  26389. parseCidRange(cMap, lexer);
  26390. break;
  26391. }
  26392. }
  26393. } catch (ex) {
  26394. if (ex instanceof MissingDataException) {
  26395. throw ex;
  26396. }
  26397. warn('Invalid cMap data: ' + ex);
  26398. continue;
  26399. }
  26400. }
  26401. if (!useCMap && embededUseCMap) {
  26402. // Load the usecmap definition from the file only if there wasn't one
  26403. // specified.
  26404. useCMap = embededUseCMap;
  26405. }
  26406. if (useCMap) {
  26407. return extendCMap(cMap, builtInCMapParams, useCMap);
  26408. }
  26409. return Promise.resolve(cMap);
  26410. }
  26411. function extendCMap(cMap, builtInCMapParams, useCMap) {
  26412. return createBuiltInCMap(useCMap, builtInCMapParams).then(
  26413. function(newCMap) {
  26414. cMap.useCMap = newCMap;
  26415. // If there aren't any code space ranges defined clone all the parent ones
  26416. // into this cMap.
  26417. if (cMap.numCodespaceRanges === 0) {
  26418. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  26419. for (var i = 0; i < useCodespaceRanges.length; i++) {
  26420. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  26421. }
  26422. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  26423. }
  26424. // Merge the map into the current one, making sure not to override
  26425. // any previously defined entries.
  26426. cMap.useCMap.forEach(function(key, value) {
  26427. if (!cMap.contains(key)) {
  26428. cMap.mapOne(key, cMap.useCMap.lookup(key));
  26429. }
  26430. });
  26431. return cMap;
  26432. });
  26433. }
  26434. function parseBinaryCMap(name, builtInCMapParams) {
  26435. var url = builtInCMapParams.url + name + '.bcmap';
  26436. var cMap = new CMap(true);
  26437. return new BinaryCMapReader().read(url, cMap, function (useCMap) {
  26438. return extendCMap(cMap, builtInCMapParams, useCMap);
  26439. });
  26440. }
  26441. function createBuiltInCMap(name, builtInCMapParams) {
  26442. if (name === 'Identity-H') {
  26443. return Promise.resolve(new IdentityCMap(false, 2));
  26444. } else if (name === 'Identity-V') {
  26445. return Promise.resolve(new IdentityCMap(true, 2));
  26446. }
  26447. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  26448. return Promise.reject(new Error('Unknown cMap name: ' + name));
  26449. }
  26450. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  26451. if (builtInCMapParams.packed) {
  26452. return parseBinaryCMap(name, builtInCMapParams);
  26453. }
  26454. return new Promise(function (resolve, reject) {
  26455. var url = builtInCMapParams.url + name;
  26456. var request = new XMLHttpRequest();
  26457. request.onreadystatechange = function () {
  26458. if (request.readyState === XMLHttpRequest.DONE) {
  26459. if (request.status === 200 || request.status === 0) {
  26460. var cMap = new CMap(true);
  26461. var lexer = new Lexer(new StringStream(request.responseText));
  26462. parseCMap(cMap, lexer, builtInCMapParams, null).then(
  26463. function (parsedCMap) {
  26464. resolve(parsedCMap);
  26465. });
  26466. } else {
  26467. reject(new Error('Unable to get cMap at: ' + url));
  26468. }
  26469. }
  26470. };
  26471. request.open('GET', url, true);
  26472. request.send(null);
  26473. });
  26474. }
  26475. return {
  26476. create: function (encoding, builtInCMapParams, useCMap) {
  26477. if (isName(encoding)) {
  26478. return createBuiltInCMap(encoding.name, builtInCMapParams);
  26479. } else if (isStream(encoding)) {
  26480. var cMap = new CMap();
  26481. var lexer = new Lexer(encoding);
  26482. return parseCMap(cMap, lexer, builtInCMapParams, useCMap).then(
  26483. function (parsedCMap) {
  26484. if (parsedCMap.isIdentityCMap) {
  26485. return createBuiltInCMap(parsedCMap.name, builtInCMapParams);
  26486. }
  26487. return parsedCMap;
  26488. });
  26489. }
  26490. return Promise.reject(new Error('Encoding required.'));
  26491. }
  26492. };
  26493. })();
  26494. exports.CMap = CMap;
  26495. exports.CMapFactory = CMapFactory;
  26496. exports.IdentityCMap = IdentityCMap;
  26497. }));
  26498. (function (root, factory) {
  26499. {
  26500. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  26501. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreGlyphList,
  26502. root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings,
  26503. root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode,
  26504. root.pdfjsCoreType1Parser, root.pdfjsCoreCFFParser);
  26505. }
  26506. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  26507. coreGlyphList, coreFontRenderer, coreEncodings,
  26508. coreStandardFonts, coreUnicode, coreType1Parser,
  26509. coreCFFParser) {
  26510. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  26511. var FontType = sharedUtil.FontType;
  26512. var assert = sharedUtil.assert;
  26513. var bytesToString = sharedUtil.bytesToString;
  26514. var error = sharedUtil.error;
  26515. var info = sharedUtil.info;
  26516. var isArray = sharedUtil.isArray;
  26517. var isInt = sharedUtil.isInt;
  26518. var isNum = sharedUtil.isNum;
  26519. var readUint32 = sharedUtil.readUint32;
  26520. var shadow = sharedUtil.shadow;
  26521. var string32 = sharedUtil.string32;
  26522. var warn = sharedUtil.warn;
  26523. var MissingDataException = sharedUtil.MissingDataException;
  26524. var isSpace = sharedUtil.isSpace;
  26525. var Stream = coreStream.Stream;
  26526. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  26527. var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
  26528. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  26529. var StandardEncoding = coreEncodings.StandardEncoding;
  26530. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  26531. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  26532. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  26533. var getEncoding = coreEncodings.getEncoding;
  26534. var getStdFontMap = coreStandardFonts.getStdFontMap;
  26535. var getNonStdFontMap = coreStandardFonts.getNonStdFontMap;
  26536. var getGlyphMapForStandardFonts = coreStandardFonts.getGlyphMapForStandardFonts;
  26537. var getSupplementalGlyphMapForArialBlack =
  26538. coreStandardFonts.getSupplementalGlyphMapForArialBlack;
  26539. var getUnicodeRangeFor = coreUnicode.getUnicodeRangeFor;
  26540. var mapSpecialUnicodeValues = coreUnicode.mapSpecialUnicodeValues;
  26541. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  26542. var Type1Parser = coreType1Parser.Type1Parser;
  26543. var CFFStandardStrings = coreCFFParser.CFFStandardStrings;
  26544. var CFFParser = coreCFFParser.CFFParser;
  26545. var CFFCompiler = coreCFFParser.CFFCompiler;
  26546. var CFF = coreCFFParser.CFF;
  26547. var CFFHeader = coreCFFParser.CFFHeader;
  26548. var CFFTopDict = coreCFFParser.CFFTopDict;
  26549. var CFFPrivateDict = coreCFFParser.CFFPrivateDict;
  26550. var CFFStrings = coreCFFParser.CFFStrings;
  26551. var CFFIndex = coreCFFParser.CFFIndex;
  26552. var CFFCharset = coreCFFParser.CFFCharset;
  26553. // Unicode Private Use Area
  26554. var PRIVATE_USE_OFFSET_START = 0xE000;
  26555. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  26556. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  26557. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  26558. // except for Type 3 fonts
  26559. var PDF_GLYPH_SPACE_UNITS = 1000;
  26560. // Accented charactars are not displayed properly on Windows, using this flag
  26561. // to control analysis of seac charstrings.
  26562. var SEAC_ANALYSIS_ENABLED = false;
  26563. var FontFlags = {
  26564. FixedPitch: 1,
  26565. Serif: 2,
  26566. Symbolic: 4,
  26567. Script: 8,
  26568. Nonsymbolic: 32,
  26569. Italic: 64,
  26570. AllCap: 65536,
  26571. SmallCap: 131072,
  26572. ForceBold: 262144
  26573. };
  26574. var MacStandardGlyphOrdering = [
  26575. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  26576. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  26577. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  26578. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  26579. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  26580. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  26581. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  26582. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  26583. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  26584. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  26585. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  26586. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  26587. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  26588. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  26589. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  26590. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  26591. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  26592. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  26593. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  26594. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  26595. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  26596. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  26597. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  26598. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  26599. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  26600. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  26601. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  26602. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  26603. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  26604. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  26605. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  26606. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  26607. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  26608. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  26609. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  26610. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  26611. function adjustWidths(properties) {
  26612. if (!properties.fontMatrix) {
  26613. return;
  26614. }
  26615. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  26616. return;
  26617. }
  26618. // adjusting width to fontMatrix scale
  26619. var scale = 0.001 / properties.fontMatrix[0];
  26620. var glyphsWidths = properties.widths;
  26621. for (var glyph in glyphsWidths) {
  26622. glyphsWidths[glyph] *= scale;
  26623. }
  26624. properties.defaultWidth *= scale;
  26625. }
  26626. function adjustToUnicode(properties, builtInEncoding) {
  26627. if (properties.hasIncludedToUnicodeMap) {
  26628. return; // The font dictionary has a `ToUnicode` entry.
  26629. }
  26630. if (properties.hasEncoding) {
  26631. return; // The font dictionary has an `Encoding` entry.
  26632. }
  26633. if (builtInEncoding === properties.defaultEncoding) {
  26634. return; // No point in trying to adjust `toUnicode` if the encodings match.
  26635. }
  26636. if (properties.toUnicode instanceof IdentityToUnicodeMap) {
  26637. return;
  26638. }
  26639. var toUnicode = [], glyphsUnicodeMap = getGlyphsUnicode();
  26640. for (var charCode in builtInEncoding) {
  26641. var glyphName = builtInEncoding[charCode];
  26642. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  26643. if (unicode !== -1) {
  26644. toUnicode[charCode] = String.fromCharCode(unicode);
  26645. }
  26646. }
  26647. properties.toUnicode.amend(toUnicode);
  26648. }
  26649. function getFontType(type, subtype) {
  26650. switch (type) {
  26651. case 'Type1':
  26652. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  26653. case 'CIDFontType0':
  26654. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  26655. FontType.CIDFONTTYPE0;
  26656. case 'OpenType':
  26657. return FontType.OPENTYPE;
  26658. case 'TrueType':
  26659. return FontType.TRUETYPE;
  26660. case 'CIDFontType2':
  26661. return FontType.CIDFONTTYPE2;
  26662. case 'MMType1':
  26663. return FontType.MMTYPE1;
  26664. case 'Type0':
  26665. return FontType.TYPE0;
  26666. default:
  26667. return FontType.UNKNOWN;
  26668. }
  26669. }
  26670. // Some bad PDF generators, e.g. Scribus PDF, include glyph names
  26671. // in a 'uniXXXX' format -- attempting to recover proper ones.
  26672. function recoverGlyphName(name, glyphsUnicodeMap) {
  26673. if (glyphsUnicodeMap[name] !== undefined) {
  26674. return name;
  26675. }
  26676. // The glyph name is non-standard, trying to recover.
  26677. var unicode = getUnicodeForGlyph(name, glyphsUnicodeMap);
  26678. if (unicode !== -1) {
  26679. for (var key in glyphsUnicodeMap) {
  26680. if (glyphsUnicodeMap[key] === unicode) {
  26681. return key;
  26682. }
  26683. }
  26684. }
  26685. info('Unable to recover a standard glyph name for: ' + name);
  26686. return name;
  26687. }
  26688. var Glyph = (function GlyphClosure() {
  26689. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  26690. isSpace, isInFont) {
  26691. this.fontChar = fontChar;
  26692. this.unicode = unicode;
  26693. this.accent = accent;
  26694. this.width = width;
  26695. this.vmetric = vmetric;
  26696. this.operatorListId = operatorListId;
  26697. this.isSpace = isSpace;
  26698. this.isInFont = isInFont;
  26699. }
  26700. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  26701. vmetric, operatorListId, isSpace,
  26702. isInFont) {
  26703. return this.fontChar === fontChar &&
  26704. this.unicode === unicode &&
  26705. this.accent === accent &&
  26706. this.width === width &&
  26707. this.vmetric === vmetric &&
  26708. this.operatorListId === operatorListId &&
  26709. this.isSpace === isSpace &&
  26710. this.isInFont === isInFont;
  26711. };
  26712. return Glyph;
  26713. })();
  26714. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  26715. function ToUnicodeMap(cmap) {
  26716. // The elements of this._map can be integers or strings, depending on how
  26717. // |cmap| was created.
  26718. this._map = cmap;
  26719. }
  26720. ToUnicodeMap.prototype = {
  26721. get length() {
  26722. return this._map.length;
  26723. },
  26724. forEach: function(callback) {
  26725. for (var charCode in this._map) {
  26726. callback(charCode, this._map[charCode].charCodeAt(0));
  26727. }
  26728. },
  26729. has: function(i) {
  26730. return this._map[i] !== undefined;
  26731. },
  26732. get: function(i) {
  26733. return this._map[i];
  26734. },
  26735. charCodeOf: function(v) {
  26736. return this._map.indexOf(v);
  26737. },
  26738. amend: function (map) {
  26739. for (var charCode in map) {
  26740. this._map[charCode] = map[charCode];
  26741. }
  26742. },
  26743. };
  26744. return ToUnicodeMap;
  26745. })();
  26746. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  26747. function IdentityToUnicodeMap(firstChar, lastChar) {
  26748. this.firstChar = firstChar;
  26749. this.lastChar = lastChar;
  26750. }
  26751. IdentityToUnicodeMap.prototype = {
  26752. get length() {
  26753. return (this.lastChar + 1) - this.firstChar;
  26754. },
  26755. forEach: function (callback) {
  26756. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  26757. callback(i, i);
  26758. }
  26759. },
  26760. has: function (i) {
  26761. return this.firstChar <= i && i <= this.lastChar;
  26762. },
  26763. get: function (i) {
  26764. if (this.firstChar <= i && i <= this.lastChar) {
  26765. return String.fromCharCode(i);
  26766. }
  26767. return undefined;
  26768. },
  26769. charCodeOf: function (v) {
  26770. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  26771. },
  26772. amend: function (map) {
  26773. error('Should not call amend()');
  26774. },
  26775. };
  26776. return IdentityToUnicodeMap;
  26777. })();
  26778. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  26779. function writeInt16(dest, offset, num) {
  26780. dest[offset] = (num >> 8) & 0xFF;
  26781. dest[offset + 1] = num & 0xFF;
  26782. }
  26783. function writeInt32(dest, offset, num) {
  26784. dest[offset] = (num >> 24) & 0xFF;
  26785. dest[offset + 1] = (num >> 16) & 0xFF;
  26786. dest[offset + 2] = (num >> 8) & 0xFF;
  26787. dest[offset + 3] = num & 0xFF;
  26788. }
  26789. function writeData(dest, offset, data) {
  26790. var i, ii;
  26791. if (data instanceof Uint8Array) {
  26792. dest.set(data, offset);
  26793. } else if (typeof data === 'string') {
  26794. for (i = 0, ii = data.length; i < ii; i++) {
  26795. dest[offset++] = data.charCodeAt(i) & 0xFF;
  26796. }
  26797. } else {
  26798. // treating everything else as array
  26799. for (i = 0, ii = data.length; i < ii; i++) {
  26800. dest[offset++] = data[i] & 0xFF;
  26801. }
  26802. }
  26803. }
  26804. function OpenTypeFileBuilder(sfnt) {
  26805. this.sfnt = sfnt;
  26806. this.tables = Object.create(null);
  26807. }
  26808. OpenTypeFileBuilder.getSearchParams =
  26809. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  26810. var maxPower2 = 1, log2 = 0;
  26811. while ((maxPower2 ^ entriesCount) > maxPower2) {
  26812. maxPower2 <<= 1;
  26813. log2++;
  26814. }
  26815. var searchRange = maxPower2 * entrySize;
  26816. return {
  26817. range: searchRange,
  26818. entry: log2,
  26819. rangeShift: entrySize * entriesCount - searchRange
  26820. };
  26821. };
  26822. var OTF_HEADER_SIZE = 12;
  26823. var OTF_TABLE_ENTRY_SIZE = 16;
  26824. OpenTypeFileBuilder.prototype = {
  26825. toArray: function OpenTypeFileBuilder_toArray() {
  26826. var sfnt = this.sfnt;
  26827. // Tables needs to be written by ascendant alphabetic order
  26828. var tables = this.tables;
  26829. var tablesNames = Object.keys(tables);
  26830. tablesNames.sort();
  26831. var numTables = tablesNames.length;
  26832. var i, j, jj, table, tableName;
  26833. // layout the tables data
  26834. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  26835. var tableOffsets = [offset];
  26836. for (i = 0; i < numTables; i++) {
  26837. table = tables[tablesNames[i]];
  26838. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  26839. offset += paddedLength;
  26840. tableOffsets.push(offset);
  26841. }
  26842. var file = new Uint8Array(offset);
  26843. // write the table data first (mostly for checksum)
  26844. for (i = 0; i < numTables; i++) {
  26845. table = tables[tablesNames[i]];
  26846. writeData(file, tableOffsets[i], table);
  26847. }
  26848. // sfnt version (4 bytes)
  26849. if (sfnt === 'true') {
  26850. // Windows hates the Mac TrueType sfnt version number
  26851. sfnt = string32(0x00010000);
  26852. }
  26853. file[0] = sfnt.charCodeAt(0) & 0xFF;
  26854. file[1] = sfnt.charCodeAt(1) & 0xFF;
  26855. file[2] = sfnt.charCodeAt(2) & 0xFF;
  26856. file[3] = sfnt.charCodeAt(3) & 0xFF;
  26857. // numTables (2 bytes)
  26858. writeInt16(file, 4, numTables);
  26859. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  26860. // searchRange (2 bytes)
  26861. writeInt16(file, 6, searchParams.range);
  26862. // entrySelector (2 bytes)
  26863. writeInt16(file, 8, searchParams.entry);
  26864. // rangeShift (2 bytes)
  26865. writeInt16(file, 10, searchParams.rangeShift);
  26866. offset = OTF_HEADER_SIZE;
  26867. // writing table entries
  26868. for (i = 0; i < numTables; i++) {
  26869. tableName = tablesNames[i];
  26870. file[offset] = tableName.charCodeAt(0) & 0xFF;
  26871. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  26872. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  26873. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  26874. // checksum
  26875. var checksum = 0;
  26876. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  26877. var quad = readUint32(file, j);
  26878. checksum = (checksum + quad) >>> 0;
  26879. }
  26880. writeInt32(file, offset + 4, checksum);
  26881. // offset
  26882. writeInt32(file, offset + 8, tableOffsets[i]);
  26883. // length
  26884. writeInt32(file, offset + 12, tables[tableName].length);
  26885. offset += OTF_TABLE_ENTRY_SIZE;
  26886. }
  26887. return file;
  26888. },
  26889. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  26890. if (tag in this.tables) {
  26891. throw new Error('Table ' + tag + ' already exists');
  26892. }
  26893. this.tables[tag] = data;
  26894. }
  26895. };
  26896. return OpenTypeFileBuilder;
  26897. })();
  26898. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  26899. // issues when they are painted on the canvas, e.g. complex-script shaping or
  26900. // control/whitespace characters. The ranges are listed in pairs: the first item
  26901. // is a code of the first problematic code, the second one is the next
  26902. // non-problematic code. The ranges must be in sorted order.
  26903. var ProblematicCharRanges = new Int32Array([
  26904. // Control characters.
  26905. 0x0000, 0x0020,
  26906. 0x007F, 0x00A1,
  26907. 0x00AD, 0x00AE,
  26908. // Chars that is used in complex-script shaping.
  26909. 0x0600, 0x0780,
  26910. 0x08A0, 0x10A0,
  26911. 0x1780, 0x1800,
  26912. 0x1C00, 0x1C50,
  26913. // General punctuation chars.
  26914. 0x2000, 0x2010,
  26915. 0x2011, 0x2012,
  26916. 0x2028, 0x2030,
  26917. 0x205F, 0x2070,
  26918. 0x25CC, 0x25CD,
  26919. 0x3000, 0x3001,
  26920. // Chars that is used in complex-script shaping.
  26921. 0xAA60, 0xAA80,
  26922. // Specials Unicode block.
  26923. 0xFFF0, 0x10000
  26924. ]);
  26925. /**
  26926. * 'Font' is the class the outside world should use, it encapsulate all the font
  26927. * decoding logics whatever type it is (assuming the font type is supported).
  26928. *
  26929. * For example to read a Type1 font and to attach it to the document:
  26930. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  26931. * type1Font.bind();
  26932. */
  26933. var Font = (function FontClosure() {
  26934. function Font(name, file, properties) {
  26935. var charCode, glyphName, unicode;
  26936. this.name = name;
  26937. this.loadedName = properties.loadedName;
  26938. this.isType3Font = properties.isType3Font;
  26939. this.sizes = [];
  26940. this.missingFile = false;
  26941. this.glyphCache = Object.create(null);
  26942. var names = name.split('+');
  26943. names = names.length > 1 ? names[1] : names[0];
  26944. names = names.split(/[-,_]/g)[0];
  26945. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  26946. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  26947. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  26948. var type = properties.type;
  26949. var subtype = properties.subtype;
  26950. this.type = type;
  26951. this.fallbackName = (this.isMonospace ? 'monospace' :
  26952. (this.isSerifFont ? 'serif' : 'sans-serif'));
  26953. this.differences = properties.differences;
  26954. this.widths = properties.widths;
  26955. this.defaultWidth = properties.defaultWidth;
  26956. this.composite = properties.composite;
  26957. this.wideChars = properties.wideChars;
  26958. this.cMap = properties.cMap;
  26959. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  26960. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  26961. this.fontMatrix = properties.fontMatrix;
  26962. this.bbox = properties.bbox;
  26963. this.toUnicode = properties.toUnicode;
  26964. this.toFontChar = [];
  26965. if (properties.type === 'Type3') {
  26966. for (charCode = 0; charCode < 256; charCode++) {
  26967. this.toFontChar[charCode] = (this.differences[charCode] ||
  26968. properties.defaultEncoding[charCode]);
  26969. }
  26970. this.fontType = FontType.TYPE3;
  26971. return;
  26972. }
  26973. this.cidEncoding = properties.cidEncoding;
  26974. this.vertical = properties.vertical;
  26975. if (this.vertical) {
  26976. this.vmetrics = properties.vmetrics;
  26977. this.defaultVMetrics = properties.defaultVMetrics;
  26978. }
  26979. var glyphsUnicodeMap;
  26980. if (!file || file.isEmpty) {
  26981. if (file) {
  26982. // Some bad PDF generators will include empty font files,
  26983. // attempting to recover by assuming that no file exists.
  26984. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  26985. }
  26986. this.missingFile = true;
  26987. // The file data is not specified. Trying to fix the font name
  26988. // to be used with the canvas.font.
  26989. var fontName = name.replace(/[,_]/g, '-');
  26990. var stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap();
  26991. var isStandardFont = !!stdFontMap[fontName] ||
  26992. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  26993. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  26994. this.bold = (fontName.search(/bold/gi) !== -1);
  26995. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  26996. (fontName.search(/italic/gi) !== -1));
  26997. // Use 'name' instead of 'fontName' here because the original
  26998. // name ArialBlack for example will be replaced by Helvetica.
  26999. this.black = (name.search(/Black/g) !== -1);
  27000. // if at least one width is present, remeasure all chars when exists
  27001. this.remeasure = Object.keys(this.widths).length > 0;
  27002. if (isStandardFont && type === 'CIDFontType2' &&
  27003. properties.cidEncoding.indexOf('Identity-') === 0) {
  27004. var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
  27005. // Standard fonts might be embedded as CID font without glyph mapping.
  27006. // Building one based on GlyphMapForStandardFonts.
  27007. var map = [];
  27008. for (charCode in GlyphMapForStandardFonts) {
  27009. map[+charCode] = GlyphMapForStandardFonts[charCode];
  27010. }
  27011. if (/ArialBlack/i.test(name)) {
  27012. var SupplementalGlyphMapForArialBlack =
  27013. getSupplementalGlyphMapForArialBlack();
  27014. for (charCode in SupplementalGlyphMapForArialBlack) {
  27015. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  27016. }
  27017. }
  27018. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  27019. if (!isIdentityUnicode) {
  27020. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  27021. map[+charCode] = unicodeCharCode;
  27022. });
  27023. }
  27024. this.toFontChar = map;
  27025. this.toUnicode = new ToUnicodeMap(map);
  27026. } else if (/Symbol/i.test(fontName)) {
  27027. this.toFontChar = buildToFontChar(SymbolSetEncoding, getGlyphsUnicode(),
  27028. properties.differences);
  27029. } else if (/Dingbats/i.test(fontName)) {
  27030. if (/Wingdings/i.test(name)) {
  27031. warn('Non-embedded Wingdings font, falling back to ZapfDingbats.');
  27032. }
  27033. this.toFontChar = buildToFontChar(ZapfDingbatsEncoding,
  27034. getDingbatsGlyphsUnicode(),
  27035. properties.differences);
  27036. } else if (isStandardFont) {
  27037. this.toFontChar = buildToFontChar(properties.defaultEncoding,
  27038. getGlyphsUnicode(),
  27039. properties.differences);
  27040. } else {
  27041. glyphsUnicodeMap = getGlyphsUnicode();
  27042. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  27043. if (!this.composite) {
  27044. glyphName = (properties.differences[charCode] ||
  27045. properties.defaultEncoding[charCode]);
  27046. unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  27047. if (unicode !== -1) {
  27048. unicodeCharCode = unicode;
  27049. }
  27050. }
  27051. this.toFontChar[charCode] = unicodeCharCode;
  27052. }.bind(this));
  27053. }
  27054. this.loadedName = fontName.split('-')[0];
  27055. this.loading = false;
  27056. this.fontType = getFontType(type, subtype);
  27057. return;
  27058. }
  27059. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  27060. if (subtype === 'Type1C') {
  27061. if (type !== 'Type1' && type !== 'MMType1') {
  27062. // Some TrueType fonts by mistake claim Type1C
  27063. if (isTrueTypeFile(file)) {
  27064. subtype = 'TrueType';
  27065. } else {
  27066. type = 'Type1';
  27067. }
  27068. } else if (isOpenTypeFile(file)) {
  27069. // Sometimes the type/subtype can be a complete lie (see issue7598.pdf).
  27070. type = subtype = 'OpenType';
  27071. }
  27072. }
  27073. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  27074. type = 'CIDFontType0';
  27075. }
  27076. if (subtype === 'OpenType') {
  27077. type = 'OpenType';
  27078. }
  27079. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  27080. if (type === 'CIDFontType0') {
  27081. if (isType1File(file)) {
  27082. subtype = 'CIDFontType0';
  27083. } else if (isOpenTypeFile(file)) {
  27084. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  27085. type = subtype = 'OpenType';
  27086. } else {
  27087. subtype = 'CIDFontType0C';
  27088. }
  27089. }
  27090. var data;
  27091. switch (type) {
  27092. case 'MMType1':
  27093. info('MMType1 font (' + name + '), falling back to Type1.');
  27094. /* falls through */
  27095. case 'Type1':
  27096. case 'CIDFontType0':
  27097. this.mimetype = 'font/opentype';
  27098. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  27099. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  27100. adjustWidths(properties);
  27101. // Wrap the CFF data inside an OTF font file
  27102. data = this.convert(name, cff, properties);
  27103. break;
  27104. case 'OpenType':
  27105. case 'TrueType':
  27106. case 'CIDFontType2':
  27107. this.mimetype = 'font/opentype';
  27108. // Repair the TrueType file. It is can be damaged in the point of
  27109. // view of the sanitizer
  27110. data = this.checkAndRepair(name, file, properties);
  27111. if (this.isOpenType) {
  27112. adjustWidths(properties);
  27113. type = 'OpenType';
  27114. }
  27115. break;
  27116. default:
  27117. error('Font ' + type + ' is not supported');
  27118. break;
  27119. }
  27120. this.data = data;
  27121. this.fontType = getFontType(type, subtype);
  27122. // Transfer some properties again that could change during font conversion
  27123. this.fontMatrix = properties.fontMatrix;
  27124. this.widths = properties.widths;
  27125. this.defaultWidth = properties.defaultWidth;
  27126. this.toUnicode = properties.toUnicode;
  27127. this.encoding = properties.baseEncoding;
  27128. this.seacMap = properties.seacMap;
  27129. this.loading = true;
  27130. }
  27131. Font.getFontID = (function () {
  27132. var ID = 1;
  27133. return function Font_getFontID() {
  27134. return String(ID++);
  27135. };
  27136. })();
  27137. function int16(b0, b1) {
  27138. return (b0 << 8) + b1;
  27139. }
  27140. function signedInt16(b0, b1) {
  27141. var value = (b0 << 8) + b1;
  27142. return value & (1 << 15) ? value - 0x10000 : value;
  27143. }
  27144. function int32(b0, b1, b2, b3) {
  27145. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  27146. }
  27147. function string16(value) {
  27148. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  27149. }
  27150. function safeString16(value) {
  27151. // clamp value to the 16-bit int range
  27152. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  27153. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  27154. }
  27155. function isTrueTypeFile(file) {
  27156. var header = file.peekBytes(4);
  27157. return readUint32(header, 0) === 0x00010000;
  27158. }
  27159. function isOpenTypeFile(file) {
  27160. var header = file.peekBytes(4);
  27161. return bytesToString(header) === 'OTTO';
  27162. }
  27163. function isType1File(file) {
  27164. var header = file.peekBytes(2);
  27165. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  27166. if (header[0] === 0x25 && header[1] === 0x21) {
  27167. return true;
  27168. }
  27169. // ... obviously some fonts violate that part of the specification,
  27170. // please refer to the comment in |Type1Font| below.
  27171. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  27172. return true;
  27173. }
  27174. return false;
  27175. }
  27176. function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
  27177. var toFontChar = [], unicode;
  27178. for (var i = 0, ii = encoding.length; i < ii; i++) {
  27179. unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap);
  27180. if (unicode !== -1) {
  27181. toFontChar[i] = unicode;
  27182. }
  27183. }
  27184. for (var charCode in differences) {
  27185. unicode = getUnicodeForGlyph(differences[charCode], glyphsUnicodeMap);
  27186. if (unicode !== -1) {
  27187. toFontChar[+charCode] = unicode;
  27188. }
  27189. }
  27190. return toFontChar;
  27191. }
  27192. /**
  27193. * Helper function for |adjustMapping|.
  27194. * @return {boolean}
  27195. */
  27196. function isProblematicUnicodeLocation(code) {
  27197. // Using binary search to find a range start.
  27198. var i = 0, j = ProblematicCharRanges.length - 1;
  27199. while (i < j) {
  27200. var c = (i + j + 1) >> 1;
  27201. if (code < ProblematicCharRanges[c]) {
  27202. j = c - 1;
  27203. } else {
  27204. i = c;
  27205. }
  27206. }
  27207. // Even index means code in problematic range.
  27208. return !(i & 1);
  27209. }
  27210. /**
  27211. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  27212. * with their unicode value. It also moves char codes that are in known
  27213. * problematic locations.
  27214. * @return {Object} Two properties:
  27215. * 'toFontChar' - maps original char codes(the value that will be read
  27216. * from commands such as show text) to the char codes that will be used in the
  27217. * font that we build
  27218. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  27219. */
  27220. function adjustMapping(charCodeToGlyphId, properties) {
  27221. var toUnicode = properties.toUnicode;
  27222. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  27223. var isIdentityUnicode =
  27224. properties.toUnicode instanceof IdentityToUnicodeMap;
  27225. var newMap = Object.create(null);
  27226. var toFontChar = [];
  27227. var usedFontCharCodes = [];
  27228. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  27229. for (var originalCharCode in charCodeToGlyphId) {
  27230. originalCharCode |= 0;
  27231. var glyphId = charCodeToGlyphId[originalCharCode];
  27232. var fontCharCode = originalCharCode;
  27233. // First try to map the value to a unicode position if a non identity map
  27234. // was created.
  27235. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  27236. var unicode = toUnicode.get(fontCharCode);
  27237. // TODO: Try to map ligatures to the correct spot.
  27238. if (unicode.length === 1) {
  27239. fontCharCode = unicode.charCodeAt(0);
  27240. }
  27241. }
  27242. // Try to move control characters, special characters and already mapped
  27243. // characters to the private use area since they will not be drawn by
  27244. // canvas if left in their current position. Also, move characters if the
  27245. // font was symbolic and there is only an identity unicode map since the
  27246. // characters probably aren't in the correct position (fixes an issue
  27247. // with firefox and thuluthfont).
  27248. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  27249. isProblematicUnicodeLocation(fontCharCode) ||
  27250. (isSymbolic && isIdentityUnicode)) &&
  27251. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  27252. // Loop to try and find a free spot in the private use area.
  27253. do {
  27254. fontCharCode = nextAvailableFontCharCode++;
  27255. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  27256. fontCharCode = 0xF020;
  27257. nextAvailableFontCharCode = fontCharCode + 1;
  27258. }
  27259. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  27260. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  27261. }
  27262. newMap[fontCharCode] = glyphId;
  27263. toFontChar[originalCharCode] = fontCharCode;
  27264. usedFontCharCodes[fontCharCode] = true;
  27265. }
  27266. return {
  27267. toFontChar: toFontChar,
  27268. charCodeToGlyphId: newMap,
  27269. nextAvailableFontCharCode: nextAvailableFontCharCode
  27270. };
  27271. }
  27272. function getRanges(glyphs, numGlyphs) {
  27273. // Array.sort() sorts by characters, not numerically, so convert to an
  27274. // array of characters.
  27275. var codes = [];
  27276. for (var charCode in glyphs) {
  27277. // Remove an invalid glyph ID mappings to make OTS happy.
  27278. if (glyphs[charCode] >= numGlyphs) {
  27279. continue;
  27280. }
  27281. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  27282. }
  27283. codes.sort(function fontGetRangesSort(a, b) {
  27284. return a.fontCharCode - b.fontCharCode;
  27285. });
  27286. // Split the sorted codes into ranges.
  27287. var ranges = [];
  27288. var length = codes.length;
  27289. for (var n = 0; n < length; ) {
  27290. var start = codes[n].fontCharCode;
  27291. var codeIndices = [codes[n].glyphId];
  27292. ++n;
  27293. var end = start;
  27294. while (n < length && end + 1 === codes[n].fontCharCode) {
  27295. codeIndices.push(codes[n].glyphId);
  27296. ++end;
  27297. ++n;
  27298. if (end === 0xFFFF) {
  27299. break;
  27300. }
  27301. }
  27302. ranges.push([start, end, codeIndices]);
  27303. }
  27304. return ranges;
  27305. }
  27306. function createCmapTable(glyphs, numGlyphs) {
  27307. var ranges = getRanges(glyphs, numGlyphs);
  27308. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  27309. var cmap = '\x00\x00' + // version
  27310. string16(numTables) + // numTables
  27311. '\x00\x03' + // platformID
  27312. '\x00\x01' + // encodingID
  27313. string32(4 + numTables * 8); // start of the table record
  27314. var i, ii, j, jj;
  27315. for (i = ranges.length - 1; i >= 0; --i) {
  27316. if (ranges[i][0] <= 0xFFFF) { break; }
  27317. }
  27318. var bmpLength = i + 1;
  27319. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  27320. ranges[i][1] = 0xFFFE;
  27321. }
  27322. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  27323. var segCount = bmpLength + trailingRangesCount;
  27324. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  27325. // Fill up the 4 parallel arrays describing the segments.
  27326. var startCount = '';
  27327. var endCount = '';
  27328. var idDeltas = '';
  27329. var idRangeOffsets = '';
  27330. var glyphsIds = '';
  27331. var bias = 0;
  27332. var range, start, end, codes;
  27333. for (i = 0, ii = bmpLength; i < ii; i++) {
  27334. range = ranges[i];
  27335. start = range[0];
  27336. end = range[1];
  27337. startCount += string16(start);
  27338. endCount += string16(end);
  27339. codes = range[2];
  27340. var contiguous = true;
  27341. for (j = 1, jj = codes.length; j < jj; ++j) {
  27342. if (codes[j] !== codes[j - 1] + 1) {
  27343. contiguous = false;
  27344. break;
  27345. }
  27346. }
  27347. if (!contiguous) {
  27348. var offset = (segCount - i) * 2 + bias * 2;
  27349. bias += (end - start + 1);
  27350. idDeltas += string16(0);
  27351. idRangeOffsets += string16(offset);
  27352. for (j = 0, jj = codes.length; j < jj; ++j) {
  27353. glyphsIds += string16(codes[j]);
  27354. }
  27355. } else {
  27356. var startCode = codes[0];
  27357. idDeltas += string16((startCode - start) & 0xFFFF);
  27358. idRangeOffsets += string16(0);
  27359. }
  27360. }
  27361. if (trailingRangesCount > 0) {
  27362. endCount += '\xFF\xFF';
  27363. startCount += '\xFF\xFF';
  27364. idDeltas += '\x00\x01';
  27365. idRangeOffsets += '\x00\x00';
  27366. }
  27367. var format314 = '\x00\x00' + // language
  27368. string16(2 * segCount) +
  27369. string16(searchParams.range) +
  27370. string16(searchParams.entry) +
  27371. string16(searchParams.rangeShift) +
  27372. endCount + '\x00\x00' + startCount +
  27373. idDeltas + idRangeOffsets + glyphsIds;
  27374. var format31012 = '';
  27375. var header31012 = '';
  27376. if (numTables > 1) {
  27377. cmap += '\x00\x03' + // platformID
  27378. '\x00\x0A' + // encodingID
  27379. string32(4 + numTables * 8 +
  27380. 4 + format314.length); // start of the table record
  27381. format31012 = '';
  27382. for (i = 0, ii = ranges.length; i < ii; i++) {
  27383. range = ranges[i];
  27384. start = range[0];
  27385. codes = range[2];
  27386. var code = codes[0];
  27387. for (j = 1, jj = codes.length; j < jj; ++j) {
  27388. if (codes[j] !== codes[j - 1] + 1) {
  27389. end = range[0] + j - 1;
  27390. format31012 += string32(start) + // startCharCode
  27391. string32(end) + // endCharCode
  27392. string32(code); // startGlyphID
  27393. start = end + 1;
  27394. code = codes[j];
  27395. }
  27396. }
  27397. format31012 += string32(start) + // startCharCode
  27398. string32(range[1]) + // endCharCode
  27399. string32(code); // startGlyphID
  27400. }
  27401. header31012 = '\x00\x0C' + // format
  27402. '\x00\x00' + // reserved
  27403. string32(format31012.length + 16) + // length
  27404. '\x00\x00\x00\x00' + // language
  27405. string32(format31012.length / 12); // nGroups
  27406. }
  27407. return cmap + '\x00\x04' + // format
  27408. string16(format314.length + 4) + // length
  27409. format314 + header31012 + format31012;
  27410. }
  27411. function validateOS2Table(os2) {
  27412. var stream = new Stream(os2.data);
  27413. var version = stream.getUint16();
  27414. // TODO verify all OS/2 tables fields, but currently we validate only those
  27415. // that give us issues
  27416. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  27417. var selection = stream.getUint16();
  27418. if (version < 4 && (selection & 0x0300)) {
  27419. return false;
  27420. }
  27421. var firstChar = stream.getUint16();
  27422. var lastChar = stream.getUint16();
  27423. if (firstChar > lastChar) {
  27424. return false;
  27425. }
  27426. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  27427. var usWinAscent = stream.getUint16();
  27428. if (usWinAscent === 0) { // makes font unreadable by windows
  27429. return false;
  27430. }
  27431. // OS/2 appears to be valid, resetting some fields
  27432. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  27433. return true;
  27434. }
  27435. function createOS2Table(properties, charstrings, override) {
  27436. override = override || {
  27437. unitsPerEm: 0,
  27438. yMax: 0,
  27439. yMin: 0,
  27440. ascent: 0,
  27441. descent: 0
  27442. };
  27443. var ulUnicodeRange1 = 0;
  27444. var ulUnicodeRange2 = 0;
  27445. var ulUnicodeRange3 = 0;
  27446. var ulUnicodeRange4 = 0;
  27447. var firstCharIndex = null;
  27448. var lastCharIndex = 0;
  27449. if (charstrings) {
  27450. for (var code in charstrings) {
  27451. code |= 0;
  27452. if (firstCharIndex > code || !firstCharIndex) {
  27453. firstCharIndex = code;
  27454. }
  27455. if (lastCharIndex < code) {
  27456. lastCharIndex = code;
  27457. }
  27458. var position = getUnicodeRangeFor(code);
  27459. if (position < 32) {
  27460. ulUnicodeRange1 |= 1 << position;
  27461. } else if (position < 64) {
  27462. ulUnicodeRange2 |= 1 << position - 32;
  27463. } else if (position < 96) {
  27464. ulUnicodeRange3 |= 1 << position - 64;
  27465. } else if (position < 123) {
  27466. ulUnicodeRange4 |= 1 << position - 96;
  27467. } else {
  27468. error('Unicode ranges Bits > 123 are reserved for internal usage');
  27469. }
  27470. }
  27471. } else {
  27472. // TODO
  27473. firstCharIndex = 0;
  27474. lastCharIndex = 255;
  27475. }
  27476. var bbox = properties.bbox || [0, 0, 0, 0];
  27477. var unitsPerEm = (override.unitsPerEm ||
  27478. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  27479. // if the font units differ to the PDF glyph space units
  27480. // then scale up the values
  27481. var scale = (properties.ascentScaled ? 1.0 :
  27482. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  27483. var typoAscent = (override.ascent ||
  27484. Math.round(scale * (properties.ascent || bbox[3])));
  27485. var typoDescent = (override.descent ||
  27486. Math.round(scale * (properties.descent || bbox[1])));
  27487. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  27488. typoDescent = -typoDescent; // fixing incorrect descent
  27489. }
  27490. var winAscent = override.yMax || typoAscent;
  27491. var winDescent = -override.yMin || -typoDescent;
  27492. return '\x00\x03' + // version
  27493. '\x02\x24' + // xAvgCharWidth
  27494. '\x01\xF4' + // usWeightClass
  27495. '\x00\x05' + // usWidthClass
  27496. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  27497. '\x02\x8A' + // ySubscriptXSize
  27498. '\x02\xBB' + // ySubscriptYSize
  27499. '\x00\x00' + // ySubscriptXOffset
  27500. '\x00\x8C' + // ySubscriptYOffset
  27501. '\x02\x8A' + // ySuperScriptXSize
  27502. '\x02\xBB' + // ySuperScriptYSize
  27503. '\x00\x00' + // ySuperScriptXOffset
  27504. '\x01\xDF' + // ySuperScriptYOffset
  27505. '\x00\x31' + // yStrikeOutSize
  27506. '\x01\x02' + // yStrikeOutPosition
  27507. '\x00\x00' + // sFamilyClass
  27508. '\x00\x00\x06' +
  27509. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  27510. '\x00\x00\x00\x00\x00\x00' + // Panose
  27511. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  27512. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  27513. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  27514. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  27515. '\x2A\x32\x31\x2A' + // achVendID
  27516. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  27517. string16(firstCharIndex ||
  27518. properties.firstChar) + // usFirstCharIndex
  27519. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  27520. string16(typoAscent) + // sTypoAscender
  27521. string16(typoDescent) + // sTypoDescender
  27522. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  27523. string16(winAscent) + // usWinAscent
  27524. string16(winDescent) + // usWinDescent
  27525. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  27526. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  27527. string16(properties.xHeight) + // sxHeight
  27528. string16(properties.capHeight) + // sCapHeight
  27529. string16(0) + // usDefaultChar
  27530. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  27531. '\x00\x03'; // usMaxContext
  27532. }
  27533. function createPostTable(properties) {
  27534. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  27535. return ('\x00\x03\x00\x00' + // Version number
  27536. string32(angle) + // italicAngle
  27537. '\x00\x00' + // underlinePosition
  27538. '\x00\x00' + // underlineThickness
  27539. string32(properties.fixedPitch) + // isFixedPitch
  27540. '\x00\x00\x00\x00' + // minMemType42
  27541. '\x00\x00\x00\x00' + // maxMemType42
  27542. '\x00\x00\x00\x00' + // minMemType1
  27543. '\x00\x00\x00\x00'); // maxMemType1
  27544. }
  27545. function createNameTable(name, proto) {
  27546. if (!proto) {
  27547. proto = [[], []]; // no strings and unicode strings
  27548. }
  27549. var strings = [
  27550. proto[0][0] || 'Original licence', // 0.Copyright
  27551. proto[0][1] || name, // 1.Font family
  27552. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  27553. proto[0][3] || 'uniqueID', // 3.Unique ID
  27554. proto[0][4] || name, // 4.Full font name
  27555. proto[0][5] || 'Version 0.11', // 5.Version
  27556. proto[0][6] || '', // 6.Postscript name
  27557. proto[0][7] || 'Unknown', // 7.Trademark
  27558. proto[0][8] || 'Unknown', // 8.Manufacturer
  27559. proto[0][9] || 'Unknown' // 9.Designer
  27560. ];
  27561. // Mac want 1-byte per character strings while Windows want
  27562. // 2-bytes per character, so duplicate the names table
  27563. var stringsUnicode = [];
  27564. var i, ii, j, jj, str;
  27565. for (i = 0, ii = strings.length; i < ii; i++) {
  27566. str = proto[1][i] || strings[i];
  27567. var strBufUnicode = [];
  27568. for (j = 0, jj = str.length; j < jj; j++) {
  27569. strBufUnicode.push(string16(str.charCodeAt(j)));
  27570. }
  27571. stringsUnicode.push(strBufUnicode.join(''));
  27572. }
  27573. var names = [strings, stringsUnicode];
  27574. var platforms = ['\x00\x01', '\x00\x03'];
  27575. var encodings = ['\x00\x00', '\x00\x01'];
  27576. var languages = ['\x00\x00', '\x04\x09'];
  27577. var namesRecordCount = strings.length * platforms.length;
  27578. var nameTable =
  27579. '\x00\x00' + // format
  27580. string16(namesRecordCount) + // Number of names Record
  27581. string16(namesRecordCount * 12 + 6); // Storage
  27582. // Build the name records field
  27583. var strOffset = 0;
  27584. for (i = 0, ii = platforms.length; i < ii; i++) {
  27585. var strs = names[i];
  27586. for (j = 0, jj = strs.length; j < jj; j++) {
  27587. str = strs[j];
  27588. var nameRecord =
  27589. platforms[i] + // platform ID
  27590. encodings[i] + // encoding ID
  27591. languages[i] + // language ID
  27592. string16(j) + // name ID
  27593. string16(str.length) +
  27594. string16(strOffset);
  27595. nameTable += nameRecord;
  27596. strOffset += str.length;
  27597. }
  27598. }
  27599. nameTable += strings.join('') + stringsUnicode.join('');
  27600. return nameTable;
  27601. }
  27602. Font.prototype = {
  27603. name: null,
  27604. font: null,
  27605. mimetype: null,
  27606. encoding: null,
  27607. get renderer() {
  27608. var renderer = FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
  27609. return shadow(this, 'renderer', renderer);
  27610. },
  27611. exportData: function Font_exportData() {
  27612. // TODO remove enumerating of the properties, e.g. hardcode exact names.
  27613. var data = {};
  27614. for (var i in this) {
  27615. if (this.hasOwnProperty(i)) {
  27616. data[i] = this[i];
  27617. }
  27618. }
  27619. return data;
  27620. },
  27621. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  27622. function readTableEntry(file) {
  27623. var tag = bytesToString(file.getBytes(4));
  27624. var checksum = file.getInt32() >>> 0;
  27625. var offset = file.getInt32() >>> 0;
  27626. var length = file.getInt32() >>> 0;
  27627. // Read the table associated data
  27628. var previousPosition = file.pos;
  27629. file.pos = file.start ? file.start : 0;
  27630. file.skip(offset);
  27631. var data = file.getBytes(length);
  27632. file.pos = previousPosition;
  27633. if (tag === 'head') {
  27634. // clearing checksum adjustment
  27635. data[8] = data[9] = data[10] = data[11] = 0;
  27636. data[17] |= 0x20; //Set font optimized for cleartype flag
  27637. }
  27638. return {
  27639. tag: tag,
  27640. checksum: checksum,
  27641. length: length,
  27642. offset: offset,
  27643. data: data
  27644. };
  27645. }
  27646. function readOpenTypeHeader(ttf) {
  27647. return {
  27648. version: bytesToString(ttf.getBytes(4)),
  27649. numTables: ttf.getUint16(),
  27650. searchRange: ttf.getUint16(),
  27651. entrySelector: ttf.getUint16(),
  27652. rangeShift: ttf.getUint16()
  27653. };
  27654. }
  27655. /**
  27656. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  27657. * PDF spec
  27658. */
  27659. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  27660. if (!cmap) {
  27661. warn('No cmap table available.');
  27662. return {
  27663. platformId: -1,
  27664. encodingId: -1,
  27665. mappings: [],
  27666. hasShortCmap: false
  27667. };
  27668. }
  27669. var segment;
  27670. var start = (font.start ? font.start : 0) + cmap.offset;
  27671. font.pos = start;
  27672. var version = font.getUint16();
  27673. var numTables = font.getUint16();
  27674. var potentialTable;
  27675. var canBreak = false;
  27676. // There's an order of preference in terms of which cmap subtable to
  27677. // use:
  27678. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  27679. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  27680. // The following takes advantage of the fact that the tables are sorted
  27681. // to work.
  27682. for (var i = 0; i < numTables; i++) {
  27683. var platformId = font.getUint16();
  27684. var encodingId = font.getUint16();
  27685. var offset = font.getInt32() >>> 0;
  27686. var useTable = false;
  27687. if (platformId === 0 && encodingId === 0) {
  27688. useTable = true;
  27689. // Continue the loop since there still may be a higher priority
  27690. // table.
  27691. } else if (platformId === 1 && encodingId === 0) {
  27692. useTable = true;
  27693. // Continue the loop since there still may be a higher priority
  27694. // table.
  27695. } else if (platformId === 3 && encodingId === 1 &&
  27696. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  27697. useTable = true;
  27698. if (!isSymbolicFont) {
  27699. canBreak = true;
  27700. }
  27701. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  27702. useTable = true;
  27703. canBreak = true;
  27704. }
  27705. if (useTable) {
  27706. potentialTable = {
  27707. platformId: platformId,
  27708. encodingId: encodingId,
  27709. offset: offset
  27710. };
  27711. }
  27712. if (canBreak) {
  27713. break;
  27714. }
  27715. }
  27716. if (potentialTable) {
  27717. font.pos = start + potentialTable.offset;
  27718. }
  27719. if (!potentialTable || font.peekByte() === -1) {
  27720. warn('Could not find a preferred cmap table.');
  27721. return {
  27722. platformId: -1,
  27723. encodingId: -1,
  27724. mappings: [],
  27725. hasShortCmap: false
  27726. };
  27727. }
  27728. var format = font.getUint16();
  27729. var length = font.getUint16();
  27730. var language = font.getUint16();
  27731. var hasShortCmap = false;
  27732. var mappings = [];
  27733. var j, glyphId;
  27734. // TODO(mack): refactor this cmap subtable reading logic out
  27735. if (format === 0) {
  27736. for (j = 0; j < 256; j++) {
  27737. var index = font.getByte();
  27738. if (!index) {
  27739. continue;
  27740. }
  27741. mappings.push({
  27742. charCode: j,
  27743. glyphId: index
  27744. });
  27745. }
  27746. hasShortCmap = true;
  27747. } else if (format === 4) {
  27748. // re-creating the table in format 4 since the encoding
  27749. // might be changed
  27750. var segCount = (font.getUint16() >> 1);
  27751. font.getBytes(6); // skipping range fields
  27752. var segIndex, segments = [];
  27753. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27754. segments.push({ end: font.getUint16() });
  27755. }
  27756. font.getUint16();
  27757. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27758. segments[segIndex].start = font.getUint16();
  27759. }
  27760. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27761. segments[segIndex].delta = font.getUint16();
  27762. }
  27763. var offsetsCount = 0;
  27764. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27765. segment = segments[segIndex];
  27766. var rangeOffset = font.getUint16();
  27767. if (!rangeOffset) {
  27768. segment.offsetIndex = -1;
  27769. continue;
  27770. }
  27771. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  27772. segment.offsetIndex = offsetIndex;
  27773. offsetsCount = Math.max(offsetsCount, offsetIndex +
  27774. segment.end - segment.start + 1);
  27775. }
  27776. var offsets = [];
  27777. for (j = 0; j < offsetsCount; j++) {
  27778. offsets.push(font.getUint16());
  27779. }
  27780. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27781. segment = segments[segIndex];
  27782. start = segment.start;
  27783. var end = segment.end;
  27784. var delta = segment.delta;
  27785. offsetIndex = segment.offsetIndex;
  27786. for (j = start; j <= end; j++) {
  27787. if (j === 0xFFFF) {
  27788. continue;
  27789. }
  27790. glyphId = (offsetIndex < 0 ?
  27791. j : offsets[offsetIndex + j - start]);
  27792. glyphId = (glyphId + delta) & 0xFFFF;
  27793. if (glyphId === 0) {
  27794. continue;
  27795. }
  27796. mappings.push({
  27797. charCode: j,
  27798. glyphId: glyphId
  27799. });
  27800. }
  27801. }
  27802. } else if (format === 6) {
  27803. // Format 6 is a 2-bytes dense mapping, which means the font data
  27804. // lives glue together even if they are pretty far in the unicode
  27805. // table. (This looks weird, so I can have missed something), this
  27806. // works on Linux but seems to fails on Mac so let's rewrite the
  27807. // cmap table to a 3-1-4 style
  27808. var firstCode = font.getUint16();
  27809. var entryCount = font.getUint16();
  27810. for (j = 0; j < entryCount; j++) {
  27811. glyphId = font.getUint16();
  27812. var charCode = firstCode + j;
  27813. mappings.push({
  27814. charCode: charCode,
  27815. glyphId: glyphId
  27816. });
  27817. }
  27818. } else {
  27819. warn('cmap table has unsupported format: ' + format);
  27820. return {
  27821. platformId: -1,
  27822. encodingId: -1,
  27823. mappings: [],
  27824. hasShortCmap: false
  27825. };
  27826. }
  27827. // removing duplicate entries
  27828. mappings.sort(function (a, b) {
  27829. return a.charCode - b.charCode;
  27830. });
  27831. for (i = 1; i < mappings.length; i++) {
  27832. if (mappings[i - 1].charCode === mappings[i].charCode) {
  27833. mappings.splice(i, 1);
  27834. i--;
  27835. }
  27836. }
  27837. return {
  27838. platformId: potentialTable.platformId,
  27839. encodingId: potentialTable.encodingId,
  27840. mappings: mappings,
  27841. hasShortCmap: hasShortCmap
  27842. };
  27843. }
  27844. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  27845. if (!header) {
  27846. if (metrics) {
  27847. metrics.data = null;
  27848. }
  27849. return;
  27850. }
  27851. font.pos = (font.start ? font.start : 0) + header.offset;
  27852. font.pos += header.length - 2;
  27853. var numOfMetrics = font.getUint16();
  27854. if (numOfMetrics > numGlyphs) {
  27855. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  27856. 'greater than the numGlyphs (' + numGlyphs + ')');
  27857. // Reduce numOfMetrics if it is greater than numGlyphs
  27858. numOfMetrics = numGlyphs;
  27859. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  27860. header.data[35] = numOfMetrics & 0x00ff;
  27861. }
  27862. var numOfSidebearings = numGlyphs - numOfMetrics;
  27863. var numMissing = numOfSidebearings -
  27864. ((metrics.length - numOfMetrics * 4) >> 1);
  27865. if (numMissing > 0) {
  27866. // For each missing glyph, we set both the width and lsb to 0 (zero).
  27867. // Since we need to add two properties for each glyph, this explains
  27868. // the use of |numMissing * 2| when initializing the typed array.
  27869. var entries = new Uint8Array(metrics.length + numMissing * 2);
  27870. entries.set(metrics.data);
  27871. metrics.data = entries;
  27872. }
  27873. }
  27874. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  27875. hintsValid) {
  27876. if (sourceEnd - sourceStart <= 12) {
  27877. // glyph with data less than 12 is invalid one
  27878. return 0;
  27879. }
  27880. var glyf = source.subarray(sourceStart, sourceEnd);
  27881. var contoursCount = (glyf[0] << 8) | glyf[1];
  27882. if (contoursCount & 0x8000) {
  27883. // complex glyph, writing as is
  27884. dest.set(glyf, destStart);
  27885. return glyf.length;
  27886. }
  27887. var i, j = 10, flagsCount = 0;
  27888. for (i = 0; i < contoursCount; i++) {
  27889. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  27890. flagsCount = endPoint + 1;
  27891. j += 2;
  27892. }
  27893. // skipping instructions
  27894. var instructionsStart = j;
  27895. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  27896. j += 2 + instructionsLength;
  27897. var instructionsEnd = j;
  27898. // validating flags
  27899. var coordinatesLength = 0;
  27900. for (i = 0; i < flagsCount; i++) {
  27901. var flag = glyf[j++];
  27902. if (flag & 0xC0) {
  27903. // reserved flags must be zero, cleaning up
  27904. glyf[j - 1] = flag & 0x3F;
  27905. }
  27906. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  27907. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  27908. coordinatesLength += xyLength;
  27909. if (flag & 8) {
  27910. var repeat = glyf[j++];
  27911. i += repeat;
  27912. coordinatesLength += repeat * xyLength;
  27913. }
  27914. }
  27915. // glyph without coordinates will be rejected
  27916. if (coordinatesLength === 0) {
  27917. return 0;
  27918. }
  27919. var glyphDataLength = j + coordinatesLength;
  27920. if (glyphDataLength > glyf.length) {
  27921. // not enough data for coordinates
  27922. return 0;
  27923. }
  27924. if (!hintsValid && instructionsLength > 0) {
  27925. dest.set(glyf.subarray(0, instructionsStart), destStart);
  27926. dest.set([0, 0], destStart + instructionsStart);
  27927. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  27928. destStart + instructionsStart + 2);
  27929. glyphDataLength -= instructionsLength;
  27930. if (glyf.length - glyphDataLength > 3) {
  27931. glyphDataLength = (glyphDataLength + 3) & ~3;
  27932. }
  27933. return glyphDataLength;
  27934. }
  27935. if (glyf.length - glyphDataLength > 3) {
  27936. // truncating and aligning to 4 bytes the long glyph data
  27937. glyphDataLength = (glyphDataLength + 3) & ~3;
  27938. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  27939. return glyphDataLength;
  27940. }
  27941. // glyph data is fine
  27942. dest.set(glyf, destStart);
  27943. return glyf.length;
  27944. }
  27945. function sanitizeHead(head, numGlyphs, locaLength) {
  27946. var data = head.data;
  27947. // Validate version:
  27948. // Should always be 0x00010000
  27949. var version = int32(data[0], data[1], data[2], data[3]);
  27950. if (version >> 16 !== 1) {
  27951. info('Attempting to fix invalid version in head table: ' + version);
  27952. data[0] = 0;
  27953. data[1] = 1;
  27954. data[2] = 0;
  27955. data[3] = 0;
  27956. }
  27957. var indexToLocFormat = int16(data[50], data[51]);
  27958. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  27959. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  27960. indexToLocFormat);
  27961. // The value of indexToLocFormat should be 0 if the loca table
  27962. // consists of short offsets, and should be 1 if the loca table
  27963. // consists of long offsets.
  27964. //
  27965. // The number of entries in the loca table should be numGlyphs + 1.
  27966. //
  27967. // Using this information, we can work backwards to deduce if the
  27968. // size of each offset in the loca table, and thus figure out the
  27969. // appropriate value for indexToLocFormat.
  27970. var numGlyphsPlusOne = numGlyphs + 1;
  27971. if (locaLength === numGlyphsPlusOne << 1) {
  27972. // 0x0000 indicates the loca table consists of short offsets
  27973. data[50] = 0;
  27974. data[51] = 0;
  27975. } else if (locaLength === numGlyphsPlusOne << 2) {
  27976. // 0x0001 indicates the loca table consists of long offsets
  27977. data[50] = 0;
  27978. data[51] = 1;
  27979. } else {
  27980. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  27981. }
  27982. }
  27983. }
  27984. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  27985. isGlyphLocationsLong, hintsValid,
  27986. dupFirstEntry) {
  27987. var itemSize, itemDecode, itemEncode;
  27988. if (isGlyphLocationsLong) {
  27989. itemSize = 4;
  27990. itemDecode = function fontItemDecodeLong(data, offset) {
  27991. return (data[offset] << 24) | (data[offset + 1] << 16) |
  27992. (data[offset + 2] << 8) | data[offset + 3];
  27993. };
  27994. itemEncode = function fontItemEncodeLong(data, offset, value) {
  27995. data[offset] = (value >>> 24) & 0xFF;
  27996. data[offset + 1] = (value >> 16) & 0xFF;
  27997. data[offset + 2] = (value >> 8) & 0xFF;
  27998. data[offset + 3] = value & 0xFF;
  27999. };
  28000. } else {
  28001. itemSize = 2;
  28002. itemDecode = function fontItemDecode(data, offset) {
  28003. return (data[offset] << 9) | (data[offset + 1] << 1);
  28004. };
  28005. itemEncode = function fontItemEncode(data, offset, value) {
  28006. data[offset] = (value >> 9) & 0xFF;
  28007. data[offset + 1] = (value >> 1) & 0xFF;
  28008. };
  28009. }
  28010. var locaData = loca.data;
  28011. var locaDataSize = itemSize * (1 + numGlyphs);
  28012. // is loca.data too short or long?
  28013. if (locaData.length !== locaDataSize) {
  28014. locaData = new Uint8Array(locaDataSize);
  28015. locaData.set(loca.data.subarray(0, locaDataSize));
  28016. loca.data = locaData;
  28017. }
  28018. // removing the invalid glyphs
  28019. var oldGlyfData = glyf.data;
  28020. var oldGlyfDataLength = oldGlyfData.length;
  28021. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  28022. var startOffset = itemDecode(locaData, 0);
  28023. var writeOffset = 0;
  28024. var missingGlyphData = Object.create(null);
  28025. itemEncode(locaData, 0, writeOffset);
  28026. var i, j;
  28027. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  28028. var endOffset = itemDecode(locaData, j);
  28029. if (endOffset > oldGlyfDataLength &&
  28030. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  28031. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  28032. // the glyf table size, which makes last glyph out of range.
  28033. endOffset = oldGlyfDataLength;
  28034. }
  28035. if (endOffset > oldGlyfDataLength) {
  28036. // glyph end offset points outside glyf data, rejecting the glyph
  28037. itemEncode(locaData, j, writeOffset);
  28038. startOffset = endOffset;
  28039. continue;
  28040. }
  28041. if (startOffset === endOffset) {
  28042. missingGlyphData[i] = true;
  28043. }
  28044. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  28045. newGlyfData, writeOffset, hintsValid);
  28046. writeOffset += newLength;
  28047. itemEncode(locaData, j, writeOffset);
  28048. startOffset = endOffset;
  28049. }
  28050. if (writeOffset === 0) {
  28051. // glyf table cannot be empty -- redoing the glyf and loca tables
  28052. // to have single glyph with one point
  28053. var simpleGlyph = new Uint8Array(
  28054. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  28055. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  28056. itemEncode(locaData, j, simpleGlyph.length);
  28057. }
  28058. glyf.data = simpleGlyph;
  28059. return missingGlyphData;
  28060. }
  28061. if (dupFirstEntry) {
  28062. var firstEntryLength = itemDecode(locaData, itemSize);
  28063. if (newGlyfData.length > firstEntryLength + writeOffset) {
  28064. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  28065. } else {
  28066. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  28067. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  28068. }
  28069. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  28070. itemEncode(loca.data, locaData.length - itemSize,
  28071. writeOffset + firstEntryLength);
  28072. } else {
  28073. glyf.data = newGlyfData.subarray(0, writeOffset);
  28074. }
  28075. return missingGlyphData;
  28076. }
  28077. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  28078. var start = (font.start ? font.start : 0) + post.offset;
  28079. font.pos = start;
  28080. var length = post.length, end = start + length;
  28081. var version = font.getInt32();
  28082. // skip rest to the tables
  28083. font.getBytes(28);
  28084. var glyphNames;
  28085. var valid = true;
  28086. var i;
  28087. switch (version) {
  28088. case 0x00010000:
  28089. glyphNames = MacStandardGlyphOrdering;
  28090. break;
  28091. case 0x00020000:
  28092. var numGlyphs = font.getUint16();
  28093. if (numGlyphs !== maxpNumGlyphs) {
  28094. valid = false;
  28095. break;
  28096. }
  28097. var glyphNameIndexes = [];
  28098. for (i = 0; i < numGlyphs; ++i) {
  28099. var index = font.getUint16();
  28100. if (index >= 32768) {
  28101. valid = false;
  28102. break;
  28103. }
  28104. glyphNameIndexes.push(index);
  28105. }
  28106. if (!valid) {
  28107. break;
  28108. }
  28109. var customNames = [];
  28110. var strBuf = [];
  28111. while (font.pos < end) {
  28112. var stringLength = font.getByte();
  28113. strBuf.length = stringLength;
  28114. for (i = 0; i < stringLength; ++i) {
  28115. strBuf[i] = String.fromCharCode(font.getByte());
  28116. }
  28117. customNames.push(strBuf.join(''));
  28118. }
  28119. glyphNames = [];
  28120. for (i = 0; i < numGlyphs; ++i) {
  28121. var j = glyphNameIndexes[i];
  28122. if (j < 258) {
  28123. glyphNames.push(MacStandardGlyphOrdering[j]);
  28124. continue;
  28125. }
  28126. glyphNames.push(customNames[j - 258]);
  28127. }
  28128. break;
  28129. case 0x00030000:
  28130. break;
  28131. default:
  28132. warn('Unknown/unsupported post table version ' + version);
  28133. valid = false;
  28134. if (properties.defaultEncoding) {
  28135. glyphNames = properties.defaultEncoding;
  28136. }
  28137. break;
  28138. }
  28139. properties.glyphNames = glyphNames;
  28140. return valid;
  28141. }
  28142. function readNameTable(nameTable) {
  28143. var start = (font.start ? font.start : 0) + nameTable.offset;
  28144. font.pos = start;
  28145. var names = [[], []];
  28146. var length = nameTable.length, end = start + length;
  28147. var format = font.getUint16();
  28148. var FORMAT_0_HEADER_LENGTH = 6;
  28149. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  28150. // unsupported name table format or table "too" small
  28151. return names;
  28152. }
  28153. var numRecords = font.getUint16();
  28154. var stringsStart = font.getUint16();
  28155. var records = [];
  28156. var NAME_RECORD_LENGTH = 12;
  28157. var i, ii;
  28158. for (i = 0; i < numRecords &&
  28159. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  28160. var r = {
  28161. platform: font.getUint16(),
  28162. encoding: font.getUint16(),
  28163. language: font.getUint16(),
  28164. name: font.getUint16(),
  28165. length: font.getUint16(),
  28166. offset: font.getUint16()
  28167. };
  28168. // using only Macintosh and Windows platform/encoding names
  28169. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  28170. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  28171. records.push(r);
  28172. }
  28173. }
  28174. for (i = 0, ii = records.length; i < ii; i++) {
  28175. var record = records[i];
  28176. if (record.length <= 0) {
  28177. continue; // Nothing to process, ignoring.
  28178. }
  28179. var pos = start + stringsStart + record.offset;
  28180. if (pos + record.length > end) {
  28181. continue; // outside of name table, ignoring
  28182. }
  28183. font.pos = pos;
  28184. var nameIndex = record.name;
  28185. if (record.encoding) {
  28186. // unicode
  28187. var str = '';
  28188. for (var j = 0, jj = record.length; j < jj; j += 2) {
  28189. str += String.fromCharCode(font.getUint16());
  28190. }
  28191. names[1][nameIndex] = str;
  28192. } else {
  28193. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  28194. }
  28195. }
  28196. return names;
  28197. }
  28198. var TTOpsStackDeltas = [
  28199. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  28200. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  28201. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  28202. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  28203. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  28204. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  28205. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  28206. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  28207. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  28208. // 0xC0-DF == -1 and 0xE0-FF == -2
  28209. function sanitizeTTProgram(table, ttContext) {
  28210. var data = table.data;
  28211. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  28212. var stack = [];
  28213. var callstack = [];
  28214. var functionsCalled = [];
  28215. var tooComplexToFollowFunctions =
  28216. ttContext.tooComplexToFollowFunctions;
  28217. var inFDEF = false, ifLevel = 0, inELSE = 0;
  28218. for (var ii = data.length; i < ii;) {
  28219. var op = data[i++];
  28220. // The TrueType instruction set docs can be found at
  28221. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  28222. if (op === 0x40) { // NPUSHB - pushes n bytes
  28223. n = data[i++];
  28224. if (inFDEF || inELSE) {
  28225. i += n;
  28226. } else {
  28227. for (j = 0; j < n; j++) {
  28228. stack.push(data[i++]);
  28229. }
  28230. }
  28231. } else if (op === 0x41) { // NPUSHW - pushes n words
  28232. n = data[i++];
  28233. if (inFDEF || inELSE) {
  28234. i += n * 2;
  28235. } else {
  28236. for (j = 0; j < n; j++) {
  28237. b = data[i++];
  28238. stack.push((b << 8) | data[i++]);
  28239. }
  28240. }
  28241. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  28242. n = op - 0xB0 + 1;
  28243. if (inFDEF || inELSE) {
  28244. i += n;
  28245. } else {
  28246. for (j = 0; j < n; j++) {
  28247. stack.push(data[i++]);
  28248. }
  28249. }
  28250. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  28251. n = op - 0xB8 + 1;
  28252. if (inFDEF || inELSE) {
  28253. i += n * 2;
  28254. } else {
  28255. for (j = 0; j < n; j++) {
  28256. b = data[i++];
  28257. stack.push((b << 8) | data[i++]);
  28258. }
  28259. }
  28260. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  28261. if (!inFDEF && !inELSE) {
  28262. // collecting inforamtion about which functions are used
  28263. funcId = stack[stack.length - 1];
  28264. ttContext.functionsUsed[funcId] = true;
  28265. if (funcId in ttContext.functionsStackDeltas) {
  28266. stack.length += ttContext.functionsStackDeltas[funcId];
  28267. } else if (funcId in ttContext.functionsDefined &&
  28268. functionsCalled.indexOf(funcId) < 0) {
  28269. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  28270. functionsCalled.push(funcId);
  28271. pc = ttContext.functionsDefined[funcId];
  28272. if (!pc) {
  28273. warn('TT: CALL non-existent function');
  28274. ttContext.hintsValid = false;
  28275. return;
  28276. }
  28277. data = pc.data;
  28278. i = pc.i;
  28279. }
  28280. }
  28281. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  28282. if (inFDEF || inELSE) {
  28283. warn('TT: nested FDEFs not allowed');
  28284. tooComplexToFollowFunctions = true;
  28285. }
  28286. inFDEF = true;
  28287. // collecting inforamtion about which functions are defined
  28288. lastDeff = i;
  28289. funcId = stack.pop();
  28290. ttContext.functionsDefined[funcId] = {data: data, i: i};
  28291. } else if (op === 0x2D) { // ENDF - end of function
  28292. if (inFDEF) {
  28293. inFDEF = false;
  28294. lastEndf = i;
  28295. } else {
  28296. pc = callstack.pop();
  28297. if (!pc) {
  28298. warn('TT: ENDF bad stack');
  28299. ttContext.hintsValid = false;
  28300. return;
  28301. }
  28302. funcId = functionsCalled.pop();
  28303. data = pc.data;
  28304. i = pc.i;
  28305. ttContext.functionsStackDeltas[funcId] =
  28306. stack.length - pc.stackTop;
  28307. }
  28308. } else if (op === 0x89) { // IDEF - instruction definition
  28309. if (inFDEF || inELSE) {
  28310. warn('TT: nested IDEFs not allowed');
  28311. tooComplexToFollowFunctions = true;
  28312. }
  28313. inFDEF = true;
  28314. // recording it as a function to track ENDF
  28315. lastDeff = i;
  28316. } else if (op === 0x58) { // IF
  28317. ++ifLevel;
  28318. } else if (op === 0x1B) { // ELSE
  28319. inELSE = ifLevel;
  28320. } else if (op === 0x59) { // EIF
  28321. if (inELSE === ifLevel) {
  28322. inELSE = 0;
  28323. }
  28324. --ifLevel;
  28325. } else if (op === 0x1C) { // JMPR
  28326. if (!inFDEF && !inELSE) {
  28327. var offset = stack[stack.length - 1];
  28328. // only jumping forward to prevent infinite loop
  28329. if (offset > 0) {
  28330. i += offset - 1;
  28331. }
  28332. }
  28333. }
  28334. // Adjusting stack not extactly, but just enough to get function id
  28335. if (!inFDEF && !inELSE) {
  28336. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  28337. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  28338. if (op >= 0x71 && op <= 0x75) {
  28339. n = stack.pop();
  28340. if (n === n) {
  28341. stackDelta = -n * 2;
  28342. }
  28343. }
  28344. while (stackDelta < 0 && stack.length > 0) {
  28345. stack.pop();
  28346. stackDelta++;
  28347. }
  28348. while (stackDelta > 0) {
  28349. stack.push(NaN); // pushing any number into stack
  28350. stackDelta--;
  28351. }
  28352. }
  28353. }
  28354. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  28355. var content = [data];
  28356. if (i > data.length) {
  28357. content.push(new Uint8Array(i - data.length));
  28358. }
  28359. if (lastDeff > lastEndf) {
  28360. warn('TT: complementing a missing function tail');
  28361. // new function definition started, but not finished
  28362. // complete function by [CLEAR, ENDF]
  28363. content.push(new Uint8Array([0x22, 0x2D]));
  28364. }
  28365. foldTTTable(table, content);
  28366. }
  28367. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  28368. if (ttContext.tooComplexToFollowFunctions) {
  28369. return;
  28370. }
  28371. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  28372. warn('TT: more functions defined than expected');
  28373. ttContext.hintsValid = false;
  28374. return;
  28375. }
  28376. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  28377. if (j > maxFunctionDefs) {
  28378. warn('TT: invalid function id: ' + j);
  28379. ttContext.hintsValid = false;
  28380. return;
  28381. }
  28382. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  28383. warn('TT: undefined function: ' + j);
  28384. ttContext.hintsValid = false;
  28385. return;
  28386. }
  28387. }
  28388. }
  28389. function foldTTTable(table, content) {
  28390. if (content.length > 1) {
  28391. // concatenating the content items
  28392. var newLength = 0;
  28393. var j, jj;
  28394. for (j = 0, jj = content.length; j < jj; j++) {
  28395. newLength += content[j].length;
  28396. }
  28397. newLength = (newLength + 3) & ~3;
  28398. var result = new Uint8Array(newLength);
  28399. var pos = 0;
  28400. for (j = 0, jj = content.length; j < jj; j++) {
  28401. result.set(content[j], pos);
  28402. pos += content[j].length;
  28403. }
  28404. table.data = result;
  28405. table.length = newLength;
  28406. }
  28407. }
  28408. function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) {
  28409. var ttContext = {
  28410. functionsDefined: [],
  28411. functionsUsed: [],
  28412. functionsStackDeltas: [],
  28413. tooComplexToFollowFunctions: false,
  28414. hintsValid: true
  28415. };
  28416. if (fpgm) {
  28417. sanitizeTTProgram(fpgm, ttContext);
  28418. }
  28419. if (prep) {
  28420. sanitizeTTProgram(prep, ttContext);
  28421. }
  28422. if (fpgm) {
  28423. checkInvalidFunctions(ttContext, maxFunctionDefs);
  28424. }
  28425. if (cvt && (cvt.length & 1)) {
  28426. var cvtData = new Uint8Array(cvt.length + 1);
  28427. cvtData.set(cvt.data);
  28428. cvt.data = cvtData;
  28429. }
  28430. return ttContext.hintsValid;
  28431. }
  28432. // The following steps modify the original font data, making copy
  28433. font = new Stream(new Uint8Array(font.getBytes()));
  28434. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  28435. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  28436. var header = readOpenTypeHeader(font);
  28437. var numTables = header.numTables;
  28438. var cff, cffFile;
  28439. var tables = Object.create(null);
  28440. tables['OS/2'] = null;
  28441. tables['cmap'] = null;
  28442. tables['head'] = null;
  28443. tables['hhea'] = null;
  28444. tables['hmtx'] = null;
  28445. tables['maxp'] = null;
  28446. tables['name'] = null;
  28447. tables['post'] = null;
  28448. var table;
  28449. for (var i = 0; i < numTables; i++) {
  28450. table = readTableEntry(font);
  28451. if (VALID_TABLES.indexOf(table.tag) < 0) {
  28452. continue; // skipping table if it's not a required or optional table
  28453. }
  28454. if (table.length === 0) {
  28455. continue; // skipping empty tables
  28456. }
  28457. tables[table.tag] = table;
  28458. }
  28459. var isTrueType = !tables['CFF '];
  28460. if (!isTrueType) {
  28461. // OpenType font
  28462. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  28463. !tables['head'] || !tables['hhea'] || !tables['maxp'] ||
  28464. !tables['post']) {
  28465. // no major tables: throwing everything at CFFFont
  28466. cffFile = new Stream(tables['CFF '].data);
  28467. cff = new CFFFont(cffFile, properties);
  28468. adjustWidths(properties);
  28469. return this.convert(name, cff, properties);
  28470. }
  28471. delete tables['glyf'];
  28472. delete tables['loca'];
  28473. delete tables['fpgm'];
  28474. delete tables['prep'];
  28475. delete tables['cvt '];
  28476. this.isOpenType = true;
  28477. } else {
  28478. if (!tables['loca']) {
  28479. error('Required "loca" table is not found');
  28480. }
  28481. if (!tables['glyf']) {
  28482. warn('Required "glyf" table is not found -- trying to recover.');
  28483. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  28484. tables['glyf'] = {
  28485. tag: 'glyf',
  28486. data: new Uint8Array(0),
  28487. };
  28488. }
  28489. this.isOpenType = false;
  28490. }
  28491. if (!tables['maxp']) {
  28492. error('Required "maxp" table is not found');
  28493. }
  28494. font.pos = (font.start || 0) + tables['maxp'].offset;
  28495. var version = font.getInt32();
  28496. var numGlyphs = font.getUint16();
  28497. var maxFunctionDefs = 0;
  28498. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  28499. // maxZones can be invalid
  28500. font.pos += 8;
  28501. var maxZones = font.getUint16();
  28502. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  28503. tables['maxp'].data[14] = 0;
  28504. tables['maxp'].data[15] = 2;
  28505. }
  28506. font.pos += 4;
  28507. maxFunctionDefs = font.getUint16();
  28508. }
  28509. var dupFirstEntry = false;
  28510. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  28511. properties.toUnicode.get(0) > '\u0000') {
  28512. // oracle's defect (see 3427), duplicating first entry
  28513. dupFirstEntry = true;
  28514. numGlyphs++;
  28515. tables['maxp'].data[4] = numGlyphs >> 8;
  28516. tables['maxp'].data[5] = numGlyphs & 255;
  28517. }
  28518. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'],
  28519. tables['cvt '], maxFunctionDefs);
  28520. if (!hintsValid) {
  28521. delete tables['fpgm'];
  28522. delete tables['prep'];
  28523. delete tables['cvt '];
  28524. }
  28525. // Ensure the hmtx table contains the advance width and
  28526. // sidebearings information for numGlyphs in the maxp table
  28527. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  28528. if (!tables['head']) {
  28529. error('Required "head" table is not found');
  28530. }
  28531. sanitizeHead(tables['head'], numGlyphs,
  28532. isTrueType ? tables['loca'].length : 0);
  28533. var missingGlyphs = Object.create(null);
  28534. if (isTrueType) {
  28535. var isGlyphLocationsLong = int16(tables['head'].data[50],
  28536. tables['head'].data[51]);
  28537. missingGlyphs = sanitizeGlyphLocations(tables['loca'], tables['glyf'],
  28538. numGlyphs, isGlyphLocationsLong,
  28539. hintsValid, dupFirstEntry);
  28540. }
  28541. if (!tables['hhea']) {
  28542. error('Required "hhea" table is not found');
  28543. }
  28544. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  28545. // Sometimes it's 0. That needs to be fixed
  28546. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  28547. tables['hhea'].data[10] = 0xFF;
  28548. tables['hhea'].data[11] = 0xFF;
  28549. }
  28550. // Extract some more font properties from the OpenType head and
  28551. // hhea tables; yMin and descent value are always negative.
  28552. var metricsOverride = {
  28553. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  28554. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  28555. yMin: signedInt16(tables['head'].data[38], tables['head'].data[39]),
  28556. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  28557. descent: signedInt16(tables['hhea'].data[6], tables['hhea'].data[7])
  28558. };
  28559. // PDF FontDescriptor metrics lie -- using data from actual font.
  28560. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  28561. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  28562. // The 'post' table has glyphs names.
  28563. if (tables['post']) {
  28564. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  28565. if (!valid) {
  28566. tables['post'] = null;
  28567. }
  28568. }
  28569. var charCodeToGlyphId = [], charCode;
  28570. var toUnicode = properties.toUnicode, widths = properties.widths;
  28571. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  28572. toUnicode.length === 0x10000);
  28573. // Helper function to try to skip mapping of empty glyphs.
  28574. // Note: In some cases, just relying on the glyph data doesn't work,
  28575. // hence we also use a few heuristics to fix various PDF files.
  28576. function hasGlyph(glyphId, charCode, widthCode) {
  28577. if (!missingGlyphs[glyphId]) {
  28578. return true;
  28579. }
  28580. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  28581. return true;
  28582. }
  28583. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  28584. return true;
  28585. }
  28586. return false;
  28587. }
  28588. if (properties.type === 'CIDFontType2') {
  28589. var cidToGidMap = properties.cidToGidMap || [];
  28590. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  28591. properties.cMap.forEach(function(charCode, cid) {
  28592. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  28593. var glyphId = -1;
  28594. if (isCidToGidMapEmpty) {
  28595. glyphId = cid;
  28596. } else if (cidToGidMap[cid] !== undefined) {
  28597. glyphId = cidToGidMap[cid];
  28598. }
  28599. if (glyphId >= 0 && glyphId < numGlyphs &&
  28600. hasGlyph(glyphId, charCode, cid)) {
  28601. charCodeToGlyphId[charCode] = glyphId;
  28602. }
  28603. });
  28604. if (dupFirstEntry && (isCidToGidMapEmpty || !charCodeToGlyphId[0])) {
  28605. // We don't duplicate the first entry in the `charCodeToGlyphId` map
  28606. // if the font has a `CIDToGIDMap` which has already mapped the first
  28607. // entry to a non-zero `glyphId` (fixes issue7544.pdf).
  28608. charCodeToGlyphId[0] = numGlyphs - 1;
  28609. }
  28610. } else {
  28611. // Most of the following logic in this code branch is based on the
  28612. // 9.6.6.4 of the PDF spec.
  28613. var cmapTable = readCmapTable(tables['cmap'], font, this.isSymbolicFont,
  28614. properties.hasEncoding);
  28615. var cmapPlatformId = cmapTable.platformId;
  28616. var cmapEncodingId = cmapTable.encodingId;
  28617. var cmapMappings = cmapTable.mappings;
  28618. var cmapMappingsLength = cmapMappings.length;
  28619. // The spec seems to imply that if the font is symbolic the encoding
  28620. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  28621. // where the the font is symbolic and it has an encoding.
  28622. if (properties.hasEncoding &&
  28623. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  28624. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  28625. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  28626. !!getEncoding(properties.baseEncodingName))) { // Temporary hack
  28627. // When no preferred cmap table was found and |baseEncodingName| is
  28628. // one of the predefined encodings, we seem to obtain a better
  28629. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  28630. // TODO: Note that this is a hack which should be removed as soon as
  28631. // we have proper support for more exotic cmap tables.
  28632. var baseEncoding = [];
  28633. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  28634. properties.baseEncodingName === 'WinAnsiEncoding') {
  28635. baseEncoding = getEncoding(properties.baseEncodingName);
  28636. }
  28637. var glyphsUnicodeMap = getGlyphsUnicode();
  28638. for (charCode = 0; charCode < 256; charCode++) {
  28639. var glyphName, standardGlyphName;
  28640. if (this.differences && charCode in this.differences) {
  28641. glyphName = this.differences[charCode];
  28642. } else if (charCode in baseEncoding &&
  28643. baseEncoding[charCode] !== '') {
  28644. glyphName = baseEncoding[charCode];
  28645. } else {
  28646. glyphName = StandardEncoding[charCode];
  28647. }
  28648. if (!glyphName) {
  28649. continue;
  28650. }
  28651. // Ensure that non-standard glyph names are resolved to valid ones.
  28652. standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  28653. var unicodeOrCharCode, isUnicode = false;
  28654. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  28655. unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName];
  28656. isUnicode = true;
  28657. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  28658. // TODO: the encoding needs to be updated with mac os table.
  28659. unicodeOrCharCode = MacRomanEncoding.indexOf(standardGlyphName);
  28660. }
  28661. var found = false;
  28662. for (i = 0; i < cmapMappingsLength; ++i) {
  28663. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  28664. continue;
  28665. }
  28666. var code = isUnicode ? charCode : unicodeOrCharCode;
  28667. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  28668. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  28669. found = true;
  28670. break;
  28671. }
  28672. }
  28673. if (!found && properties.glyphNames) {
  28674. // Try to map using the post table.
  28675. var glyphId = properties.glyphNames.indexOf(glyphName);
  28676. // The post table ought to use the same kind of glyph names as the
  28677. // `differences` array, but check the standard ones as a fallback.
  28678. if (glyphId === -1 && standardGlyphName !== glyphName) {
  28679. glyphId = properties.glyphNames.indexOf(standardGlyphName);
  28680. }
  28681. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  28682. charCodeToGlyphId[charCode] = glyphId;
  28683. found = true;
  28684. }
  28685. }
  28686. if (!found) {
  28687. charCodeToGlyphId[charCode] = 0; // notdef
  28688. }
  28689. }
  28690. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  28691. // Default Unicode semantics, use the charcodes as is.
  28692. for (i = 0; i < cmapMappingsLength; ++i) {
  28693. charCodeToGlyphId[cmapMappings[i].charCode] =
  28694. cmapMappings[i].glyphId;
  28695. }
  28696. } else {
  28697. // For (3, 0) cmap tables:
  28698. // The charcode key being stored in charCodeToGlyphId is the lower
  28699. // byte of the two-byte charcodes of the cmap table since according to
  28700. // the spec: 'each byte from the string shall be prepended with the
  28701. // high byte of the range [of charcodes in the cmap table], to form
  28702. // a two-byte character, which shall be used to select the
  28703. // associated glyph description from the subtable'.
  28704. //
  28705. // For (1, 0) cmap tables:
  28706. // 'single bytes from the string shall be used to look up the
  28707. // associated glyph descriptions from the subtable'. This means
  28708. // charcodes in the cmap will be single bytes, so no-op since
  28709. // glyph.charCode & 0xFF === glyph.charCode
  28710. for (i = 0; i < cmapMappingsLength; ++i) {
  28711. charCode = cmapMappings[i].charCode & 0xFF;
  28712. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  28713. }
  28714. }
  28715. }
  28716. if (charCodeToGlyphId.length === 0) {
  28717. // defines at least one glyph
  28718. charCodeToGlyphId[0] = 0;
  28719. }
  28720. // Converting glyphs and ids into font's cmap table
  28721. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  28722. this.toFontChar = newMapping.toFontChar;
  28723. tables['cmap'] = {
  28724. tag: 'cmap',
  28725. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  28726. };
  28727. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  28728. tables['OS/2'] = {
  28729. tag: 'OS/2',
  28730. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  28731. metricsOverride)
  28732. };
  28733. }
  28734. // Rewrite the 'post' table if needed
  28735. if (!tables['post']) {
  28736. tables['post'] = {
  28737. tag: 'post',
  28738. data: createPostTable(properties)
  28739. };
  28740. }
  28741. if (!isTrueType) {
  28742. try {
  28743. // Trying to repair CFF file
  28744. cffFile = new Stream(tables['CFF '].data);
  28745. var parser = new CFFParser(cffFile, properties,
  28746. SEAC_ANALYSIS_ENABLED);
  28747. cff = parser.parse();
  28748. var compiler = new CFFCompiler(cff);
  28749. tables['CFF '].data = compiler.compile();
  28750. } catch (e) {
  28751. warn('Failed to compile font ' + properties.loadedName);
  28752. }
  28753. }
  28754. // Re-creating 'name' table
  28755. if (!tables['name']) {
  28756. tables['name'] = {
  28757. tag: 'name',
  28758. data: createNameTable(this.name)
  28759. };
  28760. } else {
  28761. // ... using existing 'name' table as prototype
  28762. var namePrototype = readNameTable(tables['name']);
  28763. tables['name'].data = createNameTable(name, namePrototype);
  28764. }
  28765. var builder = new OpenTypeFileBuilder(header.version);
  28766. for (var tableTag in tables) {
  28767. builder.addTable(tableTag, tables[tableTag].data);
  28768. }
  28769. return builder.toArray();
  28770. },
  28771. convert: function Font_convert(fontName, font, properties) {
  28772. // TODO: Check the charstring widths to determine this.
  28773. properties.fixedPitch = false;
  28774. if (properties.builtInEncoding) {
  28775. // For Type1 fonts that do not include either `ToUnicode` or `Encoding`
  28776. // data, attempt to use the `builtInEncoding` to improve text selection.
  28777. adjustToUnicode(properties, properties.builtInEncoding);
  28778. }
  28779. var mapping = font.getGlyphMapping(properties);
  28780. var newMapping = adjustMapping(mapping, properties);
  28781. this.toFontChar = newMapping.toFontChar;
  28782. var numGlyphs = font.numGlyphs;
  28783. function getCharCodes(charCodeToGlyphId, glyphId) {
  28784. var charCodes = null;
  28785. for (var charCode in charCodeToGlyphId) {
  28786. if (glyphId === charCodeToGlyphId[charCode]) {
  28787. if (!charCodes) {
  28788. charCodes = [];
  28789. }
  28790. charCodes.push(charCode | 0);
  28791. }
  28792. }
  28793. return charCodes;
  28794. }
  28795. function createCharCode(charCodeToGlyphId, glyphId) {
  28796. for (var charCode in charCodeToGlyphId) {
  28797. if (glyphId === charCodeToGlyphId[charCode]) {
  28798. return charCode | 0;
  28799. }
  28800. }
  28801. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  28802. glyphId;
  28803. return newMapping.nextAvailableFontCharCode++;
  28804. }
  28805. var seacs = font.seacs;
  28806. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  28807. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  28808. var charset = font.getCharset();
  28809. var seacMap = Object.create(null);
  28810. for (var glyphId in seacs) {
  28811. glyphId |= 0;
  28812. var seac = seacs[glyphId];
  28813. var baseGlyphName = StandardEncoding[seac[2]];
  28814. var accentGlyphName = StandardEncoding[seac[3]];
  28815. var baseGlyphId = charset.indexOf(baseGlyphName);
  28816. var accentGlyphId = charset.indexOf(accentGlyphName);
  28817. if (baseGlyphId < 0 || accentGlyphId < 0) {
  28818. continue;
  28819. }
  28820. var accentOffset = {
  28821. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  28822. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  28823. };
  28824. var charCodes = getCharCodes(mapping, glyphId);
  28825. if (!charCodes) {
  28826. // There's no point in mapping it if the char code was never mapped
  28827. // to begin with.
  28828. continue;
  28829. }
  28830. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  28831. var charCode = charCodes[i];
  28832. // Find a fontCharCode that maps to the base and accent glyphs.
  28833. // If one doesn't exists, create it.
  28834. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  28835. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  28836. baseGlyphId);
  28837. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  28838. accentGlyphId);
  28839. seacMap[charCode] = {
  28840. baseFontCharCode: baseFontCharCode,
  28841. accentFontCharCode: accentFontCharCode,
  28842. accentOffset: accentOffset
  28843. };
  28844. }
  28845. }
  28846. properties.seacMap = seacMap;
  28847. }
  28848. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  28849. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  28850. // PostScript Font Program
  28851. builder.addTable('CFF ', font.data);
  28852. // OS/2 and Windows Specific metrics
  28853. builder.addTable('OS/2', createOS2Table(properties,
  28854. newMapping.charCodeToGlyphId));
  28855. // Character to glyphs mapping
  28856. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  28857. numGlyphs));
  28858. // Font header
  28859. builder.addTable('head',
  28860. '\x00\x01\x00\x00' + // Version number
  28861. '\x00\x00\x10\x00' + // fontRevision
  28862. '\x00\x00\x00\x00' + // checksumAdjustement
  28863. '\x5F\x0F\x3C\xF5' + // magicNumber
  28864. '\x00\x00' + // Flags
  28865. safeString16(unitsPerEm) + // unitsPerEM
  28866. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  28867. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  28868. '\x00\x00' + // xMin
  28869. safeString16(properties.descent) + // yMin
  28870. '\x0F\xFF' + // xMax
  28871. safeString16(properties.ascent) + // yMax
  28872. string16(properties.italicAngle ? 2 : 0) + // macStyle
  28873. '\x00\x11' + // lowestRecPPEM
  28874. '\x00\x00' + // fontDirectionHint
  28875. '\x00\x00' + // indexToLocFormat
  28876. '\x00\x00'); // glyphDataFormat
  28877. // Horizontal header
  28878. builder.addTable('hhea',
  28879. '\x00\x01\x00\x00' + // Version number
  28880. safeString16(properties.ascent) + // Typographic Ascent
  28881. safeString16(properties.descent) + // Typographic Descent
  28882. '\x00\x00' + // Line Gap
  28883. '\xFF\xFF' + // advanceWidthMax
  28884. '\x00\x00' + // minLeftSidebearing
  28885. '\x00\x00' + // minRightSidebearing
  28886. '\x00\x00' + // xMaxExtent
  28887. safeString16(properties.capHeight) + // caretSlopeRise
  28888. safeString16(Math.tan(properties.italicAngle) *
  28889. properties.xHeight) + // caretSlopeRun
  28890. '\x00\x00' + // caretOffset
  28891. '\x00\x00' + // -reserved-
  28892. '\x00\x00' + // -reserved-
  28893. '\x00\x00' + // -reserved-
  28894. '\x00\x00' + // -reserved-
  28895. '\x00\x00' + // metricDataFormat
  28896. string16(numGlyphs)); // Number of HMetrics
  28897. // Horizontal metrics
  28898. builder.addTable('hmtx', (function fontFieldsHmtx() {
  28899. var charstrings = font.charstrings;
  28900. var cffWidths = font.cff ? font.cff.widths : null;
  28901. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  28902. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  28903. var width = 0;
  28904. if (charstrings) {
  28905. var charstring = charstrings[i - 1];
  28906. width = 'width' in charstring ? charstring.width : 0;
  28907. } else if (cffWidths) {
  28908. width = Math.ceil(cffWidths[i] || 0);
  28909. }
  28910. hmtx += string16(width) + string16(0);
  28911. }
  28912. return hmtx;
  28913. })());
  28914. // Maximum profile
  28915. builder.addTable('maxp',
  28916. '\x00\x00\x50\x00' + // Version number
  28917. string16(numGlyphs)); // Num of glyphs
  28918. // Naming tables
  28919. builder.addTable('name', createNameTable(fontName));
  28920. // PostScript information
  28921. builder.addTable('post', createPostTable(properties));
  28922. return builder.toArray();
  28923. },
  28924. get spaceWidth() {
  28925. if ('_shadowWidth' in this) {
  28926. return this._shadowWidth;
  28927. }
  28928. // trying to estimate space character width
  28929. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i', 'I'];
  28930. var width;
  28931. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  28932. var glyphName = possibleSpaceReplacements[i];
  28933. // if possible, getting width by glyph name
  28934. if (glyphName in this.widths) {
  28935. width = this.widths[glyphName];
  28936. break;
  28937. }
  28938. var glyphsUnicodeMap = getGlyphsUnicode();
  28939. var glyphUnicode = glyphsUnicodeMap[glyphName];
  28940. // finding the charcode via unicodeToCID map
  28941. var charcode = 0;
  28942. if (this.composite) {
  28943. if (this.cMap.contains(glyphUnicode)) {
  28944. charcode = this.cMap.lookup(glyphUnicode);
  28945. }
  28946. }
  28947. // ... via toUnicode map
  28948. if (!charcode && this.toUnicode) {
  28949. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  28950. }
  28951. // setting it to unicode if negative or undefined
  28952. if (charcode <= 0) {
  28953. charcode = glyphUnicode;
  28954. }
  28955. // trying to get width via charcode
  28956. width = this.widths[charcode];
  28957. if (width) {
  28958. break; // the non-zero width found
  28959. }
  28960. }
  28961. width = width || this.defaultWidth;
  28962. // Do not shadow the property here. See discussion:
  28963. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  28964. this._shadowWidth = width;
  28965. return width;
  28966. },
  28967. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  28968. var fontCharCode, width, operatorListId;
  28969. var widthCode = charcode;
  28970. if (this.cMap && this.cMap.contains(charcode)) {
  28971. widthCode = this.cMap.lookup(charcode);
  28972. }
  28973. width = this.widths[widthCode];
  28974. width = isNum(width) ? width : this.defaultWidth;
  28975. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  28976. var unicode = this.toUnicode.get(charcode) || charcode;
  28977. if (typeof unicode === 'number') {
  28978. unicode = String.fromCharCode(unicode);
  28979. }
  28980. var isInFont = charcode in this.toFontChar;
  28981. // First try the toFontChar map, if it's not there then try falling
  28982. // back to the char code.
  28983. fontCharCode = this.toFontChar[charcode] || charcode;
  28984. if (this.missingFile) {
  28985. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  28986. }
  28987. if (this.isType3Font) {
  28988. // Font char code in this case is actually a glyph name.
  28989. operatorListId = fontCharCode;
  28990. }
  28991. var accent = null;
  28992. if (this.seacMap && this.seacMap[charcode]) {
  28993. isInFont = true;
  28994. var seac = this.seacMap[charcode];
  28995. fontCharCode = seac.baseFontCharCode;
  28996. accent = {
  28997. fontChar: String.fromCharCode(seac.accentFontCharCode),
  28998. offset: seac.accentOffset
  28999. };
  29000. }
  29001. var fontChar = String.fromCharCode(fontCharCode);
  29002. var glyph = this.glyphCache[charcode];
  29003. if (!glyph ||
  29004. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  29005. operatorListId, isSpace, isInFont)) {
  29006. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  29007. operatorListId, isSpace, isInFont);
  29008. this.glyphCache[charcode] = glyph;
  29009. }
  29010. return glyph;
  29011. },
  29012. charsToGlyphs: function Font_charsToGlyphs(chars) {
  29013. var charsCache = this.charsCache;
  29014. var glyphs, glyph, charcode;
  29015. // if we translated this string before, just grab it from the cache
  29016. if (charsCache) {
  29017. glyphs = charsCache[chars];
  29018. if (glyphs) {
  29019. return glyphs;
  29020. }
  29021. }
  29022. // lazily create the translation cache
  29023. if (!charsCache) {
  29024. charsCache = this.charsCache = Object.create(null);
  29025. }
  29026. glyphs = [];
  29027. var charsCacheKey = chars;
  29028. var i = 0, ii;
  29029. if (this.cMap) {
  29030. // composite fonts have multi-byte strings convert the string from
  29031. // single-byte to multi-byte
  29032. var c = Object.create(null);
  29033. while (i < chars.length) {
  29034. this.cMap.readCharCode(chars, i, c);
  29035. charcode = c.charcode;
  29036. var length = c.length;
  29037. i += length;
  29038. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  29039. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  29040. glyph = this.charToGlyph(charcode, isSpace);
  29041. glyphs.push(glyph);
  29042. }
  29043. } else {
  29044. for (i = 0, ii = chars.length; i < ii; ++i) {
  29045. charcode = chars.charCodeAt(i);
  29046. glyph = this.charToGlyph(charcode, charcode === 0x20);
  29047. glyphs.push(glyph);
  29048. }
  29049. }
  29050. // Enter the translated string into the cache
  29051. return (charsCache[charsCacheKey] = glyphs);
  29052. }
  29053. };
  29054. return Font;
  29055. })();
  29056. var ErrorFont = (function ErrorFontClosure() {
  29057. function ErrorFont(error) {
  29058. this.error = error;
  29059. this.loadedName = 'g_font_error';
  29060. this.loading = false;
  29061. }
  29062. ErrorFont.prototype = {
  29063. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  29064. return [];
  29065. },
  29066. exportData: function ErrorFont_exportData() {
  29067. return {error: this.error};
  29068. }
  29069. };
  29070. return ErrorFont;
  29071. })();
  29072. /**
  29073. * Shared logic for building a char code to glyph id mapping for Type1 and
  29074. * simple CFF fonts. See section 9.6.6.2 of the spec.
  29075. * @param {Object} properties Font properties object.
  29076. * @param {Object} builtInEncoding The encoding contained within the actual font
  29077. * data.
  29078. * @param {Array} glyphNames Array of glyph names where the index is the
  29079. * glyph ID.
  29080. * @returns {Object} A char code to glyph ID map.
  29081. */
  29082. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  29083. var charCodeToGlyphId = Object.create(null);
  29084. var glyphId, charCode, baseEncoding;
  29085. if (properties.baseEncodingName) {
  29086. // If a valid base encoding name was used, the mapping is initialized with
  29087. // that.
  29088. baseEncoding = getEncoding(properties.baseEncodingName);
  29089. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  29090. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  29091. if (glyphId >= 0) {
  29092. charCodeToGlyphId[charCode] = glyphId;
  29093. } else {
  29094. charCodeToGlyphId[charCode] = 0; // notdef
  29095. }
  29096. }
  29097. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  29098. // For a symbolic font the encoding should be the fonts built-in
  29099. // encoding.
  29100. for (charCode in builtInEncoding) {
  29101. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  29102. }
  29103. } else {
  29104. // For non-symbolic fonts that don't have a base encoding the standard
  29105. // encoding should be used.
  29106. baseEncoding = StandardEncoding;
  29107. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  29108. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  29109. if (glyphId >= 0) {
  29110. charCodeToGlyphId[charCode] = glyphId;
  29111. } else {
  29112. charCodeToGlyphId[charCode] = 0; // notdef
  29113. }
  29114. }
  29115. }
  29116. // Lastly, merge in the differences.
  29117. var differences = properties.differences, glyphsUnicodeMap;
  29118. if (differences) {
  29119. for (charCode in differences) {
  29120. var glyphName = differences[charCode];
  29121. glyphId = glyphNames.indexOf(glyphName);
  29122. if (glyphId === -1) {
  29123. if (!glyphsUnicodeMap) {
  29124. glyphsUnicodeMap = getGlyphsUnicode();
  29125. }
  29126. var standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  29127. if (standardGlyphName !== glyphName) {
  29128. glyphId = glyphNames.indexOf(standardGlyphName);
  29129. }
  29130. }
  29131. if (glyphId >= 0) {
  29132. charCodeToGlyphId[charCode] = glyphId;
  29133. } else {
  29134. charCodeToGlyphId[charCode] = 0; // notdef
  29135. }
  29136. }
  29137. }
  29138. return charCodeToGlyphId;
  29139. }
  29140. // Type1Font is also a CIDFontType0.
  29141. var Type1Font = (function Type1FontClosure() {
  29142. function findBlock(streamBytes, signature, startIndex) {
  29143. var streamBytesLength = streamBytes.length;
  29144. var signatureLength = signature.length;
  29145. var scanLength = streamBytesLength - signatureLength;
  29146. var i = startIndex, j, found = false;
  29147. while (i < scanLength) {
  29148. j = 0;
  29149. while (j < signatureLength && streamBytes[i + j] === signature[j]) {
  29150. j++;
  29151. }
  29152. if (j >= signatureLength) { // `signature` found, skip over whitespace.
  29153. i += j;
  29154. while (i < streamBytesLength && isSpace(streamBytes[i])) {
  29155. i++;
  29156. }
  29157. found = true;
  29158. break;
  29159. }
  29160. i++;
  29161. }
  29162. return {
  29163. found: found,
  29164. length: i,
  29165. };
  29166. }
  29167. function getHeaderBlock(stream, suggestedLength) {
  29168. var EEXEC_SIGNATURE = [0x65, 0x65, 0x78, 0x65, 0x63];
  29169. var streamStartPos = stream.pos; // Save the initial stream position.
  29170. var headerBytes, headerBytesLength, block;
  29171. try {
  29172. headerBytes = stream.getBytes(suggestedLength);
  29173. headerBytesLength = headerBytes.length;
  29174. } catch (ex) {
  29175. if (ex instanceof MissingDataException) {
  29176. throw ex;
  29177. }
  29178. // Ignore errors if the `suggestedLength` is huge enough that a Uint8Array
  29179. // cannot hold the result of `getBytes`, and fallback to simply checking
  29180. // the entire stream (fixes issue3928.pdf).
  29181. }
  29182. if (headerBytesLength === suggestedLength) {
  29183. // Most of the time `suggestedLength` is correct, so to speed things up we
  29184. // initially only check the last few bytes to see if the header was found.
  29185. // Otherwise we (potentially) check the entire stream to prevent errors in
  29186. // `Type1Parser` (fixes issue5686.pdf).
  29187. block = findBlock(headerBytes, EEXEC_SIGNATURE,
  29188. suggestedLength - 2 * EEXEC_SIGNATURE.length);
  29189. if (block.found && block.length === suggestedLength) {
  29190. return {
  29191. stream: new Stream(headerBytes),
  29192. length: suggestedLength,
  29193. };
  29194. }
  29195. }
  29196. warn('Invalid "Length1" property in Type1 font -- trying to recover.');
  29197. stream.pos = streamStartPos; // Reset the stream position.
  29198. var SCAN_BLOCK_LENGTH = 2048;
  29199. var actualLength;
  29200. while (true) {
  29201. var scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
  29202. block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
  29203. if (block.length === 0) {
  29204. break;
  29205. }
  29206. stream.pos += block.length; // Update the stream position.
  29207. if (block.found) {
  29208. actualLength = stream.pos - streamStartPos;
  29209. break;
  29210. }
  29211. }
  29212. stream.pos = streamStartPos; // Reset the stream position.
  29213. if (actualLength) {
  29214. return {
  29215. stream: new Stream(stream.getBytes(actualLength)),
  29216. length: actualLength,
  29217. };
  29218. }
  29219. warn('Unable to recover "Length1" property in Type1 font -- using as is.');
  29220. return {
  29221. stream: new Stream(stream.getBytes(suggestedLength)),
  29222. length: suggestedLength,
  29223. };
  29224. }
  29225. function getEexecBlock(stream, suggestedLength) {
  29226. // We should ideally parse the eexec block to ensure that `suggestedLength`
  29227. // is correct, so we don't truncate the block data if it's too small.
  29228. // However, this would also require checking if the fixed-content portion
  29229. // exists (using the 'Length3' property), and ensuring that it's valid.
  29230. //
  29231. // Given that `suggestedLength` almost always is correct, all the validation
  29232. // would require a great deal of unnecessary parsing for most fonts.
  29233. // To save time, we always fetch the entire stream instead, which also avoid
  29234. // issues if `suggestedLength` is huge (see comment in `getHeaderBlock`).
  29235. //
  29236. // NOTE: This means that the function can include the fixed-content portion
  29237. // in the returned eexec block. In practice this does *not* seem to matter,
  29238. // since `Type1Parser_extractFontProgram` will skip over any non-commands.
  29239. var eexecBytes = stream.getBytes();
  29240. return {
  29241. stream: new Stream(eexecBytes),
  29242. length: eexecBytes.length,
  29243. };
  29244. }
  29245. function Type1Font(name, file, properties) {
  29246. // Some bad generators embed pfb file as is, we have to strip 6-byte header.
  29247. // Also, length1 and length2 might be off by 6 bytes as well.
  29248. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  29249. var PFB_HEADER_SIZE = 6;
  29250. var headerBlockLength = properties.length1;
  29251. var eexecBlockLength = properties.length2;
  29252. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  29253. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  29254. if (pfbHeaderPresent) {
  29255. file.skip(PFB_HEADER_SIZE);
  29256. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  29257. (pfbHeader[3] << 8) | pfbHeader[2];
  29258. }
  29259. // Get the data block containing glyphs and subrs information
  29260. var headerBlock = getHeaderBlock(file, headerBlockLength);
  29261. headerBlockLength = headerBlock.length;
  29262. var headerBlockParser = new Type1Parser(headerBlock.stream, false,
  29263. SEAC_ANALYSIS_ENABLED);
  29264. headerBlockParser.extractFontHeader(properties);
  29265. if (pfbHeaderPresent) {
  29266. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  29267. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  29268. (pfbHeader[3] << 8) | pfbHeader[2];
  29269. }
  29270. // Decrypt the data blocks and retrieve it's content
  29271. var eexecBlock = getEexecBlock(file, eexecBlockLength);
  29272. eexecBlockLength = eexecBlock.length;
  29273. var eexecBlockParser = new Type1Parser(eexecBlock.stream, true,
  29274. SEAC_ANALYSIS_ENABLED);
  29275. var data = eexecBlockParser.extractFontProgram();
  29276. for (var info in data.properties) {
  29277. properties[info] = data.properties[info];
  29278. }
  29279. var charstrings = data.charstrings;
  29280. var type2Charstrings = this.getType2Charstrings(charstrings);
  29281. var subrs = this.getType2Subrs(data.subrs);
  29282. this.charstrings = charstrings;
  29283. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  29284. subrs, properties);
  29285. this.seacs = this.getSeacs(data.charstrings);
  29286. }
  29287. Type1Font.prototype = {
  29288. get numGlyphs() {
  29289. return this.charstrings.length + 1;
  29290. },
  29291. getCharset: function Type1Font_getCharset() {
  29292. var charset = ['.notdef'];
  29293. var charstrings = this.charstrings;
  29294. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  29295. charset.push(charstrings[glyphId].glyphName);
  29296. }
  29297. return charset;
  29298. },
  29299. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  29300. var charstrings = this.charstrings;
  29301. var glyphNames = ['.notdef'], glyphId;
  29302. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  29303. glyphNames.push(charstrings[glyphId].glyphName);
  29304. }
  29305. var encoding = properties.builtInEncoding;
  29306. if (encoding) {
  29307. var builtInEncoding = Object.create(null);
  29308. for (var charCode in encoding) {
  29309. glyphId = glyphNames.indexOf(encoding[charCode]);
  29310. if (glyphId >= 0) {
  29311. builtInEncoding[charCode] = glyphId;
  29312. }
  29313. }
  29314. }
  29315. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  29316. },
  29317. getSeacs: function Type1Font_getSeacs(charstrings) {
  29318. var i, ii;
  29319. var seacMap = [];
  29320. for (i = 0, ii = charstrings.length; i < ii; i++) {
  29321. var charstring = charstrings[i];
  29322. if (charstring.seac) {
  29323. // Offset by 1 for .notdef
  29324. seacMap[i + 1] = charstring.seac;
  29325. }
  29326. }
  29327. return seacMap;
  29328. },
  29329. getType2Charstrings: function Type1Font_getType2Charstrings(
  29330. type1Charstrings) {
  29331. var type2Charstrings = [];
  29332. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  29333. type2Charstrings.push(type1Charstrings[i].charstring);
  29334. }
  29335. return type2Charstrings;
  29336. },
  29337. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  29338. var bias = 0;
  29339. var count = type1Subrs.length;
  29340. if (count < 1133) {
  29341. bias = 107;
  29342. } else if (count < 33769) {
  29343. bias = 1131;
  29344. } else {
  29345. bias = 32768;
  29346. }
  29347. // Add a bunch of empty subrs to deal with the Type2 bias
  29348. var type2Subrs = [];
  29349. var i;
  29350. for (i = 0; i < bias; i++) {
  29351. type2Subrs.push([0x0B]);
  29352. }
  29353. for (i = 0; i < count; i++) {
  29354. type2Subrs.push(type1Subrs[i]);
  29355. }
  29356. return type2Subrs;
  29357. },
  29358. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs,
  29359. properties) {
  29360. var cff = new CFF();
  29361. cff.header = new CFFHeader(1, 0, 4, 4);
  29362. cff.names = [name];
  29363. var topDict = new CFFTopDict();
  29364. // CFF strings IDs 0...390 are predefined names, so refering
  29365. // to entries in our own String INDEX starts at SID 391.
  29366. topDict.setByName('version', 391);
  29367. topDict.setByName('Notice', 392);
  29368. topDict.setByName('FullName', 393);
  29369. topDict.setByName('FamilyName', 394);
  29370. topDict.setByName('Weight', 395);
  29371. topDict.setByName('Encoding', null); // placeholder
  29372. topDict.setByName('FontMatrix', properties.fontMatrix);
  29373. topDict.setByName('FontBBox', properties.bbox);
  29374. topDict.setByName('charset', null); // placeholder
  29375. topDict.setByName('CharStrings', null); // placeholder
  29376. topDict.setByName('Private', null); // placeholder
  29377. cff.topDict = topDict;
  29378. var strings = new CFFStrings();
  29379. strings.add('Version 0.11'); // Version
  29380. strings.add('See original notice'); // Notice
  29381. strings.add(name); // FullName
  29382. strings.add(name); // FamilyName
  29383. strings.add('Medium'); // Weight
  29384. cff.strings = strings;
  29385. cff.globalSubrIndex = new CFFIndex();
  29386. var count = glyphs.length;
  29387. var charsetArray = [0];
  29388. var i, ii;
  29389. for (i = 0; i < count; i++) {
  29390. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  29391. // TODO: Insert the string and correctly map it. Previously it was
  29392. // thought mapping names that aren't in the standard strings to .notdef
  29393. // was fine, however in issue818 when mapping them all to .notdef the
  29394. // adieresis glyph no longer worked.
  29395. if (index === -1) {
  29396. index = 0;
  29397. }
  29398. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  29399. }
  29400. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  29401. var charStringsIndex = new CFFIndex();
  29402. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  29403. for (i = 0; i < count; i++) {
  29404. var glyph = glyphs[i];
  29405. // If the CharString outline is empty, replace it with .notdef to
  29406. // prevent OTS from rejecting the font (fixes bug1252420.pdf).
  29407. if (glyph.length === 0) {
  29408. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  29409. continue;
  29410. }
  29411. charStringsIndex.add(glyph);
  29412. }
  29413. cff.charStrings = charStringsIndex;
  29414. var privateDict = new CFFPrivateDict();
  29415. privateDict.setByName('Subrs', null); // placeholder
  29416. var fields = [
  29417. 'BlueValues',
  29418. 'OtherBlues',
  29419. 'FamilyBlues',
  29420. 'FamilyOtherBlues',
  29421. 'StemSnapH',
  29422. 'StemSnapV',
  29423. 'BlueShift',
  29424. 'BlueFuzz',
  29425. 'BlueScale',
  29426. 'LanguageGroup',
  29427. 'ExpansionFactor',
  29428. 'ForceBold',
  29429. 'StdHW',
  29430. 'StdVW'
  29431. ];
  29432. for (i = 0, ii = fields.length; i < ii; i++) {
  29433. var field = fields[i];
  29434. if (!(field in properties.privateData)) {
  29435. continue;
  29436. }
  29437. var value = properties.privateData[field];
  29438. if (isArray(value)) {
  29439. // All of the private dictionary array data in CFF must be stored as
  29440. // "delta-encoded" numbers.
  29441. for (var j = value.length - 1; j > 0; j--) {
  29442. value[j] -= value[j - 1]; // ... difference from previous value
  29443. }
  29444. }
  29445. privateDict.setByName(field, value);
  29446. }
  29447. cff.topDict.privateDict = privateDict;
  29448. var subrIndex = new CFFIndex();
  29449. for (i = 0, ii = subrs.length; i < ii; i++) {
  29450. subrIndex.add(subrs[i]);
  29451. }
  29452. privateDict.subrsIndex = subrIndex;
  29453. var compiler = new CFFCompiler(cff);
  29454. return compiler.compile();
  29455. }
  29456. };
  29457. return Type1Font;
  29458. })();
  29459. var CFFFont = (function CFFFontClosure() {
  29460. function CFFFont(file, properties) {
  29461. this.properties = properties;
  29462. var parser = new CFFParser(file, properties, SEAC_ANALYSIS_ENABLED);
  29463. this.cff = parser.parse();
  29464. var compiler = new CFFCompiler(this.cff);
  29465. this.seacs = this.cff.seacs;
  29466. try {
  29467. this.data = compiler.compile();
  29468. } catch (e) {
  29469. warn('Failed to compile font ' + properties.loadedName);
  29470. // There may have just been an issue with the compiler, set the data
  29471. // anyway and hope the font loaded.
  29472. this.data = file;
  29473. }
  29474. }
  29475. CFFFont.prototype = {
  29476. get numGlyphs() {
  29477. return this.cff.charStrings.count;
  29478. },
  29479. getCharset: function CFFFont_getCharset() {
  29480. return this.cff.charset.charset;
  29481. },
  29482. getGlyphMapping: function CFFFont_getGlyphMapping() {
  29483. var cff = this.cff;
  29484. var properties = this.properties;
  29485. var charsets = cff.charset.charset;
  29486. var charCodeToGlyphId;
  29487. var glyphId;
  29488. if (properties.composite) {
  29489. charCodeToGlyphId = Object.create(null);
  29490. if (cff.isCIDFont) {
  29491. // If the font is actually a CID font then we should use the charset
  29492. // to map CIDs to GIDs.
  29493. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  29494. var cid = charsets[glyphId];
  29495. var charCode = properties.cMap.charCodeOf(cid);
  29496. charCodeToGlyphId[charCode] = glyphId;
  29497. }
  29498. } else {
  29499. // If it is NOT actually a CID font then CIDs should be mapped
  29500. // directly to GIDs.
  29501. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  29502. charCodeToGlyphId[glyphId] = glyphId;
  29503. }
  29504. }
  29505. return charCodeToGlyphId;
  29506. }
  29507. var encoding = cff.encoding ? cff.encoding.encoding : null;
  29508. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  29509. return charCodeToGlyphId;
  29510. }
  29511. };
  29512. return CFFFont;
  29513. })();
  29514. // Workaround for seac on Windows.
  29515. (function checkSeacSupport() {
  29516. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  29517. SEAC_ANALYSIS_ENABLED = true;
  29518. }
  29519. })();
  29520. // Workaround for Private Use Area characters in Chrome on Windows
  29521. // http://code.google.com/p/chromium/issues/detail?id=122465
  29522. // https://github.com/mozilla/pdf.js/issues/1689
  29523. (function checkChromeWindows() {
  29524. if (typeof navigator !== 'undefined' &&
  29525. /Windows.*Chrome/.test(navigator.userAgent)) {
  29526. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  29527. }
  29528. })();
  29529. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  29530. exports.ErrorFont = ErrorFont;
  29531. exports.Font = Font;
  29532. exports.FontFlags = FontFlags;
  29533. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  29534. exports.ToUnicodeMap = ToUnicodeMap;
  29535. exports.getFontType = getFontType;
  29536. }));
  29537. (function (root, factory) {
  29538. {
  29539. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  29540. root.pdfjsCoreParser);
  29541. }
  29542. }(this, function (exports, sharedUtil, coreParser) {
  29543. var error = sharedUtil.error;
  29544. var isSpace = sharedUtil.isSpace;
  29545. var EOF = coreParser.EOF;
  29546. var PostScriptParser = (function PostScriptParserClosure() {
  29547. function PostScriptParser(lexer) {
  29548. this.lexer = lexer;
  29549. this.operators = [];
  29550. this.token = null;
  29551. this.prev = null;
  29552. }
  29553. PostScriptParser.prototype = {
  29554. nextToken: function PostScriptParser_nextToken() {
  29555. this.prev = this.token;
  29556. this.token = this.lexer.getToken();
  29557. },
  29558. accept: function PostScriptParser_accept(type) {
  29559. if (this.token.type === type) {
  29560. this.nextToken();
  29561. return true;
  29562. }
  29563. return false;
  29564. },
  29565. expect: function PostScriptParser_expect(type) {
  29566. if (this.accept(type)) {
  29567. return true;
  29568. }
  29569. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  29570. type + '.');
  29571. },
  29572. parse: function PostScriptParser_parse() {
  29573. this.nextToken();
  29574. this.expect(PostScriptTokenTypes.LBRACE);
  29575. this.parseBlock();
  29576. this.expect(PostScriptTokenTypes.RBRACE);
  29577. return this.operators;
  29578. },
  29579. parseBlock: function PostScriptParser_parseBlock() {
  29580. while (true) {
  29581. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  29582. this.operators.push(this.prev.value);
  29583. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  29584. this.operators.push(this.prev.value);
  29585. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29586. this.parseCondition();
  29587. } else {
  29588. return;
  29589. }
  29590. }
  29591. },
  29592. parseCondition: function PostScriptParser_parseCondition() {
  29593. // Add two place holders that will be updated later
  29594. var conditionLocation = this.operators.length;
  29595. this.operators.push(null, null);
  29596. this.parseBlock();
  29597. this.expect(PostScriptTokenTypes.RBRACE);
  29598. if (this.accept(PostScriptTokenTypes.IF)) {
  29599. // The true block is right after the 'if' so it just falls through on
  29600. // true else it jumps and skips the true block.
  29601. this.operators[conditionLocation] = this.operators.length;
  29602. this.operators[conditionLocation + 1] = 'jz';
  29603. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29604. var jumpLocation = this.operators.length;
  29605. this.operators.push(null, null);
  29606. var endOfTrue = this.operators.length;
  29607. this.parseBlock();
  29608. this.expect(PostScriptTokenTypes.RBRACE);
  29609. this.expect(PostScriptTokenTypes.IFELSE);
  29610. // The jump is added at the end of the true block to skip the false
  29611. // block.
  29612. this.operators[jumpLocation] = this.operators.length;
  29613. this.operators[jumpLocation + 1] = 'j';
  29614. this.operators[conditionLocation] = endOfTrue;
  29615. this.operators[conditionLocation + 1] = 'jz';
  29616. } else {
  29617. error('PS Function: error parsing conditional.');
  29618. }
  29619. }
  29620. };
  29621. return PostScriptParser;
  29622. })();
  29623. var PostScriptTokenTypes = {
  29624. LBRACE: 0,
  29625. RBRACE: 1,
  29626. NUMBER: 2,
  29627. OPERATOR: 3,
  29628. IF: 4,
  29629. IFELSE: 5
  29630. };
  29631. var PostScriptToken = (function PostScriptTokenClosure() {
  29632. function PostScriptToken(type, value) {
  29633. this.type = type;
  29634. this.value = value;
  29635. }
  29636. var opCache = Object.create(null);
  29637. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  29638. var opValue = opCache[op];
  29639. if (opValue) {
  29640. return opValue;
  29641. }
  29642. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  29643. };
  29644. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  29645. '{');
  29646. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  29647. '}');
  29648. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  29649. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  29650. 'IFELSE');
  29651. return PostScriptToken;
  29652. })();
  29653. var PostScriptLexer = (function PostScriptLexerClosure() {
  29654. function PostScriptLexer(stream) {
  29655. this.stream = stream;
  29656. this.nextChar();
  29657. this.strBuf = [];
  29658. }
  29659. PostScriptLexer.prototype = {
  29660. nextChar: function PostScriptLexer_nextChar() {
  29661. return (this.currentChar = this.stream.getByte());
  29662. },
  29663. getToken: function PostScriptLexer_getToken() {
  29664. var comment = false;
  29665. var ch = this.currentChar;
  29666. // skip comments
  29667. while (true) {
  29668. if (ch < 0) {
  29669. return EOF;
  29670. }
  29671. if (comment) {
  29672. if (ch === 0x0A || ch === 0x0D) {
  29673. comment = false;
  29674. }
  29675. } else if (ch === 0x25) { // '%'
  29676. comment = true;
  29677. } else if (!isSpace(ch)) {
  29678. break;
  29679. }
  29680. ch = this.nextChar();
  29681. }
  29682. switch (ch | 0) {
  29683. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29684. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29685. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29686. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  29687. this.getNumber());
  29688. case 0x7B: // '{'
  29689. this.nextChar();
  29690. return PostScriptToken.LBRACE;
  29691. case 0x7D: // '}'
  29692. this.nextChar();
  29693. return PostScriptToken.RBRACE;
  29694. }
  29695. // operator
  29696. var strBuf = this.strBuf;
  29697. strBuf.length = 0;
  29698. strBuf[0] = String.fromCharCode(ch);
  29699. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  29700. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  29701. strBuf.push(String.fromCharCode(ch));
  29702. }
  29703. var str = strBuf.join('');
  29704. switch (str.toLowerCase()) {
  29705. case 'if':
  29706. return PostScriptToken.IF;
  29707. case 'ifelse':
  29708. return PostScriptToken.IFELSE;
  29709. default:
  29710. return PostScriptToken.getOperator(str);
  29711. }
  29712. },
  29713. getNumber: function PostScriptLexer_getNumber() {
  29714. var ch = this.currentChar;
  29715. var strBuf = this.strBuf;
  29716. strBuf.length = 0;
  29717. strBuf[0] = String.fromCharCode(ch);
  29718. while ((ch = this.nextChar()) >= 0) {
  29719. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  29720. ch === 0x2D || ch === 0x2E) { // '-', '.'
  29721. strBuf.push(String.fromCharCode(ch));
  29722. } else {
  29723. break;
  29724. }
  29725. }
  29726. var value = parseFloat(strBuf.join(''));
  29727. if (isNaN(value)) {
  29728. error('Invalid floating point number: ' + value);
  29729. }
  29730. return value;
  29731. }
  29732. };
  29733. return PostScriptLexer;
  29734. })();
  29735. exports.PostScriptLexer = PostScriptLexer;
  29736. exports.PostScriptParser = PostScriptParser;
  29737. }));
  29738. (function (root, factory) {
  29739. {
  29740. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  29741. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  29742. }
  29743. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  29744. var error = sharedUtil.error;
  29745. var info = sharedUtil.info;
  29746. var isArray = sharedUtil.isArray;
  29747. var isBool = sharedUtil.isBool;
  29748. var isDict = corePrimitives.isDict;
  29749. var isStream = corePrimitives.isStream;
  29750. var PostScriptLexer = corePsParser.PostScriptLexer;
  29751. var PostScriptParser = corePsParser.PostScriptParser;
  29752. var PDFFunction = (function PDFFunctionClosure() {
  29753. var CONSTRUCT_SAMPLED = 0;
  29754. var CONSTRUCT_INTERPOLATED = 2;
  29755. var CONSTRUCT_STICHED = 3;
  29756. var CONSTRUCT_POSTSCRIPT = 4;
  29757. return {
  29758. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  29759. str) {
  29760. var i, ii;
  29761. var length = 1;
  29762. for (i = 0, ii = size.length; i < ii; i++) {
  29763. length *= size[i];
  29764. }
  29765. length *= outputSize;
  29766. var array = new Array(length);
  29767. var codeSize = 0;
  29768. var codeBuf = 0;
  29769. // 32 is a valid bps so shifting won't work
  29770. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  29771. var strBytes = str.getBytes((length * bps + 7) / 8);
  29772. var strIdx = 0;
  29773. for (i = 0; i < length; i++) {
  29774. while (codeSize < bps) {
  29775. codeBuf <<= 8;
  29776. codeBuf |= strBytes[strIdx++];
  29777. codeSize += 8;
  29778. }
  29779. codeSize -= bps;
  29780. array[i] = (codeBuf >> codeSize) * sampleMul;
  29781. codeBuf &= (1 << codeSize) - 1;
  29782. }
  29783. return array;
  29784. },
  29785. getIR: function PDFFunction_getIR(xref, fn) {
  29786. var dict = fn.dict;
  29787. if (!dict) {
  29788. dict = fn;
  29789. }
  29790. var types = [this.constructSampled,
  29791. null,
  29792. this.constructInterpolated,
  29793. this.constructStiched,
  29794. this.constructPostScript];
  29795. var typeNum = dict.get('FunctionType');
  29796. var typeFn = types[typeNum];
  29797. if (!typeFn) {
  29798. error('Unknown type of function');
  29799. }
  29800. return typeFn.call(this, fn, dict, xref);
  29801. },
  29802. fromIR: function PDFFunction_fromIR(IR) {
  29803. var type = IR[0];
  29804. switch (type) {
  29805. case CONSTRUCT_SAMPLED:
  29806. return this.constructSampledFromIR(IR);
  29807. case CONSTRUCT_INTERPOLATED:
  29808. return this.constructInterpolatedFromIR(IR);
  29809. case CONSTRUCT_STICHED:
  29810. return this.constructStichedFromIR(IR);
  29811. //case CONSTRUCT_POSTSCRIPT:
  29812. default:
  29813. return this.constructPostScriptFromIR(IR);
  29814. }
  29815. },
  29816. parse: function PDFFunction_parse(xref, fn) {
  29817. var IR = this.getIR(xref, fn);
  29818. return this.fromIR(IR);
  29819. },
  29820. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  29821. if (!isArray(fnObj)) {
  29822. // not an array -- parsing as regular function
  29823. return this.parse(xref, fnObj);
  29824. }
  29825. var fnArray = [];
  29826. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  29827. var obj = xref.fetchIfRef(fnObj[j]);
  29828. fnArray.push(PDFFunction.parse(xref, obj));
  29829. }
  29830. return function (src, srcOffset, dest, destOffset) {
  29831. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  29832. fnArray[i](src, srcOffset, dest, destOffset + i);
  29833. }
  29834. };
  29835. },
  29836. constructSampled: function PDFFunction_constructSampled(str, dict) {
  29837. function toMultiArray(arr) {
  29838. var inputLength = arr.length;
  29839. var out = [];
  29840. var index = 0;
  29841. for (var i = 0; i < inputLength; i += 2) {
  29842. out[index] = [arr[i], arr[i + 1]];
  29843. ++index;
  29844. }
  29845. return out;
  29846. }
  29847. var domain = dict.getArray('Domain');
  29848. var range = dict.getArray('Range');
  29849. if (!domain || !range) {
  29850. error('No domain or range');
  29851. }
  29852. var inputSize = domain.length / 2;
  29853. var outputSize = range.length / 2;
  29854. domain = toMultiArray(domain);
  29855. range = toMultiArray(range);
  29856. var size = dict.get('Size');
  29857. var bps = dict.get('BitsPerSample');
  29858. var order = dict.get('Order') || 1;
  29859. if (order !== 1) {
  29860. // No description how cubic spline interpolation works in PDF32000:2008
  29861. // As in poppler, ignoring order, linear interpolation may work as good
  29862. info('No support for cubic spline interpolation: ' + order);
  29863. }
  29864. var encode = dict.getArray('Encode');
  29865. if (!encode) {
  29866. encode = [];
  29867. for (var i = 0; i < inputSize; ++i) {
  29868. encode.push(0);
  29869. encode.push(size[i] - 1);
  29870. }
  29871. }
  29872. encode = toMultiArray(encode);
  29873. var decode = dict.getArray('Decode');
  29874. if (!decode) {
  29875. decode = range;
  29876. } else {
  29877. decode = toMultiArray(decode);
  29878. }
  29879. var samples = this.getSampleArray(size, outputSize, bps, str);
  29880. return [
  29881. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  29882. outputSize, Math.pow(2, bps) - 1, range
  29883. ];
  29884. },
  29885. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  29886. // See chapter 3, page 109 of the PDF reference
  29887. function interpolate(x, xmin, xmax, ymin, ymax) {
  29888. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  29889. }
  29890. return function constructSampledFromIRResult(src, srcOffset,
  29891. dest, destOffset) {
  29892. // See chapter 3, page 110 of the PDF reference.
  29893. var m = IR[1];
  29894. var domain = IR[2];
  29895. var encode = IR[3];
  29896. var decode = IR[4];
  29897. var samples = IR[5];
  29898. var size = IR[6];
  29899. var n = IR[7];
  29900. //var mask = IR[8];
  29901. var range = IR[9];
  29902. // Building the cube vertices: its part and sample index
  29903. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  29904. var cubeVertices = 1 << m;
  29905. var cubeN = new Float64Array(cubeVertices);
  29906. var cubeVertex = new Uint32Array(cubeVertices);
  29907. var i, j;
  29908. for (j = 0; j < cubeVertices; j++) {
  29909. cubeN[j] = 1;
  29910. }
  29911. var k = n, pos = 1;
  29912. // Map x_i to y_j for 0 <= i < m using the sampled function.
  29913. for (i = 0; i < m; ++i) {
  29914. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  29915. var domain_2i = domain[i][0];
  29916. var domain_2i_1 = domain[i][1];
  29917. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  29918. domain_2i_1);
  29919. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  29920. // Encode_2i, Encode_2i+1)
  29921. var e = interpolate(xi, domain_2i, domain_2i_1,
  29922. encode[i][0], encode[i][1]);
  29923. // e_i' = min(max(e_i, 0), Size_i - 1)
  29924. var size_i = size[i];
  29925. e = Math.min(Math.max(e, 0), size_i - 1);
  29926. // Adjusting the cube: N and vertex sample index
  29927. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  29928. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  29929. var n1 = e - e0; // (e - e0) / (e1 - e0);
  29930. var offset0 = e0 * k;
  29931. var offset1 = offset0 + k; // e1 * k
  29932. for (j = 0; j < cubeVertices; j++) {
  29933. if (j & pos) {
  29934. cubeN[j] *= n1;
  29935. cubeVertex[j] += offset1;
  29936. } else {
  29937. cubeN[j] *= n0;
  29938. cubeVertex[j] += offset0;
  29939. }
  29940. }
  29941. k *= size_i;
  29942. pos <<= 1;
  29943. }
  29944. for (j = 0; j < n; ++j) {
  29945. // Sum all cube vertices' samples portions
  29946. var rj = 0;
  29947. for (i = 0; i < cubeVertices; i++) {
  29948. rj += samples[cubeVertex[i] + j] * cubeN[i];
  29949. }
  29950. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  29951. // Decode_2j, Decode_2j+1)
  29952. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  29953. // y_j = min(max(r_j, range_2j), range_2j+1)
  29954. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  29955. range[j][1]);
  29956. }
  29957. };
  29958. },
  29959. constructInterpolated: function PDFFunction_constructInterpolated(str,
  29960. dict) {
  29961. var c0 = dict.getArray('C0') || [0];
  29962. var c1 = dict.getArray('C1') || [1];
  29963. var n = dict.get('N');
  29964. if (!isArray(c0) || !isArray(c1)) {
  29965. error('Illegal dictionary for interpolated function');
  29966. }
  29967. var length = c0.length;
  29968. var diff = [];
  29969. for (var i = 0; i < length; ++i) {
  29970. diff.push(c1[i] - c0[i]);
  29971. }
  29972. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  29973. },
  29974. constructInterpolatedFromIR:
  29975. function PDFFunction_constructInterpolatedFromIR(IR) {
  29976. var c0 = IR[1];
  29977. var diff = IR[2];
  29978. var n = IR[3];
  29979. var length = diff.length;
  29980. return function constructInterpolatedFromIRResult(src, srcOffset,
  29981. dest, destOffset) {
  29982. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  29983. for (var j = 0; j < length; ++j) {
  29984. dest[destOffset + j] = c0[j] + (x * diff[j]);
  29985. }
  29986. };
  29987. },
  29988. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  29989. var domain = dict.getArray('Domain');
  29990. if (!domain) {
  29991. error('No domain');
  29992. }
  29993. var inputSize = domain.length / 2;
  29994. if (inputSize !== 1) {
  29995. error('Bad domain for stiched function');
  29996. }
  29997. var fnRefs = dict.get('Functions');
  29998. var fns = [];
  29999. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  30000. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  30001. }
  30002. var bounds = dict.getArray('Bounds');
  30003. var encode = dict.getArray('Encode');
  30004. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  30005. },
  30006. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  30007. var domain = IR[1];
  30008. var bounds = IR[2];
  30009. var encode = IR[3];
  30010. var fnsIR = IR[4];
  30011. var fns = [];
  30012. var tmpBuf = new Float32Array(1);
  30013. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  30014. fns.push(PDFFunction.fromIR(fnsIR[i]));
  30015. }
  30016. return function constructStichedFromIRResult(src, srcOffset,
  30017. dest, destOffset) {
  30018. var clip = function constructStichedFromIRClip(v, min, max) {
  30019. if (v > max) {
  30020. v = max;
  30021. } else if (v < min) {
  30022. v = min;
  30023. }
  30024. return v;
  30025. };
  30026. // clip to domain
  30027. var v = clip(src[srcOffset], domain[0], domain[1]);
  30028. // calculate which bound the value is in
  30029. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  30030. if (v < bounds[i]) {
  30031. break;
  30032. }
  30033. }
  30034. // encode value into domain of function
  30035. var dmin = domain[0];
  30036. if (i > 0) {
  30037. dmin = bounds[i - 1];
  30038. }
  30039. var dmax = domain[1];
  30040. if (i < bounds.length) {
  30041. dmax = bounds[i];
  30042. }
  30043. var rmin = encode[2 * i];
  30044. var rmax = encode[2 * i + 1];
  30045. // Prevent the value from becoming NaN as a result
  30046. // of division by zero (fixes issue6113.pdf).
  30047. tmpBuf[0] = dmin === dmax ? rmin :
  30048. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  30049. // call the appropriate function
  30050. fns[i](tmpBuf, 0, dest, destOffset);
  30051. };
  30052. },
  30053. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  30054. xref) {
  30055. var domain = dict.getArray('Domain');
  30056. var range = dict.getArray('Range');
  30057. if (!domain) {
  30058. error('No domain.');
  30059. }
  30060. if (!range) {
  30061. error('No range.');
  30062. }
  30063. var lexer = new PostScriptLexer(fn);
  30064. var parser = new PostScriptParser(lexer);
  30065. var code = parser.parse();
  30066. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  30067. },
  30068. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  30069. IR) {
  30070. var domain = IR[1];
  30071. var range = IR[2];
  30072. var code = IR[3];
  30073. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  30074. if (compiled) {
  30075. // Compiled function consists of simple expressions such as addition,
  30076. // subtraction, Math.max, and also contains 'var' and 'return'
  30077. // statements. See the generation in the PostScriptCompiler below.
  30078. /*jshint -W054 */
  30079. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  30080. }
  30081. info('Unable to compile PS function');
  30082. var numOutputs = range.length >> 1;
  30083. var numInputs = domain.length >> 1;
  30084. var evaluator = new PostScriptEvaluator(code);
  30085. // Cache the values for a big speed up, the cache size is limited though
  30086. // since the number of possible values can be huge from a PS function.
  30087. var cache = Object.create(null);
  30088. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  30089. // seen in our tests.
  30090. var MAX_CACHE_SIZE = 2048 * 4;
  30091. var cache_available = MAX_CACHE_SIZE;
  30092. var tmpBuf = new Float32Array(numInputs);
  30093. return function constructPostScriptFromIRResult(src, srcOffset,
  30094. dest, destOffset) {
  30095. var i, value;
  30096. var key = '';
  30097. var input = tmpBuf;
  30098. for (i = 0; i < numInputs; i++) {
  30099. value = src[srcOffset + i];
  30100. input[i] = value;
  30101. key += value + '_';
  30102. }
  30103. var cachedValue = cache[key];
  30104. if (cachedValue !== undefined) {
  30105. dest.set(cachedValue, destOffset);
  30106. return;
  30107. }
  30108. var output = new Float32Array(numOutputs);
  30109. var stack = evaluator.execute(input);
  30110. var stackIndex = stack.length - numOutputs;
  30111. for (i = 0; i < numOutputs; i++) {
  30112. value = stack[stackIndex + i];
  30113. var bound = range[i * 2];
  30114. if (value < bound) {
  30115. value = bound;
  30116. } else {
  30117. bound = range[i * 2 +1];
  30118. if (value > bound) {
  30119. value = bound;
  30120. }
  30121. }
  30122. output[i] = value;
  30123. }
  30124. if (cache_available > 0) {
  30125. cache_available--;
  30126. cache[key] = output;
  30127. }
  30128. dest.set(output, destOffset);
  30129. };
  30130. }
  30131. };
  30132. })();
  30133. function isPDFFunction(v) {
  30134. var fnDict;
  30135. if (typeof v !== 'object') {
  30136. return false;
  30137. } else if (isDict(v)) {
  30138. fnDict = v;
  30139. } else if (isStream(v)) {
  30140. fnDict = v.dict;
  30141. } else {
  30142. return false;
  30143. }
  30144. return fnDict.has('FunctionType');
  30145. }
  30146. var PostScriptStack = (function PostScriptStackClosure() {
  30147. var MAX_STACK_SIZE = 100;
  30148. function PostScriptStack(initialStack) {
  30149. this.stack = !initialStack ? [] :
  30150. Array.prototype.slice.call(initialStack, 0);
  30151. }
  30152. PostScriptStack.prototype = {
  30153. push: function PostScriptStack_push(value) {
  30154. if (this.stack.length >= MAX_STACK_SIZE) {
  30155. error('PostScript function stack overflow.');
  30156. }
  30157. this.stack.push(value);
  30158. },
  30159. pop: function PostScriptStack_pop() {
  30160. if (this.stack.length <= 0) {
  30161. error('PostScript function stack underflow.');
  30162. }
  30163. return this.stack.pop();
  30164. },
  30165. copy: function PostScriptStack_copy(n) {
  30166. if (this.stack.length + n >= MAX_STACK_SIZE) {
  30167. error('PostScript function stack overflow.');
  30168. }
  30169. var stack = this.stack;
  30170. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  30171. stack.push(stack[i]);
  30172. }
  30173. },
  30174. index: function PostScriptStack_index(n) {
  30175. this.push(this.stack[this.stack.length - n - 1]);
  30176. },
  30177. // rotate the last n stack elements p times
  30178. roll: function PostScriptStack_roll(n, p) {
  30179. var stack = this.stack;
  30180. var l = stack.length - n;
  30181. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  30182. for (i = l, j = r; i < j; i++, j--) {
  30183. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30184. }
  30185. for (i = l, j = c - 1; i < j; i++, j--) {
  30186. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30187. }
  30188. for (i = c, j = r; i < j; i++, j--) {
  30189. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30190. }
  30191. }
  30192. };
  30193. return PostScriptStack;
  30194. })();
  30195. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  30196. function PostScriptEvaluator(operators) {
  30197. this.operators = operators;
  30198. }
  30199. PostScriptEvaluator.prototype = {
  30200. execute: function PostScriptEvaluator_execute(initialStack) {
  30201. var stack = new PostScriptStack(initialStack);
  30202. var counter = 0;
  30203. var operators = this.operators;
  30204. var length = operators.length;
  30205. var operator, a, b;
  30206. while (counter < length) {
  30207. operator = operators[counter++];
  30208. if (typeof operator === 'number') {
  30209. // Operator is really an operand and should be pushed to the stack.
  30210. stack.push(operator);
  30211. continue;
  30212. }
  30213. switch (operator) {
  30214. // non standard ps operators
  30215. case 'jz': // jump if false
  30216. b = stack.pop();
  30217. a = stack.pop();
  30218. if (!a) {
  30219. counter = b;
  30220. }
  30221. break;
  30222. case 'j': // jump
  30223. a = stack.pop();
  30224. counter = a;
  30225. break;
  30226. // all ps operators in alphabetical order (excluding if/ifelse)
  30227. case 'abs':
  30228. a = stack.pop();
  30229. stack.push(Math.abs(a));
  30230. break;
  30231. case 'add':
  30232. b = stack.pop();
  30233. a = stack.pop();
  30234. stack.push(a + b);
  30235. break;
  30236. case 'and':
  30237. b = stack.pop();
  30238. a = stack.pop();
  30239. if (isBool(a) && isBool(b)) {
  30240. stack.push(a && b);
  30241. } else {
  30242. stack.push(a & b);
  30243. }
  30244. break;
  30245. case 'atan':
  30246. a = stack.pop();
  30247. stack.push(Math.atan(a));
  30248. break;
  30249. case 'bitshift':
  30250. b = stack.pop();
  30251. a = stack.pop();
  30252. if (a > 0) {
  30253. stack.push(a << b);
  30254. } else {
  30255. stack.push(a >> b);
  30256. }
  30257. break;
  30258. case 'ceiling':
  30259. a = stack.pop();
  30260. stack.push(Math.ceil(a));
  30261. break;
  30262. case 'copy':
  30263. a = stack.pop();
  30264. stack.copy(a);
  30265. break;
  30266. case 'cos':
  30267. a = stack.pop();
  30268. stack.push(Math.cos(a));
  30269. break;
  30270. case 'cvi':
  30271. a = stack.pop() | 0;
  30272. stack.push(a);
  30273. break;
  30274. case 'cvr':
  30275. // noop
  30276. break;
  30277. case 'div':
  30278. b = stack.pop();
  30279. a = stack.pop();
  30280. stack.push(a / b);
  30281. break;
  30282. case 'dup':
  30283. stack.copy(1);
  30284. break;
  30285. case 'eq':
  30286. b = stack.pop();
  30287. a = stack.pop();
  30288. stack.push(a === b);
  30289. break;
  30290. case 'exch':
  30291. stack.roll(2, 1);
  30292. break;
  30293. case 'exp':
  30294. b = stack.pop();
  30295. a = stack.pop();
  30296. stack.push(Math.pow(a, b));
  30297. break;
  30298. case 'false':
  30299. stack.push(false);
  30300. break;
  30301. case 'floor':
  30302. a = stack.pop();
  30303. stack.push(Math.floor(a));
  30304. break;
  30305. case 'ge':
  30306. b = stack.pop();
  30307. a = stack.pop();
  30308. stack.push(a >= b);
  30309. break;
  30310. case 'gt':
  30311. b = stack.pop();
  30312. a = stack.pop();
  30313. stack.push(a > b);
  30314. break;
  30315. case 'idiv':
  30316. b = stack.pop();
  30317. a = stack.pop();
  30318. stack.push((a / b) | 0);
  30319. break;
  30320. case 'index':
  30321. a = stack.pop();
  30322. stack.index(a);
  30323. break;
  30324. case 'le':
  30325. b = stack.pop();
  30326. a = stack.pop();
  30327. stack.push(a <= b);
  30328. break;
  30329. case 'ln':
  30330. a = stack.pop();
  30331. stack.push(Math.log(a));
  30332. break;
  30333. case 'log':
  30334. a = stack.pop();
  30335. stack.push(Math.log(a) / Math.LN10);
  30336. break;
  30337. case 'lt':
  30338. b = stack.pop();
  30339. a = stack.pop();
  30340. stack.push(a < b);
  30341. break;
  30342. case 'mod':
  30343. b = stack.pop();
  30344. a = stack.pop();
  30345. stack.push(a % b);
  30346. break;
  30347. case 'mul':
  30348. b = stack.pop();
  30349. a = stack.pop();
  30350. stack.push(a * b);
  30351. break;
  30352. case 'ne':
  30353. b = stack.pop();
  30354. a = stack.pop();
  30355. stack.push(a !== b);
  30356. break;
  30357. case 'neg':
  30358. a = stack.pop();
  30359. stack.push(-a);
  30360. break;
  30361. case 'not':
  30362. a = stack.pop();
  30363. if (isBool(a)) {
  30364. stack.push(!a);
  30365. } else {
  30366. stack.push(~a);
  30367. }
  30368. break;
  30369. case 'or':
  30370. b = stack.pop();
  30371. a = stack.pop();
  30372. if (isBool(a) && isBool(b)) {
  30373. stack.push(a || b);
  30374. } else {
  30375. stack.push(a | b);
  30376. }
  30377. break;
  30378. case 'pop':
  30379. stack.pop();
  30380. break;
  30381. case 'roll':
  30382. b = stack.pop();
  30383. a = stack.pop();
  30384. stack.roll(a, b);
  30385. break;
  30386. case 'round':
  30387. a = stack.pop();
  30388. stack.push(Math.round(a));
  30389. break;
  30390. case 'sin':
  30391. a = stack.pop();
  30392. stack.push(Math.sin(a));
  30393. break;
  30394. case 'sqrt':
  30395. a = stack.pop();
  30396. stack.push(Math.sqrt(a));
  30397. break;
  30398. case 'sub':
  30399. b = stack.pop();
  30400. a = stack.pop();
  30401. stack.push(a - b);
  30402. break;
  30403. case 'true':
  30404. stack.push(true);
  30405. break;
  30406. case 'truncate':
  30407. a = stack.pop();
  30408. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  30409. stack.push(a);
  30410. break;
  30411. case 'xor':
  30412. b = stack.pop();
  30413. a = stack.pop();
  30414. if (isBool(a) && isBool(b)) {
  30415. stack.push(a !== b);
  30416. } else {
  30417. stack.push(a ^ b);
  30418. }
  30419. break;
  30420. default:
  30421. error('Unknown operator ' + operator);
  30422. break;
  30423. }
  30424. }
  30425. return stack.stack;
  30426. }
  30427. };
  30428. return PostScriptEvaluator;
  30429. })();
  30430. // Most of the PDFs functions consist of simple operations such as:
  30431. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  30432. //
  30433. // We can compile most of such programs, and at the same moment, we can
  30434. // optimize some expressions using basic math properties. Keeping track of
  30435. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  30436. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  30437. function AstNode(type) {
  30438. this.type = type;
  30439. }
  30440. AstNode.prototype.visit = function (visitor) {
  30441. throw new Error('abstract method');
  30442. };
  30443. function AstArgument(index, min, max) {
  30444. AstNode.call(this, 'args');
  30445. this.index = index;
  30446. this.min = min;
  30447. this.max = max;
  30448. }
  30449. AstArgument.prototype = Object.create(AstNode.prototype);
  30450. AstArgument.prototype.visit = function (visitor) {
  30451. visitor.visitArgument(this);
  30452. };
  30453. function AstLiteral(number) {
  30454. AstNode.call(this, 'literal');
  30455. this.number = number;
  30456. this.min = number;
  30457. this.max = number;
  30458. }
  30459. AstLiteral.prototype = Object.create(AstNode.prototype);
  30460. AstLiteral.prototype.visit = function (visitor) {
  30461. visitor.visitLiteral(this);
  30462. };
  30463. function AstBinaryOperation(op, arg1, arg2, min, max) {
  30464. AstNode.call(this, 'binary');
  30465. this.op = op;
  30466. this.arg1 = arg1;
  30467. this.arg2 = arg2;
  30468. this.min = min;
  30469. this.max = max;
  30470. }
  30471. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  30472. AstBinaryOperation.prototype.visit = function (visitor) {
  30473. visitor.visitBinaryOperation(this);
  30474. };
  30475. function AstMin(arg, max) {
  30476. AstNode.call(this, 'max');
  30477. this.arg = arg;
  30478. this.min = arg.min;
  30479. this.max = max;
  30480. }
  30481. AstMin.prototype = Object.create(AstNode.prototype);
  30482. AstMin.prototype.visit = function (visitor) {
  30483. visitor.visitMin(this);
  30484. };
  30485. function AstVariable(index, min, max) {
  30486. AstNode.call(this, 'var');
  30487. this.index = index;
  30488. this.min = min;
  30489. this.max = max;
  30490. }
  30491. AstVariable.prototype = Object.create(AstNode.prototype);
  30492. AstVariable.prototype.visit = function (visitor) {
  30493. visitor.visitVariable(this);
  30494. };
  30495. function AstVariableDefinition(variable, arg) {
  30496. AstNode.call(this, 'definition');
  30497. this.variable = variable;
  30498. this.arg = arg;
  30499. }
  30500. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  30501. AstVariableDefinition.prototype.visit = function (visitor) {
  30502. visitor.visitVariableDefinition(this);
  30503. };
  30504. function ExpressionBuilderVisitor() {
  30505. this.parts = [];
  30506. }
  30507. ExpressionBuilderVisitor.prototype = {
  30508. visitArgument: function (arg) {
  30509. this.parts.push('Math.max(', arg.min, ', Math.min(',
  30510. arg.max, ', src[srcOffset + ', arg.index, ']))');
  30511. },
  30512. visitVariable: function (variable) {
  30513. this.parts.push('v', variable.index);
  30514. },
  30515. visitLiteral: function (literal) {
  30516. this.parts.push(literal.number);
  30517. },
  30518. visitBinaryOperation: function (operation) {
  30519. this.parts.push('(');
  30520. operation.arg1.visit(this);
  30521. this.parts.push(' ', operation.op, ' ');
  30522. operation.arg2.visit(this);
  30523. this.parts.push(')');
  30524. },
  30525. visitVariableDefinition: function (definition) {
  30526. this.parts.push('var ');
  30527. definition.variable.visit(this);
  30528. this.parts.push(' = ');
  30529. definition.arg.visit(this);
  30530. this.parts.push(';');
  30531. },
  30532. visitMin: function (max) {
  30533. this.parts.push('Math.min(');
  30534. max.arg.visit(this);
  30535. this.parts.push(', ', max.max, ')');
  30536. },
  30537. toString: function () {
  30538. return this.parts.join('');
  30539. }
  30540. };
  30541. function buildAddOperation(num1, num2) {
  30542. if (num2.type === 'literal' && num2.number === 0) {
  30543. // optimization: second operand is 0
  30544. return num1;
  30545. }
  30546. if (num1.type === 'literal' && num1.number === 0) {
  30547. // optimization: first operand is 0
  30548. return num2;
  30549. }
  30550. if (num2.type === 'literal' && num1.type === 'literal') {
  30551. // optimization: operands operand are literals
  30552. return new AstLiteral(num1.number + num2.number);
  30553. }
  30554. return new AstBinaryOperation('+', num1, num2,
  30555. num1.min + num2.min, num1.max + num2.max);
  30556. }
  30557. function buildMulOperation(num1, num2) {
  30558. if (num2.type === 'literal') {
  30559. // optimization: second operands is a literal...
  30560. if (num2.number === 0) {
  30561. return new AstLiteral(0); // and it's 0
  30562. } else if (num2.number === 1) {
  30563. return num1; // and it's 1
  30564. } else if (num1.type === 'literal') {
  30565. // ... and first operands is a literal too
  30566. return new AstLiteral(num1.number * num2.number);
  30567. }
  30568. }
  30569. if (num1.type === 'literal') {
  30570. // optimization: first operands is a literal...
  30571. if (num1.number === 0) {
  30572. return new AstLiteral(0); // and it's 0
  30573. } else if (num1.number === 1) {
  30574. return num2; // and it's 1
  30575. }
  30576. }
  30577. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  30578. num1.max * num2.min, num1.max * num2.max);
  30579. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  30580. num1.max * num2.min, num1.max * num2.max);
  30581. return new AstBinaryOperation('*', num1, num2, min, max);
  30582. }
  30583. function buildSubOperation(num1, num2) {
  30584. if (num2.type === 'literal') {
  30585. // optimization: second operands is a literal...
  30586. if (num2.number === 0) {
  30587. return num1; // ... and it's 0
  30588. } else if (num1.type === 'literal') {
  30589. // ... and first operands is a literal too
  30590. return new AstLiteral(num1.number - num2.number);
  30591. }
  30592. }
  30593. if (num2.type === 'binary' && num2.op === '-' &&
  30594. num1.type === 'literal' && num1.number === 1 &&
  30595. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  30596. // optimization for case: 1 - (1 - x)
  30597. return num2.arg2;
  30598. }
  30599. return new AstBinaryOperation('-', num1, num2,
  30600. num1.min - num2.max, num1.max - num2.min);
  30601. }
  30602. function buildMinOperation(num1, max) {
  30603. if (num1.min >= max) {
  30604. // optimization: num1 min value is not less than required max
  30605. return new AstLiteral(max); // just returning max
  30606. } else if (num1.max <= max) {
  30607. // optimization: num1 max value is not greater than required max
  30608. return num1; // just returning an argument
  30609. }
  30610. return new AstMin(num1, max);
  30611. }
  30612. function PostScriptCompiler() {}
  30613. PostScriptCompiler.prototype = {
  30614. compile: function PostScriptCompiler_compile(code, domain, range) {
  30615. var stack = [];
  30616. var i, ii;
  30617. var instructions = [];
  30618. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  30619. var lastRegister = 0;
  30620. var n, j;
  30621. var num1, num2, ast1, ast2, tmpVar, item;
  30622. for (i = 0; i < inputSize; i++) {
  30623. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  30624. }
  30625. for (i = 0, ii = code.length; i < ii; i++) {
  30626. item = code[i];
  30627. if (typeof item === 'number') {
  30628. stack.push(new AstLiteral(item));
  30629. continue;
  30630. }
  30631. switch (item) {
  30632. case 'add':
  30633. if (stack.length < 2) {
  30634. return null;
  30635. }
  30636. num2 = stack.pop();
  30637. num1 = stack.pop();
  30638. stack.push(buildAddOperation(num1, num2));
  30639. break;
  30640. case 'cvr':
  30641. if (stack.length < 1) {
  30642. return null;
  30643. }
  30644. break;
  30645. case 'mul':
  30646. if (stack.length < 2) {
  30647. return null;
  30648. }
  30649. num2 = stack.pop();
  30650. num1 = stack.pop();
  30651. stack.push(buildMulOperation(num1, num2));
  30652. break;
  30653. case 'sub':
  30654. if (stack.length < 2) {
  30655. return null;
  30656. }
  30657. num2 = stack.pop();
  30658. num1 = stack.pop();
  30659. stack.push(buildSubOperation(num1, num2));
  30660. break;
  30661. case 'exch':
  30662. if (stack.length < 2) {
  30663. return null;
  30664. }
  30665. ast1 = stack.pop(); ast2 = stack.pop();
  30666. stack.push(ast1, ast2);
  30667. break;
  30668. case 'pop':
  30669. if (stack.length < 1) {
  30670. return null;
  30671. }
  30672. stack.pop();
  30673. break;
  30674. case 'index':
  30675. if (stack.length < 1) {
  30676. return null;
  30677. }
  30678. num1 = stack.pop();
  30679. if (num1.type !== 'literal') {
  30680. return null;
  30681. }
  30682. n = num1.number;
  30683. if (n < 0 || (n|0) !== n || stack.length < n) {
  30684. return null;
  30685. }
  30686. ast1 = stack[stack.length - n - 1];
  30687. if (ast1.type === 'literal' || ast1.type === 'var') {
  30688. stack.push(ast1);
  30689. break;
  30690. }
  30691. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  30692. stack[stack.length - n - 1] = tmpVar;
  30693. stack.push(tmpVar);
  30694. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  30695. break;
  30696. case 'dup':
  30697. if (stack.length < 1) {
  30698. return null;
  30699. }
  30700. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  30701. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  30702. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  30703. // special case of the commands sequence for the min operation
  30704. num1 = stack.pop();
  30705. stack.push(buildMinOperation(num1, code[i + 1]));
  30706. i += 6;
  30707. break;
  30708. }
  30709. ast1 = stack[stack.length - 1];
  30710. if (ast1.type === 'literal' || ast1.type === 'var') {
  30711. // we don't have to save into intermediate variable a literal or
  30712. // variable.
  30713. stack.push(ast1);
  30714. break;
  30715. }
  30716. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  30717. stack[stack.length - 1] = tmpVar;
  30718. stack.push(tmpVar);
  30719. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  30720. break;
  30721. case 'roll':
  30722. if (stack.length < 2) {
  30723. return null;
  30724. }
  30725. num2 = stack.pop();
  30726. num1 = stack.pop();
  30727. if (num2.type !== 'literal' || num1.type !== 'literal') {
  30728. // both roll operands must be numbers
  30729. return null;
  30730. }
  30731. j = num2.number;
  30732. n = num1.number;
  30733. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  30734. // ... and integers
  30735. return null;
  30736. }
  30737. j = ((j % n) + n) % n;
  30738. if (j === 0) {
  30739. break; // just skipping -- there are nothing to rotate
  30740. }
  30741. Array.prototype.push.apply(stack,
  30742. stack.splice(stack.length - n, n - j));
  30743. break;
  30744. default:
  30745. return null; // unsupported operator
  30746. }
  30747. }
  30748. if (stack.length !== outputSize) {
  30749. return null;
  30750. }
  30751. var result = [];
  30752. instructions.forEach(function (instruction) {
  30753. var statementBuilder = new ExpressionBuilderVisitor();
  30754. instruction.visit(statementBuilder);
  30755. result.push(statementBuilder.toString());
  30756. });
  30757. stack.forEach(function (expr, i) {
  30758. var statementBuilder = new ExpressionBuilderVisitor();
  30759. expr.visit(statementBuilder);
  30760. var min = range[i * 2], max = range[i * 2 + 1];
  30761. var out = [statementBuilder.toString()];
  30762. if (min > expr.min) {
  30763. out.unshift('Math.max(', min, ', ');
  30764. out.push(')');
  30765. }
  30766. if (max < expr.max) {
  30767. out.unshift('Math.min(', max, ', ');
  30768. out.push(')');
  30769. }
  30770. out.unshift('dest[destOffset + ', i, '] = ');
  30771. out.push(';');
  30772. result.push(out.join(''));
  30773. });
  30774. return result.join('\n');
  30775. }
  30776. };
  30777. return PostScriptCompiler;
  30778. })();
  30779. exports.isPDFFunction = isPDFFunction;
  30780. exports.PDFFunction = PDFFunction;
  30781. exports.PostScriptEvaluator = PostScriptEvaluator;
  30782. exports.PostScriptCompiler = PostScriptCompiler;
  30783. }));
  30784. (function (root, factory) {
  30785. {
  30786. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  30787. root.pdfjsCorePrimitives, root.pdfjsCoreFunction);
  30788. }
  30789. }(this, function (exports, sharedUtil, corePrimitives, coreFunction) {
  30790. var error = sharedUtil.error;
  30791. var info = sharedUtil.info;
  30792. var isArray = sharedUtil.isArray;
  30793. var isString = sharedUtil.isString;
  30794. var shadow = sharedUtil.shadow;
  30795. var warn = sharedUtil.warn;
  30796. var isDict = corePrimitives.isDict;
  30797. var isName = corePrimitives.isName;
  30798. var isStream = corePrimitives.isStream;
  30799. var PDFFunction = coreFunction.PDFFunction;
  30800. var ColorSpace = (function ColorSpaceClosure() {
  30801. /**
  30802. * Resizes an RGB image with 3 components.
  30803. * @param {TypedArray} src - The source buffer.
  30804. * @param {Number} bpc - Number of bits per component.
  30805. * @param {Number} w1 - Original width.
  30806. * @param {Number} h1 - Original height.
  30807. * @param {Number} w2 - New width.
  30808. * @param {Number} h2 - New height.
  30809. * @param {Number} alpha01 - Size reserved for the alpha channel.
  30810. * @param {TypedArray} dest - The destination buffer.
  30811. */
  30812. function resizeRgbImage(src, bpc, w1, h1, w2, h2, alpha01, dest) {
  30813. var COMPONENTS = 3;
  30814. alpha01 = alpha01 !== 1 ? 0 : alpha01;
  30815. var xRatio = w1 / w2;
  30816. var yRatio = h1 / h2;
  30817. var i, j, py, newIndex = 0, oldIndex;
  30818. var xScaled = new Uint16Array(w2);
  30819. var w1Scanline = w1 * COMPONENTS;
  30820. for (i = 0; i < w2; i++) {
  30821. xScaled[i] = Math.floor(i * xRatio) * COMPONENTS;
  30822. }
  30823. for (i = 0; i < h2; i++) {
  30824. py = Math.floor(i * yRatio) * w1Scanline;
  30825. for (j = 0; j < w2; j++) {
  30826. oldIndex = py + xScaled[j];
  30827. dest[newIndex++] = src[oldIndex++];
  30828. dest[newIndex++] = src[oldIndex++];
  30829. dest[newIndex++] = src[oldIndex++];
  30830. newIndex += alpha01;
  30831. }
  30832. }
  30833. }
  30834. // Constructor should define this.numComps, this.defaultColor, this.name
  30835. function ColorSpace() {
  30836. error('should not call ColorSpace constructor');
  30837. }
  30838. ColorSpace.prototype = {
  30839. /**
  30840. * Converts the color value to the RGB color. The color components are
  30841. * located in the src array starting from the srcOffset. Returns the array
  30842. * of the rgb components, each value ranging from [0,255].
  30843. */
  30844. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  30845. var rgb = new Uint8Array(3);
  30846. this.getRgbItem(src, srcOffset, rgb, 0);
  30847. return rgb;
  30848. },
  30849. /**
  30850. * Converts the color value to the RGB color, similar to the getRgb method.
  30851. * The result placed into the dest array starting from the destOffset.
  30852. */
  30853. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  30854. dest, destOffset) {
  30855. error('Should not call ColorSpace.getRgbItem');
  30856. },
  30857. /**
  30858. * Converts the specified number of the color values to the RGB colors.
  30859. * The colors are located in the src array starting from the srcOffset.
  30860. * The result is placed into the dest array starting from the destOffset.
  30861. * The src array items shall be in [0,2^bits) range, the dest array items
  30862. * will be in [0,255] range. alpha01 indicates how many alpha components
  30863. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  30864. * array).
  30865. */
  30866. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  30867. dest, destOffset, bits,
  30868. alpha01) {
  30869. error('Should not call ColorSpace.getRgbBuffer');
  30870. },
  30871. /**
  30872. * Determines the number of bytes required to store the result of the
  30873. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  30874. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  30875. */
  30876. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  30877. alpha01) {
  30878. error('Should not call ColorSpace.getOutputLength');
  30879. },
  30880. /**
  30881. * Returns true if source data will be equal the result/output data.
  30882. */
  30883. isPassthrough: function ColorSpace_isPassthrough(bits) {
  30884. return false;
  30885. },
  30886. /**
  30887. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  30888. * how many alpha components there are in the dest array; it will be either
  30889. * 0 (RGB array) or 1 (RGBA array).
  30890. */
  30891. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  30892. originalHeight, width, height,
  30893. actualHeight, bpc, comps, alpha01) {
  30894. var count = originalWidth * originalHeight;
  30895. var rgbBuf = null;
  30896. var numComponentColors = 1 << bpc;
  30897. var needsResizing = originalHeight !== height || originalWidth !== width;
  30898. var i, ii;
  30899. if (this.isPassthrough(bpc)) {
  30900. rgbBuf = comps;
  30901. } else if (this.numComps === 1 && count > numComponentColors &&
  30902. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  30903. // Optimization: create a color map when there is just one component and
  30904. // we are converting more colors than the size of the color map. We
  30905. // don't build the map if the colorspace is gray or rgb since those
  30906. // methods are faster than building a map. This mainly offers big speed
  30907. // ups for indexed and alternate colorspaces.
  30908. //
  30909. // TODO it may be worth while to cache the color map. While running
  30910. // testing I never hit a cache so I will leave that out for now (perhaps
  30911. // we are reparsing colorspaces too much?).
  30912. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  30913. new Uint16Array(numComponentColors);
  30914. var key;
  30915. for (i = 0; i < numComponentColors; i++) {
  30916. allColors[i] = i;
  30917. }
  30918. var colorMap = new Uint8Array(numComponentColors * 3);
  30919. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  30920. /* alpha01 = */ 0);
  30921. var destPos, rgbPos;
  30922. if (!needsResizing) {
  30923. // Fill in the RGB values directly into |dest|.
  30924. destPos = 0;
  30925. for (i = 0; i < count; ++i) {
  30926. key = comps[i] * 3;
  30927. dest[destPos++] = colorMap[key];
  30928. dest[destPos++] = colorMap[key + 1];
  30929. dest[destPos++] = colorMap[key + 2];
  30930. destPos += alpha01;
  30931. }
  30932. } else {
  30933. rgbBuf = new Uint8Array(count * 3);
  30934. rgbPos = 0;
  30935. for (i = 0; i < count; ++i) {
  30936. key = comps[i] * 3;
  30937. rgbBuf[rgbPos++] = colorMap[key];
  30938. rgbBuf[rgbPos++] = colorMap[key + 1];
  30939. rgbBuf[rgbPos++] = colorMap[key + 2];
  30940. }
  30941. }
  30942. } else {
  30943. if (!needsResizing) {
  30944. // Fill in the RGB values directly into |dest|.
  30945. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  30946. alpha01);
  30947. } else {
  30948. rgbBuf = new Uint8Array(count * 3);
  30949. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  30950. /* alpha01 = */ 0);
  30951. }
  30952. }
  30953. if (rgbBuf) {
  30954. if (needsResizing) {
  30955. resizeRgbImage(rgbBuf, bpc, originalWidth, originalHeight,
  30956. width, height, alpha01, dest);
  30957. } else {
  30958. rgbPos = 0;
  30959. destPos = 0;
  30960. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  30961. dest[destPos++] = rgbBuf[rgbPos++];
  30962. dest[destPos++] = rgbBuf[rgbPos++];
  30963. dest[destPos++] = rgbBuf[rgbPos++];
  30964. destPos += alpha01;
  30965. }
  30966. }
  30967. }
  30968. },
  30969. /**
  30970. * True if the colorspace has components in the default range of [0, 1].
  30971. * This should be true for all colorspaces except for lab color spaces
  30972. * which are [0,100], [-128, 127], [-128, 127].
  30973. */
  30974. usesZeroToOneRange: true
  30975. };
  30976. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  30977. var IR = ColorSpace.parseToIR(cs, xref, res);
  30978. if (IR instanceof AlternateCS) {
  30979. return IR;
  30980. }
  30981. return ColorSpace.fromIR(IR);
  30982. };
  30983. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  30984. var name = isArray(IR) ? IR[0] : IR;
  30985. var whitePoint, blackPoint, gamma;
  30986. switch (name) {
  30987. case 'DeviceGrayCS':
  30988. return this.singletons.gray;
  30989. case 'DeviceRgbCS':
  30990. return this.singletons.rgb;
  30991. case 'DeviceCmykCS':
  30992. return this.singletons.cmyk;
  30993. case 'CalGrayCS':
  30994. whitePoint = IR[1];
  30995. blackPoint = IR[2];
  30996. gamma = IR[3];
  30997. return new CalGrayCS(whitePoint, blackPoint, gamma);
  30998. case 'CalRGBCS':
  30999. whitePoint = IR[1];
  31000. blackPoint = IR[2];
  31001. gamma = IR[3];
  31002. var matrix = IR[4];
  31003. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  31004. case 'PatternCS':
  31005. var basePatternCS = IR[1];
  31006. if (basePatternCS) {
  31007. basePatternCS = ColorSpace.fromIR(basePatternCS);
  31008. }
  31009. return new PatternCS(basePatternCS);
  31010. case 'IndexedCS':
  31011. var baseIndexedCS = IR[1];
  31012. var hiVal = IR[2];
  31013. var lookup = IR[3];
  31014. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  31015. case 'AlternateCS':
  31016. var numComps = IR[1];
  31017. var alt = IR[2];
  31018. var tintFnIR = IR[3];
  31019. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  31020. PDFFunction.fromIR(tintFnIR));
  31021. case 'LabCS':
  31022. whitePoint = IR[1];
  31023. blackPoint = IR[2];
  31024. var range = IR[3];
  31025. return new LabCS(whitePoint, blackPoint, range);
  31026. default:
  31027. error('Unknown name ' + name);
  31028. }
  31029. return null;
  31030. };
  31031. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  31032. if (isName(cs)) {
  31033. var colorSpaces = res.get('ColorSpace');
  31034. if (isDict(colorSpaces)) {
  31035. var refcs = colorSpaces.get(cs.name);
  31036. if (refcs) {
  31037. cs = refcs;
  31038. }
  31039. }
  31040. }
  31041. cs = xref.fetchIfRef(cs);
  31042. var mode;
  31043. if (isName(cs)) {
  31044. mode = cs.name;
  31045. this.mode = mode;
  31046. switch (mode) {
  31047. case 'DeviceGray':
  31048. case 'G':
  31049. return 'DeviceGrayCS';
  31050. case 'DeviceRGB':
  31051. case 'RGB':
  31052. return 'DeviceRgbCS';
  31053. case 'DeviceCMYK':
  31054. case 'CMYK':
  31055. return 'DeviceCmykCS';
  31056. case 'Pattern':
  31057. return ['PatternCS', null];
  31058. default:
  31059. error('unrecognized colorspace ' + mode);
  31060. }
  31061. } else if (isArray(cs)) {
  31062. mode = xref.fetchIfRef(cs[0]).name;
  31063. this.mode = mode;
  31064. var numComps, params, alt, whitePoint, blackPoint, gamma;
  31065. switch (mode) {
  31066. case 'DeviceGray':
  31067. case 'G':
  31068. return 'DeviceGrayCS';
  31069. case 'DeviceRGB':
  31070. case 'RGB':
  31071. return 'DeviceRgbCS';
  31072. case 'DeviceCMYK':
  31073. case 'CMYK':
  31074. return 'DeviceCmykCS';
  31075. case 'CalGray':
  31076. params = xref.fetchIfRef(cs[1]);
  31077. whitePoint = params.getArray('WhitePoint');
  31078. blackPoint = params.getArray('BlackPoint');
  31079. gamma = params.get('Gamma');
  31080. return ['CalGrayCS', whitePoint, blackPoint, gamma];
  31081. case 'CalRGB':
  31082. params = xref.fetchIfRef(cs[1]);
  31083. whitePoint = params.getArray('WhitePoint');
  31084. blackPoint = params.getArray('BlackPoint');
  31085. gamma = params.getArray('Gamma');
  31086. var matrix = params.getArray('Matrix');
  31087. return ['CalRGBCS', whitePoint, blackPoint, gamma, matrix];
  31088. case 'ICCBased':
  31089. var stream = xref.fetchIfRef(cs[1]);
  31090. var dict = stream.dict;
  31091. numComps = dict.get('N');
  31092. alt = dict.get('Alternate');
  31093. if (alt) {
  31094. var altIR = ColorSpace.parseToIR(alt, xref, res);
  31095. // Parse the /Alternate CS to ensure that the number of components
  31096. // are correct, and also (indirectly) that it is not a PatternCS.
  31097. var altCS = ColorSpace.fromIR(altIR);
  31098. if (altCS.numComps === numComps) {
  31099. return altIR;
  31100. }
  31101. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  31102. }
  31103. if (numComps === 1) {
  31104. return 'DeviceGrayCS';
  31105. } else if (numComps === 3) {
  31106. return 'DeviceRgbCS';
  31107. } else if (numComps === 4) {
  31108. return 'DeviceCmykCS';
  31109. }
  31110. break;
  31111. case 'Pattern':
  31112. var basePatternCS = cs[1] || null;
  31113. if (basePatternCS) {
  31114. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  31115. }
  31116. return ['PatternCS', basePatternCS];
  31117. case 'Indexed':
  31118. case 'I':
  31119. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  31120. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  31121. var lookup = xref.fetchIfRef(cs[3]);
  31122. if (isStream(lookup)) {
  31123. lookup = lookup.getBytes();
  31124. }
  31125. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  31126. case 'Separation':
  31127. case 'DeviceN':
  31128. var name = xref.fetchIfRef(cs[1]);
  31129. numComps = 1;
  31130. if (isName(name)) {
  31131. numComps = 1;
  31132. } else if (isArray(name)) {
  31133. numComps = name.length;
  31134. }
  31135. alt = ColorSpace.parseToIR(cs[2], xref, res);
  31136. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  31137. return ['AlternateCS', numComps, alt, tintFnIR];
  31138. case 'Lab':
  31139. params = xref.fetchIfRef(cs[1]);
  31140. whitePoint = params.getArray('WhitePoint');
  31141. blackPoint = params.getArray('BlackPoint');
  31142. var range = params.getArray('Range');
  31143. return ['LabCS', whitePoint, blackPoint, range];
  31144. default:
  31145. error('unimplemented color space object "' + mode + '"');
  31146. }
  31147. } else {
  31148. error('unrecognized color space object: "' + cs + '"');
  31149. }
  31150. return null;
  31151. };
  31152. /**
  31153. * Checks if a decode map matches the default decode map for a color space.
  31154. * This handles the general decode maps where there are two values per
  31155. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  31156. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  31157. * slightly different.
  31158. * @param {Array} decode Decode map (usually from an image).
  31159. * @param {Number} n Number of components the color space has.
  31160. */
  31161. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  31162. if (!isArray(decode)) {
  31163. return true;
  31164. }
  31165. if (n * 2 !== decode.length) {
  31166. warn('The decode map is not the correct length');
  31167. return true;
  31168. }
  31169. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  31170. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  31171. return false;
  31172. }
  31173. }
  31174. return true;
  31175. };
  31176. ColorSpace.singletons = {
  31177. get gray() {
  31178. return shadow(this, 'gray', new DeviceGrayCS());
  31179. },
  31180. get rgb() {
  31181. return shadow(this, 'rgb', new DeviceRgbCS());
  31182. },
  31183. get cmyk() {
  31184. return shadow(this, 'cmyk', new DeviceCmykCS());
  31185. }
  31186. };
  31187. return ColorSpace;
  31188. })();
  31189. /**
  31190. * Alternate color space handles both Separation and DeviceN color spaces. A
  31191. * Separation color space is actually just a DeviceN with one color component.
  31192. * Both color spaces use a tinting function to convert colors to a base color
  31193. * space.
  31194. */
  31195. var AlternateCS = (function AlternateCSClosure() {
  31196. function AlternateCS(numComps, base, tintFn) {
  31197. this.name = 'Alternate';
  31198. this.numComps = numComps;
  31199. this.defaultColor = new Float32Array(numComps);
  31200. for (var i = 0; i < numComps; ++i) {
  31201. this.defaultColor[i] = 1;
  31202. }
  31203. this.base = base;
  31204. this.tintFn = tintFn;
  31205. this.tmpBuf = new Float32Array(base.numComps);
  31206. }
  31207. AlternateCS.prototype = {
  31208. getRgb: ColorSpace.prototype.getRgb,
  31209. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  31210. dest, destOffset) {
  31211. var tmpBuf = this.tmpBuf;
  31212. this.tintFn(src, srcOffset, tmpBuf, 0);
  31213. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  31214. },
  31215. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  31216. dest, destOffset, bits,
  31217. alpha01) {
  31218. var tintFn = this.tintFn;
  31219. var base = this.base;
  31220. var scale = 1 / ((1 << bits) - 1);
  31221. var baseNumComps = base.numComps;
  31222. var usesZeroToOneRange = base.usesZeroToOneRange;
  31223. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  31224. alpha01 === 0;
  31225. var pos = isPassthrough ? destOffset : 0;
  31226. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  31227. var numComps = this.numComps;
  31228. var scaled = new Float32Array(numComps);
  31229. var tinted = new Float32Array(baseNumComps);
  31230. var i, j;
  31231. if (usesZeroToOneRange) {
  31232. for (i = 0; i < count; i++) {
  31233. for (j = 0; j < numComps; j++) {
  31234. scaled[j] = src[srcOffset++] * scale;
  31235. }
  31236. tintFn(scaled, 0, tinted, 0);
  31237. for (j = 0; j < baseNumComps; j++) {
  31238. baseBuf[pos++] = tinted[j] * 255;
  31239. }
  31240. }
  31241. } else {
  31242. for (i = 0; i < count; i++) {
  31243. for (j = 0; j < numComps; j++) {
  31244. scaled[j] = src[srcOffset++] * scale;
  31245. }
  31246. tintFn(scaled, 0, tinted, 0);
  31247. base.getRgbItem(tinted, 0, baseBuf, pos);
  31248. pos += baseNumComps;
  31249. }
  31250. }
  31251. if (!isPassthrough) {
  31252. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  31253. }
  31254. },
  31255. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  31256. alpha01) {
  31257. return this.base.getOutputLength(inputLength *
  31258. this.base.numComps / this.numComps,
  31259. alpha01);
  31260. },
  31261. isPassthrough: ColorSpace.prototype.isPassthrough,
  31262. fillRgb: ColorSpace.prototype.fillRgb,
  31263. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  31264. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31265. },
  31266. usesZeroToOneRange: true
  31267. };
  31268. return AlternateCS;
  31269. })();
  31270. var PatternCS = (function PatternCSClosure() {
  31271. function PatternCS(baseCS) {
  31272. this.name = 'Pattern';
  31273. this.base = baseCS;
  31274. }
  31275. PatternCS.prototype = {};
  31276. return PatternCS;
  31277. })();
  31278. var IndexedCS = (function IndexedCSClosure() {
  31279. function IndexedCS(base, highVal, lookup) {
  31280. this.name = 'Indexed';
  31281. this.numComps = 1;
  31282. this.defaultColor = new Uint8Array([0]);
  31283. this.base = base;
  31284. this.highVal = highVal;
  31285. var baseNumComps = base.numComps;
  31286. var length = baseNumComps * highVal;
  31287. var lookupArray;
  31288. if (isStream(lookup)) {
  31289. lookupArray = new Uint8Array(length);
  31290. var bytes = lookup.getBytes(length);
  31291. lookupArray.set(bytes);
  31292. } else if (isString(lookup)) {
  31293. lookupArray = new Uint8Array(length);
  31294. for (var i = 0; i < length; ++i) {
  31295. lookupArray[i] = lookup.charCodeAt(i);
  31296. }
  31297. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  31298. lookupArray = lookup;
  31299. } else {
  31300. error('Unrecognized lookup table: ' + lookup);
  31301. }
  31302. this.lookup = lookupArray;
  31303. }
  31304. IndexedCS.prototype = {
  31305. getRgb: ColorSpace.prototype.getRgb,
  31306. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  31307. dest, destOffset) {
  31308. var numComps = this.base.numComps;
  31309. var start = src[srcOffset] * numComps;
  31310. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  31311. },
  31312. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  31313. dest, destOffset, bits,
  31314. alpha01) {
  31315. var base = this.base;
  31316. var numComps = base.numComps;
  31317. var outputDelta = base.getOutputLength(numComps, alpha01);
  31318. var lookup = this.lookup;
  31319. for (var i = 0; i < count; ++i) {
  31320. var lookupPos = src[srcOffset++] * numComps;
  31321. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  31322. destOffset += outputDelta;
  31323. }
  31324. },
  31325. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  31326. return this.base.getOutputLength(inputLength * this.base.numComps,
  31327. alpha01);
  31328. },
  31329. isPassthrough: ColorSpace.prototype.isPassthrough,
  31330. fillRgb: ColorSpace.prototype.fillRgb,
  31331. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  31332. // indexed color maps shouldn't be changed
  31333. return true;
  31334. },
  31335. usesZeroToOneRange: true
  31336. };
  31337. return IndexedCS;
  31338. })();
  31339. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  31340. function DeviceGrayCS() {
  31341. this.name = 'DeviceGray';
  31342. this.numComps = 1;
  31343. this.defaultColor = new Float32Array([0]);
  31344. }
  31345. DeviceGrayCS.prototype = {
  31346. getRgb: ColorSpace.prototype.getRgb,
  31347. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  31348. dest, destOffset) {
  31349. var c = (src[srcOffset] * 255) | 0;
  31350. c = c < 0 ? 0 : c > 255 ? 255 : c;
  31351. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  31352. },
  31353. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  31354. dest, destOffset, bits,
  31355. alpha01) {
  31356. var scale = 255 / ((1 << bits) - 1);
  31357. var j = srcOffset, q = destOffset;
  31358. for (var i = 0; i < count; ++i) {
  31359. var c = (scale * src[j++]) | 0;
  31360. dest[q++] = c;
  31361. dest[q++] = c;
  31362. dest[q++] = c;
  31363. q += alpha01;
  31364. }
  31365. },
  31366. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  31367. alpha01) {
  31368. return inputLength * (3 + alpha01);
  31369. },
  31370. isPassthrough: ColorSpace.prototype.isPassthrough,
  31371. fillRgb: ColorSpace.prototype.fillRgb,
  31372. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  31373. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31374. },
  31375. usesZeroToOneRange: true
  31376. };
  31377. return DeviceGrayCS;
  31378. })();
  31379. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  31380. function DeviceRgbCS() {
  31381. this.name = 'DeviceRGB';
  31382. this.numComps = 3;
  31383. this.defaultColor = new Float32Array([0, 0, 0]);
  31384. }
  31385. DeviceRgbCS.prototype = {
  31386. getRgb: ColorSpace.prototype.getRgb,
  31387. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  31388. dest, destOffset) {
  31389. var r = (src[srcOffset] * 255) | 0;
  31390. var g = (src[srcOffset + 1] * 255) | 0;
  31391. var b = (src[srcOffset + 2] * 255) | 0;
  31392. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  31393. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  31394. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  31395. },
  31396. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  31397. dest, destOffset, bits,
  31398. alpha01) {
  31399. if (bits === 8 && alpha01 === 0) {
  31400. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  31401. return;
  31402. }
  31403. var scale = 255 / ((1 << bits) - 1);
  31404. var j = srcOffset, q = destOffset;
  31405. for (var i = 0; i < count; ++i) {
  31406. dest[q++] = (scale * src[j++]) | 0;
  31407. dest[q++] = (scale * src[j++]) | 0;
  31408. dest[q++] = (scale * src[j++]) | 0;
  31409. q += alpha01;
  31410. }
  31411. },
  31412. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  31413. alpha01) {
  31414. return (inputLength * (3 + alpha01) / 3) | 0;
  31415. },
  31416. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  31417. return bits === 8;
  31418. },
  31419. fillRgb: ColorSpace.prototype.fillRgb,
  31420. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  31421. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31422. },
  31423. usesZeroToOneRange: true
  31424. };
  31425. return DeviceRgbCS;
  31426. })();
  31427. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  31428. // The coefficients below was found using numerical analysis: the method of
  31429. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  31430. // where color_value is the tabular value from the table of sampled RGB colors
  31431. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  31432. // CMYK color conversion using the estimation below:
  31433. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  31434. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  31435. var c = src[srcOffset + 0] * srcScale;
  31436. var m = src[srcOffset + 1] * srcScale;
  31437. var y = src[srcOffset + 2] * srcScale;
  31438. var k = src[srcOffset + 3] * srcScale;
  31439. var r =
  31440. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  31441. 18.82290502165302 * y + 212.25662451639585 * k +
  31442. -285.2331026137004) +
  31443. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  31444. -17.873870861415444 * k - 5.497006427196366) +
  31445. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  31446. 17.5119270841813) +
  31447. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  31448. var g =
  31449. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  31450. 6.871425592049007 * y + 31.159100130055922 * k +
  31451. -79.2970844816548) +
  31452. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  31453. 131.35250912493976 * k - 190.9453302588951) +
  31454. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  31455. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  31456. var b =
  31457. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  31458. 30.89978309703729 * y - 0.23883238689178934 * k +
  31459. -14.183576799673286) +
  31460. m * (10.49593273432072 * m + 63.02378494754052 * y +
  31461. 50.606957656360734 * k - 112.23884253719248) +
  31462. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  31463. -193.58209356861505) +
  31464. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  31465. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  31466. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  31467. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  31468. }
  31469. function DeviceCmykCS() {
  31470. this.name = 'DeviceCMYK';
  31471. this.numComps = 4;
  31472. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  31473. }
  31474. DeviceCmykCS.prototype = {
  31475. getRgb: ColorSpace.prototype.getRgb,
  31476. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  31477. dest, destOffset) {
  31478. convertToRgb(src, srcOffset, 1, dest, destOffset);
  31479. },
  31480. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  31481. dest, destOffset, bits,
  31482. alpha01) {
  31483. var scale = 1 / ((1 << bits) - 1);
  31484. for (var i = 0; i < count; i++) {
  31485. convertToRgb(src, srcOffset, scale, dest, destOffset);
  31486. srcOffset += 4;
  31487. destOffset += 3 + alpha01;
  31488. }
  31489. },
  31490. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  31491. alpha01) {
  31492. return (inputLength / 4 * (3 + alpha01)) | 0;
  31493. },
  31494. isPassthrough: ColorSpace.prototype.isPassthrough,
  31495. fillRgb: ColorSpace.prototype.fillRgb,
  31496. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  31497. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31498. },
  31499. usesZeroToOneRange: true
  31500. };
  31501. return DeviceCmykCS;
  31502. })();
  31503. //
  31504. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  31505. //
  31506. var CalGrayCS = (function CalGrayCSClosure() {
  31507. function CalGrayCS(whitePoint, blackPoint, gamma) {
  31508. this.name = 'CalGray';
  31509. this.numComps = 1;
  31510. this.defaultColor = new Float32Array([0]);
  31511. if (!whitePoint) {
  31512. error('WhitePoint missing - required for color space CalGray');
  31513. }
  31514. blackPoint = blackPoint || [0, 0, 0];
  31515. gamma = gamma || 1;
  31516. // Translate arguments to spec variables.
  31517. this.XW = whitePoint[0];
  31518. this.YW = whitePoint[1];
  31519. this.ZW = whitePoint[2];
  31520. this.XB = blackPoint[0];
  31521. this.YB = blackPoint[1];
  31522. this.ZB = blackPoint[2];
  31523. this.G = gamma;
  31524. // Validate variables as per spec.
  31525. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  31526. error('Invalid WhitePoint components for ' + this.name +
  31527. ', no fallback available');
  31528. }
  31529. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  31530. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  31531. this.XB = this.YB = this.ZB = 0;
  31532. }
  31533. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  31534. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  31535. ', ZB: ' + this.ZB + ', only default values are supported.');
  31536. }
  31537. if (this.G < 1) {
  31538. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  31539. ', falling back to default');
  31540. this.G = 1;
  31541. }
  31542. }
  31543. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  31544. // A represents a gray component of a calibrated gray space.
  31545. // A <---> AG in the spec
  31546. var A = src[srcOffset] * scale;
  31547. var AG = Math.pow(A, cs.G);
  31548. // Computes L as per spec. ( = cs.YW * AG )
  31549. // Except if other than default BlackPoint values are used.
  31550. var L = cs.YW * AG;
  31551. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  31552. // Convert values to rgb range [0, 255].
  31553. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  31554. dest[destOffset] = val;
  31555. dest[destOffset + 1] = val;
  31556. dest[destOffset + 2] = val;
  31557. }
  31558. CalGrayCS.prototype = {
  31559. getRgb: ColorSpace.prototype.getRgb,
  31560. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  31561. dest, destOffset) {
  31562. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  31563. },
  31564. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  31565. dest, destOffset, bits,
  31566. alpha01) {
  31567. var scale = 1 / ((1 << bits) - 1);
  31568. for (var i = 0; i < count; ++i) {
  31569. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  31570. srcOffset += 1;
  31571. destOffset += 3 + alpha01;
  31572. }
  31573. },
  31574. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  31575. return inputLength * (3 + alpha01);
  31576. },
  31577. isPassthrough: ColorSpace.prototype.isPassthrough,
  31578. fillRgb: ColorSpace.prototype.fillRgb,
  31579. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  31580. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31581. },
  31582. usesZeroToOneRange: true
  31583. };
  31584. return CalGrayCS;
  31585. })();
  31586. //
  31587. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  31588. //
  31589. var CalRGBCS = (function CalRGBCSClosure() {
  31590. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  31591. // matrices.
  31592. var BRADFORD_SCALE_MATRIX = new Float32Array([
  31593. 0.8951, 0.2664, -0.1614,
  31594. -0.7502, 1.7135, 0.0367,
  31595. 0.0389, -0.0685, 1.0296]);
  31596. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  31597. 0.9869929, -0.1470543, 0.1599627,
  31598. 0.4323053, 0.5183603, 0.0492912,
  31599. -0.0085287, 0.0400428, 0.9684867]);
  31600. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  31601. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  31602. 3.2404542, -1.5371385, -0.4985314,
  31603. -0.9692660, 1.8760108, 0.0415560,
  31604. 0.0556434, -0.2040259, 1.0572252]);
  31605. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  31606. var tempNormalizeMatrix = new Float32Array(3);
  31607. var tempConvertMatrix1 = new Float32Array(3);
  31608. var tempConvertMatrix2 = new Float32Array(3);
  31609. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  31610. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  31611. this.name = 'CalRGB';
  31612. this.numComps = 3;
  31613. this.defaultColor = new Float32Array(3);
  31614. if (!whitePoint) {
  31615. error('WhitePoint missing - required for color space CalRGB');
  31616. }
  31617. blackPoint = blackPoint || new Float32Array(3);
  31618. gamma = gamma || new Float32Array([1, 1, 1]);
  31619. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  31620. // Translate arguments to spec variables.
  31621. var XW = whitePoint[0];
  31622. var YW = whitePoint[1];
  31623. var ZW = whitePoint[2];
  31624. this.whitePoint = whitePoint;
  31625. var XB = blackPoint[0];
  31626. var YB = blackPoint[1];
  31627. var ZB = blackPoint[2];
  31628. this.blackPoint = blackPoint;
  31629. this.GR = gamma[0];
  31630. this.GG = gamma[1];
  31631. this.GB = gamma[2];
  31632. this.MXA = matrix[0];
  31633. this.MYA = matrix[1];
  31634. this.MZA = matrix[2];
  31635. this.MXB = matrix[3];
  31636. this.MYB = matrix[4];
  31637. this.MZB = matrix[5];
  31638. this.MXC = matrix[6];
  31639. this.MYC = matrix[7];
  31640. this.MZC = matrix[8];
  31641. // Validate variables as per spec.
  31642. if (XW < 0 || ZW < 0 || YW !== 1) {
  31643. error('Invalid WhitePoint components for ' + this.name +
  31644. ', no fallback available');
  31645. }
  31646. if (XB < 0 || YB < 0 || ZB < 0) {
  31647. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  31648. ', ' + ZB + '], falling back to default');
  31649. this.blackPoint = new Float32Array(3);
  31650. }
  31651. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  31652. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  31653. '] for ' + this.name + ', falling back to default');
  31654. this.GR = this.GG = this.GB = 1;
  31655. }
  31656. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  31657. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  31658. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  31659. info('Invalid Matrix for ' + this.name + ' [' +
  31660. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  31661. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  31662. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  31663. '], falling back to default');
  31664. this.MXA = this.MYB = this.MZC = 1;
  31665. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  31666. }
  31667. }
  31668. function matrixProduct(a, b, result) {
  31669. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  31670. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  31671. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  31672. }
  31673. function convertToFlat(sourceWhitePoint, LMS, result) {
  31674. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  31675. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  31676. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  31677. }
  31678. function convertToD65(sourceWhitePoint, LMS, result) {
  31679. var D65X = 0.95047;
  31680. var D65Y = 1;
  31681. var D65Z = 1.08883;
  31682. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  31683. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  31684. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  31685. }
  31686. function sRGBTransferFunction(color) {
  31687. // See http://en.wikipedia.org/wiki/SRGB.
  31688. if (color <= 0.0031308){
  31689. return adjustToRange(0, 1, 12.92 * color);
  31690. }
  31691. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  31692. }
  31693. function adjustToRange(min, max, value) {
  31694. return Math.max(min, Math.min(max, value));
  31695. }
  31696. function decodeL(L) {
  31697. if (L < 0) {
  31698. return -decodeL(-L);
  31699. }
  31700. if (L > 8.0) {
  31701. return Math.pow(((L + 16) / 116), 3);
  31702. }
  31703. return L * DECODE_L_CONSTANT;
  31704. }
  31705. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  31706. // In case the blackPoint is already the default blackPoint then there is
  31707. // no need to do compensation.
  31708. if (sourceBlackPoint[0] === 0 &&
  31709. sourceBlackPoint[1] === 0 &&
  31710. sourceBlackPoint[2] === 0) {
  31711. result[0] = XYZ_Flat[0];
  31712. result[1] = XYZ_Flat[1];
  31713. result[2] = XYZ_Flat[2];
  31714. return;
  31715. }
  31716. // For the blackPoint calculation details, please see
  31717. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  31718. // AdobeBPC.pdf.
  31719. // The destination blackPoint is the default blackPoint [0, 0, 0].
  31720. var zeroDecodeL = decodeL(0);
  31721. var X_DST = zeroDecodeL;
  31722. var X_SRC = decodeL(sourceBlackPoint[0]);
  31723. var Y_DST = zeroDecodeL;
  31724. var Y_SRC = decodeL(sourceBlackPoint[1]);
  31725. var Z_DST = zeroDecodeL;
  31726. var Z_SRC = decodeL(sourceBlackPoint[2]);
  31727. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  31728. var X_Offset = 1 - X_Scale;
  31729. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  31730. var Y_Offset = 1 - Y_Scale;
  31731. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  31732. var Z_Offset = 1 - Z_Scale;
  31733. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  31734. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  31735. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  31736. }
  31737. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  31738. // In case the whitePoint is already flat then there is no need to do
  31739. // normalization.
  31740. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  31741. result[0] = XYZ_In[0];
  31742. result[1] = XYZ_In[1];
  31743. result[2] = XYZ_In[2];
  31744. return;
  31745. }
  31746. var LMS = result;
  31747. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  31748. var LMS_Flat = tempNormalizeMatrix;
  31749. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  31750. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  31751. }
  31752. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  31753. var LMS = result;
  31754. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  31755. var LMS_D65 = tempNormalizeMatrix;
  31756. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  31757. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  31758. }
  31759. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  31760. // A, B and C represent a red, green and blue components of a calibrated
  31761. // rgb space.
  31762. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  31763. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  31764. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  31765. // A <---> AGR in the spec
  31766. // B <---> BGG in the spec
  31767. // C <---> CGB in the spec
  31768. var AGR = Math.pow(A, cs.GR);
  31769. var BGG = Math.pow(B, cs.GG);
  31770. var CGB = Math.pow(C, cs.GB);
  31771. // Computes intermediate variables L, M, N as per spec.
  31772. // To decode X, Y, Z values map L, M, N directly to them.
  31773. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  31774. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  31775. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  31776. // The following calculations are based on this document:
  31777. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  31778. // AdobeBPC.pdf.
  31779. var XYZ = tempConvertMatrix1;
  31780. XYZ[0] = X;
  31781. XYZ[1] = Y;
  31782. XYZ[2] = Z;
  31783. var XYZ_Flat = tempConvertMatrix2;
  31784. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  31785. var XYZ_Black = tempConvertMatrix1;
  31786. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  31787. var XYZ_D65 = tempConvertMatrix2;
  31788. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  31789. var SRGB = tempConvertMatrix1;
  31790. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  31791. var sR = sRGBTransferFunction(SRGB[0]);
  31792. var sG = sRGBTransferFunction(SRGB[1]);
  31793. var sB = sRGBTransferFunction(SRGB[2]);
  31794. // Convert the values to rgb range [0, 255].
  31795. dest[destOffset] = Math.round(sR * 255);
  31796. dest[destOffset + 1] = Math.round(sG * 255);
  31797. dest[destOffset + 2] = Math.round(sB * 255);
  31798. }
  31799. CalRGBCS.prototype = {
  31800. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  31801. var rgb = new Uint8Array(3);
  31802. this.getRgbItem(src, srcOffset, rgb, 0);
  31803. return rgb;
  31804. },
  31805. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  31806. dest, destOffset) {
  31807. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  31808. },
  31809. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  31810. dest, destOffset, bits,
  31811. alpha01) {
  31812. var scale = 1 / ((1 << bits) - 1);
  31813. for (var i = 0; i < count; ++i) {
  31814. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  31815. srcOffset += 3;
  31816. destOffset += 3 + alpha01;
  31817. }
  31818. },
  31819. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  31820. return (inputLength * (3 + alpha01) / 3) | 0;
  31821. },
  31822. isPassthrough: ColorSpace.prototype.isPassthrough,
  31823. fillRgb: ColorSpace.prototype.fillRgb,
  31824. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  31825. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31826. },
  31827. usesZeroToOneRange: true
  31828. };
  31829. return CalRGBCS;
  31830. })();
  31831. //
  31832. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  31833. //
  31834. var LabCS = (function LabCSClosure() {
  31835. function LabCS(whitePoint, blackPoint, range) {
  31836. this.name = 'Lab';
  31837. this.numComps = 3;
  31838. this.defaultColor = new Float32Array([0, 0, 0]);
  31839. if (!whitePoint) {
  31840. error('WhitePoint missing - required for color space Lab');
  31841. }
  31842. blackPoint = blackPoint || [0, 0, 0];
  31843. range = range || [-100, 100, -100, 100];
  31844. // Translate args to spec variables
  31845. this.XW = whitePoint[0];
  31846. this.YW = whitePoint[1];
  31847. this.ZW = whitePoint[2];
  31848. this.amin = range[0];
  31849. this.amax = range[1];
  31850. this.bmin = range[2];
  31851. this.bmax = range[3];
  31852. // These are here just for completeness - the spec doesn't offer any
  31853. // formulas that use BlackPoint in Lab
  31854. this.XB = blackPoint[0];
  31855. this.YB = blackPoint[1];
  31856. this.ZB = blackPoint[2];
  31857. // Validate vars as per spec
  31858. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  31859. error('Invalid WhitePoint components, no fallback available');
  31860. }
  31861. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  31862. info('Invalid BlackPoint, falling back to default');
  31863. this.XB = this.YB = this.ZB = 0;
  31864. }
  31865. if (this.amin > this.amax || this.bmin > this.bmax) {
  31866. info('Invalid Range, falling back to defaults');
  31867. this.amin = -100;
  31868. this.amax = 100;
  31869. this.bmin = -100;
  31870. this.bmax = 100;
  31871. }
  31872. }
  31873. // Function g(x) from spec
  31874. function fn_g(x) {
  31875. if (x >= 6 / 29) {
  31876. return x * x * x;
  31877. } else {
  31878. return (108 / 841) * (x - 4 / 29);
  31879. }
  31880. }
  31881. function decode(value, high1, low2, high2) {
  31882. return low2 + (value) * (high2 - low2) / (high1);
  31883. }
  31884. // If decoding is needed maxVal should be 2^bits per component - 1.
  31885. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  31886. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  31887. // not the usual [0, 1]. If a command like setFillColor is used the src
  31888. // values will already be within the correct range. However, if we are
  31889. // converting an image we have to map the values to the correct range given
  31890. // above.
  31891. // Ls,as,bs <---> L*,a*,b* in the spec
  31892. var Ls = src[srcOffset];
  31893. var as = src[srcOffset + 1];
  31894. var bs = src[srcOffset + 2];
  31895. if (maxVal !== false) {
  31896. Ls = decode(Ls, maxVal, 0, 100);
  31897. as = decode(as, maxVal, cs.amin, cs.amax);
  31898. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  31899. }
  31900. // Adjust limits of 'as' and 'bs'
  31901. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  31902. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  31903. // Computes intermediate variables X,Y,Z as per spec
  31904. var M = (Ls + 16) / 116;
  31905. var L = M + (as / 500);
  31906. var N = M - (bs / 200);
  31907. var X = cs.XW * fn_g(L);
  31908. var Y = cs.YW * fn_g(M);
  31909. var Z = cs.ZW * fn_g(N);
  31910. var r, g, b;
  31911. // Using different conversions for D50 and D65 white points,
  31912. // per http://www.color.org/srgb.pdf
  31913. if (cs.ZW < 1) {
  31914. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  31915. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  31916. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  31917. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  31918. } else {
  31919. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  31920. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  31921. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  31922. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  31923. }
  31924. // clamp color values to [0,1] range then convert to [0,255] range.
  31925. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  31926. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  31927. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  31928. }
  31929. LabCS.prototype = {
  31930. getRgb: ColorSpace.prototype.getRgb,
  31931. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  31932. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  31933. },
  31934. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  31935. dest, destOffset, bits,
  31936. alpha01) {
  31937. var maxVal = (1 << bits) - 1;
  31938. for (var i = 0; i < count; i++) {
  31939. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  31940. srcOffset += 3;
  31941. destOffset += 3 + alpha01;
  31942. }
  31943. },
  31944. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  31945. return (inputLength * (3 + alpha01) / 3) | 0;
  31946. },
  31947. isPassthrough: ColorSpace.prototype.isPassthrough,
  31948. fillRgb: ColorSpace.prototype.fillRgb,
  31949. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  31950. // XXX: Decoding is handled with the lab conversion because of the strange
  31951. // ranges that are used.
  31952. return true;
  31953. },
  31954. usesZeroToOneRange: false
  31955. };
  31956. return LabCS;
  31957. })();
  31958. exports.ColorSpace = ColorSpace;
  31959. }));
  31960. (function (root, factory) {
  31961. {
  31962. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  31963. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  31964. root.pdfjsCoreJpx);
  31965. }
  31966. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  31967. coreStream, coreJpx) {
  31968. var ImageKind = sharedUtil.ImageKind;
  31969. var assert = sharedUtil.assert;
  31970. var error = sharedUtil.error;
  31971. var info = sharedUtil.info;
  31972. var isArray = sharedUtil.isArray;
  31973. var warn = sharedUtil.warn;
  31974. var Name = corePrimitives.Name;
  31975. var isStream = corePrimitives.isStream;
  31976. var ColorSpace = coreColorSpace.ColorSpace;
  31977. var DecodeStream = coreStream.DecodeStream;
  31978. var JpegStream = coreStream.JpegStream;
  31979. var JpxImage = coreJpx.JpxImage;
  31980. var PDFImage = (function PDFImageClosure() {
  31981. /**
  31982. * Decodes the image using native decoder if possible. Resolves the promise
  31983. * when the image data is ready.
  31984. */
  31985. function handleImageData(image, nativeDecoder) {
  31986. if (nativeDecoder && nativeDecoder.canDecode(image)) {
  31987. return nativeDecoder.decode(image);
  31988. } else {
  31989. return Promise.resolve(image);
  31990. }
  31991. }
  31992. /**
  31993. * Decode and clamp a value. The formula is different from the spec because we
  31994. * don't decode to float range [0,1], we decode it in the [0,max] range.
  31995. */
  31996. function decodeAndClamp(value, addend, coefficient, max) {
  31997. value = addend + value * coefficient;
  31998. // Clamp the value to the range
  31999. return (value < 0 ? 0 : (value > max ? max : value));
  32000. }
  32001. /**
  32002. * Resizes an image mask with 1 component.
  32003. * @param {TypedArray} src - The source buffer.
  32004. * @param {Number} bpc - Number of bits per component.
  32005. * @param {Number} w1 - Original width.
  32006. * @param {Number} h1 - Original height.
  32007. * @param {Number} w2 - New width.
  32008. * @param {Number} h2 - New height.
  32009. * @returns {TypedArray} The resized image mask buffer.
  32010. */
  32011. function resizeImageMask(src, bpc, w1, h1, w2, h2) {
  32012. var length = w2 * h2;
  32013. var dest = (bpc <= 8 ? new Uint8Array(length) :
  32014. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  32015. var xRatio = w1 / w2;
  32016. var yRatio = h1 / h2;
  32017. var i, j, py, newIndex = 0, oldIndex;
  32018. var xScaled = new Uint16Array(w2);
  32019. var w1Scanline = w1;
  32020. for (i = 0; i < w2; i++) {
  32021. xScaled[i] = Math.floor(i * xRatio);
  32022. }
  32023. for (i = 0; i < h2; i++) {
  32024. py = Math.floor(i * yRatio) * w1Scanline;
  32025. for (j = 0; j < w2; j++) {
  32026. oldIndex = py + xScaled[j];
  32027. dest[newIndex++] = src[oldIndex];
  32028. }
  32029. }
  32030. return dest;
  32031. }
  32032. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  32033. this.image = image;
  32034. var dict = image.dict;
  32035. if (dict.has('Filter')) {
  32036. var filter = dict.get('Filter').name;
  32037. if (filter === 'JPXDecode') {
  32038. var jpxImage = new JpxImage();
  32039. jpxImage.parseImageProperties(image.stream);
  32040. image.stream.reset();
  32041. image.bitsPerComponent = jpxImage.bitsPerComponent;
  32042. image.numComps = jpxImage.componentsCount;
  32043. } else if (filter === 'JBIG2Decode') {
  32044. image.bitsPerComponent = 1;
  32045. image.numComps = 1;
  32046. }
  32047. }
  32048. // TODO cache rendered images?
  32049. this.width = dict.get('Width', 'W');
  32050. this.height = dict.get('Height', 'H');
  32051. if (this.width < 1 || this.height < 1) {
  32052. error('Invalid image width: ' + this.width + ' or height: ' +
  32053. this.height);
  32054. }
  32055. this.interpolate = dict.get('Interpolate', 'I') || false;
  32056. this.imageMask = dict.get('ImageMask', 'IM') || false;
  32057. this.matte = dict.get('Matte') || false;
  32058. var bitsPerComponent = image.bitsPerComponent;
  32059. if (!bitsPerComponent) {
  32060. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  32061. if (!bitsPerComponent) {
  32062. if (this.imageMask) {
  32063. bitsPerComponent = 1;
  32064. } else {
  32065. error('Bits per component missing in image: ' + this.imageMask);
  32066. }
  32067. }
  32068. }
  32069. this.bpc = bitsPerComponent;
  32070. if (!this.imageMask) {
  32071. var colorSpace = dict.get('ColorSpace', 'CS');
  32072. if (!colorSpace) {
  32073. info('JPX images (which do not require color spaces)');
  32074. switch (image.numComps) {
  32075. case 1:
  32076. colorSpace = Name.get('DeviceGray');
  32077. break;
  32078. case 3:
  32079. colorSpace = Name.get('DeviceRGB');
  32080. break;
  32081. case 4:
  32082. colorSpace = Name.get('DeviceCMYK');
  32083. break;
  32084. default:
  32085. error('JPX images with ' + this.numComps +
  32086. ' color components not supported.');
  32087. }
  32088. }
  32089. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  32090. this.numComps = this.colorSpace.numComps;
  32091. }
  32092. this.decode = dict.getArray('Decode', 'D');
  32093. this.needsDecode = false;
  32094. if (this.decode &&
  32095. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  32096. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  32097. this.needsDecode = true;
  32098. // Do some preprocessing to avoid more math.
  32099. var max = (1 << bitsPerComponent) - 1;
  32100. this.decodeCoefficients = [];
  32101. this.decodeAddends = [];
  32102. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  32103. var dmin = this.decode[i];
  32104. var dmax = this.decode[i + 1];
  32105. this.decodeCoefficients[j] = dmax - dmin;
  32106. this.decodeAddends[j] = max * dmin;
  32107. }
  32108. }
  32109. if (smask) {
  32110. this.smask = new PDFImage(xref, res, smask, false);
  32111. } else if (mask) {
  32112. if (isStream(mask)) {
  32113. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  32114. if (!imageMask) {
  32115. warn('Ignoring /Mask in image without /ImageMask.');
  32116. } else {
  32117. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  32118. }
  32119. } else {
  32120. // Color key mask (just an array).
  32121. this.mask = mask;
  32122. }
  32123. }
  32124. }
  32125. /**
  32126. * Handles processing of image data and returns the Promise that is resolved
  32127. * with a PDFImage when the image is ready to be used.
  32128. */
  32129. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  32130. res, image, inline,
  32131. nativeDecoder) {
  32132. var imagePromise = handleImageData(image, nativeDecoder);
  32133. var smaskPromise;
  32134. var maskPromise;
  32135. var smask = image.dict.get('SMask');
  32136. var mask = image.dict.get('Mask');
  32137. if (smask) {
  32138. smaskPromise = handleImageData(smask, nativeDecoder);
  32139. maskPromise = Promise.resolve(null);
  32140. } else {
  32141. smaskPromise = Promise.resolve(null);
  32142. if (mask) {
  32143. if (isStream(mask)) {
  32144. maskPromise = handleImageData(mask, nativeDecoder);
  32145. } else if (isArray(mask)) {
  32146. maskPromise = Promise.resolve(mask);
  32147. } else {
  32148. warn('Unsupported mask format.');
  32149. maskPromise = Promise.resolve(null);
  32150. }
  32151. } else {
  32152. maskPromise = Promise.resolve(null);
  32153. }
  32154. }
  32155. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  32156. function(results) {
  32157. var imageData = results[0];
  32158. var smaskData = results[1];
  32159. var maskData = results[2];
  32160. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  32161. });
  32162. };
  32163. PDFImage.createMask =
  32164. function PDFImage_createMask(imgArray, width, height,
  32165. imageIsFromDecodeStream, inverseDecode) {
  32166. // |imgArray| might not contain full data for every pixel of the mask, so
  32167. // we need to distinguish between |computedLength| and |actualLength|.
  32168. // In particular, if inverseDecode is true, then the array we return must
  32169. // have a length of |computedLength|.
  32170. var computedLength = ((width + 7) >> 3) * height;
  32171. var actualLength = imgArray.byteLength;
  32172. var haveFullData = computedLength === actualLength;
  32173. var data, i;
  32174. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  32175. // imgArray came from a DecodeStream and its data is in an appropriate
  32176. // form, so we can just transfer it.
  32177. data = imgArray;
  32178. } else if (!inverseDecode) {
  32179. data = new Uint8Array(actualLength);
  32180. data.set(imgArray);
  32181. } else {
  32182. data = new Uint8Array(computedLength);
  32183. data.set(imgArray);
  32184. for (i = actualLength; i < computedLength; i++) {
  32185. data[i] = 0xff;
  32186. }
  32187. }
  32188. // If necessary, invert the original mask data (but not any extra we might
  32189. // have added above). It's safe to modify the array -- whether it's the
  32190. // original or a copy, we're about to transfer it anyway, so nothing else
  32191. // in this thread can be relying on its contents.
  32192. if (inverseDecode) {
  32193. for (i = 0; i < actualLength; i++) {
  32194. data[i] = ~data[i];
  32195. }
  32196. }
  32197. return {data: data, width: width, height: height};
  32198. };
  32199. PDFImage.prototype = {
  32200. get drawWidth() {
  32201. return Math.max(this.width,
  32202. this.smask && this.smask.width || 0,
  32203. this.mask && this.mask.width || 0);
  32204. },
  32205. get drawHeight() {
  32206. return Math.max(this.height,
  32207. this.smask && this.smask.height || 0,
  32208. this.mask && this.mask.height || 0);
  32209. },
  32210. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  32211. var bpc = this.bpc;
  32212. var numComps = this.numComps;
  32213. var decodeAddends = this.decodeAddends;
  32214. var decodeCoefficients = this.decodeCoefficients;
  32215. var max = (1 << bpc) - 1;
  32216. var i, ii;
  32217. if (bpc === 1) {
  32218. // If the buffer needed decode that means it just needs to be inverted.
  32219. for (i = 0, ii = buffer.length; i < ii; i++) {
  32220. buffer[i] = +!(buffer[i]);
  32221. }
  32222. return;
  32223. }
  32224. var index = 0;
  32225. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  32226. for (var j = 0; j < numComps; j++) {
  32227. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  32228. decodeCoefficients[j], max);
  32229. index++;
  32230. }
  32231. }
  32232. },
  32233. getComponents: function PDFImage_getComponents(buffer) {
  32234. var bpc = this.bpc;
  32235. // This image doesn't require any extra work.
  32236. if (bpc === 8) {
  32237. return buffer;
  32238. }
  32239. var width = this.width;
  32240. var height = this.height;
  32241. var numComps = this.numComps;
  32242. var length = width * height * numComps;
  32243. var bufferPos = 0;
  32244. var output = (bpc <= 8 ? new Uint8Array(length) :
  32245. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  32246. var rowComps = width * numComps;
  32247. var max = (1 << bpc) - 1;
  32248. var i = 0, ii, buf;
  32249. if (bpc === 1) {
  32250. // Optimization for reading 1 bpc images.
  32251. var mask, loop1End, loop2End;
  32252. for (var j = 0; j < height; j++) {
  32253. loop1End = i + (rowComps & ~7);
  32254. loop2End = i + rowComps;
  32255. // unroll loop for all full bytes
  32256. while (i < loop1End) {
  32257. buf = buffer[bufferPos++];
  32258. output[i] = (buf >> 7) & 1;
  32259. output[i + 1] = (buf >> 6) & 1;
  32260. output[i + 2] = (buf >> 5) & 1;
  32261. output[i + 3] = (buf >> 4) & 1;
  32262. output[i + 4] = (buf >> 3) & 1;
  32263. output[i + 5] = (buf >> 2) & 1;
  32264. output[i + 6] = (buf >> 1) & 1;
  32265. output[i + 7] = buf & 1;
  32266. i += 8;
  32267. }
  32268. // handle remaining bits
  32269. if (i < loop2End) {
  32270. buf = buffer[bufferPos++];
  32271. mask = 128;
  32272. while (i < loop2End) {
  32273. output[i++] = +!!(buf & mask);
  32274. mask >>= 1;
  32275. }
  32276. }
  32277. }
  32278. } else {
  32279. // The general case that handles all other bpc values.
  32280. var bits = 0;
  32281. buf = 0;
  32282. for (i = 0, ii = length; i < ii; ++i) {
  32283. if (i % rowComps === 0) {
  32284. buf = 0;
  32285. bits = 0;
  32286. }
  32287. while (bits < bpc) {
  32288. buf = (buf << 8) | buffer[bufferPos++];
  32289. bits += 8;
  32290. }
  32291. var remainingBits = bits - bpc;
  32292. var value = buf >> remainingBits;
  32293. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  32294. buf = buf & ((1 << remainingBits) - 1);
  32295. bits = remainingBits;
  32296. }
  32297. }
  32298. return output;
  32299. },
  32300. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  32301. actualHeight, image) {
  32302. var smask = this.smask;
  32303. var mask = this.mask;
  32304. var alphaBuf, sw, sh, i, ii, j;
  32305. if (smask) {
  32306. sw = smask.width;
  32307. sh = smask.height;
  32308. alphaBuf = new Uint8Array(sw * sh);
  32309. smask.fillGrayBuffer(alphaBuf);
  32310. if (sw !== width || sh !== height) {
  32311. alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh,
  32312. width, height);
  32313. }
  32314. } else if (mask) {
  32315. if (mask instanceof PDFImage) {
  32316. sw = mask.width;
  32317. sh = mask.height;
  32318. alphaBuf = new Uint8Array(sw * sh);
  32319. mask.numComps = 1;
  32320. mask.fillGrayBuffer(alphaBuf);
  32321. // Need to invert values in rgbaBuf
  32322. for (i = 0, ii = sw * sh; i < ii; ++i) {
  32323. alphaBuf[i] = 255 - alphaBuf[i];
  32324. }
  32325. if (sw !== width || sh !== height) {
  32326. alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh,
  32327. width, height);
  32328. }
  32329. } else if (isArray(mask)) {
  32330. // Color key mask: if any of the components are outside the range
  32331. // then they should be painted.
  32332. alphaBuf = new Uint8Array(width * height);
  32333. var numComps = this.numComps;
  32334. for (i = 0, ii = width * height; i < ii; ++i) {
  32335. var opacity = 0;
  32336. var imageOffset = i * numComps;
  32337. for (j = 0; j < numComps; ++j) {
  32338. var color = image[imageOffset + j];
  32339. var maskOffset = j * 2;
  32340. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  32341. opacity = 255;
  32342. break;
  32343. }
  32344. }
  32345. alphaBuf[i] = opacity;
  32346. }
  32347. } else {
  32348. error('Unknown mask format.');
  32349. }
  32350. }
  32351. if (alphaBuf) {
  32352. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  32353. rgbaBuf[j] = alphaBuf[i];
  32354. }
  32355. } else {
  32356. // No mask.
  32357. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  32358. rgbaBuf[j] = 255;
  32359. }
  32360. }
  32361. },
  32362. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  32363. var matte = this.smask && this.smask.matte;
  32364. if (!matte) {
  32365. return;
  32366. }
  32367. var matteRgb = this.colorSpace.getRgb(matte, 0);
  32368. var matteR = matteRgb[0];
  32369. var matteG = matteRgb[1];
  32370. var matteB = matteRgb[2];
  32371. var length = width * height * 4;
  32372. var r, g, b;
  32373. for (var i = 0; i < length; i += 4) {
  32374. var alpha = buffer[i + 3];
  32375. if (alpha === 0) {
  32376. // according formula we have to get Infinity in all components
  32377. // making it white (typical paper color) should be okay
  32378. buffer[i] = 255;
  32379. buffer[i + 1] = 255;
  32380. buffer[i + 2] = 255;
  32381. continue;
  32382. }
  32383. var k = 255 / alpha;
  32384. r = (buffer[i] - matteR) * k + matteR;
  32385. g = (buffer[i + 1] - matteG) * k + matteG;
  32386. b = (buffer[i + 2] - matteB) * k + matteB;
  32387. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  32388. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  32389. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  32390. }
  32391. },
  32392. createImageData: function PDFImage_createImageData(forceRGBA) {
  32393. var drawWidth = this.drawWidth;
  32394. var drawHeight = this.drawHeight;
  32395. var imgData = { // other fields are filled in below
  32396. width: drawWidth,
  32397. height: drawHeight
  32398. };
  32399. var numComps = this.numComps;
  32400. var originalWidth = this.width;
  32401. var originalHeight = this.height;
  32402. var bpc = this.bpc;
  32403. // Rows start at byte boundary.
  32404. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  32405. var imgArray;
  32406. if (!forceRGBA) {
  32407. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  32408. // without any complications, we pass a same-sized copy to the main
  32409. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  32410. // of memory for many scanned documents. It's also much faster.
  32411. //
  32412. // Similarly, if it is a 24-bit-per pixel RGB image without any
  32413. // complications, we avoid expanding by 1.333x to RGBA form.
  32414. var kind;
  32415. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  32416. kind = ImageKind.GRAYSCALE_1BPP;
  32417. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  32418. !this.needsDecode) {
  32419. kind = ImageKind.RGB_24BPP;
  32420. }
  32421. if (kind && !this.smask && !this.mask &&
  32422. drawWidth === originalWidth && drawHeight === originalHeight) {
  32423. imgData.kind = kind;
  32424. imgArray = this.getImageBytes(originalHeight * rowBytes);
  32425. // If imgArray came from a DecodeStream, we're safe to transfer it
  32426. // (and thus detach its underlying buffer) because it will constitute
  32427. // the entire DecodeStream's data. But if it came from a Stream, we
  32428. // need to copy it because it'll only be a portion of the Stream's
  32429. // data, and the rest will be read later on.
  32430. if (this.image instanceof DecodeStream) {
  32431. imgData.data = imgArray;
  32432. } else {
  32433. var newArray = new Uint8Array(imgArray.length);
  32434. newArray.set(imgArray);
  32435. imgData.data = newArray;
  32436. }
  32437. if (this.needsDecode) {
  32438. // Invert the buffer (which must be grayscale if we reached here).
  32439. assert(kind === ImageKind.GRAYSCALE_1BPP);
  32440. var buffer = imgData.data;
  32441. for (var i = 0, ii = buffer.length; i < ii; i++) {
  32442. buffer[i] ^= 0xff;
  32443. }
  32444. }
  32445. return imgData;
  32446. }
  32447. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  32448. (this.colorSpace.name === 'DeviceGray' ||
  32449. this.colorSpace.name === 'DeviceRGB' ||
  32450. this.colorSpace.name === 'DeviceCMYK')) {
  32451. imgData.kind = ImageKind.RGB_24BPP;
  32452. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  32453. drawWidth, drawHeight, true);
  32454. return imgData;
  32455. }
  32456. }
  32457. imgArray = this.getImageBytes(originalHeight * rowBytes);
  32458. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  32459. var actualHeight = 0 | (imgArray.length / rowBytes *
  32460. drawHeight / originalHeight);
  32461. var comps = this.getComponents(imgArray);
  32462. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  32463. // more compact RGB_24BPP form if allowable.
  32464. var alpha01, maybeUndoPreblend;
  32465. if (!forceRGBA && !this.smask && !this.mask) {
  32466. imgData.kind = ImageKind.RGB_24BPP;
  32467. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  32468. alpha01 = 0;
  32469. maybeUndoPreblend = false;
  32470. } else {
  32471. imgData.kind = ImageKind.RGBA_32BPP;
  32472. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  32473. alpha01 = 1;
  32474. maybeUndoPreblend = true;
  32475. // Color key masking (opacity) must be performed before decoding.
  32476. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  32477. comps);
  32478. }
  32479. if (this.needsDecode) {
  32480. this.decodeBuffer(comps);
  32481. }
  32482. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  32483. drawWidth, drawHeight, actualHeight, bpc, comps,
  32484. alpha01);
  32485. if (maybeUndoPreblend) {
  32486. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  32487. }
  32488. return imgData;
  32489. },
  32490. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  32491. var numComps = this.numComps;
  32492. if (numComps !== 1) {
  32493. error('Reading gray scale from a color image: ' + numComps);
  32494. }
  32495. var width = this.width;
  32496. var height = this.height;
  32497. var bpc = this.bpc;
  32498. // rows start at byte boundary
  32499. var rowBytes = (width * numComps * bpc + 7) >> 3;
  32500. var imgArray = this.getImageBytes(height * rowBytes);
  32501. var comps = this.getComponents(imgArray);
  32502. var i, length;
  32503. if (bpc === 1) {
  32504. // inline decoding (= inversion) for 1 bpc images
  32505. length = width * height;
  32506. if (this.needsDecode) {
  32507. // invert and scale to {0, 255}
  32508. for (i = 0; i < length; ++i) {
  32509. buffer[i] = (comps[i] - 1) & 255;
  32510. }
  32511. } else {
  32512. // scale to {0, 255}
  32513. for (i = 0; i < length; ++i) {
  32514. buffer[i] = (-comps[i]) & 255;
  32515. }
  32516. }
  32517. return;
  32518. }
  32519. if (this.needsDecode) {
  32520. this.decodeBuffer(comps);
  32521. }
  32522. length = width * height;
  32523. // we aren't using a colorspace so we need to scale the value
  32524. var scale = 255 / ((1 << bpc) - 1);
  32525. for (i = 0; i < length; ++i) {
  32526. buffer[i] = (scale * comps[i]) | 0;
  32527. }
  32528. },
  32529. getImageBytes: function PDFImage_getImageBytes(length,
  32530. drawWidth, drawHeight,
  32531. forceRGB) {
  32532. this.image.reset();
  32533. this.image.drawWidth = drawWidth || this.width;
  32534. this.image.drawHeight = drawHeight || this.height;
  32535. this.image.forceRGB = !!forceRGB;
  32536. return this.image.getBytes(length);
  32537. }
  32538. };
  32539. return PDFImage;
  32540. })();
  32541. exports.PDFImage = PDFImage;
  32542. }));
  32543. (function (root, factory) {
  32544. {
  32545. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  32546. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  32547. root.pdfjsCoreChunkedStream, root.pdfjsCoreColorSpace);
  32548. }
  32549. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  32550. coreChunkedStream, coreColorSpace) {
  32551. var InvalidPDFException = sharedUtil.InvalidPDFException;
  32552. var MissingDataException = sharedUtil.MissingDataException;
  32553. var XRefParseException = sharedUtil.XRefParseException;
  32554. var assert = sharedUtil.assert;
  32555. var bytesToString = sharedUtil.bytesToString;
  32556. var createPromiseCapability = sharedUtil.createPromiseCapability;
  32557. var error = sharedUtil.error;
  32558. var info = sharedUtil.info;
  32559. var isArray = sharedUtil.isArray;
  32560. var isInt = sharedUtil.isInt;
  32561. var isString = sharedUtil.isString;
  32562. var shadow = sharedUtil.shadow;
  32563. var stringToPDFString = sharedUtil.stringToPDFString;
  32564. var stringToUTF8String = sharedUtil.stringToUTF8String;
  32565. var warn = sharedUtil.warn;
  32566. var isValidUrl = sharedUtil.isValidUrl;
  32567. var Util = sharedUtil.Util;
  32568. var Ref = corePrimitives.Ref;
  32569. var RefSet = corePrimitives.RefSet;
  32570. var RefSetCache = corePrimitives.RefSetCache;
  32571. var isName = corePrimitives.isName;
  32572. var isCmd = corePrimitives.isCmd;
  32573. var isDict = corePrimitives.isDict;
  32574. var isRef = corePrimitives.isRef;
  32575. var isRefsEqual = corePrimitives.isRefsEqual;
  32576. var isStream = corePrimitives.isStream;
  32577. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  32578. var Lexer = coreParser.Lexer;
  32579. var Parser = coreParser.Parser;
  32580. var ChunkedStream = coreChunkedStream.ChunkedStream;
  32581. var ColorSpace = coreColorSpace.ColorSpace;
  32582. var Catalog = (function CatalogClosure() {
  32583. function Catalog(pdfManager, xref, pageFactory) {
  32584. this.pdfManager = pdfManager;
  32585. this.xref = xref;
  32586. this.catDict = xref.getCatalogObj();
  32587. this.fontCache = new RefSetCache();
  32588. assert(isDict(this.catDict),
  32589. 'catalog object is not a dictionary');
  32590. // TODO refactor to move getPage() to the PDFDocument.
  32591. this.pageFactory = pageFactory;
  32592. this.pagePromises = [];
  32593. }
  32594. Catalog.prototype = {
  32595. get metadata() {
  32596. var streamRef = this.catDict.getRaw('Metadata');
  32597. if (!isRef(streamRef)) {
  32598. return shadow(this, 'metadata', null);
  32599. }
  32600. var encryptMetadata = (!this.xref.encrypt ? false :
  32601. this.xref.encrypt.encryptMetadata);
  32602. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  32603. var metadata;
  32604. if (stream && isDict(stream.dict)) {
  32605. var type = stream.dict.get('Type');
  32606. var subtype = stream.dict.get('Subtype');
  32607. if (isName(type, 'Metadata') && isName(subtype, 'XML')) {
  32608. // XXX: This should examine the charset the XML document defines,
  32609. // however since there are currently no real means to decode
  32610. // arbitrary charsets, let's just hope that the author of the PDF
  32611. // was reasonable enough to stick with the XML default charset,
  32612. // which is UTF-8.
  32613. try {
  32614. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  32615. } catch (e) {
  32616. info('Skipping invalid metadata.');
  32617. }
  32618. }
  32619. }
  32620. return shadow(this, 'metadata', metadata);
  32621. },
  32622. get toplevelPagesDict() {
  32623. var pagesObj = this.catDict.get('Pages');
  32624. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  32625. // shadow the prototype getter
  32626. return shadow(this, 'toplevelPagesDict', pagesObj);
  32627. },
  32628. get documentOutline() {
  32629. var obj = null;
  32630. try {
  32631. obj = this.readDocumentOutline();
  32632. } catch (ex) {
  32633. if (ex instanceof MissingDataException) {
  32634. throw ex;
  32635. }
  32636. warn('Unable to read document outline');
  32637. }
  32638. return shadow(this, 'documentOutline', obj);
  32639. },
  32640. readDocumentOutline: function Catalog_readDocumentOutline() {
  32641. var obj = this.catDict.get('Outlines');
  32642. if (!isDict(obj)) {
  32643. return null;
  32644. }
  32645. obj = obj.getRaw('First');
  32646. if (!isRef(obj)) {
  32647. return null;
  32648. }
  32649. var root = { items: [] };
  32650. var queue = [{obj: obj, parent: root}];
  32651. // To avoid recursion, keep track of the already processed items.
  32652. var processed = new RefSet();
  32653. processed.put(obj);
  32654. var xref = this.xref, blackColor = new Uint8Array(3);
  32655. while (queue.length > 0) {
  32656. var i = queue.shift();
  32657. var outlineDict = xref.fetchIfRef(i.obj);
  32658. if (outlineDict === null) {
  32659. continue;
  32660. }
  32661. assert(outlineDict.has('Title'), 'Invalid outline item');
  32662. var actionDict = outlineDict.get('A'), dest = null, url = null;
  32663. if (actionDict) {
  32664. var destEntry = actionDict.get('D');
  32665. if (destEntry) {
  32666. dest = destEntry;
  32667. } else {
  32668. var uriEntry = actionDict.get('URI');
  32669. if (isString(uriEntry) && isValidUrl(uriEntry, false)) {
  32670. url = uriEntry;
  32671. }
  32672. }
  32673. } else if (outlineDict.has('Dest')) {
  32674. dest = outlineDict.getRaw('Dest');
  32675. if (isName(dest)) {
  32676. dest = dest.name;
  32677. }
  32678. }
  32679. var title = outlineDict.get('Title');
  32680. var flags = outlineDict.get('F') || 0;
  32681. var color = outlineDict.getArray('C'), rgbColor = blackColor;
  32682. // We only need to parse the color when it's valid, and non-default.
  32683. if (isArray(color) && color.length === 3 &&
  32684. (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
  32685. rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
  32686. }
  32687. var outlineItem = {
  32688. dest: dest,
  32689. url: url,
  32690. title: stringToPDFString(title),
  32691. color: rgbColor,
  32692. count: outlineDict.get('Count'),
  32693. bold: !!(flags & 2),
  32694. italic: !!(flags & 1),
  32695. items: []
  32696. };
  32697. i.parent.items.push(outlineItem);
  32698. obj = outlineDict.getRaw('First');
  32699. if (isRef(obj) && !processed.has(obj)) {
  32700. queue.push({obj: obj, parent: outlineItem});
  32701. processed.put(obj);
  32702. }
  32703. obj = outlineDict.getRaw('Next');
  32704. if (isRef(obj) && !processed.has(obj)) {
  32705. queue.push({obj: obj, parent: i.parent});
  32706. processed.put(obj);
  32707. }
  32708. }
  32709. return (root.items.length > 0 ? root.items : null);
  32710. },
  32711. get numPages() {
  32712. var obj = this.toplevelPagesDict.get('Count');
  32713. assert(
  32714. isInt(obj),
  32715. 'page count in top level pages object is not an integer'
  32716. );
  32717. // shadow the prototype getter
  32718. return shadow(this, 'num', obj);
  32719. },
  32720. get destinations() {
  32721. function fetchDestination(dest) {
  32722. return isDict(dest) ? dest.get('D') : dest;
  32723. }
  32724. var xref = this.xref;
  32725. var dests = {}, nameTreeRef, nameDictionaryRef;
  32726. var obj = this.catDict.get('Names');
  32727. if (obj && obj.has('Dests')) {
  32728. nameTreeRef = obj.getRaw('Dests');
  32729. } else if (this.catDict.has('Dests')) {
  32730. nameDictionaryRef = this.catDict.get('Dests');
  32731. }
  32732. if (nameDictionaryRef) {
  32733. // reading simple destination dictionary
  32734. obj = nameDictionaryRef;
  32735. obj.forEach(function catalogForEach(key, value) {
  32736. if (!value) {
  32737. return;
  32738. }
  32739. dests[key] = fetchDestination(value);
  32740. });
  32741. }
  32742. if (nameTreeRef) {
  32743. var nameTree = new NameTree(nameTreeRef, xref);
  32744. var names = nameTree.getAll();
  32745. for (var name in names) {
  32746. dests[name] = fetchDestination(names[name]);
  32747. }
  32748. }
  32749. return shadow(this, 'destinations', dests);
  32750. },
  32751. getDestination: function Catalog_getDestination(destinationId) {
  32752. function fetchDestination(dest) {
  32753. return isDict(dest) ? dest.get('D') : dest;
  32754. }
  32755. var xref = this.xref;
  32756. var dest = null, nameTreeRef, nameDictionaryRef;
  32757. var obj = this.catDict.get('Names');
  32758. if (obj && obj.has('Dests')) {
  32759. nameTreeRef = obj.getRaw('Dests');
  32760. } else if (this.catDict.has('Dests')) {
  32761. nameDictionaryRef = this.catDict.get('Dests');
  32762. }
  32763. if (nameDictionaryRef) { // Simple destination dictionary.
  32764. var value = nameDictionaryRef.get(destinationId);
  32765. if (value) {
  32766. dest = fetchDestination(value);
  32767. }
  32768. }
  32769. if (nameTreeRef) {
  32770. var nameTree = new NameTree(nameTreeRef, xref);
  32771. dest = fetchDestination(nameTree.get(destinationId));
  32772. }
  32773. return dest;
  32774. },
  32775. get pageLabels() {
  32776. var obj = null;
  32777. try {
  32778. obj = this.readPageLabels();
  32779. } catch (ex) {
  32780. if (ex instanceof MissingDataException) {
  32781. throw ex;
  32782. }
  32783. warn('Unable to read page labels.');
  32784. }
  32785. return shadow(this, 'pageLabels', obj);
  32786. },
  32787. readPageLabels: function Catalog_readPageLabels() {
  32788. var obj = this.catDict.getRaw('PageLabels');
  32789. if (!obj) {
  32790. return null;
  32791. }
  32792. var pageLabels = new Array(this.numPages);
  32793. var style = null;
  32794. var prefix = '';
  32795. var start = 1;
  32796. var numberTree = new NumberTree(obj, this.xref);
  32797. var nums = numberTree.getAll();
  32798. var currentLabel = '', currentIndex = 1;
  32799. for (var i = 0, ii = this.numPages; i < ii; i++) {
  32800. if (i in nums) {
  32801. var labelDict = nums[i];
  32802. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  32803. var type = labelDict.get('Type');
  32804. assert(!type || isName(type, 'PageLabel'),
  32805. 'Invalid type in PageLabel dictionary.');
  32806. var s = labelDict.get('S');
  32807. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  32808. style = (s ? s.name : null);
  32809. prefix = labelDict.get('P') || '';
  32810. assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
  32811. start = labelDict.get('St') || 1;
  32812. assert(isInt(start), 'Invalid start in PageLabel dictionary.');
  32813. currentIndex = start;
  32814. }
  32815. switch (style) {
  32816. case 'D':
  32817. currentLabel = currentIndex;
  32818. break;
  32819. case 'R':
  32820. case 'r':
  32821. currentLabel = Util.toRoman(currentIndex, style === 'r');
  32822. break;
  32823. case 'A':
  32824. case 'a':
  32825. var LIMIT = 26; // Use only the characters A--Z, or a--z.
  32826. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  32827. var baseCharCode = (style === 'a' ? A_LOWER_CASE : A_UPPER_CASE);
  32828. var letterIndex = currentIndex - 1;
  32829. var character = String.fromCharCode(baseCharCode +
  32830. (letterIndex % LIMIT));
  32831. var charBuf = [];
  32832. for (var j = 0, jj = (letterIndex / LIMIT) | 0; j <= jj; j++) {
  32833. charBuf.push(character);
  32834. }
  32835. currentLabel = charBuf.join('');
  32836. break;
  32837. default:
  32838. assert(!style,
  32839. 'Invalid style "' + style + '" in PageLabel dictionary.');
  32840. }
  32841. pageLabels[i] = prefix + currentLabel;
  32842. currentLabel = '';
  32843. currentIndex++;
  32844. }
  32845. return pageLabels;
  32846. },
  32847. get attachments() {
  32848. var xref = this.xref;
  32849. var attachments = null, nameTreeRef;
  32850. var obj = this.catDict.get('Names');
  32851. if (obj) {
  32852. nameTreeRef = obj.getRaw('EmbeddedFiles');
  32853. }
  32854. if (nameTreeRef) {
  32855. var nameTree = new NameTree(nameTreeRef, xref);
  32856. var names = nameTree.getAll();
  32857. for (var name in names) {
  32858. var fs = new FileSpec(names[name], xref);
  32859. if (!attachments) {
  32860. attachments = Object.create(null);
  32861. }
  32862. attachments[stringToPDFString(name)] = fs.serializable;
  32863. }
  32864. }
  32865. return shadow(this, 'attachments', attachments);
  32866. },
  32867. get javaScript() {
  32868. var xref = this.xref;
  32869. var obj = this.catDict.get('Names');
  32870. var javaScript = [];
  32871. function appendIfJavaScriptDict(jsDict) {
  32872. var type = jsDict.get('S');
  32873. if (!isName(type, 'JavaScript')) {
  32874. return;
  32875. }
  32876. var js = jsDict.get('JS');
  32877. if (isStream(js)) {
  32878. js = bytesToString(js.getBytes());
  32879. } else if (!isString(js)) {
  32880. return;
  32881. }
  32882. javaScript.push(stringToPDFString(js));
  32883. }
  32884. if (obj && obj.has('JavaScript')) {
  32885. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  32886. var names = nameTree.getAll();
  32887. for (var name in names) {
  32888. // We don't really use the JavaScript right now. This code is
  32889. // defensive so we don't cause errors on document load.
  32890. var jsDict = names[name];
  32891. if (isDict(jsDict)) {
  32892. appendIfJavaScriptDict(jsDict);
  32893. }
  32894. }
  32895. }
  32896. // Append OpenAction actions to javaScript array
  32897. var openactionDict = this.catDict.get('OpenAction');
  32898. if (isDict(openactionDict, 'Action')) {
  32899. var actionType = openactionDict.get('S');
  32900. if (isName(actionType, 'Named')) {
  32901. // The named Print action is not a part of the PDF 1.7 specification,
  32902. // but is supported by many PDF readers/writers (including Adobe's).
  32903. var action = openactionDict.get('N');
  32904. if (isName(action, 'Print')) {
  32905. javaScript.push('print({});');
  32906. }
  32907. } else {
  32908. appendIfJavaScriptDict(openactionDict);
  32909. }
  32910. }
  32911. return shadow(this, 'javaScript', javaScript);
  32912. },
  32913. cleanup: function Catalog_cleanup() {
  32914. var promises = [];
  32915. this.fontCache.forEach(function (promise) {
  32916. promises.push(promise);
  32917. });
  32918. return Promise.all(promises).then(function (translatedFonts) {
  32919. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  32920. var font = translatedFonts[i].dict;
  32921. delete font.translated;
  32922. }
  32923. this.fontCache.clear();
  32924. }.bind(this));
  32925. },
  32926. getPage: function Catalog_getPage(pageIndex) {
  32927. if (!(pageIndex in this.pagePromises)) {
  32928. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  32929. function (a) {
  32930. var dict = a[0];
  32931. var ref = a[1];
  32932. return this.pageFactory.createPage(pageIndex, dict, ref,
  32933. this.fontCache);
  32934. }.bind(this)
  32935. );
  32936. }
  32937. return this.pagePromises[pageIndex];
  32938. },
  32939. getPageDict: function Catalog_getPageDict(pageIndex) {
  32940. var capability = createPromiseCapability();
  32941. var nodesToVisit = [this.catDict.getRaw('Pages')];
  32942. var currentPageIndex = 0;
  32943. var xref = this.xref;
  32944. var checkAllKids = false;
  32945. function next() {
  32946. while (nodesToVisit.length) {
  32947. var currentNode = nodesToVisit.pop();
  32948. if (isRef(currentNode)) {
  32949. xref.fetchAsync(currentNode).then(function (obj) {
  32950. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  32951. if (pageIndex === currentPageIndex) {
  32952. capability.resolve([obj, currentNode]);
  32953. } else {
  32954. currentPageIndex++;
  32955. next();
  32956. }
  32957. return;
  32958. }
  32959. nodesToVisit.push(obj);
  32960. next();
  32961. }, capability.reject);
  32962. return;
  32963. }
  32964. // Must be a child page dictionary.
  32965. assert(
  32966. isDict(currentNode),
  32967. 'page dictionary kid reference points to wrong type of object'
  32968. );
  32969. var count = currentNode.get('Count');
  32970. // If the current node doesn't have any children, avoid getting stuck
  32971. // in an empty node further down in the tree (see issue5644.pdf).
  32972. if (count === 0) {
  32973. checkAllKids = true;
  32974. }
  32975. // Skip nodes where the page can't be.
  32976. if (currentPageIndex + count <= pageIndex) {
  32977. currentPageIndex += count;
  32978. continue;
  32979. }
  32980. var kids = currentNode.get('Kids');
  32981. assert(isArray(kids), 'page dictionary kids object is not an array');
  32982. if (!checkAllKids && count === kids.length) {
  32983. // Nodes that don't have the page have been skipped and this is the
  32984. // bottom of the tree which means the page requested must be a
  32985. // descendant of this pages node. Ideally we would just resolve the
  32986. // promise with the page ref here, but there is the case where more
  32987. // pages nodes could link to single a page (see issue 3666 pdf). To
  32988. // handle this push it back on the queue so if it is a pages node it
  32989. // will be descended into.
  32990. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  32991. currentPageIndex = pageIndex;
  32992. continue;
  32993. } else {
  32994. for (var last = kids.length - 1; last >= 0; last--) {
  32995. nodesToVisit.push(kids[last]);
  32996. }
  32997. }
  32998. }
  32999. capability.reject('Page index ' + pageIndex + ' not found.');
  33000. }
  33001. next();
  33002. return capability.promise;
  33003. },
  33004. getPageIndex: function Catalog_getPageIndex(pageRef) {
  33005. // The page tree nodes have the count of all the leaves below them. To get
  33006. // how many pages are before we just have to walk up the tree and keep
  33007. // adding the count of siblings to the left of the node.
  33008. var xref = this.xref;
  33009. function pagesBeforeRef(kidRef) {
  33010. var total = 0;
  33011. var parentRef;
  33012. return xref.fetchAsync(kidRef).then(function (node) {
  33013. if (isRefsEqual(kidRef, pageRef) && !isDict(node, 'Page') &&
  33014. !(isDict(node) && !node.has('Type') && node.has('Contents'))) {
  33015. throw new Error('The reference does not point to a /Page Dict.');
  33016. }
  33017. if (!node) {
  33018. return null;
  33019. }
  33020. assert(isDict(node), 'node must be a Dict.');
  33021. parentRef = node.getRaw('Parent');
  33022. return node.getAsync('Parent');
  33023. }).then(function (parent) {
  33024. if (!parent) {
  33025. return null;
  33026. }
  33027. assert(isDict(parent), 'parent must be a Dict.');
  33028. return parent.getAsync('Kids');
  33029. }).then(function (kids) {
  33030. if (!kids) {
  33031. return null;
  33032. }
  33033. var kidPromises = [];
  33034. var found = false;
  33035. for (var i = 0; i < kids.length; i++) {
  33036. var kid = kids[i];
  33037. assert(isRef(kid), 'kid must be a Ref.');
  33038. if (kid.num === kidRef.num) {
  33039. found = true;
  33040. break;
  33041. }
  33042. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  33043. if (kid.has('Count')) {
  33044. var count = kid.get('Count');
  33045. total += count;
  33046. } else { // page leaf node
  33047. total++;
  33048. }
  33049. }));
  33050. }
  33051. if (!found) {
  33052. error('kid ref not found in parents kids');
  33053. }
  33054. return Promise.all(kidPromises).then(function () {
  33055. return [total, parentRef];
  33056. });
  33057. });
  33058. }
  33059. var total = 0;
  33060. function next(ref) {
  33061. return pagesBeforeRef(ref).then(function (args) {
  33062. if (!args) {
  33063. return total;
  33064. }
  33065. var count = args[0];
  33066. var parentRef = args[1];
  33067. total += count;
  33068. return next(parentRef);
  33069. });
  33070. }
  33071. return next(pageRef);
  33072. }
  33073. };
  33074. return Catalog;
  33075. })();
  33076. var XRef = (function XRefClosure() {
  33077. function XRef(stream, password) {
  33078. this.stream = stream;
  33079. this.entries = [];
  33080. this.xrefstms = Object.create(null);
  33081. // prepare the XRef cache
  33082. this.cache = [];
  33083. this.password = password;
  33084. this.stats = {
  33085. streamTypes: [],
  33086. fontTypes: []
  33087. };
  33088. }
  33089. XRef.prototype = {
  33090. setStartXRef: function XRef_setStartXRef(startXRef) {
  33091. // Store the starting positions of xref tables as we process them
  33092. // so we can recover from missing data errors
  33093. this.startXRefQueue = [startXRef];
  33094. },
  33095. parse: function XRef_parse(recoveryMode) {
  33096. var trailerDict;
  33097. if (!recoveryMode) {
  33098. trailerDict = this.readXRef();
  33099. } else {
  33100. warn('Indexing all PDF objects');
  33101. trailerDict = this.indexObjects();
  33102. }
  33103. trailerDict.assignXref(this);
  33104. this.trailer = trailerDict;
  33105. var encrypt = trailerDict.get('Encrypt');
  33106. if (encrypt) {
  33107. var ids = trailerDict.get('ID');
  33108. var fileId = (ids && ids.length) ? ids[0] : '';
  33109. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  33110. this.password);
  33111. }
  33112. // get the root dictionary (catalog) object
  33113. if (!(this.root = trailerDict.get('Root'))) {
  33114. error('Invalid root reference');
  33115. }
  33116. },
  33117. processXRefTable: function XRef_processXRefTable(parser) {
  33118. if (!('tableState' in this)) {
  33119. // Stores state of the table as we process it so we can resume
  33120. // from middle of table in case of missing data error
  33121. this.tableState = {
  33122. entryNum: 0,
  33123. streamPos: parser.lexer.stream.pos,
  33124. parserBuf1: parser.buf1,
  33125. parserBuf2: parser.buf2
  33126. };
  33127. }
  33128. var obj = this.readXRefTable(parser);
  33129. // Sanity check
  33130. if (!isCmd(obj, 'trailer')) {
  33131. error('Invalid XRef table: could not find trailer dictionary');
  33132. }
  33133. // Read trailer dictionary, e.g.
  33134. // trailer
  33135. // << /Size 22
  33136. // /Root 20R
  33137. // /Info 10R
  33138. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  33139. // >>
  33140. // The parser goes through the entire stream << ... >> and provides
  33141. // a getter interface for the key-value table
  33142. var dict = parser.getObj();
  33143. // The pdflib PDF generator can generate a nested trailer dictionary
  33144. if (!isDict(dict) && dict.dict) {
  33145. dict = dict.dict;
  33146. }
  33147. if (!isDict(dict)) {
  33148. error('Invalid XRef table: could not parse trailer dictionary');
  33149. }
  33150. delete this.tableState;
  33151. return dict;
  33152. },
  33153. readXRefTable: function XRef_readXRefTable(parser) {
  33154. // Example of cross-reference table:
  33155. // xref
  33156. // 0 1 <-- subsection header (first obj #, obj count)
  33157. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  33158. // 23 2 <-- subsection header ... and so on ...
  33159. // 0000025518 00002 n
  33160. // 0000025635 00000 n
  33161. // trailer
  33162. // ...
  33163. var stream = parser.lexer.stream;
  33164. var tableState = this.tableState;
  33165. stream.pos = tableState.streamPos;
  33166. parser.buf1 = tableState.parserBuf1;
  33167. parser.buf2 = tableState.parserBuf2;
  33168. // Outer loop is over subsection headers
  33169. var obj;
  33170. while (true) {
  33171. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  33172. if (isCmd(obj = parser.getObj(), 'trailer')) {
  33173. break;
  33174. }
  33175. tableState.firstEntryNum = obj;
  33176. tableState.entryCount = parser.getObj();
  33177. }
  33178. var first = tableState.firstEntryNum;
  33179. var count = tableState.entryCount;
  33180. if (!isInt(first) || !isInt(count)) {
  33181. error('Invalid XRef table: wrong types in subsection header');
  33182. }
  33183. // Inner loop is over objects themselves
  33184. for (var i = tableState.entryNum; i < count; i++) {
  33185. tableState.streamPos = stream.pos;
  33186. tableState.entryNum = i;
  33187. tableState.parserBuf1 = parser.buf1;
  33188. tableState.parserBuf2 = parser.buf2;
  33189. var entry = {};
  33190. entry.offset = parser.getObj();
  33191. entry.gen = parser.getObj();
  33192. var type = parser.getObj();
  33193. if (isCmd(type, 'f')) {
  33194. entry.free = true;
  33195. } else if (isCmd(type, 'n')) {
  33196. entry.uncompressed = true;
  33197. }
  33198. // Validate entry obj
  33199. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  33200. !(entry.free || entry.uncompressed)) {
  33201. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  33202. }
  33203. // The first xref table entry, i.e. obj 0, should be free. Attempting
  33204. // to adjust an incorrect first obj # (fixes issue 3248 and 7229).
  33205. if (i === 0 && entry.free && first === 1) {
  33206. first = 0;
  33207. }
  33208. if (!this.entries[i + first]) {
  33209. this.entries[i + first] = entry;
  33210. }
  33211. }
  33212. tableState.entryNum = 0;
  33213. tableState.streamPos = stream.pos;
  33214. tableState.parserBuf1 = parser.buf1;
  33215. tableState.parserBuf2 = parser.buf2;
  33216. delete tableState.firstEntryNum;
  33217. delete tableState.entryCount;
  33218. }
  33219. // Sanity check: as per spec, first object must be free
  33220. if (this.entries[0] && !this.entries[0].free) {
  33221. error('Invalid XRef table: unexpected first object');
  33222. }
  33223. return obj;
  33224. },
  33225. processXRefStream: function XRef_processXRefStream(stream) {
  33226. if (!('streamState' in this)) {
  33227. // Stores state of the stream as we process it so we can resume
  33228. // from middle of stream in case of missing data error
  33229. var streamParameters = stream.dict;
  33230. var byteWidths = streamParameters.get('W');
  33231. var range = streamParameters.get('Index');
  33232. if (!range) {
  33233. range = [0, streamParameters.get('Size')];
  33234. }
  33235. this.streamState = {
  33236. entryRanges: range,
  33237. byteWidths: byteWidths,
  33238. entryNum: 0,
  33239. streamPos: stream.pos
  33240. };
  33241. }
  33242. this.readXRefStream(stream);
  33243. delete this.streamState;
  33244. return stream.dict;
  33245. },
  33246. readXRefStream: function XRef_readXRefStream(stream) {
  33247. var i, j;
  33248. var streamState = this.streamState;
  33249. stream.pos = streamState.streamPos;
  33250. var byteWidths = streamState.byteWidths;
  33251. var typeFieldWidth = byteWidths[0];
  33252. var offsetFieldWidth = byteWidths[1];
  33253. var generationFieldWidth = byteWidths[2];
  33254. var entryRanges = streamState.entryRanges;
  33255. while (entryRanges.length > 0) {
  33256. var first = entryRanges[0];
  33257. var n = entryRanges[1];
  33258. if (!isInt(first) || !isInt(n)) {
  33259. error('Invalid XRef range fields: ' + first + ', ' + n);
  33260. }
  33261. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  33262. !isInt(generationFieldWidth)) {
  33263. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  33264. }
  33265. for (i = streamState.entryNum; i < n; ++i) {
  33266. streamState.entryNum = i;
  33267. streamState.streamPos = stream.pos;
  33268. var type = 0, offset = 0, generation = 0;
  33269. for (j = 0; j < typeFieldWidth; ++j) {
  33270. type = (type << 8) | stream.getByte();
  33271. }
  33272. // if type field is absent, its default value is 1
  33273. if (typeFieldWidth === 0) {
  33274. type = 1;
  33275. }
  33276. for (j = 0; j < offsetFieldWidth; ++j) {
  33277. offset = (offset << 8) | stream.getByte();
  33278. }
  33279. for (j = 0; j < generationFieldWidth; ++j) {
  33280. generation = (generation << 8) | stream.getByte();
  33281. }
  33282. var entry = {};
  33283. entry.offset = offset;
  33284. entry.gen = generation;
  33285. switch (type) {
  33286. case 0:
  33287. entry.free = true;
  33288. break;
  33289. case 1:
  33290. entry.uncompressed = true;
  33291. break;
  33292. case 2:
  33293. break;
  33294. default:
  33295. error('Invalid XRef entry type: ' + type);
  33296. }
  33297. if (!this.entries[first + i]) {
  33298. this.entries[first + i] = entry;
  33299. }
  33300. }
  33301. streamState.entryNum = 0;
  33302. streamState.streamPos = stream.pos;
  33303. entryRanges.splice(0, 2);
  33304. }
  33305. },
  33306. indexObjects: function XRef_indexObjects() {
  33307. // Simple scan through the PDF content to find objects,
  33308. // trailers and XRef streams.
  33309. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  33310. var PERCENT = 0x25, LT = 0x3C;
  33311. function readToken(data, offset) {
  33312. var token = '', ch = data[offset];
  33313. while (ch !== LF && ch !== CR && ch !== LT) {
  33314. if (++offset >= data.length) {
  33315. break;
  33316. }
  33317. token += String.fromCharCode(ch);
  33318. ch = data[offset];
  33319. }
  33320. return token;
  33321. }
  33322. function skipUntil(data, offset, what) {
  33323. var length = what.length, dataLength = data.length;
  33324. var skipped = 0;
  33325. // finding byte sequence
  33326. while (offset < dataLength) {
  33327. var i = 0;
  33328. while (i < length && data[offset + i] === what[i]) {
  33329. ++i;
  33330. }
  33331. if (i >= length) {
  33332. break; // sequence found
  33333. }
  33334. offset++;
  33335. skipped++;
  33336. }
  33337. return skipped;
  33338. }
  33339. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  33340. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  33341. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  33342. 101, 102]);
  33343. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  33344. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  33345. // Clear out any existing entries, since they may be bogus.
  33346. this.entries.length = 0;
  33347. var stream = this.stream;
  33348. stream.pos = 0;
  33349. var buffer = stream.getBytes();
  33350. var position = stream.start, length = buffer.length;
  33351. var trailers = [], xrefStms = [];
  33352. while (position < length) {
  33353. var ch = buffer[position];
  33354. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  33355. ++position;
  33356. continue;
  33357. }
  33358. if (ch === PERCENT) { // %-comment
  33359. do {
  33360. ++position;
  33361. if (position >= length) {
  33362. break;
  33363. }
  33364. ch = buffer[position];
  33365. } while (ch !== LF && ch !== CR);
  33366. continue;
  33367. }
  33368. var token = readToken(buffer, position);
  33369. var m;
  33370. if (token.indexOf('xref') === 0 &&
  33371. (token.length === 4 || /\s/.test(token[4]))) {
  33372. position += skipUntil(buffer, position, trailerBytes);
  33373. trailers.push(position);
  33374. position += skipUntil(buffer, position, startxrefBytes);
  33375. } else if ((m = objRegExp.exec(token))) {
  33376. if (typeof this.entries[m[1]] === 'undefined') {
  33377. this.entries[m[1]] = {
  33378. offset: position - stream.start,
  33379. gen: m[2] | 0,
  33380. uncompressed: true
  33381. };
  33382. }
  33383. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  33384. var content = buffer.subarray(position, position + contentLength);
  33385. // checking XRef stream suspect
  33386. // (it shall have '/XRef' and next char is not a letter)
  33387. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  33388. if (xrefTagOffset < contentLength &&
  33389. content[xrefTagOffset + 5] < 64) {
  33390. xrefStms.push(position - stream.start);
  33391. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  33392. }
  33393. position += contentLength;
  33394. } else if (token.indexOf('trailer') === 0 &&
  33395. (token.length === 7 || /\s/.test(token[7]))) {
  33396. trailers.push(position);
  33397. position += skipUntil(buffer, position, startxrefBytes);
  33398. } else {
  33399. position += token.length + 1;
  33400. }
  33401. }
  33402. // reading XRef streams
  33403. var i, ii;
  33404. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  33405. this.startXRefQueue.push(xrefStms[i]);
  33406. this.readXRef(/* recoveryMode */ true);
  33407. }
  33408. // finding main trailer
  33409. var dict;
  33410. for (i = 0, ii = trailers.length; i < ii; ++i) {
  33411. stream.pos = trailers[i];
  33412. var parser = new Parser(new Lexer(stream), /* allowStreams = */ true,
  33413. /* xref = */ this, /* recoveryMode = */ true);
  33414. var obj = parser.getObj();
  33415. if (!isCmd(obj, 'trailer')) {
  33416. continue;
  33417. }
  33418. // read the trailer dictionary
  33419. dict = parser.getObj();
  33420. if (!isDict(dict)) {
  33421. continue;
  33422. }
  33423. // taking the first one with 'ID'
  33424. if (dict.has('ID')) {
  33425. return dict;
  33426. }
  33427. }
  33428. // no tailer with 'ID', taking last one (if exists)
  33429. if (dict) {
  33430. return dict;
  33431. }
  33432. // nothing helps
  33433. // calling error() would reject worker with an UnknownErrorException.
  33434. throw new InvalidPDFException('Invalid PDF structure');
  33435. },
  33436. readXRef: function XRef_readXRef(recoveryMode) {
  33437. var stream = this.stream;
  33438. try {
  33439. while (this.startXRefQueue.length) {
  33440. var startXRef = this.startXRefQueue[0];
  33441. stream.pos = startXRef + stream.start;
  33442. var parser = new Parser(new Lexer(stream), true, this);
  33443. var obj = parser.getObj();
  33444. var dict;
  33445. // Get dictionary
  33446. if (isCmd(obj, 'xref')) {
  33447. // Parse end-of-file XRef
  33448. dict = this.processXRefTable(parser);
  33449. if (!this.topDict) {
  33450. this.topDict = dict;
  33451. }
  33452. // Recursively get other XRefs 'XRefStm', if any
  33453. obj = dict.get('XRefStm');
  33454. if (isInt(obj)) {
  33455. var pos = obj;
  33456. // ignore previously loaded xref streams
  33457. // (possible infinite recursion)
  33458. if (!(pos in this.xrefstms)) {
  33459. this.xrefstms[pos] = 1;
  33460. this.startXRefQueue.push(pos);
  33461. }
  33462. }
  33463. } else if (isInt(obj)) {
  33464. // Parse in-stream XRef
  33465. if (!isInt(parser.getObj()) ||
  33466. !isCmd(parser.getObj(), 'obj') ||
  33467. !isStream(obj = parser.getObj())) {
  33468. error('Invalid XRef stream');
  33469. }
  33470. dict = this.processXRefStream(obj);
  33471. if (!this.topDict) {
  33472. this.topDict = dict;
  33473. }
  33474. if (!dict) {
  33475. error('Failed to read XRef stream');
  33476. }
  33477. } else {
  33478. error('Invalid XRef stream header');
  33479. }
  33480. // Recursively get previous dictionary, if any
  33481. obj = dict.get('Prev');
  33482. if (isInt(obj)) {
  33483. this.startXRefQueue.push(obj);
  33484. } else if (isRef(obj)) {
  33485. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  33486. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  33487. this.startXRefQueue.push(obj.num);
  33488. }
  33489. this.startXRefQueue.shift();
  33490. }
  33491. return this.topDict;
  33492. } catch (e) {
  33493. if (e instanceof MissingDataException) {
  33494. throw e;
  33495. }
  33496. info('(while reading XRef): ' + e);
  33497. }
  33498. if (recoveryMode) {
  33499. return;
  33500. }
  33501. throw new XRefParseException();
  33502. },
  33503. getEntry: function XRef_getEntry(i) {
  33504. var xrefEntry = this.entries[i];
  33505. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  33506. return xrefEntry;
  33507. }
  33508. return null;
  33509. },
  33510. fetchIfRef: function XRef_fetchIfRef(obj) {
  33511. if (!isRef(obj)) {
  33512. return obj;
  33513. }
  33514. return this.fetch(obj);
  33515. },
  33516. fetch: function XRef_fetch(ref, suppressEncryption) {
  33517. assert(isRef(ref), 'ref object is not a reference');
  33518. var num = ref.num;
  33519. if (num in this.cache) {
  33520. var cacheEntry = this.cache[num];
  33521. return cacheEntry;
  33522. }
  33523. var xrefEntry = this.getEntry(num);
  33524. // the referenced entry can be free
  33525. if (xrefEntry === null) {
  33526. return (this.cache[num] = null);
  33527. }
  33528. if (xrefEntry.uncompressed) {
  33529. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  33530. } else {
  33531. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  33532. }
  33533. if (isDict(xrefEntry)){
  33534. xrefEntry.objId = ref.toString();
  33535. } else if (isStream(xrefEntry)) {
  33536. xrefEntry.dict.objId = ref.toString();
  33537. }
  33538. return xrefEntry;
  33539. },
  33540. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  33541. suppressEncryption) {
  33542. var gen = ref.gen;
  33543. var num = ref.num;
  33544. if (xrefEntry.gen !== gen) {
  33545. error('inconsistent generation in XRef');
  33546. }
  33547. var stream = this.stream.makeSubStream(xrefEntry.offset +
  33548. this.stream.start);
  33549. var parser = new Parser(new Lexer(stream), true, this);
  33550. var obj1 = parser.getObj();
  33551. var obj2 = parser.getObj();
  33552. var obj3 = parser.getObj();
  33553. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  33554. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  33555. !isCmd(obj3)) {
  33556. error('bad XRef entry');
  33557. }
  33558. if (!isCmd(obj3, 'obj')) {
  33559. // some bad PDFs use "obj1234" and really mean 1234
  33560. if (obj3.cmd.indexOf('obj') === 0) {
  33561. num = parseInt(obj3.cmd.substring(3), 10);
  33562. if (!isNaN(num)) {
  33563. return num;
  33564. }
  33565. }
  33566. error('bad XRef entry');
  33567. }
  33568. if (this.encrypt && !suppressEncryption) {
  33569. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  33570. } else {
  33571. xrefEntry = parser.getObj();
  33572. }
  33573. if (!isStream(xrefEntry)) {
  33574. this.cache[num] = xrefEntry;
  33575. }
  33576. return xrefEntry;
  33577. },
  33578. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  33579. suppressEncryption) {
  33580. var tableOffset = xrefEntry.offset;
  33581. var stream = this.fetch(new Ref(tableOffset, 0));
  33582. if (!isStream(stream)) {
  33583. error('bad ObjStm stream');
  33584. }
  33585. var first = stream.dict.get('First');
  33586. var n = stream.dict.get('N');
  33587. if (!isInt(first) || !isInt(n)) {
  33588. error('invalid first and n parameters for ObjStm stream');
  33589. }
  33590. var parser = new Parser(new Lexer(stream), false, this);
  33591. parser.allowStreams = true;
  33592. var i, entries = [], num, nums = [];
  33593. // read the object numbers to populate cache
  33594. for (i = 0; i < n; ++i) {
  33595. num = parser.getObj();
  33596. if (!isInt(num)) {
  33597. error('invalid object number in the ObjStm stream: ' + num);
  33598. }
  33599. nums.push(num);
  33600. var offset = parser.getObj();
  33601. if (!isInt(offset)) {
  33602. error('invalid object offset in the ObjStm stream: ' + offset);
  33603. }
  33604. }
  33605. // read stream objects for cache
  33606. for (i = 0; i < n; ++i) {
  33607. entries.push(parser.getObj());
  33608. // The ObjStm should not contain 'endobj'. If it's present, skip over it
  33609. // to support corrupt PDFs (fixes issue 5241, bug 898610, bug 1037816).
  33610. if (isCmd(parser.buf1, 'endobj')) {
  33611. parser.shift();
  33612. }
  33613. num = nums[i];
  33614. var entry = this.entries[num];
  33615. if (entry && entry.offset === tableOffset && entry.gen === i) {
  33616. this.cache[num] = entries[i];
  33617. }
  33618. }
  33619. xrefEntry = entries[xrefEntry.gen];
  33620. if (xrefEntry === undefined) {
  33621. error('bad XRef entry for compressed object');
  33622. }
  33623. return xrefEntry;
  33624. },
  33625. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  33626. if (!isRef(obj)) {
  33627. return Promise.resolve(obj);
  33628. }
  33629. return this.fetchAsync(obj);
  33630. },
  33631. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  33632. var streamManager = this.stream.manager;
  33633. var xref = this;
  33634. return new Promise(function tryFetch(resolve, reject) {
  33635. try {
  33636. resolve(xref.fetch(ref, suppressEncryption));
  33637. } catch (e) {
  33638. if (e instanceof MissingDataException) {
  33639. streamManager.requestRange(e.begin, e.end).then(function () {
  33640. tryFetch(resolve, reject);
  33641. }, reject);
  33642. return;
  33643. }
  33644. reject(e);
  33645. }
  33646. });
  33647. },
  33648. getCatalogObj: function XRef_getCatalogObj() {
  33649. return this.root;
  33650. }
  33651. };
  33652. return XRef;
  33653. })();
  33654. /**
  33655. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  33656. * see the specification (7.9.6 and 7.9.7) for additional details.
  33657. * TODO: implement all the Dict functions and make this more efficient.
  33658. */
  33659. var NameOrNumberTree = (function NameOrNumberTreeClosure() {
  33660. function NameOrNumberTree(root, xref) {
  33661. throw new Error('Cannot initialize NameOrNumberTree.');
  33662. }
  33663. NameOrNumberTree.prototype = {
  33664. getAll: function NameOrNumberTree_getAll() {
  33665. var dict = Object.create(null);
  33666. if (!this.root) {
  33667. return dict;
  33668. }
  33669. var xref = this.xref;
  33670. // Reading Name/Number tree.
  33671. var processed = new RefSet();
  33672. processed.put(this.root);
  33673. var queue = [this.root];
  33674. while (queue.length > 0) {
  33675. var i, n;
  33676. var obj = xref.fetchIfRef(queue.shift());
  33677. if (!isDict(obj)) {
  33678. continue;
  33679. }
  33680. if (obj.has('Kids')) {
  33681. var kids = obj.get('Kids');
  33682. for (i = 0, n = kids.length; i < n; i++) {
  33683. var kid = kids[i];
  33684. assert(!processed.has(kid),
  33685. 'Duplicate entry in "' + this._type + '" tree.');
  33686. queue.push(kid);
  33687. processed.put(kid);
  33688. }
  33689. continue;
  33690. }
  33691. var entries = obj.get(this._type);
  33692. if (isArray(entries)) {
  33693. for (i = 0, n = entries.length; i < n; i += 2) {
  33694. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  33695. }
  33696. }
  33697. }
  33698. return dict;
  33699. },
  33700. get: function NameOrNumberTree_get(key) {
  33701. if (!this.root) {
  33702. return null;
  33703. }
  33704. var xref = this.xref;
  33705. var kidsOrEntries = xref.fetchIfRef(this.root);
  33706. var loopCount = 0;
  33707. var MAX_LEVELS = 10;
  33708. var l, r, m;
  33709. // Perform a binary search to quickly find the entry that
  33710. // contains the key we are looking for.
  33711. while (kidsOrEntries.has('Kids')) {
  33712. if (++loopCount > MAX_LEVELS) {
  33713. warn('Search depth limit reached for "' + this._type + '" tree.');
  33714. return null;
  33715. }
  33716. var kids = kidsOrEntries.get('Kids');
  33717. if (!isArray(kids)) {
  33718. return null;
  33719. }
  33720. l = 0;
  33721. r = kids.length - 1;
  33722. while (l <= r) {
  33723. m = (l + r) >> 1;
  33724. var kid = xref.fetchIfRef(kids[m]);
  33725. var limits = kid.get('Limits');
  33726. if (key < xref.fetchIfRef(limits[0])) {
  33727. r = m - 1;
  33728. } else if (key > xref.fetchIfRef(limits[1])) {
  33729. l = m + 1;
  33730. } else {
  33731. kidsOrEntries = xref.fetchIfRef(kids[m]);
  33732. break;
  33733. }
  33734. }
  33735. if (l > r) {
  33736. return null;
  33737. }
  33738. }
  33739. // If we get here, then we have found the right entry. Now go through the
  33740. // entries in the dictionary until we find the key we're looking for.
  33741. var entries = kidsOrEntries.get(this._type);
  33742. if (isArray(entries)) {
  33743. // Perform a binary search to reduce the lookup time.
  33744. l = 0;
  33745. r = entries.length - 2;
  33746. while (l <= r) {
  33747. // Check only even indices (0, 2, 4, ...) because the
  33748. // odd indices contain the actual data.
  33749. m = (l + r) & ~1;
  33750. var currentKey = xref.fetchIfRef(entries[m]);
  33751. if (key < currentKey) {
  33752. r = m - 2;
  33753. } else if (key > currentKey) {
  33754. l = m + 2;
  33755. } else {
  33756. return xref.fetchIfRef(entries[m + 1]);
  33757. }
  33758. }
  33759. }
  33760. return null;
  33761. }
  33762. };
  33763. return NameOrNumberTree;
  33764. })();
  33765. var NameTree = (function NameTreeClosure() {
  33766. function NameTree(root, xref) {
  33767. this.root = root;
  33768. this.xref = xref;
  33769. this._type = 'Names';
  33770. }
  33771. Util.inherit(NameTree, NameOrNumberTree, {});
  33772. return NameTree;
  33773. })();
  33774. var NumberTree = (function NumberTreeClosure() {
  33775. function NumberTree(root, xref) {
  33776. this.root = root;
  33777. this.xref = xref;
  33778. this._type = 'Nums';
  33779. }
  33780. Util.inherit(NumberTree, NameOrNumberTree, {});
  33781. return NumberTree;
  33782. })();
  33783. /**
  33784. * "A PDF file can refer to the contents of another file by using a File
  33785. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  33786. * NOTE: Only embedded files are supported (as part of the attachments support)
  33787. * TODO: support the 'URL' file system (with caching if !/V), portable
  33788. * collections attributes and related files (/RF)
  33789. */
  33790. var FileSpec = (function FileSpecClosure() {
  33791. function FileSpec(root, xref) {
  33792. if (!root || !isDict(root)) {
  33793. return;
  33794. }
  33795. this.xref = xref;
  33796. this.root = root;
  33797. if (root.has('FS')) {
  33798. this.fs = root.get('FS');
  33799. }
  33800. this.description = root.has('Desc') ?
  33801. stringToPDFString(root.get('Desc')) :
  33802. '';
  33803. if (root.has('RF')) {
  33804. warn('Related file specifications are not supported');
  33805. }
  33806. this.contentAvailable = true;
  33807. if (!root.has('EF')) {
  33808. this.contentAvailable = false;
  33809. warn('Non-embedded file specifications are not supported');
  33810. }
  33811. }
  33812. function pickPlatformItem(dict) {
  33813. // Look for the filename in this order:
  33814. // UF, F, Unix, Mac, DOS
  33815. if (dict.has('UF')) {
  33816. return dict.get('UF');
  33817. } else if (dict.has('F')) {
  33818. return dict.get('F');
  33819. } else if (dict.has('Unix')) {
  33820. return dict.get('Unix');
  33821. } else if (dict.has('Mac')) {
  33822. return dict.get('Mac');
  33823. } else if (dict.has('DOS')) {
  33824. return dict.get('DOS');
  33825. } else {
  33826. return null;
  33827. }
  33828. }
  33829. FileSpec.prototype = {
  33830. get filename() {
  33831. if (!this._filename && this.root) {
  33832. var filename = pickPlatformItem(this.root) || 'unnamed';
  33833. this._filename = stringToPDFString(filename).
  33834. replace(/\\\\/g, '\\').
  33835. replace(/\\\//g, '/').
  33836. replace(/\\/g, '/');
  33837. }
  33838. return this._filename;
  33839. },
  33840. get content() {
  33841. if (!this.contentAvailable) {
  33842. return null;
  33843. }
  33844. if (!this.contentRef && this.root) {
  33845. this.contentRef = pickPlatformItem(this.root.get('EF'));
  33846. }
  33847. var content = null;
  33848. if (this.contentRef) {
  33849. var xref = this.xref;
  33850. var fileObj = xref.fetchIfRef(this.contentRef);
  33851. if (fileObj && isStream(fileObj)) {
  33852. content = fileObj.getBytes();
  33853. } else {
  33854. warn('Embedded file specification points to non-existing/invalid ' +
  33855. 'content');
  33856. }
  33857. } else {
  33858. warn('Embedded file specification does not have a content');
  33859. }
  33860. return content;
  33861. },
  33862. get serializable() {
  33863. return {
  33864. filename: this.filename,
  33865. content: this.content
  33866. };
  33867. }
  33868. };
  33869. return FileSpec;
  33870. })();
  33871. /**
  33872. * A helper for loading missing data in object graphs. It traverses the graph
  33873. * depth first and queues up any objects that have missing data. Once it has
  33874. * has traversed as many objects that are available it attempts to bundle the
  33875. * missing data requests and then resume from the nodes that weren't ready.
  33876. *
  33877. * NOTE: It provides protection from circular references by keeping track of
  33878. * of loaded references. However, you must be careful not to load any graphs
  33879. * that have references to the catalog or other pages since that will cause the
  33880. * entire PDF document object graph to be traversed.
  33881. */
  33882. var ObjectLoader = (function() {
  33883. function mayHaveChildren(value) {
  33884. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  33885. }
  33886. function addChildren(node, nodesToVisit) {
  33887. var value;
  33888. if (isDict(node) || isStream(node)) {
  33889. var map;
  33890. if (isDict(node)) {
  33891. map = node.map;
  33892. } else {
  33893. map = node.dict.map;
  33894. }
  33895. for (var key in map) {
  33896. value = map[key];
  33897. if (mayHaveChildren(value)) {
  33898. nodesToVisit.push(value);
  33899. }
  33900. }
  33901. } else if (isArray(node)) {
  33902. for (var i = 0, ii = node.length; i < ii; i++) {
  33903. value = node[i];
  33904. if (mayHaveChildren(value)) {
  33905. nodesToVisit.push(value);
  33906. }
  33907. }
  33908. }
  33909. }
  33910. function ObjectLoader(obj, keys, xref) {
  33911. this.obj = obj;
  33912. this.keys = keys;
  33913. this.xref = xref;
  33914. this.refSet = null;
  33915. this.capability = null;
  33916. }
  33917. ObjectLoader.prototype = {
  33918. load: function ObjectLoader_load() {
  33919. var keys = this.keys;
  33920. this.capability = createPromiseCapability();
  33921. // Don't walk the graph if all the data is already loaded.
  33922. if (!(this.xref.stream instanceof ChunkedStream) ||
  33923. this.xref.stream.getMissingChunks().length === 0) {
  33924. this.capability.resolve();
  33925. return this.capability.promise;
  33926. }
  33927. this.refSet = new RefSet();
  33928. // Setup the initial nodes to visit.
  33929. var nodesToVisit = [];
  33930. for (var i = 0; i < keys.length; i++) {
  33931. nodesToVisit.push(this.obj[keys[i]]);
  33932. }
  33933. this._walk(nodesToVisit);
  33934. return this.capability.promise;
  33935. },
  33936. _walk: function ObjectLoader_walk(nodesToVisit) {
  33937. var nodesToRevisit = [];
  33938. var pendingRequests = [];
  33939. // DFS walk of the object graph.
  33940. while (nodesToVisit.length) {
  33941. var currentNode = nodesToVisit.pop();
  33942. // Only references or chunked streams can cause missing data exceptions.
  33943. if (isRef(currentNode)) {
  33944. // Skip nodes that have already been visited.
  33945. if (this.refSet.has(currentNode)) {
  33946. continue;
  33947. }
  33948. try {
  33949. var ref = currentNode;
  33950. this.refSet.put(ref);
  33951. currentNode = this.xref.fetch(currentNode);
  33952. } catch (e) {
  33953. if (!(e instanceof MissingDataException)) {
  33954. throw e;
  33955. }
  33956. nodesToRevisit.push(currentNode);
  33957. pendingRequests.push({ begin: e.begin, end: e.end });
  33958. }
  33959. }
  33960. if (currentNode && currentNode.getBaseStreams) {
  33961. var baseStreams = currentNode.getBaseStreams();
  33962. var foundMissingData = false;
  33963. for (var i = 0; i < baseStreams.length; i++) {
  33964. var stream = baseStreams[i];
  33965. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  33966. foundMissingData = true;
  33967. pendingRequests.push({
  33968. begin: stream.start,
  33969. end: stream.end
  33970. });
  33971. }
  33972. }
  33973. if (foundMissingData) {
  33974. nodesToRevisit.push(currentNode);
  33975. }
  33976. }
  33977. addChildren(currentNode, nodesToVisit);
  33978. }
  33979. if (pendingRequests.length) {
  33980. this.xref.stream.manager.requestRanges(pendingRequests).then(
  33981. function pendingRequestCallback() {
  33982. nodesToVisit = nodesToRevisit;
  33983. for (var i = 0; i < nodesToRevisit.length; i++) {
  33984. var node = nodesToRevisit[i];
  33985. // Remove any reference nodes from the currrent refset so they
  33986. // aren't skipped when we revist them.
  33987. if (isRef(node)) {
  33988. this.refSet.remove(node);
  33989. }
  33990. }
  33991. this._walk(nodesToVisit);
  33992. }.bind(this), this.capability.reject);
  33993. return;
  33994. }
  33995. // Everything is loaded.
  33996. this.refSet = null;
  33997. this.capability.resolve();
  33998. }
  33999. };
  34000. return ObjectLoader;
  34001. })();
  34002. exports.Catalog = Catalog;
  34003. exports.ObjectLoader = ObjectLoader;
  34004. exports.XRef = XRef;
  34005. exports.FileSpec = FileSpec;
  34006. }));
  34007. (function (root, factory) {
  34008. {
  34009. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  34010. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  34011. root.pdfjsCoreColorSpace);
  34012. }
  34013. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  34014. coreColorSpace) {
  34015. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  34016. var MissingDataException = sharedUtil.MissingDataException;
  34017. var Util = sharedUtil.Util;
  34018. var assert = sharedUtil.assert;
  34019. var error = sharedUtil.error;
  34020. var info = sharedUtil.info;
  34021. var warn = sharedUtil.warn;
  34022. var isStream = corePrimitives.isStream;
  34023. var PDFFunction = coreFunction.PDFFunction;
  34024. var ColorSpace = coreColorSpace.ColorSpace;
  34025. var ShadingType = {
  34026. FUNCTION_BASED: 1,
  34027. AXIAL: 2,
  34028. RADIAL: 3,
  34029. FREE_FORM_MESH: 4,
  34030. LATTICE_FORM_MESH: 5,
  34031. COONS_PATCH_MESH: 6,
  34032. TENSOR_PATCH_MESH: 7
  34033. };
  34034. var Pattern = (function PatternClosure() {
  34035. // Constructor should define this.getPattern
  34036. function Pattern() {
  34037. error('should not call Pattern constructor');
  34038. }
  34039. Pattern.prototype = {
  34040. // Input: current Canvas context
  34041. // Output: the appropriate fillStyle or strokeStyle
  34042. getPattern: function Pattern_getPattern(ctx) {
  34043. error('Should not call Pattern.getStyle: ' + ctx);
  34044. }
  34045. };
  34046. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  34047. res, handler) {
  34048. var dict = isStream(shading) ? shading.dict : shading;
  34049. var type = dict.get('ShadingType');
  34050. try {
  34051. switch (type) {
  34052. case ShadingType.AXIAL:
  34053. case ShadingType.RADIAL:
  34054. // Both radial and axial shadings are handled by RadialAxial shading.
  34055. return new Shadings.RadialAxial(dict, matrix, xref, res);
  34056. case ShadingType.FREE_FORM_MESH:
  34057. case ShadingType.LATTICE_FORM_MESH:
  34058. case ShadingType.COONS_PATCH_MESH:
  34059. case ShadingType.TENSOR_PATCH_MESH:
  34060. return new Shadings.Mesh(shading, matrix, xref, res);
  34061. default:
  34062. throw new Error('Unsupported ShadingType: ' + type);
  34063. }
  34064. } catch (ex) {
  34065. if (ex instanceof MissingDataException) {
  34066. throw ex;
  34067. }
  34068. handler.send('UnsupportedFeature',
  34069. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  34070. warn(ex);
  34071. return new Shadings.Dummy();
  34072. }
  34073. };
  34074. return Pattern;
  34075. })();
  34076. var Shadings = {};
  34077. // A small number to offset the first/last color stops so we can insert ones to
  34078. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  34079. Shadings.SMALL_NUMBER = 1e-6;
  34080. // Radial and axial shading have very similar implementations
  34081. // If needed, the implementations can be broken into two classes
  34082. Shadings.RadialAxial = (function RadialAxialClosure() {
  34083. function RadialAxial(dict, matrix, xref, res) {
  34084. this.matrix = matrix;
  34085. this.coordsArr = dict.getArray('Coords');
  34086. this.shadingType = dict.get('ShadingType');
  34087. this.type = 'Pattern';
  34088. var cs = dict.get('ColorSpace', 'CS');
  34089. cs = ColorSpace.parse(cs, xref, res);
  34090. this.cs = cs;
  34091. var t0 = 0.0, t1 = 1.0;
  34092. if (dict.has('Domain')) {
  34093. var domainArr = dict.getArray('Domain');
  34094. t0 = domainArr[0];
  34095. t1 = domainArr[1];
  34096. }
  34097. var extendStart = false, extendEnd = false;
  34098. if (dict.has('Extend')) {
  34099. var extendArr = dict.getArray('Extend');
  34100. extendStart = extendArr[0];
  34101. extendEnd = extendArr[1];
  34102. }
  34103. if (this.shadingType === ShadingType.RADIAL &&
  34104. (!extendStart || !extendEnd)) {
  34105. // Radial gradient only currently works if either circle is fully within
  34106. // the other circle.
  34107. var x1 = this.coordsArr[0];
  34108. var y1 = this.coordsArr[1];
  34109. var r1 = this.coordsArr[2];
  34110. var x2 = this.coordsArr[3];
  34111. var y2 = this.coordsArr[4];
  34112. var r2 = this.coordsArr[5];
  34113. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  34114. if (r1 <= r2 + distance &&
  34115. r2 <= r1 + distance) {
  34116. warn('Unsupported radial gradient.');
  34117. }
  34118. }
  34119. this.extendStart = extendStart;
  34120. this.extendEnd = extendEnd;
  34121. var fnObj = dict.get('Function');
  34122. var fn = PDFFunction.parseArray(xref, fnObj);
  34123. // 10 samples seems good enough for now, but probably won't work
  34124. // if there are sharp color changes. Ideally, we would implement
  34125. // the spec faithfully and add lossless optimizations.
  34126. var diff = t1 - t0;
  34127. var step = diff / 10;
  34128. var colorStops = this.colorStops = [];
  34129. // Protect against bad domains so we don't end up in an infinte loop below.
  34130. if (t0 >= t1 || step <= 0) {
  34131. // Acrobat doesn't seem to handle these cases so we'll ignore for
  34132. // now.
  34133. info('Bad shading domain.');
  34134. return;
  34135. }
  34136. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  34137. var rgbColor;
  34138. for (var i = t0; i <= t1; i += step) {
  34139. ratio[0] = i;
  34140. fn(ratio, 0, color, 0);
  34141. rgbColor = cs.getRgb(color, 0);
  34142. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  34143. colorStops.push([(i - t0) / diff, cssColor]);
  34144. }
  34145. var background = 'transparent';
  34146. if (dict.has('Background')) {
  34147. rgbColor = cs.getRgb(dict.get('Background'), 0);
  34148. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  34149. }
  34150. if (!extendStart) {
  34151. // Insert a color stop at the front and offset the first real color stop
  34152. // so it doesn't conflict with the one we insert.
  34153. colorStops.unshift([0, background]);
  34154. colorStops[1][0] += Shadings.SMALL_NUMBER;
  34155. }
  34156. if (!extendEnd) {
  34157. // Same idea as above in extendStart but for the end.
  34158. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  34159. colorStops.push([1, background]);
  34160. }
  34161. this.colorStops = colorStops;
  34162. }
  34163. RadialAxial.prototype = {
  34164. getIR: function RadialAxial_getIR() {
  34165. var coordsArr = this.coordsArr;
  34166. var shadingType = this.shadingType;
  34167. var type, p0, p1, r0, r1;
  34168. if (shadingType === ShadingType.AXIAL) {
  34169. p0 = [coordsArr[0], coordsArr[1]];
  34170. p1 = [coordsArr[2], coordsArr[3]];
  34171. r0 = null;
  34172. r1 = null;
  34173. type = 'axial';
  34174. } else if (shadingType === ShadingType.RADIAL) {
  34175. p0 = [coordsArr[0], coordsArr[1]];
  34176. p1 = [coordsArr[3], coordsArr[4]];
  34177. r0 = coordsArr[2];
  34178. r1 = coordsArr[5];
  34179. type = 'radial';
  34180. } else {
  34181. error('getPattern type unknown: ' + shadingType);
  34182. }
  34183. var matrix = this.matrix;
  34184. if (matrix) {
  34185. p0 = Util.applyTransform(p0, matrix);
  34186. p1 = Util.applyTransform(p1, matrix);
  34187. if (shadingType === ShadingType.RADIAL) {
  34188. var scale = Util.singularValueDecompose2dScale(matrix);
  34189. r0 *= scale[0];
  34190. r1 *= scale[1];
  34191. }
  34192. }
  34193. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  34194. }
  34195. };
  34196. return RadialAxial;
  34197. })();
  34198. // All mesh shading. For now, they will be presented as set of the triangles
  34199. // to be drawn on the canvas and rgb color for each vertex.
  34200. Shadings.Mesh = (function MeshClosure() {
  34201. function MeshStreamReader(stream, context) {
  34202. this.stream = stream;
  34203. this.context = context;
  34204. this.buffer = 0;
  34205. this.bufferLength = 0;
  34206. var numComps = context.numComps;
  34207. this.tmpCompsBuf = new Float32Array(numComps);
  34208. var csNumComps = context.colorSpace.numComps;
  34209. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  34210. this.tmpCompsBuf;
  34211. }
  34212. MeshStreamReader.prototype = {
  34213. get hasData() {
  34214. if (this.stream.end) {
  34215. return this.stream.pos < this.stream.end;
  34216. }
  34217. if (this.bufferLength > 0) {
  34218. return true;
  34219. }
  34220. var nextByte = this.stream.getByte();
  34221. if (nextByte < 0) {
  34222. return false;
  34223. }
  34224. this.buffer = nextByte;
  34225. this.bufferLength = 8;
  34226. return true;
  34227. },
  34228. readBits: function MeshStreamReader_readBits(n) {
  34229. var buffer = this.buffer;
  34230. var bufferLength = this.bufferLength;
  34231. if (n === 32) {
  34232. if (bufferLength === 0) {
  34233. return ((this.stream.getByte() << 24) |
  34234. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  34235. this.stream.getByte()) >>> 0;
  34236. }
  34237. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  34238. (this.stream.getByte() << 8) | this.stream.getByte();
  34239. var nextByte = this.stream.getByte();
  34240. this.buffer = nextByte & ((1 << bufferLength) - 1);
  34241. return ((buffer << (8 - bufferLength)) |
  34242. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  34243. }
  34244. if (n === 8 && bufferLength === 0) {
  34245. return this.stream.getByte();
  34246. }
  34247. while (bufferLength < n) {
  34248. buffer = (buffer << 8) | this.stream.getByte();
  34249. bufferLength += 8;
  34250. }
  34251. bufferLength -= n;
  34252. this.bufferLength = bufferLength;
  34253. this.buffer = buffer & ((1 << bufferLength) - 1);
  34254. return buffer >> bufferLength;
  34255. },
  34256. align: function MeshStreamReader_align() {
  34257. this.buffer = 0;
  34258. this.bufferLength = 0;
  34259. },
  34260. readFlag: function MeshStreamReader_readFlag() {
  34261. return this.readBits(this.context.bitsPerFlag);
  34262. },
  34263. readCoordinate: function MeshStreamReader_readCoordinate() {
  34264. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  34265. var xi = this.readBits(bitsPerCoordinate);
  34266. var yi = this.readBits(bitsPerCoordinate);
  34267. var decode = this.context.decode;
  34268. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  34269. 2.3283064365386963e-10; // 2 ^ -32
  34270. return [
  34271. xi * scale * (decode[1] - decode[0]) + decode[0],
  34272. yi * scale * (decode[3] - decode[2]) + decode[2]
  34273. ];
  34274. },
  34275. readComponents: function MeshStreamReader_readComponents() {
  34276. var numComps = this.context.numComps;
  34277. var bitsPerComponent = this.context.bitsPerComponent;
  34278. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  34279. 2.3283064365386963e-10; // 2 ^ -32
  34280. var decode = this.context.decode;
  34281. var components = this.tmpCompsBuf;
  34282. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  34283. var ci = this.readBits(bitsPerComponent);
  34284. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  34285. }
  34286. var color = this.tmpCsCompsBuf;
  34287. if (this.context.colorFn) {
  34288. this.context.colorFn(components, 0, color, 0);
  34289. }
  34290. return this.context.colorSpace.getRgb(color, 0);
  34291. }
  34292. };
  34293. function decodeType4Shading(mesh, reader) {
  34294. var coords = mesh.coords;
  34295. var colors = mesh.colors;
  34296. var operators = [];
  34297. var ps = []; // not maintaining cs since that will match ps
  34298. var verticesLeft = 0; // assuming we have all data to start a new triangle
  34299. while (reader.hasData) {
  34300. var f = reader.readFlag();
  34301. var coord = reader.readCoordinate();
  34302. var color = reader.readComponents();
  34303. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  34304. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  34305. switch (f) {
  34306. case 0:
  34307. verticesLeft = 3;
  34308. break;
  34309. case 1:
  34310. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  34311. verticesLeft = 1;
  34312. break;
  34313. case 2:
  34314. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  34315. verticesLeft = 1;
  34316. break;
  34317. }
  34318. operators.push(f);
  34319. }
  34320. ps.push(coords.length);
  34321. coords.push(coord);
  34322. colors.push(color);
  34323. verticesLeft--;
  34324. reader.align();
  34325. }
  34326. mesh.figures.push({
  34327. type: 'triangles',
  34328. coords: new Int32Array(ps),
  34329. colors: new Int32Array(ps),
  34330. });
  34331. }
  34332. function decodeType5Shading(mesh, reader, verticesPerRow) {
  34333. var coords = mesh.coords;
  34334. var colors = mesh.colors;
  34335. var ps = []; // not maintaining cs since that will match ps
  34336. while (reader.hasData) {
  34337. var coord = reader.readCoordinate();
  34338. var color = reader.readComponents();
  34339. ps.push(coords.length);
  34340. coords.push(coord);
  34341. colors.push(color);
  34342. }
  34343. mesh.figures.push({
  34344. type: 'lattice',
  34345. coords: new Int32Array(ps),
  34346. colors: new Int32Array(ps),
  34347. verticesPerRow: verticesPerRow
  34348. });
  34349. }
  34350. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  34351. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  34352. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  34353. var getB = (function getBClosure() {
  34354. function buildB(count) {
  34355. var lut = [];
  34356. for (var i = 0; i <= count; i++) {
  34357. var t = i / count, t_ = 1 - t;
  34358. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  34359. 3 * t * t * t_, t * t * t]));
  34360. }
  34361. return lut;
  34362. }
  34363. var cache = [];
  34364. return function getB(count) {
  34365. if (!cache[count]) {
  34366. cache[count] = buildB(count);
  34367. }
  34368. return cache[count];
  34369. };
  34370. })();
  34371. function buildFigureFromPatch(mesh, index) {
  34372. var figure = mesh.figures[index];
  34373. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  34374. var coords = mesh.coords, colors = mesh.colors;
  34375. var pi = figure.coords;
  34376. var ci = figure.colors;
  34377. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  34378. coords[pi[12]][0], coords[pi[15]][0]);
  34379. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  34380. coords[pi[12]][1], coords[pi[15]][1]);
  34381. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  34382. coords[pi[12]][0], coords[pi[15]][0]);
  34383. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  34384. coords[pi[12]][1], coords[pi[15]][1]);
  34385. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  34386. (mesh.bounds[2] - mesh.bounds[0]));
  34387. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  34388. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  34389. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  34390. (mesh.bounds[3] - mesh.bounds[1]));
  34391. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  34392. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  34393. var verticesPerRow = splitXBy + 1;
  34394. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  34395. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  34396. var k = 0;
  34397. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  34398. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  34399. c2 = colors[ci[2]], c3 = colors[ci[3]];
  34400. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  34401. for (var row = 0; row <= splitYBy; row++) {
  34402. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  34403. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  34404. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  34405. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  34406. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  34407. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  34408. for (var col = 0; col <= splitXBy; col++, k++) {
  34409. if ((row === 0 || row === splitYBy) &&
  34410. (col === 0 || col === splitXBy)) {
  34411. continue;
  34412. }
  34413. var x = 0, y = 0;
  34414. var q = 0;
  34415. for (var i = 0; i <= 3; i++) {
  34416. for (var j = 0; j <= 3; j++, q++) {
  34417. var m = bRow[row][i] * bCol[col][j];
  34418. x += coords[pi[q]][0] * m;
  34419. y += coords[pi[q]][1] * m;
  34420. }
  34421. }
  34422. figureCoords[k] = coords.length;
  34423. coords.push([x, y]);
  34424. figureColors[k] = colors.length;
  34425. var newColor = new Uint8Array(3);
  34426. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  34427. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  34428. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  34429. colors.push(newColor);
  34430. }
  34431. }
  34432. figureCoords[0] = pi[0];
  34433. figureColors[0] = ci[0];
  34434. figureCoords[splitXBy] = pi[3];
  34435. figureColors[splitXBy] = ci[1];
  34436. figureCoords[verticesPerRow * splitYBy] = pi[12];
  34437. figureColors[verticesPerRow * splitYBy] = ci[2];
  34438. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  34439. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  34440. mesh.figures[index] = {
  34441. type: 'lattice',
  34442. coords: figureCoords,
  34443. colors: figureColors,
  34444. verticesPerRow: verticesPerRow
  34445. };
  34446. }
  34447. function decodeType6Shading(mesh, reader) {
  34448. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  34449. var coords = mesh.coords;
  34450. var colors = mesh.colors;
  34451. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  34452. var cs = new Int32Array(4); // c00, c30, c03, c33
  34453. while (reader.hasData) {
  34454. var f = reader.readFlag();
  34455. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  34456. var i, ii;
  34457. var pi = coords.length;
  34458. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  34459. coords.push(reader.readCoordinate());
  34460. }
  34461. var ci = colors.length;
  34462. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  34463. colors.push(reader.readComponents());
  34464. }
  34465. var tmp1, tmp2, tmp3, tmp4;
  34466. switch (f) {
  34467. case 0:
  34468. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  34469. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  34470. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  34471. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  34472. cs[2] = ci + 1; cs[3] = ci + 2;
  34473. cs[0] = ci; cs[1] = ci + 3;
  34474. break;
  34475. case 1:
  34476. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  34477. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34478. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  34479. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  34480. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34481. tmp1 = cs[2]; tmp2 = cs[3];
  34482. cs[2] = tmp2; cs[3] = ci;
  34483. cs[0] = tmp1; cs[1] = ci + 1;
  34484. break;
  34485. case 2:
  34486. tmp1 = ps[15];
  34487. tmp2 = ps[11];
  34488. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34489. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  34490. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  34491. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34492. tmp1 = cs[3];
  34493. cs[2] = cs[1]; cs[3] = ci;
  34494. cs[0] = tmp1; cs[1] = ci + 1;
  34495. break;
  34496. case 3:
  34497. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34498. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  34499. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  34500. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34501. cs[2] = cs[0]; cs[3] = ci;
  34502. cs[0] = cs[1]; cs[1] = ci + 1;
  34503. break;
  34504. }
  34505. // set p11, p12, p21, p22
  34506. ps[5] = coords.length;
  34507. coords.push([
  34508. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  34509. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  34510. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  34511. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  34512. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  34513. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  34514. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  34515. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  34516. ]);
  34517. ps[6] = coords.length;
  34518. coords.push([
  34519. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  34520. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  34521. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  34522. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  34523. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  34524. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  34525. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  34526. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  34527. ]);
  34528. ps[9] = coords.length;
  34529. coords.push([
  34530. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  34531. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  34532. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  34533. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  34534. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  34535. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  34536. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  34537. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  34538. ]);
  34539. ps[10] = coords.length;
  34540. coords.push([
  34541. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  34542. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  34543. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  34544. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  34545. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  34546. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  34547. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  34548. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  34549. ]);
  34550. mesh.figures.push({
  34551. type: 'patch',
  34552. coords: new Int32Array(ps), // making copies of ps and cs
  34553. colors: new Int32Array(cs)
  34554. });
  34555. }
  34556. }
  34557. function decodeType7Shading(mesh, reader) {
  34558. var coords = mesh.coords;
  34559. var colors = mesh.colors;
  34560. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  34561. var cs = new Int32Array(4); // c00, c30, c03, c33
  34562. while (reader.hasData) {
  34563. var f = reader.readFlag();
  34564. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  34565. var i, ii;
  34566. var pi = coords.length;
  34567. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  34568. coords.push(reader.readCoordinate());
  34569. }
  34570. var ci = colors.length;
  34571. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  34572. colors.push(reader.readComponents());
  34573. }
  34574. var tmp1, tmp2, tmp3, tmp4;
  34575. switch (f) {
  34576. case 0:
  34577. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  34578. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  34579. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  34580. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  34581. cs[2] = ci + 1; cs[3] = ci + 2;
  34582. cs[0] = ci; cs[1] = ci + 3;
  34583. break;
  34584. case 1:
  34585. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  34586. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34587. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  34588. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  34589. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34590. tmp1 = cs[2]; tmp2 = cs[3];
  34591. cs[2] = tmp2; cs[3] = ci;
  34592. cs[0] = tmp1; cs[1] = ci + 1;
  34593. break;
  34594. case 2:
  34595. tmp1 = ps[15];
  34596. tmp2 = ps[11];
  34597. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34598. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  34599. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  34600. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34601. tmp1 = cs[3];
  34602. cs[2] = cs[1]; cs[3] = ci;
  34603. cs[0] = tmp1; cs[1] = ci + 1;
  34604. break;
  34605. case 3:
  34606. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34607. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  34608. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  34609. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34610. cs[2] = cs[0]; cs[3] = ci;
  34611. cs[0] = cs[1]; cs[1] = ci + 1;
  34612. break;
  34613. }
  34614. mesh.figures.push({
  34615. type: 'patch',
  34616. coords: new Int32Array(ps), // making copies of ps and cs
  34617. colors: new Int32Array(cs)
  34618. });
  34619. }
  34620. }
  34621. function updateBounds(mesh) {
  34622. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  34623. maxX = minX, maxY = minY;
  34624. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  34625. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  34626. minX = minX > x ? x : minX;
  34627. minY = minY > y ? y : minY;
  34628. maxX = maxX < x ? x : maxX;
  34629. maxY = maxY < y ? y : maxY;
  34630. }
  34631. mesh.bounds = [minX, minY, maxX, maxY];
  34632. }
  34633. function packData(mesh) {
  34634. var i, ii, j, jj;
  34635. var coords = mesh.coords;
  34636. var coordsPacked = new Float32Array(coords.length * 2);
  34637. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  34638. var xy = coords[i];
  34639. coordsPacked[j++] = xy[0];
  34640. coordsPacked[j++] = xy[1];
  34641. }
  34642. mesh.coords = coordsPacked;
  34643. var colors = mesh.colors;
  34644. var colorsPacked = new Uint8Array(colors.length * 3);
  34645. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  34646. var c = colors[i];
  34647. colorsPacked[j++] = c[0];
  34648. colorsPacked[j++] = c[1];
  34649. colorsPacked[j++] = c[2];
  34650. }
  34651. mesh.colors = colorsPacked;
  34652. var figures = mesh.figures;
  34653. for (i = 0, ii = figures.length; i < ii; i++) {
  34654. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  34655. for (j = 0, jj = ps.length; j < jj; j++) {
  34656. ps[j] *= 2;
  34657. cs[j] *= 3;
  34658. }
  34659. }
  34660. }
  34661. function Mesh(stream, matrix, xref, res) {
  34662. assert(isStream(stream), 'Mesh data is not a stream');
  34663. var dict = stream.dict;
  34664. this.matrix = matrix;
  34665. this.shadingType = dict.get('ShadingType');
  34666. this.type = 'Pattern';
  34667. this.bbox = dict.getArray('BBox');
  34668. var cs = dict.get('ColorSpace', 'CS');
  34669. cs = ColorSpace.parse(cs, xref, res);
  34670. this.cs = cs;
  34671. this.background = dict.has('Background') ?
  34672. cs.getRgb(dict.get('Background'), 0) : null;
  34673. var fnObj = dict.get('Function');
  34674. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  34675. this.coords = [];
  34676. this.colors = [];
  34677. this.figures = [];
  34678. var decodeContext = {
  34679. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  34680. bitsPerComponent: dict.get('BitsPerComponent'),
  34681. bitsPerFlag: dict.get('BitsPerFlag'),
  34682. decode: dict.getArray('Decode'),
  34683. colorFn: fn,
  34684. colorSpace: cs,
  34685. numComps: fn ? 1 : cs.numComps
  34686. };
  34687. var reader = new MeshStreamReader(stream, decodeContext);
  34688. var patchMesh = false;
  34689. switch (this.shadingType) {
  34690. case ShadingType.FREE_FORM_MESH:
  34691. decodeType4Shading(this, reader);
  34692. break;
  34693. case ShadingType.LATTICE_FORM_MESH:
  34694. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  34695. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  34696. decodeType5Shading(this, reader, verticesPerRow);
  34697. break;
  34698. case ShadingType.COONS_PATCH_MESH:
  34699. decodeType6Shading(this, reader);
  34700. patchMesh = true;
  34701. break;
  34702. case ShadingType.TENSOR_PATCH_MESH:
  34703. decodeType7Shading(this, reader);
  34704. patchMesh = true;
  34705. break;
  34706. default:
  34707. error('Unsupported mesh type.');
  34708. break;
  34709. }
  34710. if (patchMesh) {
  34711. // dirty bounds calculation for determining, how dense shall be triangles
  34712. updateBounds(this);
  34713. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  34714. buildFigureFromPatch(this, i);
  34715. }
  34716. }
  34717. // calculate bounds
  34718. updateBounds(this);
  34719. packData(this);
  34720. }
  34721. Mesh.prototype = {
  34722. getIR: function Mesh_getIR() {
  34723. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  34724. this.bounds, this.matrix, this.bbox, this.background];
  34725. }
  34726. };
  34727. return Mesh;
  34728. })();
  34729. Shadings.Dummy = (function DummyClosure() {
  34730. function Dummy() {
  34731. this.type = 'Pattern';
  34732. }
  34733. Dummy.prototype = {
  34734. getIR: function Dummy_getIR() {
  34735. return ['Dummy'];
  34736. }
  34737. };
  34738. return Dummy;
  34739. })();
  34740. function getTilingPatternIR(operatorList, dict, args) {
  34741. var matrix = dict.getArray('Matrix');
  34742. var bbox = dict.getArray('BBox');
  34743. var xstep = dict.get('XStep');
  34744. var ystep = dict.get('YStep');
  34745. var paintType = dict.get('PaintType');
  34746. var tilingType = dict.get('TilingType');
  34747. return [
  34748. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  34749. paintType, tilingType
  34750. ];
  34751. }
  34752. exports.Pattern = Pattern;
  34753. exports.getTilingPatternIR = getTilingPatternIR;
  34754. }));
  34755. (function (root, factory) {
  34756. {
  34757. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  34758. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  34759. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  34760. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  34761. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi,
  34762. root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts,
  34763. root.pdfjsCoreUnicode, root.pdfjsCoreGlyphList);
  34764. }
  34765. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  34766. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  34767. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi,
  34768. coreEncodings, coreStandardFonts, coreUnicode,
  34769. coreGlyphList) {
  34770. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  34771. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  34772. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  34773. var ImageKind = sharedUtil.ImageKind;
  34774. var OPS = sharedUtil.OPS;
  34775. var TextRenderingMode = sharedUtil.TextRenderingMode;
  34776. var Util = sharedUtil.Util;
  34777. var assert = sharedUtil.assert;
  34778. var createPromiseCapability = sharedUtil.createPromiseCapability;
  34779. var error = sharedUtil.error;
  34780. var info = sharedUtil.info;
  34781. var isArray = sharedUtil.isArray;
  34782. var isNum = sharedUtil.isNum;
  34783. var isString = sharedUtil.isString;
  34784. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  34785. var warn = sharedUtil.warn;
  34786. var Dict = corePrimitives.Dict;
  34787. var Name = corePrimitives.Name;
  34788. var isCmd = corePrimitives.isCmd;
  34789. var isDict = corePrimitives.isDict;
  34790. var isName = corePrimitives.isName;
  34791. var isRef = corePrimitives.isRef;
  34792. var isStream = corePrimitives.isStream;
  34793. var DecodeStream = coreStream.DecodeStream;
  34794. var JpegStream = coreStream.JpegStream;
  34795. var Stream = coreStream.Stream;
  34796. var Lexer = coreParser.Lexer;
  34797. var Parser = coreParser.Parser;
  34798. var isEOF = coreParser.isEOF;
  34799. var PDFImage = coreImage.PDFImage;
  34800. var ColorSpace = coreColorSpace.ColorSpace;
  34801. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  34802. var ErrorFont = coreFonts.ErrorFont;
  34803. var FontFlags = coreFonts.FontFlags;
  34804. var Font = coreFonts.Font;
  34805. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  34806. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  34807. var getFontType = coreFonts.getFontType;
  34808. var isPDFFunction = coreFunction.isPDFFunction;
  34809. var PDFFunction = coreFunction.PDFFunction;
  34810. var Pattern = corePattern.Pattern;
  34811. var getTilingPatternIR = corePattern.getTilingPatternIR;
  34812. var CMapFactory = coreCMap.CMapFactory;
  34813. var IdentityCMap = coreCMap.IdentityCMap;
  34814. var getMetrics = coreMetrics.getMetrics;
  34815. var bidi = coreBidi.bidi;
  34816. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  34817. var StandardEncoding = coreEncodings.StandardEncoding;
  34818. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  34819. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  34820. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  34821. var getEncoding = coreEncodings.getEncoding;
  34822. var getStdFontMap = coreStandardFonts.getStdFontMap;
  34823. var getSerifFonts = coreStandardFonts.getSerifFonts;
  34824. var getSymbolsFonts = coreStandardFonts.getSymbolsFonts;
  34825. var getNormalizedUnicodes = coreUnicode.getNormalizedUnicodes;
  34826. var reverseIfRtl = coreUnicode.reverseIfRtl;
  34827. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  34828. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  34829. var PartialEvaluator = (function PartialEvaluatorClosure() {
  34830. var DefaultPartialEvaluatorOptions = {
  34831. forceDataSchema: false,
  34832. maxImageSize: -1,
  34833. disableFontFace: false,
  34834. cMapOptions: { url: null, packed: false }
  34835. };
  34836. function NativeImageDecoder(xref, resources, handler, forceDataSchema) {
  34837. this.xref = xref;
  34838. this.resources = resources;
  34839. this.handler = handler;
  34840. this.forceDataSchema = forceDataSchema;
  34841. }
  34842. NativeImageDecoder.prototype = {
  34843. canDecode: function (image) {
  34844. return image instanceof JpegStream &&
  34845. NativeImageDecoder.isDecodable(image, this.xref, this.resources);
  34846. },
  34847. decode: function (image) {
  34848. // For natively supported JPEGs send them to the main thread for decoding.
  34849. var dict = image.dict;
  34850. var colorSpace = dict.get('ColorSpace', 'CS');
  34851. colorSpace = ColorSpace.parse(colorSpace, this.xref, this.resources);
  34852. var numComps = colorSpace.numComps;
  34853. var decodePromise = this.handler.sendWithPromise('JpegDecode',
  34854. [image.getIR(this.forceDataSchema), numComps]);
  34855. return decodePromise.then(function (message) {
  34856. var data = message.data;
  34857. return new Stream(data, 0, data.length, image.dict);
  34858. });
  34859. }
  34860. };
  34861. /**
  34862. * Checks if the image can be decoded and displayed by the browser without any
  34863. * further processing such as color space conversions.
  34864. */
  34865. NativeImageDecoder.isSupported =
  34866. function NativeImageDecoder_isSupported(image, xref, res) {
  34867. var cs = ColorSpace.parse(image.dict.get('ColorSpace', 'CS'), xref, res);
  34868. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  34869. cs.isDefaultDecode(image.dict.getArray('Decode', 'D'));
  34870. };
  34871. /**
  34872. * Checks if the image can be decoded by the browser.
  34873. */
  34874. NativeImageDecoder.isDecodable =
  34875. function NativeImageDecoder_isDecodable(image, xref, res) {
  34876. var cs = ColorSpace.parse(image.dict.get('ColorSpace', 'CS'), xref, res);
  34877. return (cs.numComps === 1 || cs.numComps === 3) &&
  34878. cs.isDefaultDecode(image.dict.getArray('Decode', 'D'));
  34879. };
  34880. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  34881. uniquePrefix, idCounters, fontCache, options) {
  34882. this.pdfManager = pdfManager;
  34883. this.xref = xref;
  34884. this.handler = handler;
  34885. this.pageIndex = pageIndex;
  34886. this.uniquePrefix = uniquePrefix;
  34887. this.idCounters = idCounters;
  34888. this.fontCache = fontCache;
  34889. this.options = options || DefaultPartialEvaluatorOptions;
  34890. }
  34891. // Trying to minimize Date.now() usage and check every 100 time
  34892. var TIME_SLOT_DURATION_MS = 20;
  34893. var CHECK_TIME_EVERY = 100;
  34894. function TimeSlotManager() {
  34895. this.reset();
  34896. }
  34897. TimeSlotManager.prototype = {
  34898. check: function TimeSlotManager_check() {
  34899. if (++this.checked < CHECK_TIME_EVERY) {
  34900. return false;
  34901. }
  34902. this.checked = 0;
  34903. return this.endTime <= Date.now();
  34904. },
  34905. reset: function TimeSlotManager_reset() {
  34906. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  34907. this.checked = 0;
  34908. }
  34909. };
  34910. var deferred = Promise.resolve();
  34911. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  34912. PartialEvaluator.prototype = {
  34913. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  34914. if (!isDict(resources)) {
  34915. return false;
  34916. }
  34917. var processed = Object.create(null);
  34918. if (resources.objId) {
  34919. processed[resources.objId] = true;
  34920. }
  34921. var nodes = [resources], xref = this.xref;
  34922. while (nodes.length) {
  34923. var key, i, ii;
  34924. var node = nodes.shift();
  34925. // First check the current resources for blend modes.
  34926. var graphicStates = node.get('ExtGState');
  34927. if (isDict(graphicStates)) {
  34928. var graphicStatesKeys = graphicStates.getKeys();
  34929. for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
  34930. key = graphicStatesKeys[i];
  34931. var graphicState = graphicStates.get(key);
  34932. var bm = graphicState.get('BM');
  34933. if (isName(bm) && bm.name !== 'Normal') {
  34934. return true;
  34935. }
  34936. }
  34937. }
  34938. // Descend into the XObjects to look for more resources and blend modes.
  34939. var xObjects = node.get('XObject');
  34940. if (!isDict(xObjects)) {
  34941. continue;
  34942. }
  34943. var xObjectsKeys = xObjects.getKeys();
  34944. for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
  34945. key = xObjectsKeys[i];
  34946. var xObject = xObjects.getRaw(key);
  34947. if (isRef(xObject)) {
  34948. if (processed[xObject.toString()]) {
  34949. // The XObject has already been processed, and by avoiding a
  34950. // redundant `xref.fetch` we can *significantly* reduce the load
  34951. // time for badly generated PDF files (fixes issue6961.pdf).
  34952. continue;
  34953. }
  34954. xObject = xref.fetch(xObject);
  34955. }
  34956. if (!isStream(xObject)) {
  34957. continue;
  34958. }
  34959. if (xObject.dict.objId) {
  34960. if (processed[xObject.dict.objId]) {
  34961. // stream has objId and is processed already
  34962. continue;
  34963. }
  34964. processed[xObject.dict.objId] = true;
  34965. }
  34966. var xResources = xObject.dict.get('Resources');
  34967. // Checking objId to detect an infinite loop.
  34968. if (isDict(xResources) &&
  34969. (!xResources.objId || !processed[xResources.objId])) {
  34970. nodes.push(xResources);
  34971. if (xResources.objId) {
  34972. processed[xResources.objId] = true;
  34973. }
  34974. }
  34975. }
  34976. }
  34977. return false;
  34978. },
  34979. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  34980. xobj, smask,
  34981. operatorList,
  34982. task,
  34983. initialState) {
  34984. var matrix = xobj.dict.getArray('Matrix');
  34985. var bbox = xobj.dict.getArray('BBox');
  34986. var group = xobj.dict.get('Group');
  34987. if (group) {
  34988. var groupOptions = {
  34989. matrix: matrix,
  34990. bbox: bbox,
  34991. smask: smask,
  34992. isolated: false,
  34993. knockout: false
  34994. };
  34995. var groupSubtype = group.get('S');
  34996. var colorSpace;
  34997. if (isName(groupSubtype, 'Transparency')) {
  34998. groupOptions.isolated = (group.get('I') || false);
  34999. groupOptions.knockout = (group.get('K') || false);
  35000. colorSpace = (group.has('CS') ?
  35001. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  35002. }
  35003. if (smask && smask.backdrop) {
  35004. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  35005. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  35006. }
  35007. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  35008. }
  35009. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  35010. return this.getOperatorList(xobj, task,
  35011. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  35012. then(function () {
  35013. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  35014. if (group) {
  35015. operatorList.addOp(OPS.endGroup, [groupOptions]);
  35016. }
  35017. });
  35018. },
  35019. buildPaintImageXObject:
  35020. function PartialEvaluator_buildPaintImageXObject(resources, image,
  35021. inline, operatorList,
  35022. cacheKey, imageCache) {
  35023. var self = this;
  35024. var dict = image.dict;
  35025. var w = dict.get('Width', 'W');
  35026. var h = dict.get('Height', 'H');
  35027. if (!(w && isNum(w)) || !(h && isNum(h))) {
  35028. warn('Image dimensions are missing, or not numbers.');
  35029. return;
  35030. }
  35031. var maxImageSize = this.options.maxImageSize;
  35032. if (maxImageSize !== -1 && w * h > maxImageSize) {
  35033. warn('Image exceeded maximum allowed size and was removed.');
  35034. return;
  35035. }
  35036. var imageMask = (dict.get('ImageMask', 'IM') || false);
  35037. var imgData, args;
  35038. if (imageMask) {
  35039. // This depends on a tmpCanvas being filled with the
  35040. // current fillStyle, such that processing the pixel
  35041. // data can't be done here. Instead of creating a
  35042. // complete PDFImage, only read the information needed
  35043. // for later.
  35044. var width = dict.get('Width', 'W');
  35045. var height = dict.get('Height', 'H');
  35046. var bitStrideLength = (width + 7) >> 3;
  35047. var imgArray = image.getBytes(bitStrideLength * height);
  35048. var decode = dict.getArray('Decode', 'D');
  35049. var inverseDecode = (!!decode && decode[0] > 0);
  35050. imgData = PDFImage.createMask(imgArray, width, height,
  35051. image instanceof DecodeStream,
  35052. inverseDecode);
  35053. imgData.cached = true;
  35054. args = [imgData];
  35055. operatorList.addOp(OPS.paintImageMaskXObject, args);
  35056. if (cacheKey) {
  35057. imageCache[cacheKey] = {
  35058. fn: OPS.paintImageMaskXObject,
  35059. args: args
  35060. };
  35061. }
  35062. return;
  35063. }
  35064. var softMask = (dict.get('SMask', 'SM') || false);
  35065. var mask = (dict.get('Mask') || false);
  35066. var SMALL_IMAGE_DIMENSIONS = 200;
  35067. // Inlining small images into the queue as RGB data
  35068. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  35069. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  35070. var imageObj = new PDFImage(this.xref, resources, image,
  35071. inline, null, null);
  35072. // We force the use of RGBA_32BPP images here, because we can't handle
  35073. // any other kind.
  35074. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  35075. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  35076. return;
  35077. }
  35078. // If there is no imageMask, create the PDFImage and a lot
  35079. // of image processing can be done here.
  35080. var uniquePrefix = (this.uniquePrefix || '');
  35081. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  35082. operatorList.addDependency(objId);
  35083. args = [objId, w, h];
  35084. if (!softMask && !mask && image instanceof JpegStream &&
  35085. NativeImageDecoder.isSupported(image, this.xref, resources)) {
  35086. // These JPEGs don't need any more processing so we can just send it.
  35087. operatorList.addOp(OPS.paintJpegXObject, args);
  35088. this.handler.send('obj',
  35089. [objId, this.pageIndex, 'JpegStream',
  35090. image.getIR(this.options.forceDataSchema)]);
  35091. return;
  35092. }
  35093. // Creates native image decoder only if a JPEG image or mask is present.
  35094. var nativeImageDecoder = null;
  35095. if (image instanceof JpegStream || mask instanceof JpegStream ||
  35096. softMask instanceof JpegStream) {
  35097. nativeImageDecoder = new NativeImageDecoder(self.xref, resources,
  35098. self.handler, self.options.forceDataSchema);
  35099. }
  35100. PDFImage.buildImage(self.handler, self.xref, resources, image, inline,
  35101. nativeImageDecoder).
  35102. then(function(imageObj) {
  35103. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  35104. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  35105. [imgData.data.buffer]);
  35106. }).then(undefined, function (reason) {
  35107. warn('Unable to decode image: ' + reason);
  35108. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  35109. });
  35110. operatorList.addOp(OPS.paintImageXObject, args);
  35111. if (cacheKey) {
  35112. imageCache[cacheKey] = {
  35113. fn: OPS.paintImageXObject,
  35114. args: args
  35115. };
  35116. }
  35117. },
  35118. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  35119. operatorList, task,
  35120. stateManager) {
  35121. var smaskContent = smask.get('G');
  35122. var smaskOptions = {
  35123. subtype: smask.get('S').name,
  35124. backdrop: smask.get('BC')
  35125. };
  35126. // The SMask might have a alpha/luminosity value transfer function --
  35127. // we will build a map of integer values in range 0..255 to be fast.
  35128. var transferObj = smask.get('TR');
  35129. if (isPDFFunction(transferObj)) {
  35130. var transferFn = PDFFunction.parse(this.xref, transferObj);
  35131. var transferMap = new Uint8Array(256);
  35132. var tmp = new Float32Array(1);
  35133. for (var i = 0; i < 256; i++) {
  35134. tmp[0] = i / 255;
  35135. transferFn(tmp, 0, tmp, 0);
  35136. transferMap[i] = (tmp[0] * 255) | 0;
  35137. }
  35138. smaskOptions.transferMap = transferMap;
  35139. }
  35140. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  35141. operatorList, task, stateManager.state.clone());
  35142. },
  35143. handleTilingType:
  35144. function PartialEvaluator_handleTilingType(fn, args, resources,
  35145. pattern, patternDict,
  35146. operatorList, task) {
  35147. // Create an IR of the pattern code.
  35148. var tilingOpList = new OperatorList();
  35149. // Merge the available resources, to prevent issues when the patternDict
  35150. // is missing some /Resources entries (fixes issue6541.pdf).
  35151. var resourcesArray = [patternDict.get('Resources'), resources];
  35152. var patternResources = Dict.merge(this.xref, resourcesArray);
  35153. return this.getOperatorList(pattern, task, patternResources,
  35154. tilingOpList).then(function () {
  35155. // Add the dependencies to the parent operator list so they are
  35156. // resolved before sub operator list is executed synchronously.
  35157. operatorList.addDependencies(tilingOpList.dependencies);
  35158. operatorList.addOp(fn, getTilingPatternIR({
  35159. fnArray: tilingOpList.fnArray,
  35160. argsArray: tilingOpList.argsArray
  35161. }, patternDict, args));
  35162. });
  35163. },
  35164. handleSetFont:
  35165. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  35166. operatorList, task, state) {
  35167. // TODO(mack): Not needed?
  35168. var fontName;
  35169. if (fontArgs) {
  35170. fontArgs = fontArgs.slice();
  35171. fontName = fontArgs[0].name;
  35172. }
  35173. var self = this;
  35174. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  35175. function (translated) {
  35176. if (!translated.font.isType3Font) {
  35177. return translated;
  35178. }
  35179. return translated.loadType3Data(self, resources, operatorList, task).
  35180. then(function () {
  35181. return translated;
  35182. }, function (reason) {
  35183. // Error in the font data -- sending unsupported feature notification.
  35184. self.handler.send('UnsupportedFeature',
  35185. {featureId: UNSUPPORTED_FEATURES.font});
  35186. return new TranslatedFont('g_font_error',
  35187. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  35188. });
  35189. }).then(function (translated) {
  35190. state.font = translated.font;
  35191. translated.send(self.handler);
  35192. return translated.loadedName;
  35193. });
  35194. },
  35195. handleText: function PartialEvaluator_handleText(chars, state) {
  35196. var font = state.font;
  35197. var glyphs = font.charsToGlyphs(chars);
  35198. var isAddToPathSet = !!(state.textRenderingMode &
  35199. TextRenderingMode.ADD_TO_PATH_FLAG);
  35200. if (font.data && (isAddToPathSet || this.options.disableFontFace)) {
  35201. var buildPath = function (fontChar) {
  35202. if (!font.renderer.hasBuiltPath(fontChar)) {
  35203. var path = font.renderer.getPathJs(fontChar);
  35204. this.handler.send('commonobj', [
  35205. font.loadedName + '_path_' + fontChar,
  35206. 'FontPath',
  35207. path
  35208. ]);
  35209. }
  35210. }.bind(this);
  35211. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  35212. var glyph = glyphs[i];
  35213. buildPath(glyph.fontChar);
  35214. // If the glyph has an accent we need to build a path for its
  35215. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  35216. var accent = glyph.accent;
  35217. if (accent && accent.fontChar) {
  35218. buildPath(accent.fontChar);
  35219. }
  35220. }
  35221. }
  35222. return glyphs;
  35223. },
  35224. setGState: function PartialEvaluator_setGState(resources, gState,
  35225. operatorList, task,
  35226. xref, stateManager) {
  35227. // This array holds the converted/processed state data.
  35228. var gStateObj = [];
  35229. var gStateKeys = gState.getKeys();
  35230. var self = this;
  35231. var promise = Promise.resolve();
  35232. for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
  35233. var key = gStateKeys[i];
  35234. var value = gState.get(key);
  35235. switch (key) {
  35236. case 'Type':
  35237. break;
  35238. case 'LW':
  35239. case 'LC':
  35240. case 'LJ':
  35241. case 'ML':
  35242. case 'D':
  35243. case 'RI':
  35244. case 'FL':
  35245. case 'CA':
  35246. case 'ca':
  35247. gStateObj.push([key, value]);
  35248. break;
  35249. case 'Font':
  35250. promise = promise.then(function () {
  35251. return self.handleSetFont(resources, null, value[0], operatorList,
  35252. task, stateManager.state).
  35253. then(function (loadedName) {
  35254. operatorList.addDependency(loadedName);
  35255. gStateObj.push([key, [loadedName, value[1]]]);
  35256. });
  35257. });
  35258. break;
  35259. case 'BM':
  35260. gStateObj.push([key, value]);
  35261. break;
  35262. case 'SMask':
  35263. if (isName(value, 'None')) {
  35264. gStateObj.push([key, false]);
  35265. break;
  35266. }
  35267. if (isDict(value)) {
  35268. promise = promise.then(function (dict) {
  35269. return self.handleSMask(dict, resources, operatorList,
  35270. task, stateManager);
  35271. }.bind(this, value));
  35272. gStateObj.push([key, true]);
  35273. } else {
  35274. warn('Unsupported SMask type');
  35275. }
  35276. break;
  35277. // Only generate info log messages for the following since
  35278. // they are unlikely to have a big impact on the rendering.
  35279. case 'OP':
  35280. case 'op':
  35281. case 'OPM':
  35282. case 'BG':
  35283. case 'BG2':
  35284. case 'UCR':
  35285. case 'UCR2':
  35286. case 'TR':
  35287. case 'TR2':
  35288. case 'HT':
  35289. case 'SM':
  35290. case 'SA':
  35291. case 'AIS':
  35292. case 'TK':
  35293. // TODO implement these operators.
  35294. info('graphic state operator ' + key);
  35295. break;
  35296. default:
  35297. info('Unknown graphic state operator ' + key);
  35298. break;
  35299. }
  35300. }
  35301. return promise.then(function () {
  35302. if (gStateObj.length > 0) {
  35303. operatorList.addOp(OPS.setGState, [gStateObj]);
  35304. }
  35305. });
  35306. },
  35307. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  35308. resources) {
  35309. function errorFont() {
  35310. return Promise.resolve(new TranslatedFont('g_font_error',
  35311. new ErrorFont('Font ' + fontName + ' is not available'), font));
  35312. }
  35313. var fontRef;
  35314. if (font) { // Loading by ref.
  35315. assert(isRef(font));
  35316. fontRef = font;
  35317. } else { // Loading by name.
  35318. var fontRes = resources.get('Font');
  35319. if (fontRes) {
  35320. fontRef = fontRes.getRaw(fontName);
  35321. } else {
  35322. warn('fontRes not available');
  35323. return errorFont();
  35324. }
  35325. }
  35326. if (!fontRef) {
  35327. warn('fontRef not available');
  35328. return errorFont();
  35329. }
  35330. if (this.fontCache.has(fontRef)) {
  35331. return this.fontCache.get(fontRef);
  35332. }
  35333. font = xref.fetchIfRef(fontRef);
  35334. if (!isDict(font)) {
  35335. return errorFont();
  35336. }
  35337. // We are holding `font.translated` references just for `fontRef`s that
  35338. // are not actually `Ref`s, but rather `Dict`s. See explanation below.
  35339. if (font.translated) {
  35340. return font.translated;
  35341. }
  35342. var fontCapability = createPromiseCapability();
  35343. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  35344. var descriptor = preEvaluatedFont.descriptor;
  35345. var fontRefIsRef = isRef(fontRef), fontID;
  35346. if (fontRefIsRef) {
  35347. fontID = fontRef.toString();
  35348. }
  35349. if (isDict(descriptor)) {
  35350. if (!descriptor.fontAliases) {
  35351. descriptor.fontAliases = Object.create(null);
  35352. }
  35353. var fontAliases = descriptor.fontAliases;
  35354. var hash = preEvaluatedFont.hash;
  35355. if (fontAliases[hash]) {
  35356. var aliasFontRef = fontAliases[hash].aliasRef;
  35357. if (fontRefIsRef && aliasFontRef &&
  35358. this.fontCache.has(aliasFontRef)) {
  35359. this.fontCache.putAlias(fontRef, aliasFontRef);
  35360. return this.fontCache.get(fontRef);
  35361. }
  35362. } else {
  35363. fontAliases[hash] = {
  35364. fontID: Font.getFontID()
  35365. };
  35366. }
  35367. if (fontRefIsRef) {
  35368. fontAliases[hash].aliasRef = fontRef;
  35369. }
  35370. fontID = fontAliases[hash].fontID;
  35371. }
  35372. // Workaround for bad PDF generators that reference fonts incorrectly,
  35373. // where `fontRef` is a `Dict` rather than a `Ref` (fixes bug946506.pdf).
  35374. // In this case we should not put the font into `this.fontCache` (which is
  35375. // a `RefSetCache`), since it's not meaningful to use a `Dict` as a key.
  35376. //
  35377. // However, if we don't cache the font it's not possible to remove it
  35378. // when `cleanup` is triggered from the API, which causes issues on
  35379. // subsequent rendering operations (see issue7403.pdf).
  35380. // A simple workaround would be to just not hold `font.translated`
  35381. // references in this case, but this would force us to unnecessarily load
  35382. // the same fonts over and over.
  35383. //
  35384. // Instead, we cheat a bit by attempting to use a modified `fontID` as a
  35385. // key in `this.fontCache`, to allow the font to be cached.
  35386. // NOTE: This works because `RefSetCache` calls `toString()` on provided
  35387. // keys. Also, since `fontRef` is used when getting cached fonts,
  35388. // we'll not accidentally match fonts cached with the `fontID`.
  35389. if (fontRefIsRef) {
  35390. this.fontCache.put(fontRef, fontCapability.promise);
  35391. } else {
  35392. if (!fontID) {
  35393. fontID = (this.uniquePrefix || 'F_') + (++this.idCounters.obj);
  35394. }
  35395. this.fontCache.put('id_' + fontID, fontCapability.promise);
  35396. }
  35397. assert(fontID, 'The "fontID" must be defined.');
  35398. // Keep track of each font we translated so the caller can
  35399. // load them asynchronously before calling display on a page.
  35400. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + fontID;
  35401. font.translated = fontCapability.promise;
  35402. // TODO move promises into translate font
  35403. var translatedPromise;
  35404. try {
  35405. translatedPromise = this.translateFont(preEvaluatedFont, xref);
  35406. } catch (e) {
  35407. translatedPromise = Promise.reject(e);
  35408. }
  35409. var self = this;
  35410. translatedPromise.then(function (translatedFont) {
  35411. if (translatedFont.fontType !== undefined) {
  35412. var xrefFontStats = xref.stats.fontTypes;
  35413. xrefFontStats[translatedFont.fontType] = true;
  35414. }
  35415. fontCapability.resolve(new TranslatedFont(font.loadedName,
  35416. translatedFont, font));
  35417. }, function (reason) {
  35418. // TODO fontCapability.reject?
  35419. // Error in the font data -- sending unsupported feature notification.
  35420. self.handler.send('UnsupportedFeature',
  35421. {featureId: UNSUPPORTED_FEATURES.font});
  35422. try {
  35423. // error, but it's still nice to have font type reported
  35424. var descriptor = preEvaluatedFont.descriptor;
  35425. var fontFile3 = descriptor && descriptor.get('FontFile3');
  35426. var subtype = fontFile3 && fontFile3.get('Subtype');
  35427. var fontType = getFontType(preEvaluatedFont.type,
  35428. subtype && subtype.name);
  35429. var xrefFontStats = xref.stats.fontTypes;
  35430. xrefFontStats[fontType] = true;
  35431. } catch (ex) { }
  35432. fontCapability.resolve(new TranslatedFont(font.loadedName,
  35433. new ErrorFont(reason instanceof Error ? reason.message : reason),
  35434. font));
  35435. });
  35436. return fontCapability.promise;
  35437. },
  35438. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  35439. var lastIndex = operatorList.length - 1;
  35440. if (!args) {
  35441. args = [];
  35442. }
  35443. if (lastIndex < 0 ||
  35444. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  35445. operatorList.addOp(OPS.constructPath, [[fn], args]);
  35446. } else {
  35447. var opArgs = operatorList.argsArray[lastIndex];
  35448. opArgs[0].push(fn);
  35449. Array.prototype.push.apply(opArgs[1], args);
  35450. }
  35451. },
  35452. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  35453. cs, patterns, resources, task, xref) {
  35454. // compile tiling patterns
  35455. var patternName = args[args.length - 1];
  35456. // SCN/scn applies patterns along with normal colors
  35457. var pattern;
  35458. if (isName(patternName) &&
  35459. (pattern = patterns.get(patternName.name))) {
  35460. var dict = (isStream(pattern) ? pattern.dict : pattern);
  35461. var typeNum = dict.get('PatternType');
  35462. if (typeNum === TILING_PATTERN) {
  35463. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  35464. return this.handleTilingType(fn, color, resources, pattern,
  35465. dict, operatorList, task);
  35466. } else if (typeNum === SHADING_PATTERN) {
  35467. var shading = dict.get('Shading');
  35468. var matrix = dict.getArray('Matrix');
  35469. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  35470. this.handler);
  35471. operatorList.addOp(fn, pattern.getIR());
  35472. return Promise.resolve();
  35473. } else {
  35474. return Promise.reject('Unknown PatternType: ' + typeNum);
  35475. }
  35476. }
  35477. // TODO shall we fail here?
  35478. operatorList.addOp(fn, args);
  35479. return Promise.resolve();
  35480. },
  35481. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  35482. task,
  35483. resources,
  35484. operatorList,
  35485. initialState) {
  35486. var self = this;
  35487. var xref = this.xref;
  35488. var imageCache = Object.create(null);
  35489. assert(operatorList);
  35490. resources = (resources || Dict.empty);
  35491. var xobjs = (resources.get('XObject') || Dict.empty);
  35492. var patterns = (resources.get('Pattern') || Dict.empty);
  35493. var stateManager = new StateManager(initialState || new EvalState());
  35494. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  35495. var timeSlotManager = new TimeSlotManager();
  35496. return new Promise(function promiseBody(resolve, reject) {
  35497. var next = function (promise) {
  35498. promise.then(function () {
  35499. try {
  35500. promiseBody(resolve, reject);
  35501. } catch (ex) {
  35502. reject(ex);
  35503. }
  35504. }, reject);
  35505. };
  35506. task.ensureNotTerminated();
  35507. timeSlotManager.reset();
  35508. var stop, operation = {}, i, ii, cs;
  35509. while (!(stop = timeSlotManager.check())) {
  35510. // The arguments parsed by read() are used beyond this loop, so we
  35511. // cannot reuse the same array on each iteration. Therefore we pass
  35512. // in |null| as the initial value (see the comment on
  35513. // EvaluatorPreprocessor_read() for why).
  35514. operation.args = null;
  35515. if (!(preprocessor.read(operation))) {
  35516. break;
  35517. }
  35518. var args = operation.args;
  35519. var fn = operation.fn;
  35520. switch (fn | 0) {
  35521. case OPS.paintXObject:
  35522. if (args[0].code) {
  35523. break;
  35524. }
  35525. // eagerly compile XForm objects
  35526. var name = args[0].name;
  35527. if (!name) {
  35528. warn('XObject must be referred to by name.');
  35529. continue;
  35530. }
  35531. if (imageCache[name] !== undefined) {
  35532. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  35533. args = null;
  35534. continue;
  35535. }
  35536. var xobj = xobjs.get(name);
  35537. if (xobj) {
  35538. assert(isStream(xobj), 'XObject should be a stream');
  35539. var type = xobj.dict.get('Subtype');
  35540. assert(isName(type), 'XObject should have a Name subtype');
  35541. if (type.name === 'Form') {
  35542. stateManager.save();
  35543. next(self.buildFormXObject(resources, xobj, null,
  35544. operatorList, task,
  35545. stateManager.state.clone()).
  35546. then(function () {
  35547. stateManager.restore();
  35548. }));
  35549. return;
  35550. } else if (type.name === 'Image') {
  35551. self.buildPaintImageXObject(resources, xobj, false,
  35552. operatorList, name, imageCache);
  35553. args = null;
  35554. continue;
  35555. } else if (type.name === 'PS') {
  35556. // PostScript XObjects are unused when viewing documents.
  35557. // See section 4.7.1 of Adobe's PDF reference.
  35558. info('Ignored XObject subtype PS');
  35559. continue;
  35560. } else {
  35561. error('Unhandled XObject subtype ' + type.name);
  35562. }
  35563. }
  35564. break;
  35565. case OPS.setFont:
  35566. var fontSize = args[1];
  35567. // eagerly collect all fonts
  35568. next(self.handleSetFont(resources, args, null, operatorList,
  35569. task, stateManager.state).
  35570. then(function (loadedName) {
  35571. operatorList.addDependency(loadedName);
  35572. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  35573. }));
  35574. return;
  35575. case OPS.endInlineImage:
  35576. var cacheKey = args[0].cacheKey;
  35577. if (cacheKey) {
  35578. var cacheEntry = imageCache[cacheKey];
  35579. if (cacheEntry !== undefined) {
  35580. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  35581. args = null;
  35582. continue;
  35583. }
  35584. }
  35585. self.buildPaintImageXObject(resources, args[0], true,
  35586. operatorList, cacheKey, imageCache);
  35587. args = null;
  35588. continue;
  35589. case OPS.showText:
  35590. args[0] = self.handleText(args[0], stateManager.state);
  35591. break;
  35592. case OPS.showSpacedText:
  35593. var arr = args[0];
  35594. var combinedGlyphs = [];
  35595. var arrLength = arr.length;
  35596. var state = stateManager.state;
  35597. for (i = 0; i < arrLength; ++i) {
  35598. var arrItem = arr[i];
  35599. if (isString(arrItem)) {
  35600. Array.prototype.push.apply(combinedGlyphs,
  35601. self.handleText(arrItem, state));
  35602. } else if (isNum(arrItem)) {
  35603. combinedGlyphs.push(arrItem);
  35604. }
  35605. }
  35606. args[0] = combinedGlyphs;
  35607. fn = OPS.showText;
  35608. break;
  35609. case OPS.nextLineShowText:
  35610. operatorList.addOp(OPS.nextLine);
  35611. args[0] = self.handleText(args[0], stateManager.state);
  35612. fn = OPS.showText;
  35613. break;
  35614. case OPS.nextLineSetSpacingShowText:
  35615. operatorList.addOp(OPS.nextLine);
  35616. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  35617. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  35618. args[0] = self.handleText(args[0], stateManager.state);
  35619. fn = OPS.showText;
  35620. break;
  35621. case OPS.setTextRenderingMode:
  35622. stateManager.state.textRenderingMode = args[0];
  35623. break;
  35624. case OPS.setFillColorSpace:
  35625. stateManager.state.fillColorSpace =
  35626. ColorSpace.parse(args[0], xref, resources);
  35627. continue;
  35628. case OPS.setStrokeColorSpace:
  35629. stateManager.state.strokeColorSpace =
  35630. ColorSpace.parse(args[0], xref, resources);
  35631. continue;
  35632. case OPS.setFillColor:
  35633. cs = stateManager.state.fillColorSpace;
  35634. args = cs.getRgb(args, 0);
  35635. fn = OPS.setFillRGBColor;
  35636. break;
  35637. case OPS.setStrokeColor:
  35638. cs = stateManager.state.strokeColorSpace;
  35639. args = cs.getRgb(args, 0);
  35640. fn = OPS.setStrokeRGBColor;
  35641. break;
  35642. case OPS.setFillGray:
  35643. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  35644. args = ColorSpace.singletons.gray.getRgb(args, 0);
  35645. fn = OPS.setFillRGBColor;
  35646. break;
  35647. case OPS.setStrokeGray:
  35648. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  35649. args = ColorSpace.singletons.gray.getRgb(args, 0);
  35650. fn = OPS.setStrokeRGBColor;
  35651. break;
  35652. case OPS.setFillCMYKColor:
  35653. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  35654. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  35655. fn = OPS.setFillRGBColor;
  35656. break;
  35657. case OPS.setStrokeCMYKColor:
  35658. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  35659. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  35660. fn = OPS.setStrokeRGBColor;
  35661. break;
  35662. case OPS.setFillRGBColor:
  35663. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  35664. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  35665. break;
  35666. case OPS.setStrokeRGBColor:
  35667. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  35668. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  35669. break;
  35670. case OPS.setFillColorN:
  35671. cs = stateManager.state.fillColorSpace;
  35672. if (cs.name === 'Pattern') {
  35673. next(self.handleColorN(operatorList, OPS.setFillColorN, args,
  35674. cs, patterns, resources, task, xref));
  35675. return;
  35676. }
  35677. args = cs.getRgb(args, 0);
  35678. fn = OPS.setFillRGBColor;
  35679. break;
  35680. case OPS.setStrokeColorN:
  35681. cs = stateManager.state.strokeColorSpace;
  35682. if (cs.name === 'Pattern') {
  35683. next(self.handleColorN(operatorList, OPS.setStrokeColorN, args,
  35684. cs, patterns, resources, task, xref));
  35685. return;
  35686. }
  35687. args = cs.getRgb(args, 0);
  35688. fn = OPS.setStrokeRGBColor;
  35689. break;
  35690. case OPS.shadingFill:
  35691. var shadingRes = resources.get('Shading');
  35692. if (!shadingRes) {
  35693. error('No shading resource found');
  35694. }
  35695. var shading = shadingRes.get(args[0].name);
  35696. if (!shading) {
  35697. error('No shading object found');
  35698. }
  35699. var shadingFill = Pattern.parseShading(shading, null, xref,
  35700. resources, self.handler);
  35701. var patternIR = shadingFill.getIR();
  35702. args = [patternIR];
  35703. fn = OPS.shadingFill;
  35704. break;
  35705. case OPS.setGState:
  35706. var dictName = args[0];
  35707. var extGState = resources.get('ExtGState');
  35708. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  35709. break;
  35710. }
  35711. var gState = extGState.get(dictName.name);
  35712. next(self.setGState(resources, gState, operatorList, task, xref,
  35713. stateManager));
  35714. return;
  35715. case OPS.moveTo:
  35716. case OPS.lineTo:
  35717. case OPS.curveTo:
  35718. case OPS.curveTo2:
  35719. case OPS.curveTo3:
  35720. case OPS.closePath:
  35721. self.buildPath(operatorList, fn, args);
  35722. continue;
  35723. case OPS.rectangle:
  35724. self.buildPath(operatorList, fn, args);
  35725. continue;
  35726. case OPS.markPoint:
  35727. case OPS.markPointProps:
  35728. case OPS.beginMarkedContent:
  35729. case OPS.beginMarkedContentProps:
  35730. case OPS.endMarkedContent:
  35731. case OPS.beginCompat:
  35732. case OPS.endCompat:
  35733. // Ignore operators where the corresponding handlers are known to
  35734. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  35735. // serialization errors and is also a bit more efficient.
  35736. // We could also try to serialize all objects in a general way,
  35737. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  35738. // but doing so is meaningless without knowing the semantics.
  35739. continue;
  35740. default:
  35741. // Note: Ignore the operator if it has `Dict` arguments, since
  35742. // those are non-serializable, otherwise postMessage will throw
  35743. // "An object could not be cloned.".
  35744. if (args !== null) {
  35745. for (i = 0, ii = args.length; i < ii; i++) {
  35746. if (args[i] instanceof Dict) {
  35747. break;
  35748. }
  35749. }
  35750. if (i < ii) {
  35751. warn('getOperatorList - ignoring operator: ' + fn);
  35752. continue;
  35753. }
  35754. }
  35755. }
  35756. operatorList.addOp(fn, args);
  35757. }
  35758. if (stop) {
  35759. next(deferred);
  35760. return;
  35761. }
  35762. // Some PDFs don't close all restores inside object/form.
  35763. // Closing those for them.
  35764. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  35765. operatorList.addOp(OPS.restore, []);
  35766. }
  35767. resolve();
  35768. });
  35769. },
  35770. getTextContent:
  35771. function PartialEvaluator_getTextContent(stream, task, resources,
  35772. stateManager,
  35773. normalizeWhitespace,
  35774. combineTextItems) {
  35775. stateManager = (stateManager || new StateManager(new TextState()));
  35776. var WhitespaceRegexp = /\s/g;
  35777. var textContent = {
  35778. items: [],
  35779. styles: Object.create(null)
  35780. };
  35781. var textContentItem = {
  35782. initialized: false,
  35783. str: [],
  35784. width: 0,
  35785. height: 0,
  35786. vertical: false,
  35787. lastAdvanceWidth: 0,
  35788. lastAdvanceHeight: 0,
  35789. textAdvanceScale: 0,
  35790. spaceWidth: 0,
  35791. fakeSpaceMin: Infinity,
  35792. fakeMultiSpaceMin: Infinity,
  35793. fakeMultiSpaceMax: -0,
  35794. textRunBreakAllowed: false,
  35795. transform: null,
  35796. fontName: null
  35797. };
  35798. var SPACE_FACTOR = 0.3;
  35799. var MULTI_SPACE_FACTOR = 1.5;
  35800. var MULTI_SPACE_FACTOR_MAX = 4;
  35801. var self = this;
  35802. var xref = this.xref;
  35803. resources = (xref.fetchIfRef(resources) || Dict.empty);
  35804. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  35805. var xobjs = null;
  35806. var xobjsCache = Object.create(null);
  35807. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  35808. var textState;
  35809. function ensureTextContentItem() {
  35810. if (textContentItem.initialized) {
  35811. return textContentItem;
  35812. }
  35813. var font = textState.font;
  35814. if (!(font.loadedName in textContent.styles)) {
  35815. textContent.styles[font.loadedName] = {
  35816. fontFamily: font.fallbackName,
  35817. ascent: font.ascent,
  35818. descent: font.descent,
  35819. vertical: font.vertical
  35820. };
  35821. }
  35822. textContentItem.fontName = font.loadedName;
  35823. // 9.4.4 Text Space Details
  35824. var tsm = [textState.fontSize * textState.textHScale, 0,
  35825. 0, textState.fontSize,
  35826. 0, textState.textRise];
  35827. if (font.isType3Font &&
  35828. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  35829. textState.fontSize === 1) {
  35830. var glyphHeight = font.bbox[3] - font.bbox[1];
  35831. if (glyphHeight > 0) {
  35832. glyphHeight = glyphHeight * textState.fontMatrix[3];
  35833. tsm[3] *= glyphHeight;
  35834. }
  35835. }
  35836. var trm = Util.transform(textState.ctm,
  35837. Util.transform(textState.textMatrix, tsm));
  35838. textContentItem.transform = trm;
  35839. if (!font.vertical) {
  35840. textContentItem.width = 0;
  35841. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  35842. textContentItem.vertical = false;
  35843. } else {
  35844. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  35845. textContentItem.height = 0;
  35846. textContentItem.vertical = true;
  35847. }
  35848. var a = textState.textLineMatrix[0];
  35849. var b = textState.textLineMatrix[1];
  35850. var scaleLineX = Math.sqrt(a * a + b * b);
  35851. a = textState.ctm[0];
  35852. b = textState.ctm[1];
  35853. var scaleCtmX = Math.sqrt(a * a + b * b);
  35854. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  35855. textContentItem.lastAdvanceWidth = 0;
  35856. textContentItem.lastAdvanceHeight = 0;
  35857. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  35858. if (spaceWidth) {
  35859. textContentItem.spaceWidth = spaceWidth;
  35860. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  35861. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  35862. textContentItem.fakeMultiSpaceMax =
  35863. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  35864. // It's okay for monospace fonts to fake as much space as needed.
  35865. textContentItem.textRunBreakAllowed = !font.isMonospace;
  35866. } else {
  35867. textContentItem.spaceWidth = 0;
  35868. textContentItem.fakeSpaceMin = Infinity;
  35869. textContentItem.fakeMultiSpaceMin = Infinity;
  35870. textContentItem.fakeMultiSpaceMax = 0;
  35871. textContentItem.textRunBreakAllowed = false;
  35872. }
  35873. textContentItem.initialized = true;
  35874. return textContentItem;
  35875. }
  35876. function replaceWhitespace(str) {
  35877. // Replaces all whitespaces with standard spaces (0x20), to avoid
  35878. // alignment issues between the textLayer and the canvas if the text
  35879. // contains e.g. tabs (fixes issue6612.pdf).
  35880. var i = 0, ii = str.length, code;
  35881. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  35882. i++;
  35883. }
  35884. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  35885. }
  35886. function runBidiTransform(textChunk) {
  35887. var str = textChunk.str.join('');
  35888. var bidiResult = bidi(str, -1, textChunk.vertical);
  35889. return {
  35890. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  35891. bidiResult.str),
  35892. dir: bidiResult.dir,
  35893. width: textChunk.width,
  35894. height: textChunk.height,
  35895. transform: textChunk.transform,
  35896. fontName: textChunk.fontName
  35897. };
  35898. }
  35899. function handleSetFont(fontName, fontRef) {
  35900. return self.loadFont(fontName, fontRef, xref, resources).
  35901. then(function (translated) {
  35902. textState.font = translated.font;
  35903. textState.fontMatrix = translated.font.fontMatrix ||
  35904. FONT_IDENTITY_MATRIX;
  35905. });
  35906. }
  35907. function buildTextContentItem(chars) {
  35908. var font = textState.font;
  35909. var textChunk = ensureTextContentItem();
  35910. var width = 0;
  35911. var height = 0;
  35912. var glyphs = font.charsToGlyphs(chars);
  35913. var defaultVMetrics = font.defaultVMetrics;
  35914. for (var i = 0; i < glyphs.length; i++) {
  35915. var glyph = glyphs[i];
  35916. var vMetricX = null;
  35917. var vMetricY = null;
  35918. var glyphWidth = null;
  35919. if (font.vertical) {
  35920. if (glyph.vmetric) {
  35921. glyphWidth = glyph.vmetric[0];
  35922. vMetricX = glyph.vmetric[1];
  35923. vMetricY = glyph.vmetric[2];
  35924. } else {
  35925. glyphWidth = glyph.width;
  35926. vMetricX = glyph.width * 0.5;
  35927. vMetricY = defaultVMetrics[2];
  35928. }
  35929. } else {
  35930. glyphWidth = glyph.width;
  35931. }
  35932. var glyphUnicode = glyph.unicode;
  35933. var NormalizedUnicodes = getNormalizedUnicodes();
  35934. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  35935. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  35936. }
  35937. glyphUnicode = reverseIfRtl(glyphUnicode);
  35938. // The following will calculate the x and y of the individual glyphs.
  35939. // if (font.vertical) {
  35940. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  35941. // textState.fontMatrix[0];
  35942. // tsm[5] -= vMetricY * textState.fontSize *
  35943. // textState.fontMatrix[0];
  35944. // }
  35945. // var trm = Util.transform(textState.textMatrix, tsm);
  35946. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  35947. // var x = pt[0];
  35948. // var y = pt[1];
  35949. var charSpacing = textState.charSpacing;
  35950. if (glyph.isSpace) {
  35951. var wordSpacing = textState.wordSpacing;
  35952. charSpacing += wordSpacing;
  35953. if (wordSpacing > 0) {
  35954. addFakeSpaces(wordSpacing, textChunk.str);
  35955. }
  35956. }
  35957. var tx = 0;
  35958. var ty = 0;
  35959. if (!font.vertical) {
  35960. var w0 = glyphWidth * textState.fontMatrix[0];
  35961. tx = (w0 * textState.fontSize + charSpacing) *
  35962. textState.textHScale;
  35963. width += tx;
  35964. } else {
  35965. var w1 = glyphWidth * textState.fontMatrix[0];
  35966. ty = w1 * textState.fontSize + charSpacing;
  35967. height += ty;
  35968. }
  35969. textState.translateTextMatrix(tx, ty);
  35970. textChunk.str.push(glyphUnicode);
  35971. }
  35972. if (!font.vertical) {
  35973. textChunk.lastAdvanceWidth = width;
  35974. textChunk.width += width * textChunk.textAdvanceScale;
  35975. } else {
  35976. textChunk.lastAdvanceHeight = height;
  35977. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  35978. }
  35979. return textChunk;
  35980. }
  35981. function addFakeSpaces(width, strBuf) {
  35982. if (width < textContentItem.fakeSpaceMin) {
  35983. return;
  35984. }
  35985. if (width < textContentItem.fakeMultiSpaceMin) {
  35986. strBuf.push(' ');
  35987. return;
  35988. }
  35989. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  35990. while (fakeSpaces-- > 0) {
  35991. strBuf.push(' ');
  35992. }
  35993. }
  35994. function flushTextContentItem() {
  35995. if (!textContentItem.initialized) {
  35996. return;
  35997. }
  35998. textContent.items.push(runBidiTransform(textContentItem));
  35999. textContentItem.initialized = false;
  36000. textContentItem.str.length = 0;
  36001. }
  36002. var timeSlotManager = new TimeSlotManager();
  36003. return new Promise(function promiseBody(resolve, reject) {
  36004. var next = function (promise) {
  36005. promise.then(function () {
  36006. try {
  36007. promiseBody(resolve, reject);
  36008. } catch (ex) {
  36009. reject(ex);
  36010. }
  36011. }, reject);
  36012. };
  36013. task.ensureNotTerminated();
  36014. timeSlotManager.reset();
  36015. var stop, operation = {}, args = [];
  36016. while (!(stop = timeSlotManager.check())) {
  36017. // The arguments parsed by read() are not used beyond this loop, so
  36018. // we can reuse the same array on every iteration, thus avoiding
  36019. // unnecessary allocations.
  36020. args.length = 0;
  36021. operation.args = args;
  36022. if (!(preprocessor.read(operation))) {
  36023. break;
  36024. }
  36025. textState = stateManager.state;
  36026. var fn = operation.fn;
  36027. args = operation.args;
  36028. var advance, diff;
  36029. switch (fn | 0) {
  36030. case OPS.setFont:
  36031. // Optimization to ignore multiple identical Tf commands.
  36032. var fontNameArg = args[0].name, fontSizeArg = args[1];
  36033. if (textState.font && fontNameArg === textState.fontName &&
  36034. fontSizeArg === textState.fontSize) {
  36035. break;
  36036. }
  36037. flushTextContentItem();
  36038. textState.fontName = fontNameArg;
  36039. textState.fontSize = fontSizeArg;
  36040. next(handleSetFont(fontNameArg, null));
  36041. return;
  36042. case OPS.setTextRise:
  36043. flushTextContentItem();
  36044. textState.textRise = args[0];
  36045. break;
  36046. case OPS.setHScale:
  36047. flushTextContentItem();
  36048. textState.textHScale = args[0] / 100;
  36049. break;
  36050. case OPS.setLeading:
  36051. flushTextContentItem();
  36052. textState.leading = args[0];
  36053. break;
  36054. case OPS.moveText:
  36055. // Optimization to treat same line movement as advance
  36056. var isSameTextLine = !textState.font ? false :
  36057. ((textState.font.vertical ? args[0] : args[1]) === 0);
  36058. advance = args[0] - args[1];
  36059. if (combineTextItems &&
  36060. isSameTextLine && textContentItem.initialized &&
  36061. advance > 0 &&
  36062. advance <= textContentItem.fakeMultiSpaceMax) {
  36063. textState.translateTextLineMatrix(args[0], args[1]);
  36064. textContentItem.width +=
  36065. (args[0] - textContentItem.lastAdvanceWidth);
  36066. textContentItem.height +=
  36067. (args[1] - textContentItem.lastAdvanceHeight);
  36068. diff = (args[0] - textContentItem.lastAdvanceWidth) -
  36069. (args[1] - textContentItem.lastAdvanceHeight);
  36070. addFakeSpaces(diff, textContentItem.str);
  36071. break;
  36072. }
  36073. flushTextContentItem();
  36074. textState.translateTextLineMatrix(args[0], args[1]);
  36075. textState.textMatrix = textState.textLineMatrix.slice();
  36076. break;
  36077. case OPS.setLeadingMoveText:
  36078. flushTextContentItem();
  36079. textState.leading = -args[1];
  36080. textState.translateTextLineMatrix(args[0], args[1]);
  36081. textState.textMatrix = textState.textLineMatrix.slice();
  36082. break;
  36083. case OPS.nextLine:
  36084. flushTextContentItem();
  36085. textState.carriageReturn();
  36086. break;
  36087. case OPS.setTextMatrix:
  36088. // Optimization to treat same line movement as advance.
  36089. advance = textState.calcTextLineMatrixAdvance(
  36090. args[0], args[1], args[2], args[3], args[4], args[5]);
  36091. if (combineTextItems &&
  36092. advance !== null && textContentItem.initialized &&
  36093. advance.value > 0 &&
  36094. advance.value <= textContentItem.fakeMultiSpaceMax) {
  36095. textState.translateTextLineMatrix(advance.width,
  36096. advance.height);
  36097. textContentItem.width +=
  36098. (advance.width - textContentItem.lastAdvanceWidth);
  36099. textContentItem.height +=
  36100. (advance.height - textContentItem.lastAdvanceHeight);
  36101. diff = (advance.width - textContentItem.lastAdvanceWidth) -
  36102. (advance.height - textContentItem.lastAdvanceHeight);
  36103. addFakeSpaces(diff, textContentItem.str);
  36104. break;
  36105. }
  36106. flushTextContentItem();
  36107. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  36108. args[4], args[5]);
  36109. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  36110. args[4], args[5]);
  36111. break;
  36112. case OPS.setCharSpacing:
  36113. textState.charSpacing = args[0];
  36114. break;
  36115. case OPS.setWordSpacing:
  36116. textState.wordSpacing = args[0];
  36117. break;
  36118. case OPS.beginText:
  36119. flushTextContentItem();
  36120. textState.textMatrix = IDENTITY_MATRIX.slice();
  36121. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  36122. break;
  36123. case OPS.showSpacedText:
  36124. var items = args[0];
  36125. var offset;
  36126. for (var j = 0, jj = items.length; j < jj; j++) {
  36127. if (typeof items[j] === 'string') {
  36128. buildTextContentItem(items[j]);
  36129. } else {
  36130. ensureTextContentItem();
  36131. // PDF Specification 5.3.2 states:
  36132. // The number is expressed in thousandths of a unit of text
  36133. // space.
  36134. // This amount is subtracted from the current horizontal or
  36135. // vertical coordinate, depending on the writing mode.
  36136. // In the default coordinate system, a positive adjustment
  36137. // has the effect of moving the next glyph painted either to
  36138. // the left or down by the given amount.
  36139. advance = items[j] * textState.fontSize / 1000;
  36140. var breakTextRun = false;
  36141. if (textState.font.vertical) {
  36142. offset = advance *
  36143. (textState.textHScale * textState.textMatrix[2] +
  36144. textState.textMatrix[3]);
  36145. textState.translateTextMatrix(0, advance);
  36146. breakTextRun = textContentItem.textRunBreakAllowed &&
  36147. advance > textContentItem.fakeMultiSpaceMax;
  36148. if (!breakTextRun) {
  36149. // Value needs to be added to height to paint down.
  36150. textContentItem.height += offset;
  36151. }
  36152. } else {
  36153. advance = -advance;
  36154. offset = advance * (
  36155. textState.textHScale * textState.textMatrix[0] +
  36156. textState.textMatrix[1]);
  36157. textState.translateTextMatrix(advance, 0);
  36158. breakTextRun = textContentItem.textRunBreakAllowed &&
  36159. advance > textContentItem.fakeMultiSpaceMax;
  36160. if (!breakTextRun) {
  36161. // Value needs to be subtracted from width to paint left.
  36162. textContentItem.width += offset;
  36163. }
  36164. }
  36165. if (breakTextRun) {
  36166. flushTextContentItem();
  36167. } else if (advance > 0) {
  36168. addFakeSpaces(advance, textContentItem.str);
  36169. }
  36170. }
  36171. }
  36172. break;
  36173. case OPS.showText:
  36174. buildTextContentItem(args[0]);
  36175. break;
  36176. case OPS.nextLineShowText:
  36177. flushTextContentItem();
  36178. textState.carriageReturn();
  36179. buildTextContentItem(args[0]);
  36180. break;
  36181. case OPS.nextLineSetSpacingShowText:
  36182. flushTextContentItem();
  36183. textState.wordSpacing = args[0];
  36184. textState.charSpacing = args[1];
  36185. textState.carriageReturn();
  36186. buildTextContentItem(args[2]);
  36187. break;
  36188. case OPS.paintXObject:
  36189. flushTextContentItem();
  36190. if (args[0].code) {
  36191. break;
  36192. }
  36193. if (!xobjs) {
  36194. xobjs = (resources.get('XObject') || Dict.empty);
  36195. }
  36196. var name = args[0].name;
  36197. if (xobjsCache.key === name) {
  36198. if (xobjsCache.texts) {
  36199. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  36200. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  36201. }
  36202. break;
  36203. }
  36204. var xobj = xobjs.get(name);
  36205. if (!xobj) {
  36206. break;
  36207. }
  36208. assert(isStream(xobj), 'XObject should be a stream');
  36209. var type = xobj.dict.get('Subtype');
  36210. assert(isName(type), 'XObject should have a Name subtype');
  36211. if ('Form' !== type.name) {
  36212. xobjsCache.key = name;
  36213. xobjsCache.texts = null;
  36214. break;
  36215. }
  36216. stateManager.save();
  36217. var matrix = xobj.dict.getArray('Matrix');
  36218. if (isArray(matrix) && matrix.length === 6) {
  36219. stateManager.transform(matrix);
  36220. }
  36221. next(self.getTextContent(xobj, task,
  36222. xobj.dict.get('Resources') || resources, stateManager,
  36223. normalizeWhitespace, combineTextItems).then(
  36224. function (formTextContent) {
  36225. Util.appendToArray(textContent.items, formTextContent.items);
  36226. Util.extendObj(textContent.styles, formTextContent.styles);
  36227. stateManager.restore();
  36228. xobjsCache.key = name;
  36229. xobjsCache.texts = formTextContent;
  36230. }));
  36231. return;
  36232. case OPS.setGState:
  36233. flushTextContentItem();
  36234. var dictName = args[0];
  36235. var extGState = resources.get('ExtGState');
  36236. if (!isDict(extGState) || !isName(dictName)) {
  36237. break;
  36238. }
  36239. var gState = extGState.get(dictName.name);
  36240. if (!isDict(gState)) {
  36241. break;
  36242. }
  36243. var gStateFont = gState.get('Font');
  36244. if (gStateFont) {
  36245. textState.fontName = null;
  36246. textState.fontSize = gStateFont[1];
  36247. next(handleSetFont(null, gStateFont[0]));
  36248. return;
  36249. }
  36250. break;
  36251. } // switch
  36252. } // while
  36253. if (stop) {
  36254. next(deferred);
  36255. return;
  36256. }
  36257. flushTextContentItem();
  36258. resolve(textContent);
  36259. });
  36260. },
  36261. extractDataStructures:
  36262. function PartialEvaluator_extractDataStructures(dict, baseDict,
  36263. xref, properties) {
  36264. // 9.10.2
  36265. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  36266. var toUnicodePromise = toUnicode ?
  36267. this.readToUnicode(toUnicode) : Promise.resolve(undefined);
  36268. if (properties.composite) {
  36269. // CIDSystemInfo helps to match CID to glyphs
  36270. var cidSystemInfo = dict.get('CIDSystemInfo');
  36271. if (isDict(cidSystemInfo)) {
  36272. properties.cidSystemInfo = {
  36273. registry: cidSystemInfo.get('Registry'),
  36274. ordering: cidSystemInfo.get('Ordering'),
  36275. supplement: cidSystemInfo.get('Supplement')
  36276. };
  36277. }
  36278. var cidToGidMap = dict.get('CIDToGIDMap');
  36279. if (isStream(cidToGidMap)) {
  36280. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  36281. }
  36282. }
  36283. // Based on 9.6.6 of the spec the encoding can come from multiple places
  36284. // and depends on the font type. The base encoding and differences are
  36285. // read here, but the encoding that is actually used is chosen during
  36286. // glyph mapping in the font.
  36287. // TODO: Loading the built in encoding in the font would allow the
  36288. // differences to be merged in here not require us to hold on to it.
  36289. var differences = [];
  36290. var baseEncodingName = null;
  36291. var encoding;
  36292. if (dict.has('Encoding')) {
  36293. encoding = dict.get('Encoding');
  36294. if (isDict(encoding)) {
  36295. baseEncodingName = encoding.get('BaseEncoding');
  36296. baseEncodingName = (isName(baseEncodingName) ?
  36297. baseEncodingName.name : null);
  36298. // Load the differences between the base and original
  36299. if (encoding.has('Differences')) {
  36300. var diffEncoding = encoding.get('Differences');
  36301. var index = 0;
  36302. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  36303. var data = xref.fetchIfRef(diffEncoding[j]);
  36304. if (isNum(data)) {
  36305. index = data;
  36306. } else if (isName(data)) {
  36307. differences[index++] = data.name;
  36308. } else {
  36309. error('Invalid entry in \'Differences\' array: ' + data);
  36310. }
  36311. }
  36312. }
  36313. } else if (isName(encoding)) {
  36314. baseEncodingName = encoding.name;
  36315. } else {
  36316. error('Encoding is not a Name nor a Dict');
  36317. }
  36318. // According to table 114 if the encoding is a named encoding it must be
  36319. // one of these predefined encodings.
  36320. if ((baseEncodingName !== 'MacRomanEncoding' &&
  36321. baseEncodingName !== 'MacExpertEncoding' &&
  36322. baseEncodingName !== 'WinAnsiEncoding')) {
  36323. baseEncodingName = null;
  36324. }
  36325. }
  36326. if (baseEncodingName) {
  36327. properties.defaultEncoding = getEncoding(baseEncodingName).slice();
  36328. } else {
  36329. encoding = (properties.type === 'TrueType' ?
  36330. WinAnsiEncoding : StandardEncoding);
  36331. // The Symbolic attribute can be misused for regular fonts
  36332. // Heuristic: we have to check if the font is a standard one also
  36333. if (!!(properties.flags & FontFlags.Symbolic)) {
  36334. encoding = MacRomanEncoding;
  36335. if (!properties.file) {
  36336. if (/Symbol/i.test(properties.name)) {
  36337. encoding = SymbolSetEncoding;
  36338. } else if (/Dingbats/i.test(properties.name)) {
  36339. encoding = ZapfDingbatsEncoding;
  36340. }
  36341. }
  36342. }
  36343. properties.defaultEncoding = encoding;
  36344. }
  36345. properties.differences = differences;
  36346. properties.baseEncodingName = baseEncodingName;
  36347. properties.hasEncoding = !!baseEncodingName || differences.length > 0;
  36348. properties.dict = dict;
  36349. return toUnicodePromise.then(function(toUnicode) {
  36350. properties.toUnicode = toUnicode;
  36351. return this.buildToUnicode(properties);
  36352. }.bind(this)).then(function (toUnicode) {
  36353. properties.toUnicode = toUnicode;
  36354. return properties;
  36355. });
  36356. },
  36357. /**
  36358. * Builds a char code to unicode map based on section 9.10 of the spec.
  36359. * @param {Object} properties Font properties object.
  36360. * @return {Promise} A Promise that is resolved with a
  36361. * {ToUnicodeMap|IdentityToUnicodeMap} object.
  36362. */
  36363. buildToUnicode: function PartialEvaluator_buildToUnicode(properties) {
  36364. properties.hasIncludedToUnicodeMap =
  36365. !!properties.toUnicode && properties.toUnicode.length > 0;
  36366. // Section 9.10.2 Mapping Character Codes to Unicode Values
  36367. if (properties.hasIncludedToUnicodeMap) {
  36368. return Promise.resolve(properties.toUnicode);
  36369. }
  36370. // According to the spec if the font is a simple font we should only map
  36371. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  36372. // the differences array only contains adobe standard or symbol set names,
  36373. // in pratice it seems better to always try to create a toUnicode
  36374. // map based of the default encoding.
  36375. var toUnicode, charcode, glyphName;
  36376. if (!properties.composite /* is simple font */) {
  36377. toUnicode = [];
  36378. var encoding = properties.defaultEncoding.slice();
  36379. var baseEncodingName = properties.baseEncodingName;
  36380. // Merge in the differences array.
  36381. var differences = properties.differences;
  36382. for (charcode in differences) {
  36383. glyphName = differences[charcode];
  36384. if (glyphName === '.notdef') {
  36385. // Skip .notdef to prevent rendering errors, e.g. boxes appearing
  36386. // where there should be spaces (fixes issue5256.pdf).
  36387. continue;
  36388. }
  36389. encoding[charcode] = glyphName;
  36390. }
  36391. var glyphsUnicodeMap = getGlyphsUnicode();
  36392. for (charcode in encoding) {
  36393. // a) Map the character code to a character name.
  36394. glyphName = encoding[charcode];
  36395. // b) Look up the character name in the Adobe Glyph List (see the
  36396. // Bibliography) to obtain the corresponding Unicode value.
  36397. if (glyphName === '') {
  36398. continue;
  36399. } else if (glyphsUnicodeMap[glyphName] === undefined) {
  36400. // (undocumented) c) Few heuristics to recognize unknown glyphs
  36401. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  36402. var code = 0;
  36403. switch (glyphName[0]) {
  36404. case 'G': // Gxx glyph
  36405. if (glyphName.length === 3) {
  36406. code = parseInt(glyphName.substr(1), 16);
  36407. }
  36408. break;
  36409. case 'g': // g00xx glyph
  36410. if (glyphName.length === 5) {
  36411. code = parseInt(glyphName.substr(1), 16);
  36412. }
  36413. break;
  36414. case 'C': // Cddd glyph
  36415. case 'c': // cddd glyph
  36416. if (glyphName.length >= 3) {
  36417. code = +glyphName.substr(1);
  36418. }
  36419. break;
  36420. default:
  36421. // 'uniXXXX'/'uXXXX{XX}' glyphs
  36422. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  36423. if (unicode !== -1) {
  36424. code = unicode;
  36425. }
  36426. }
  36427. if (code) {
  36428. // If |baseEncodingName| is one the predefined encodings,
  36429. // and |code| equals |charcode|, using the glyph defined in the
  36430. // baseEncoding seems to yield a better |toUnicode| mapping
  36431. // (fixes issue 5070).
  36432. if (baseEncodingName && code === +charcode) {
  36433. var baseEncoding = getEncoding(baseEncodingName);
  36434. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  36435. toUnicode[charcode] =
  36436. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  36437. continue;
  36438. }
  36439. }
  36440. toUnicode[charcode] = String.fromCharCode(code);
  36441. }
  36442. continue;
  36443. }
  36444. toUnicode[charcode] =
  36445. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  36446. }
  36447. return Promise.resolve(new ToUnicodeMap(toUnicode));
  36448. }
  36449. // If the font is a composite font that uses one of the predefined CMaps
  36450. // listed in Table 118 (except Identity–H and Identity–V) or whose
  36451. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  36452. // Adobe-Korea1 character collection:
  36453. if (properties.composite && (
  36454. (properties.cMap.builtInCMap &&
  36455. !(properties.cMap instanceof IdentityCMap)) ||
  36456. (properties.cidSystemInfo.registry === 'Adobe' &&
  36457. (properties.cidSystemInfo.ordering === 'GB1' ||
  36458. properties.cidSystemInfo.ordering === 'CNS1' ||
  36459. properties.cidSystemInfo.ordering === 'Japan1' ||
  36460. properties.cidSystemInfo.ordering === 'Korea1')))) {
  36461. // Then:
  36462. // a) Map the character code to a character identifier (CID) according
  36463. // to the font’s CMap.
  36464. // b) Obtain the registry and ordering of the character collection used
  36465. // by the font’s CMap (for example, Adobe and Japan1) from its
  36466. // CIDSystemInfo dictionary.
  36467. var registry = properties.cidSystemInfo.registry;
  36468. var ordering = properties.cidSystemInfo.ordering;
  36469. // c) Construct a second CMap name by concatenating the registry and
  36470. // ordering obtained in step (b) in the format registry–ordering–UCS2
  36471. // (for example, Adobe–Japan1–UCS2).
  36472. var ucs2CMapName = Name.get(registry + '-' + ordering + '-UCS2');
  36473. // d) Obtain the CMap with the name constructed in step (c) (available
  36474. // from the ASN Web site; see the Bibliography).
  36475. return CMapFactory.create(ucs2CMapName, this.options.cMapOptions,
  36476. null).then(
  36477. function (ucs2CMap) {
  36478. var cMap = properties.cMap;
  36479. toUnicode = [];
  36480. cMap.forEach(function(charcode, cid) {
  36481. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  36482. // e) Map the CID obtained in step (a) according to the CMap
  36483. // obtained in step (d), producing a Unicode value.
  36484. var ucs2 = ucs2CMap.lookup(cid);
  36485. if (ucs2) {
  36486. toUnicode[charcode] =
  36487. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  36488. ucs2.charCodeAt(1));
  36489. }
  36490. });
  36491. return new ToUnicodeMap(toUnicode);
  36492. });
  36493. }
  36494. // The viewer's choice, just use an identity map.
  36495. return Promise.resolve(new IdentityToUnicodeMap(properties.firstChar,
  36496. properties.lastChar));
  36497. },
  36498. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  36499. var cmapObj = toUnicode;
  36500. if (isName(cmapObj)) {
  36501. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
  36502. function (cmap) {
  36503. if (cmap instanceof IdentityCMap) {
  36504. return new IdentityToUnicodeMap(0, 0xFFFF);
  36505. }
  36506. return new ToUnicodeMap(cmap.getMap());
  36507. });
  36508. } else if (isStream(cmapObj)) {
  36509. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
  36510. function (cmap) {
  36511. if (cmap instanceof IdentityCMap) {
  36512. return new IdentityToUnicodeMap(0, 0xFFFF);
  36513. }
  36514. var map = new Array(cmap.length);
  36515. // Convert UTF-16BE
  36516. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  36517. // to iterate over all keys.
  36518. cmap.forEach(function(charCode, token) {
  36519. var str = [];
  36520. for (var k = 0; k < token.length; k += 2) {
  36521. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  36522. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  36523. str.push(w1);
  36524. continue;
  36525. }
  36526. k += 2;
  36527. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  36528. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  36529. }
  36530. map[charCode] = String.fromCharCode.apply(String, str);
  36531. });
  36532. return new ToUnicodeMap(map);
  36533. });
  36534. }
  36535. return Promise.resolve(null);
  36536. },
  36537. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  36538. // Extract the encoding from the CIDToGIDMap
  36539. var glyphsData = cidToGidStream.getBytes();
  36540. // Set encoding 0 to later verify the font has an encoding
  36541. var result = [];
  36542. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  36543. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  36544. if (glyphID === 0) {
  36545. continue;
  36546. }
  36547. var code = j >> 1;
  36548. result[code] = glyphID;
  36549. }
  36550. return result;
  36551. },
  36552. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  36553. descriptor,
  36554. properties) {
  36555. var glyphsWidths = [];
  36556. var defaultWidth = 0;
  36557. var glyphsVMetrics = [];
  36558. var defaultVMetrics;
  36559. var i, ii, j, jj, start, code, widths;
  36560. if (properties.composite) {
  36561. defaultWidth = dict.get('DW') || 1000;
  36562. widths = dict.get('W');
  36563. if (widths) {
  36564. for (i = 0, ii = widths.length; i < ii; i++) {
  36565. start = widths[i++];
  36566. code = xref.fetchIfRef(widths[i]);
  36567. if (isArray(code)) {
  36568. for (j = 0, jj = code.length; j < jj; j++) {
  36569. glyphsWidths[start++] = code[j];
  36570. }
  36571. } else {
  36572. var width = widths[++i];
  36573. for (j = start; j <= code; j++) {
  36574. glyphsWidths[j] = width;
  36575. }
  36576. }
  36577. }
  36578. }
  36579. if (properties.vertical) {
  36580. var vmetrics = (dict.get('DW2') || [880, -1000]);
  36581. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  36582. vmetrics = dict.get('W2');
  36583. if (vmetrics) {
  36584. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  36585. start = vmetrics[i++];
  36586. code = xref.fetchIfRef(vmetrics[i]);
  36587. if (isArray(code)) {
  36588. for (j = 0, jj = code.length; j < jj; j++) {
  36589. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  36590. }
  36591. } else {
  36592. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  36593. for (j = start; j <= code; j++) {
  36594. glyphsVMetrics[j] = vmetric;
  36595. }
  36596. }
  36597. }
  36598. }
  36599. }
  36600. } else {
  36601. var firstChar = properties.firstChar;
  36602. widths = dict.get('Widths');
  36603. if (widths) {
  36604. j = firstChar;
  36605. for (i = 0, ii = widths.length; i < ii; i++) {
  36606. glyphsWidths[j++] = widths[i];
  36607. }
  36608. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  36609. } else {
  36610. // Trying get the BaseFont metrics (see comment above).
  36611. var baseFontName = dict.get('BaseFont');
  36612. if (isName(baseFontName)) {
  36613. var metrics = this.getBaseFontMetrics(baseFontName.name);
  36614. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  36615. properties);
  36616. defaultWidth = metrics.defaultWidth;
  36617. }
  36618. }
  36619. }
  36620. // Heuristic: detection of monospace font by checking all non-zero widths
  36621. var isMonospace = true;
  36622. var firstWidth = defaultWidth;
  36623. for (var glyph in glyphsWidths) {
  36624. var glyphWidth = glyphsWidths[glyph];
  36625. if (!glyphWidth) {
  36626. continue;
  36627. }
  36628. if (!firstWidth) {
  36629. firstWidth = glyphWidth;
  36630. continue;
  36631. }
  36632. if (firstWidth !== glyphWidth) {
  36633. isMonospace = false;
  36634. break;
  36635. }
  36636. }
  36637. if (isMonospace) {
  36638. properties.flags |= FontFlags.FixedPitch;
  36639. }
  36640. properties.defaultWidth = defaultWidth;
  36641. properties.widths = glyphsWidths;
  36642. properties.defaultVMetrics = defaultVMetrics;
  36643. properties.vmetrics = glyphsVMetrics;
  36644. },
  36645. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  36646. // Simulating descriptor flags attribute
  36647. var fontNameWoStyle = baseFontName.split('-')[0];
  36648. return (fontNameWoStyle in getSerifFonts()) ||
  36649. (fontNameWoStyle.search(/serif/gi) !== -1);
  36650. },
  36651. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  36652. var defaultWidth = 0;
  36653. var widths = [];
  36654. var monospace = false;
  36655. var stdFontMap = getStdFontMap();
  36656. var lookupName = (stdFontMap[name] || name);
  36657. var Metrics = getMetrics();
  36658. if (!(lookupName in Metrics)) {
  36659. // Use default fonts for looking up font metrics if the passed
  36660. // font is not a base font
  36661. if (this.isSerifFont(name)) {
  36662. lookupName = 'Times-Roman';
  36663. } else {
  36664. lookupName = 'Helvetica';
  36665. }
  36666. }
  36667. var glyphWidths = Metrics[lookupName];
  36668. if (isNum(glyphWidths)) {
  36669. defaultWidth = glyphWidths;
  36670. monospace = true;
  36671. } else {
  36672. widths = glyphWidths(); // expand lazy widths array
  36673. }
  36674. return {
  36675. defaultWidth: defaultWidth,
  36676. monospace: monospace,
  36677. widths: widths
  36678. };
  36679. },
  36680. buildCharCodeToWidth:
  36681. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  36682. properties) {
  36683. var widths = Object.create(null);
  36684. var differences = properties.differences;
  36685. var encoding = properties.defaultEncoding;
  36686. for (var charCode = 0; charCode < 256; charCode++) {
  36687. if (charCode in differences &&
  36688. widthsByGlyphName[differences[charCode]]) {
  36689. widths[charCode] = widthsByGlyphName[differences[charCode]];
  36690. continue;
  36691. }
  36692. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  36693. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  36694. continue;
  36695. }
  36696. }
  36697. return widths;
  36698. },
  36699. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  36700. var baseDict = dict;
  36701. var type = dict.get('Subtype');
  36702. assert(isName(type), 'invalid font Subtype');
  36703. var composite = false;
  36704. var uint8array;
  36705. if (type.name === 'Type0') {
  36706. // If font is a composite
  36707. // - get the descendant font
  36708. // - set the type according to the descendant font
  36709. // - get the FontDescriptor from the descendant font
  36710. var df = dict.get('DescendantFonts');
  36711. if (!df) {
  36712. error('Descendant fonts are not specified');
  36713. }
  36714. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  36715. type = dict.get('Subtype');
  36716. assert(isName(type), 'invalid font Subtype');
  36717. composite = true;
  36718. }
  36719. var descriptor = dict.get('FontDescriptor');
  36720. if (descriptor) {
  36721. var hash = new MurmurHash3_64();
  36722. var encoding = baseDict.getRaw('Encoding');
  36723. if (isName(encoding)) {
  36724. hash.update(encoding.name);
  36725. } else if (isRef(encoding)) {
  36726. hash.update(encoding.toString());
  36727. } else if (isDict(encoding)) {
  36728. var keys = encoding.getKeys();
  36729. for (var i = 0, ii = keys.length; i < ii; i++) {
  36730. var entry = encoding.getRaw(keys[i]);
  36731. if (isName(entry)) {
  36732. hash.update(entry.name);
  36733. } else if (isRef(entry)) {
  36734. hash.update(entry.toString());
  36735. } else if (isArray(entry)) { // 'Differences' entry.
  36736. // Ideally we should check the contents of the array, but to avoid
  36737. // parsing it here and then again in |extractDataStructures|,
  36738. // we only use the array length for now (fixes bug1157493.pdf).
  36739. hash.update(entry.length.toString());
  36740. }
  36741. }
  36742. }
  36743. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  36744. if (isStream(toUnicode)) {
  36745. var stream = toUnicode.str || toUnicode;
  36746. uint8array = stream.buffer ?
  36747. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  36748. new Uint8Array(stream.bytes.buffer,
  36749. stream.start, stream.end - stream.start);
  36750. hash.update(uint8array);
  36751. } else if (isName(toUnicode)) {
  36752. hash.update(toUnicode.name);
  36753. }
  36754. var widths = dict.get('Widths') || baseDict.get('Widths');
  36755. if (widths) {
  36756. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  36757. hash.update(uint8array);
  36758. }
  36759. }
  36760. return {
  36761. descriptor: descriptor,
  36762. dict: dict,
  36763. baseDict: baseDict,
  36764. composite: composite,
  36765. type: type.name,
  36766. hash: hash ? hash.hexdigest() : ''
  36767. };
  36768. },
  36769. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  36770. xref) {
  36771. var baseDict = preEvaluatedFont.baseDict;
  36772. var dict = preEvaluatedFont.dict;
  36773. var composite = preEvaluatedFont.composite;
  36774. var descriptor = preEvaluatedFont.descriptor;
  36775. var type = preEvaluatedFont.type;
  36776. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  36777. var cMapOptions = this.options.cMapOptions;
  36778. var properties;
  36779. if (!descriptor) {
  36780. if (type === 'Type3') {
  36781. // FontDescriptor is only required for Type3 fonts when the document
  36782. // is a tagged pdf. Create a barbebones one to get by.
  36783. descriptor = new Dict(null);
  36784. descriptor.set('FontName', Name.get(type));
  36785. descriptor.set('FontBBox', dict.getArray('FontBBox'));
  36786. } else {
  36787. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  36788. // FontDescriptor was not required.
  36789. // This case is here for compatibility.
  36790. var baseFontName = dict.get('BaseFont');
  36791. if (!isName(baseFontName)) {
  36792. error('Base font is not specified');
  36793. }
  36794. // Using base font name as a font name.
  36795. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  36796. var metrics = this.getBaseFontMetrics(baseFontName);
  36797. // Simulating descriptor flags attribute
  36798. var fontNameWoStyle = baseFontName.split('-')[0];
  36799. var flags =
  36800. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  36801. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  36802. (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic :
  36803. FontFlags.Nonsymbolic);
  36804. properties = {
  36805. type: type,
  36806. name: baseFontName,
  36807. widths: metrics.widths,
  36808. defaultWidth: metrics.defaultWidth,
  36809. flags: flags,
  36810. firstChar: 0,
  36811. lastChar: maxCharIndex
  36812. };
  36813. return this.extractDataStructures(dict, dict, xref, properties).then(
  36814. function (properties) {
  36815. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  36816. properties);
  36817. return new Font(baseFontName, null, properties);
  36818. }.bind(this));
  36819. }
  36820. }
  36821. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  36822. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  36823. // to ignore this rule when a variant of a standard font is used.
  36824. // TODO Fill the width array depending on which of the base font this is
  36825. // a variant.
  36826. var firstChar = (dict.get('FirstChar') || 0);
  36827. var lastChar = (dict.get('LastChar') || maxCharIndex);
  36828. var fontName = descriptor.get('FontName');
  36829. var baseFont = dict.get('BaseFont');
  36830. // Some bad PDFs have a string as the font name.
  36831. if (isString(fontName)) {
  36832. fontName = Name.get(fontName);
  36833. }
  36834. if (isString(baseFont)) {
  36835. baseFont = Name.get(baseFont);
  36836. }
  36837. if (type !== 'Type3') {
  36838. var fontNameStr = fontName && fontName.name;
  36839. var baseFontStr = baseFont && baseFont.name;
  36840. if (fontNameStr !== baseFontStr) {
  36841. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  36842. '" but should be the same as the Font\'s BaseFont "' +
  36843. baseFontStr + '"');
  36844. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  36845. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  36846. if (fontNameStr && baseFontStr &&
  36847. baseFontStr.indexOf(fontNameStr) === 0) {
  36848. fontName = baseFont;
  36849. }
  36850. }
  36851. }
  36852. fontName = (fontName || baseFont);
  36853. assert(isName(fontName), 'invalid font name');
  36854. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  36855. if (fontFile) {
  36856. if (fontFile.dict) {
  36857. var subtype = fontFile.dict.get('Subtype');
  36858. if (subtype) {
  36859. subtype = subtype.name;
  36860. }
  36861. var length1 = fontFile.dict.get('Length1');
  36862. var length2 = fontFile.dict.get('Length2');
  36863. var length3 = fontFile.dict.get('Length3');
  36864. }
  36865. }
  36866. properties = {
  36867. type: type,
  36868. name: fontName.name,
  36869. subtype: subtype,
  36870. file: fontFile,
  36871. length1: length1,
  36872. length2: length2,
  36873. length3: length3,
  36874. loadedName: baseDict.loadedName,
  36875. composite: composite,
  36876. wideChars: composite,
  36877. fixedPitch: false,
  36878. fontMatrix: (dict.getArray('FontMatrix') || FONT_IDENTITY_MATRIX),
  36879. firstChar: firstChar || 0,
  36880. lastChar: (lastChar || maxCharIndex),
  36881. bbox: descriptor.getArray('FontBBox'),
  36882. ascent: descriptor.get('Ascent'),
  36883. descent: descriptor.get('Descent'),
  36884. xHeight: descriptor.get('XHeight'),
  36885. capHeight: descriptor.get('CapHeight'),
  36886. flags: descriptor.get('Flags'),
  36887. italicAngle: descriptor.get('ItalicAngle'),
  36888. coded: false
  36889. };
  36890. var cMapPromise;
  36891. if (composite) {
  36892. var cidEncoding = baseDict.get('Encoding');
  36893. if (isName(cidEncoding)) {
  36894. properties.cidEncoding = cidEncoding.name;
  36895. }
  36896. cMapPromise = CMapFactory.create(cidEncoding, cMapOptions, null).then(
  36897. function (cMap) {
  36898. properties.cMap = cMap;
  36899. properties.vertical = properties.cMap.vertical;
  36900. });
  36901. } else {
  36902. cMapPromise = Promise.resolve(undefined);
  36903. }
  36904. return cMapPromise.then(function () {
  36905. return this.extractDataStructures(dict, baseDict, xref, properties);
  36906. }.bind(this)).then(function (properties) {
  36907. this.extractWidths(dict, xref, descriptor, properties);
  36908. if (type === 'Type3') {
  36909. properties.isType3Font = true;
  36910. }
  36911. return new Font(fontName.name, fontFile, properties);
  36912. }.bind(this));
  36913. }
  36914. };
  36915. return PartialEvaluator;
  36916. })();
  36917. var TranslatedFont = (function TranslatedFontClosure() {
  36918. function TranslatedFont(loadedName, font, dict) {
  36919. this.loadedName = loadedName;
  36920. this.font = font;
  36921. this.dict = dict;
  36922. this.type3Loaded = null;
  36923. this.sent = false;
  36924. }
  36925. TranslatedFont.prototype = {
  36926. send: function (handler) {
  36927. if (this.sent) {
  36928. return;
  36929. }
  36930. var fontData = this.font.exportData();
  36931. handler.send('commonobj', [
  36932. this.loadedName,
  36933. 'Font',
  36934. fontData
  36935. ]);
  36936. this.sent = true;
  36937. },
  36938. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  36939. assert(this.font.isType3Font);
  36940. if (this.type3Loaded) {
  36941. return this.type3Loaded;
  36942. }
  36943. var translatedFont = this.font;
  36944. var loadCharProcsPromise = Promise.resolve();
  36945. var charProcs = this.dict.get('CharProcs');
  36946. var fontResources = this.dict.get('Resources') || resources;
  36947. var charProcKeys = charProcs.getKeys();
  36948. var charProcOperatorList = Object.create(null);
  36949. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  36950. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  36951. var glyphStream = charProcs.get(key);
  36952. var operatorList = new OperatorList();
  36953. return evaluator.getOperatorList(glyphStream, task, fontResources,
  36954. operatorList).then(function () {
  36955. charProcOperatorList[key] = operatorList.getIR();
  36956. // Add the dependencies to the parent operator list so they are
  36957. // resolved before sub operator list is executed synchronously.
  36958. parentOperatorList.addDependencies(operatorList.dependencies);
  36959. }, function (reason) {
  36960. warn('Type3 font resource \"' + key + '\" is not available');
  36961. var operatorList = new OperatorList();
  36962. charProcOperatorList[key] = operatorList.getIR();
  36963. });
  36964. }.bind(this, charProcKeys[i]));
  36965. }
  36966. this.type3Loaded = loadCharProcsPromise.then(function () {
  36967. translatedFont.charProcOperatorList = charProcOperatorList;
  36968. });
  36969. return this.type3Loaded;
  36970. }
  36971. };
  36972. return TranslatedFont;
  36973. })();
  36974. var OperatorList = (function OperatorListClosure() {
  36975. var CHUNK_SIZE = 1000;
  36976. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  36977. function getTransfers(queue) {
  36978. var transfers = [];
  36979. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  36980. for (var i = 0, ii = queue.length; i < ii; i++) {
  36981. switch (fnArray[i]) {
  36982. case OPS.paintInlineImageXObject:
  36983. case OPS.paintInlineImageXObjectGroup:
  36984. case OPS.paintImageMaskXObject:
  36985. var arg = argsArray[i][0]; // first param in imgData
  36986. if (!arg.cached) {
  36987. transfers.push(arg.data.buffer);
  36988. }
  36989. break;
  36990. }
  36991. }
  36992. return transfers;
  36993. }
  36994. function OperatorList(intent, messageHandler, pageIndex) {
  36995. this.messageHandler = messageHandler;
  36996. this.fnArray = [];
  36997. this.argsArray = [];
  36998. this.dependencies = Object.create(null);
  36999. this._totalLength = 0;
  37000. this.pageIndex = pageIndex;
  37001. this.intent = intent;
  37002. }
  37003. OperatorList.prototype = {
  37004. get length() {
  37005. return this.argsArray.length;
  37006. },
  37007. /**
  37008. * @returns {number} The total length of the entire operator list,
  37009. * since `this.length === 0` after flushing.
  37010. */
  37011. get totalLength() {
  37012. return (this._totalLength + this.length);
  37013. },
  37014. addOp: function(fn, args) {
  37015. this.fnArray.push(fn);
  37016. this.argsArray.push(args);
  37017. if (this.messageHandler) {
  37018. if (this.fnArray.length >= CHUNK_SIZE) {
  37019. this.flush();
  37020. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  37021. (fn === OPS.restore || fn === OPS.endText)) {
  37022. // heuristic to flush on boundary of restore or endText
  37023. this.flush();
  37024. }
  37025. }
  37026. },
  37027. addDependency: function(dependency) {
  37028. if (dependency in this.dependencies) {
  37029. return;
  37030. }
  37031. this.dependencies[dependency] = true;
  37032. this.addOp(OPS.dependency, [dependency]);
  37033. },
  37034. addDependencies: function(dependencies) {
  37035. for (var key in dependencies) {
  37036. this.addDependency(key);
  37037. }
  37038. },
  37039. addOpList: function(opList) {
  37040. Util.extendObj(this.dependencies, opList.dependencies);
  37041. for (var i = 0, ii = opList.length; i < ii; i++) {
  37042. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  37043. }
  37044. },
  37045. getIR: function() {
  37046. return {
  37047. fnArray: this.fnArray,
  37048. argsArray: this.argsArray,
  37049. length: this.length
  37050. };
  37051. },
  37052. flush: function(lastChunk) {
  37053. if (this.intent !== 'oplist') {
  37054. new QueueOptimizer().optimize(this);
  37055. }
  37056. var transfers = getTransfers(this);
  37057. var length = this.length;
  37058. this._totalLength += length;
  37059. this.messageHandler.send('RenderPageChunk', {
  37060. operatorList: {
  37061. fnArray: this.fnArray,
  37062. argsArray: this.argsArray,
  37063. lastChunk: lastChunk,
  37064. length: length
  37065. },
  37066. pageIndex: this.pageIndex,
  37067. intent: this.intent
  37068. }, transfers);
  37069. this.dependencies = Object.create(null);
  37070. this.fnArray.length = 0;
  37071. this.argsArray.length = 0;
  37072. }
  37073. };
  37074. return OperatorList;
  37075. })();
  37076. var StateManager = (function StateManagerClosure() {
  37077. function StateManager(initialState) {
  37078. this.state = initialState;
  37079. this.stateStack = [];
  37080. }
  37081. StateManager.prototype = {
  37082. save: function () {
  37083. var old = this.state;
  37084. this.stateStack.push(this.state);
  37085. this.state = old.clone();
  37086. },
  37087. restore: function () {
  37088. var prev = this.stateStack.pop();
  37089. if (prev) {
  37090. this.state = prev;
  37091. }
  37092. },
  37093. transform: function (args) {
  37094. this.state.ctm = Util.transform(this.state.ctm, args);
  37095. }
  37096. };
  37097. return StateManager;
  37098. })();
  37099. var TextState = (function TextStateClosure() {
  37100. function TextState() {
  37101. this.ctm = new Float32Array(IDENTITY_MATRIX);
  37102. this.fontName = null;
  37103. this.fontSize = 0;
  37104. this.font = null;
  37105. this.fontMatrix = FONT_IDENTITY_MATRIX;
  37106. this.textMatrix = IDENTITY_MATRIX.slice();
  37107. this.textLineMatrix = IDENTITY_MATRIX.slice();
  37108. this.charSpacing = 0;
  37109. this.wordSpacing = 0;
  37110. this.leading = 0;
  37111. this.textHScale = 1;
  37112. this.textRise = 0;
  37113. }
  37114. TextState.prototype = {
  37115. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  37116. var m = this.textMatrix;
  37117. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  37118. },
  37119. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  37120. var m = this.textLineMatrix;
  37121. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  37122. },
  37123. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  37124. var m = this.textMatrix;
  37125. m[4] = m[0] * x + m[2] * y + m[4];
  37126. m[5] = m[1] * x + m[3] * y + m[5];
  37127. },
  37128. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  37129. var m = this.textLineMatrix;
  37130. m[4] = m[0] * x + m[2] * y + m[4];
  37131. m[5] = m[1] * x + m[3] * y + m[5];
  37132. },
  37133. calcTextLineMatrixAdvance:
  37134. function TextState_calcTextLineMatrixAdvance(a, b, c, d, e, f) {
  37135. var font = this.font;
  37136. if (!font) {
  37137. return null;
  37138. }
  37139. var m = this.textLineMatrix;
  37140. if (!(a === m[0] && b === m[1] && c === m[2] && d === m[3])) {
  37141. return null;
  37142. }
  37143. var txDiff = e - m[4], tyDiff = f - m[5];
  37144. if ((font.vertical && txDiff !== 0) || (!font.vertical && tyDiff !== 0)) {
  37145. return null;
  37146. }
  37147. var tx, ty, denominator = a * d - b * c;
  37148. if (font.vertical) {
  37149. tx = -tyDiff * c / denominator;
  37150. ty = tyDiff * a / denominator;
  37151. } else {
  37152. tx = txDiff * d / denominator;
  37153. ty = -txDiff * b / denominator;
  37154. }
  37155. return { width: tx, height: ty, value: (font.vertical ? ty : tx), };
  37156. },
  37157. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  37158. // 9.4.4 Text Space Details
  37159. var tsm = [this.fontSize * this.textHScale, 0,
  37160. 0, this.fontSize,
  37161. 0, this.textRise];
  37162. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  37163. },
  37164. carriageReturn: function TextState_carriageReturn() {
  37165. this.translateTextLineMatrix(0, -this.leading);
  37166. this.textMatrix = this.textLineMatrix.slice();
  37167. },
  37168. clone: function TextState_clone() {
  37169. var clone = Object.create(this);
  37170. clone.textMatrix = this.textMatrix.slice();
  37171. clone.textLineMatrix = this.textLineMatrix.slice();
  37172. clone.fontMatrix = this.fontMatrix.slice();
  37173. return clone;
  37174. }
  37175. };
  37176. return TextState;
  37177. })();
  37178. var EvalState = (function EvalStateClosure() {
  37179. function EvalState() {
  37180. this.ctm = new Float32Array(IDENTITY_MATRIX);
  37181. this.font = null;
  37182. this.textRenderingMode = TextRenderingMode.FILL;
  37183. this.fillColorSpace = ColorSpace.singletons.gray;
  37184. this.strokeColorSpace = ColorSpace.singletons.gray;
  37185. }
  37186. EvalState.prototype = {
  37187. clone: function CanvasExtraState_clone() {
  37188. return Object.create(this);
  37189. },
  37190. };
  37191. return EvalState;
  37192. })();
  37193. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  37194. // Specifies properties for each command
  37195. //
  37196. // If variableArgs === true: [0, `numArgs`] expected
  37197. // If variableArgs === false: exactly `numArgs` expected
  37198. var getOPMap = getLookupTableFactory(function (t) {
  37199. // Graphic state
  37200. t['w'] = { id: OPS.setLineWidth, numArgs: 1, variableArgs: false };
  37201. t['J'] = { id: OPS.setLineCap, numArgs: 1, variableArgs: false };
  37202. t['j'] = { id: OPS.setLineJoin, numArgs: 1, variableArgs: false };
  37203. t['M'] = { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false };
  37204. t['d'] = { id: OPS.setDash, numArgs: 2, variableArgs: false };
  37205. t['ri'] = { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false };
  37206. t['i'] = { id: OPS.setFlatness, numArgs: 1, variableArgs: false };
  37207. t['gs'] = { id: OPS.setGState, numArgs: 1, variableArgs: false };
  37208. t['q'] = { id: OPS.save, numArgs: 0, variableArgs: false };
  37209. t['Q'] = { id: OPS.restore, numArgs: 0, variableArgs: false };
  37210. t['cm'] = { id: OPS.transform, numArgs: 6, variableArgs: false };
  37211. // Path
  37212. t['m'] = { id: OPS.moveTo, numArgs: 2, variableArgs: false };
  37213. t['l'] = { id: OPS.lineTo, numArgs: 2, variableArgs: false };
  37214. t['c'] = { id: OPS.curveTo, numArgs: 6, variableArgs: false };
  37215. t['v'] = { id: OPS.curveTo2, numArgs: 4, variableArgs: false };
  37216. t['y'] = { id: OPS.curveTo3, numArgs: 4, variableArgs: false };
  37217. t['h'] = { id: OPS.closePath, numArgs: 0, variableArgs: false };
  37218. t['re'] = { id: OPS.rectangle, numArgs: 4, variableArgs: false };
  37219. t['S'] = { id: OPS.stroke, numArgs: 0, variableArgs: false };
  37220. t['s'] = { id: OPS.closeStroke, numArgs: 0, variableArgs: false };
  37221. t['f'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  37222. t['F'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  37223. t['f*'] = { id: OPS.eoFill, numArgs: 0, variableArgs: false };
  37224. t['B'] = { id: OPS.fillStroke, numArgs: 0, variableArgs: false };
  37225. t['B*'] = { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false };
  37226. t['b'] = { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false };
  37227. t['b*'] = { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false };
  37228. t['n'] = { id: OPS.endPath, numArgs: 0, variableArgs: false };
  37229. // Clipping
  37230. t['W'] = { id: OPS.clip, numArgs: 0, variableArgs: false };
  37231. t['W*'] = { id: OPS.eoClip, numArgs: 0, variableArgs: false };
  37232. // Text
  37233. t['BT'] = { id: OPS.beginText, numArgs: 0, variableArgs: false };
  37234. t['ET'] = { id: OPS.endText, numArgs: 0, variableArgs: false };
  37235. t['Tc'] = { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false };
  37236. t['Tw'] = { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false };
  37237. t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false };
  37238. t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false };
  37239. t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false };
  37240. t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false };
  37241. t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false };
  37242. t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false };
  37243. t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false };
  37244. t['Tm'] = { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false };
  37245. t['T*'] = { id: OPS.nextLine, numArgs: 0, variableArgs: false };
  37246. t['Tj'] = { id: OPS.showText, numArgs: 1, variableArgs: false };
  37247. t['TJ'] = { id: OPS.showSpacedText, numArgs: 1, variableArgs: false };
  37248. t['\''] = { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false };
  37249. t['"'] = { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  37250. variableArgs: false };
  37251. // Type3 fonts
  37252. t['d0'] = { id: OPS.setCharWidth, numArgs: 2, variableArgs: false };
  37253. t['d1'] = { id: OPS.setCharWidthAndBounds, numArgs: 6,
  37254. variableArgs: false };
  37255. // Color
  37256. t['CS'] = { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false };
  37257. t['cs'] = { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false };
  37258. t['SC'] = { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true };
  37259. t['SCN'] = { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true };
  37260. t['sc'] = { id: OPS.setFillColor, numArgs: 4, variableArgs: true };
  37261. t['scn'] = { id: OPS.setFillColorN, numArgs: 33, variableArgs: true };
  37262. t['G'] = { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false };
  37263. t['g'] = { id: OPS.setFillGray, numArgs: 1, variableArgs: false };
  37264. t['RG'] = { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false };
  37265. t['rg'] = { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false };
  37266. t['K'] = { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false };
  37267. t['k'] = { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false };
  37268. // Shading
  37269. t['sh'] = { id: OPS.shadingFill, numArgs: 1, variableArgs: false };
  37270. // Images
  37271. t['BI'] = { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false };
  37272. t['ID'] = { id: OPS.beginImageData, numArgs: 0, variableArgs: false };
  37273. t['EI'] = { id: OPS.endInlineImage, numArgs: 1, variableArgs: false };
  37274. // XObjects
  37275. t['Do'] = { id: OPS.paintXObject, numArgs: 1, variableArgs: false };
  37276. t['MP'] = { id: OPS.markPoint, numArgs: 1, variableArgs: false };
  37277. t['DP'] = { id: OPS.markPointProps, numArgs: 2, variableArgs: false };
  37278. t['BMC'] = { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false };
  37279. t['BDC'] = { id: OPS.beginMarkedContentProps, numArgs: 2,
  37280. variableArgs: false };
  37281. t['EMC'] = { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false };
  37282. // Compatibility
  37283. t['BX'] = { id: OPS.beginCompat, numArgs: 0, variableArgs: false };
  37284. t['EX'] = { id: OPS.endCompat, numArgs: 0, variableArgs: false };
  37285. // (reserved partial commands for the lexer)
  37286. t['BM'] = null;
  37287. t['BD'] = null;
  37288. t['true'] = null;
  37289. t['fa'] = null;
  37290. t['fal'] = null;
  37291. t['fals'] = null;
  37292. t['false'] = null;
  37293. t['nu'] = null;
  37294. t['nul'] = null;
  37295. t['null'] = null;
  37296. });
  37297. function EvaluatorPreprocessor(stream, xref, stateManager) {
  37298. this.opMap = getOPMap();
  37299. // TODO(mduan): pass array of knownCommands rather than this.opMap
  37300. // dictionary
  37301. this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
  37302. this.stateManager = stateManager;
  37303. this.nonProcessedArgs = [];
  37304. }
  37305. EvaluatorPreprocessor.prototype = {
  37306. get savedStatesDepth() {
  37307. return this.stateManager.stateStack.length;
  37308. },
  37309. // |operation| is an object with two fields:
  37310. //
  37311. // - |fn| is an out param.
  37312. //
  37313. // - |args| is an inout param. On entry, it should have one of two values.
  37314. //
  37315. // - An empty array. This indicates that the caller is providing the
  37316. // array in which the args will be stored in. The caller should use
  37317. // this value if it can reuse a single array for each call to read().
  37318. //
  37319. // - |null|. This indicates that the caller needs this function to create
  37320. // the array in which any args are stored in. If there are zero args,
  37321. // this function will leave |operation.args| as |null| (thus avoiding
  37322. // allocations that would occur if we used an empty array to represent
  37323. // zero arguments). Otherwise, it will replace |null| with a new array
  37324. // containing the arguments. The caller should use this value if it
  37325. // cannot reuse an array for each call to read().
  37326. //
  37327. // These two modes are present because this function is very hot and so
  37328. // avoiding allocations where possible is worthwhile.
  37329. //
  37330. read: function EvaluatorPreprocessor_read(operation) {
  37331. var args = operation.args;
  37332. while (true) {
  37333. var obj = this.parser.getObj();
  37334. if (isCmd(obj)) {
  37335. var cmd = obj.cmd;
  37336. // Check that the command is valid
  37337. var opSpec = this.opMap[cmd];
  37338. if (!opSpec) {
  37339. warn('Unknown command "' + cmd + '"');
  37340. continue;
  37341. }
  37342. var fn = opSpec.id;
  37343. var numArgs = opSpec.numArgs;
  37344. var argsLength = args !== null ? args.length : 0;
  37345. if (!opSpec.variableArgs) {
  37346. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  37347. if (argsLength !== numArgs) {
  37348. var nonProcessedArgs = this.nonProcessedArgs;
  37349. while (argsLength > numArgs) {
  37350. nonProcessedArgs.push(args.shift());
  37351. argsLength--;
  37352. }
  37353. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  37354. if (!args) {
  37355. args = [];
  37356. }
  37357. args.unshift(nonProcessedArgs.pop());
  37358. argsLength++;
  37359. }
  37360. }
  37361. if (argsLength < numArgs) {
  37362. // If we receive too few args, it's not possible to possible
  37363. // to execute the command, so skip the command
  37364. info('Command ' + fn + ': because expected ' +
  37365. numArgs + ' args, but received ' + argsLength +
  37366. ' args; skipping');
  37367. args = null;
  37368. continue;
  37369. }
  37370. } else if (argsLength > numArgs) {
  37371. info('Command ' + fn + ': expected [0,' + numArgs +
  37372. '] args, but received ' + argsLength + ' args');
  37373. }
  37374. // TODO figure out how to type-check vararg functions
  37375. this.preprocessCommand(fn, args);
  37376. operation.fn = fn;
  37377. operation.args = args;
  37378. return true;
  37379. } else {
  37380. if (isEOF(obj)) {
  37381. return false; // no more commands
  37382. }
  37383. // argument
  37384. if (obj !== null) {
  37385. if (!args) {
  37386. args = [];
  37387. }
  37388. args.push(obj);
  37389. assert(args.length <= 33, 'Too many arguments');
  37390. }
  37391. }
  37392. }
  37393. },
  37394. preprocessCommand:
  37395. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  37396. switch (fn | 0) {
  37397. case OPS.save:
  37398. this.stateManager.save();
  37399. break;
  37400. case OPS.restore:
  37401. this.stateManager.restore();
  37402. break;
  37403. case OPS.transform:
  37404. this.stateManager.transform(args);
  37405. break;
  37406. }
  37407. }
  37408. };
  37409. return EvaluatorPreprocessor;
  37410. })();
  37411. var QueueOptimizer = (function QueueOptimizerClosure() {
  37412. function addState(parentState, pattern, fn) {
  37413. var state = parentState;
  37414. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  37415. var item = pattern[i];
  37416. state = (state[item] || (state[item] = []));
  37417. }
  37418. state[pattern[pattern.length - 1]] = fn;
  37419. }
  37420. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  37421. argsArray) {
  37422. // Handles special case of mainly LaTeX documents which use image masks to
  37423. // draw lines with the current fill style.
  37424. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  37425. // have been found at iFirstSave.
  37426. var iFirstPIMXO = iFirstSave + 2;
  37427. for (var i = 0; i < count; i++) {
  37428. var arg = argsArray[iFirstPIMXO + 4 * i];
  37429. var imageMask = arg.length === 1 && arg[0];
  37430. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  37431. (!imageMask.data.length ||
  37432. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  37433. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  37434. continue;
  37435. }
  37436. break;
  37437. }
  37438. return count - i;
  37439. }
  37440. var InitialState = [];
  37441. // This replaces (save, transform, paintInlineImageXObject, restore)+
  37442. // sequences with one |paintInlineImageXObjectGroup| operation.
  37443. addState(InitialState,
  37444. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  37445. function foundInlineImageGroup(context) {
  37446. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  37447. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  37448. var MAX_WIDTH = 1000;
  37449. var IMAGE_PADDING = 1;
  37450. var fnArray = context.fnArray, argsArray = context.argsArray;
  37451. var curr = context.iCurr;
  37452. var iFirstSave = curr - 3;
  37453. var iFirstTransform = curr - 2;
  37454. var iFirstPIIXO = curr - 1;
  37455. // Look for the quartets.
  37456. var i = iFirstSave + 4;
  37457. var ii = fnArray.length;
  37458. while (i + 3 < ii) {
  37459. if (fnArray[i] !== OPS.save ||
  37460. fnArray[i + 1] !== OPS.transform ||
  37461. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  37462. fnArray[i + 3] !== OPS.restore) {
  37463. break; // ops don't match
  37464. }
  37465. i += 4;
  37466. }
  37467. // At this point, i is the index of the first op past the last valid
  37468. // quartet.
  37469. var count = Math.min((i - iFirstSave) / 4,
  37470. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  37471. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  37472. return i;
  37473. }
  37474. // assuming that heights of those image is too small (~1 pixel)
  37475. // packing as much as possible by lines
  37476. var maxX = 0;
  37477. var map = [], maxLineHeight = 0;
  37478. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  37479. var q;
  37480. for (q = 0; q < count; q++) {
  37481. var transform = argsArray[iFirstTransform + (q << 2)];
  37482. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  37483. if (currentX + img.width > MAX_WIDTH) {
  37484. // starting new line
  37485. maxX = Math.max(maxX, currentX);
  37486. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  37487. currentX = 0;
  37488. maxLineHeight = 0;
  37489. }
  37490. map.push({
  37491. transform: transform,
  37492. x: currentX, y: currentY,
  37493. w: img.width, h: img.height
  37494. });
  37495. currentX += img.width + 2 * IMAGE_PADDING;
  37496. maxLineHeight = Math.max(maxLineHeight, img.height);
  37497. }
  37498. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  37499. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  37500. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  37501. var imgRowSize = imgWidth << 2;
  37502. for (q = 0; q < count; q++) {
  37503. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  37504. // Copy image by lines and extends pixels into padding.
  37505. var rowSize = map[q].w << 2;
  37506. var dataOffset = 0;
  37507. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  37508. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  37509. for (var k = 0, kk = map[q].h; k < kk; k++) {
  37510. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  37511. dataOffset += rowSize;
  37512. offset += imgRowSize;
  37513. }
  37514. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  37515. while (offset >= 0) {
  37516. data[offset - 4] = data[offset];
  37517. data[offset - 3] = data[offset + 1];
  37518. data[offset - 2] = data[offset + 2];
  37519. data[offset - 1] = data[offset + 3];
  37520. data[offset + rowSize] = data[offset + rowSize - 4];
  37521. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  37522. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  37523. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  37524. offset -= imgRowSize;
  37525. }
  37526. }
  37527. // Replace queue items.
  37528. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  37529. argsArray.splice(iFirstSave, count * 4,
  37530. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  37531. data: imgData }, map]);
  37532. return iFirstSave + 1;
  37533. });
  37534. // This replaces (save, transform, paintImageMaskXObject, restore)+
  37535. // sequences with one |paintImageMaskXObjectGroup| or one
  37536. // |paintImageMaskXObjectRepeat| operation.
  37537. addState(InitialState,
  37538. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  37539. function foundImageMaskGroup(context) {
  37540. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  37541. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  37542. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  37543. var fnArray = context.fnArray, argsArray = context.argsArray;
  37544. var curr = context.iCurr;
  37545. var iFirstSave = curr - 3;
  37546. var iFirstTransform = curr - 2;
  37547. var iFirstPIMXO = curr - 1;
  37548. // Look for the quartets.
  37549. var i = iFirstSave + 4;
  37550. var ii = fnArray.length;
  37551. while (i + 3 < ii) {
  37552. if (fnArray[i] !== OPS.save ||
  37553. fnArray[i + 1] !== OPS.transform ||
  37554. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  37555. fnArray[i + 3] !== OPS.restore) {
  37556. break; // ops don't match
  37557. }
  37558. i += 4;
  37559. }
  37560. // At this point, i is the index of the first op past the last valid
  37561. // quartet.
  37562. var count = (i - iFirstSave) / 4;
  37563. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  37564. argsArray);
  37565. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  37566. return i;
  37567. }
  37568. var q;
  37569. var isSameImage = false;
  37570. var iTransform, transformArgs;
  37571. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  37572. if (argsArray[iFirstTransform][1] === 0 &&
  37573. argsArray[iFirstTransform][2] === 0) {
  37574. isSameImage = true;
  37575. var firstTransformArg0 = argsArray[iFirstTransform][0];
  37576. var firstTransformArg3 = argsArray[iFirstTransform][3];
  37577. iTransform = iFirstTransform + 4;
  37578. var iPIMXO = iFirstPIMXO + 4;
  37579. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  37580. transformArgs = argsArray[iTransform];
  37581. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  37582. transformArgs[0] !== firstTransformArg0 ||
  37583. transformArgs[1] !== 0 ||
  37584. transformArgs[2] !== 0 ||
  37585. transformArgs[3] !== firstTransformArg3) {
  37586. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  37587. isSameImage = false;
  37588. } else {
  37589. count = q;
  37590. }
  37591. break; // different image or transform
  37592. }
  37593. }
  37594. }
  37595. if (isSameImage) {
  37596. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  37597. var positions = new Float32Array(count * 2);
  37598. iTransform = iFirstTransform;
  37599. for (q = 0; q < count; q++, iTransform += 4) {
  37600. transformArgs = argsArray[iTransform];
  37601. positions[(q << 1)] = transformArgs[4];
  37602. positions[(q << 1) + 1] = transformArgs[5];
  37603. }
  37604. // Replace queue items.
  37605. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  37606. argsArray.splice(iFirstSave, count * 4,
  37607. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  37608. } else {
  37609. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  37610. var images = [];
  37611. for (q = 0; q < count; q++) {
  37612. transformArgs = argsArray[iFirstTransform + (q << 2)];
  37613. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  37614. images.push({ data: maskParams.data, width: maskParams.width,
  37615. height: maskParams.height,
  37616. transform: transformArgs });
  37617. }
  37618. // Replace queue items.
  37619. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  37620. argsArray.splice(iFirstSave, count * 4, [images]);
  37621. }
  37622. return iFirstSave + 1;
  37623. });
  37624. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  37625. // with one paintImageXObjectRepeat operation, if the |transform| and
  37626. // |paintImageXObjectRepeat| ops are appropriate.
  37627. addState(InitialState,
  37628. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  37629. function (context) {
  37630. var MIN_IMAGES_IN_BLOCK = 3;
  37631. var MAX_IMAGES_IN_BLOCK = 1000;
  37632. var fnArray = context.fnArray, argsArray = context.argsArray;
  37633. var curr = context.iCurr;
  37634. var iFirstSave = curr - 3;
  37635. var iFirstTransform = curr - 2;
  37636. var iFirstPIXO = curr - 1;
  37637. var iFirstRestore = curr;
  37638. if (argsArray[iFirstTransform][1] !== 0 ||
  37639. argsArray[iFirstTransform][2] !== 0) {
  37640. return iFirstRestore + 1; // transform has the wrong form
  37641. }
  37642. // Look for the quartets.
  37643. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  37644. var firstTransformArg0 = argsArray[iFirstTransform][0];
  37645. var firstTransformArg3 = argsArray[iFirstTransform][3];
  37646. var i = iFirstSave + 4;
  37647. var ii = fnArray.length;
  37648. while (i + 3 < ii) {
  37649. if (fnArray[i] !== OPS.save ||
  37650. fnArray[i + 1] !== OPS.transform ||
  37651. fnArray[i + 2] !== OPS.paintImageXObject ||
  37652. fnArray[i + 3] !== OPS.restore) {
  37653. break; // ops don't match
  37654. }
  37655. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  37656. argsArray[i + 1][1] !== 0 ||
  37657. argsArray[i + 1][2] !== 0 ||
  37658. argsArray[i + 1][3] !== firstTransformArg3) {
  37659. break; // transforms don't match
  37660. }
  37661. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  37662. break; // images don't match
  37663. }
  37664. i += 4;
  37665. }
  37666. // At this point, i is the index of the first op past the last valid
  37667. // quartet.
  37668. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  37669. if (count < MIN_IMAGES_IN_BLOCK) {
  37670. return i;
  37671. }
  37672. // Extract the (x,y) positions from all of the matching transforms.
  37673. var positions = new Float32Array(count * 2);
  37674. var iTransform = iFirstTransform;
  37675. for (var q = 0; q < count; q++, iTransform += 4) {
  37676. var transformArgs = argsArray[iTransform];
  37677. positions[(q << 1)] = transformArgs[4];
  37678. positions[(q << 1) + 1] = transformArgs[5];
  37679. }
  37680. // Replace queue items.
  37681. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  37682. positions];
  37683. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  37684. argsArray.splice(iFirstSave, count * 4, args);
  37685. return iFirstSave + 1;
  37686. });
  37687. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  37688. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  37689. // sequences, if the font for each one is the same.
  37690. addState(InitialState,
  37691. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  37692. function (context) {
  37693. var MIN_CHARS_IN_BLOCK = 3;
  37694. var MAX_CHARS_IN_BLOCK = 1000;
  37695. var fnArray = context.fnArray, argsArray = context.argsArray;
  37696. var curr = context.iCurr;
  37697. var iFirstBeginText = curr - 4;
  37698. var iFirstSetFont = curr - 3;
  37699. var iFirstSetTextMatrix = curr - 2;
  37700. var iFirstShowText = curr - 1;
  37701. var iFirstEndText = curr;
  37702. // Look for the quintets.
  37703. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  37704. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  37705. var i = iFirstBeginText + 5;
  37706. var ii = fnArray.length;
  37707. while (i + 4 < ii) {
  37708. if (fnArray[i] !== OPS.beginText ||
  37709. fnArray[i + 1] !== OPS.setFont ||
  37710. fnArray[i + 2] !== OPS.setTextMatrix ||
  37711. fnArray[i + 3] !== OPS.showText ||
  37712. fnArray[i + 4] !== OPS.endText) {
  37713. break; // ops don't match
  37714. }
  37715. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  37716. argsArray[i + 1][1] !== firstSetFontArg1) {
  37717. break; // fonts don't match
  37718. }
  37719. i += 5;
  37720. }
  37721. // At this point, i is the index of the first op past the last valid
  37722. // quintet.
  37723. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  37724. if (count < MIN_CHARS_IN_BLOCK) {
  37725. return i;
  37726. }
  37727. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  37728. // showText, endText), include that as well. (E.g. <something> might be
  37729. // |dependency|.)
  37730. var iFirst = iFirstBeginText;
  37731. if (iFirstBeginText >= 4 &&
  37732. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  37733. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  37734. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  37735. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  37736. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  37737. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  37738. count++;
  37739. iFirst -= 5;
  37740. }
  37741. // Remove (endText, beginText, setFont) trios.
  37742. var iEndText = iFirst + 4;
  37743. for (var q = 1; q < count; q++) {
  37744. fnArray.splice(iEndText, 3);
  37745. argsArray.splice(iEndText, 3);
  37746. iEndText += 2;
  37747. }
  37748. return iEndText + 1;
  37749. });
  37750. function QueueOptimizer() {}
  37751. QueueOptimizer.prototype = {
  37752. optimize: function QueueOptimizer_optimize(queue) {
  37753. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  37754. var context = {
  37755. iCurr: 0,
  37756. fnArray: fnArray,
  37757. argsArray: argsArray
  37758. };
  37759. var state;
  37760. var i = 0, ii = fnArray.length;
  37761. while (i < ii) {
  37762. state = (state || InitialState)[fnArray[i]];
  37763. if (typeof state === 'function') { // we found some handler
  37764. context.iCurr = i;
  37765. // state() returns the index of the first non-matching op (if we
  37766. // didn't match) or the first op past the modified ops (if we did
  37767. // match and replace).
  37768. i = state(context);
  37769. state = undefined; // reset the state machine
  37770. ii = context.fnArray.length;
  37771. } else {
  37772. i++;
  37773. }
  37774. }
  37775. }
  37776. };
  37777. return QueueOptimizer;
  37778. })();
  37779. exports.OperatorList = OperatorList;
  37780. exports.PartialEvaluator = PartialEvaluator;
  37781. }));
  37782. (function (root, factory) {
  37783. {
  37784. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  37785. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  37786. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  37787. }
  37788. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  37789. coreColorSpace, coreObj, coreEvaluator) {
  37790. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  37791. var AnnotationFieldFlag = sharedUtil.AnnotationFieldFlag;
  37792. var AnnotationFlag = sharedUtil.AnnotationFlag;
  37793. var AnnotationType = sharedUtil.AnnotationType;
  37794. var OPS = sharedUtil.OPS;
  37795. var Util = sharedUtil.Util;
  37796. var isBool = sharedUtil.isBool;
  37797. var isString = sharedUtil.isString;
  37798. var isArray = sharedUtil.isArray;
  37799. var isInt = sharedUtil.isInt;
  37800. var isValidUrl = sharedUtil.isValidUrl;
  37801. var stringToBytes = sharedUtil.stringToBytes;
  37802. var stringToPDFString = sharedUtil.stringToPDFString;
  37803. var stringToUTF8String = sharedUtil.stringToUTF8String;
  37804. var warn = sharedUtil.warn;
  37805. var Dict = corePrimitives.Dict;
  37806. var isDict = corePrimitives.isDict;
  37807. var isName = corePrimitives.isName;
  37808. var isRef = corePrimitives.isRef;
  37809. var Stream = coreStream.Stream;
  37810. var ColorSpace = coreColorSpace.ColorSpace;
  37811. var ObjectLoader = coreObj.ObjectLoader;
  37812. var FileSpec = coreObj.FileSpec;
  37813. var OperatorList = coreEvaluator.OperatorList;
  37814. /**
  37815. * @class
  37816. * @alias AnnotationFactory
  37817. */
  37818. function AnnotationFactory() {}
  37819. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  37820. /**
  37821. * @param {XRef} xref
  37822. * @param {Object} ref
  37823. * @param {string} uniquePrefix
  37824. * @param {Object} idCounters
  37825. * @returns {Annotation}
  37826. */
  37827. create: function AnnotationFactory_create(xref, ref,
  37828. uniquePrefix, idCounters) {
  37829. var dict = xref.fetchIfRef(ref);
  37830. if (!isDict(dict)) {
  37831. return;
  37832. }
  37833. var id = isRef(ref) ? ref.toString() :
  37834. 'annot_' + (uniquePrefix || '') + (++idCounters.obj);
  37835. // Determine the annotation's subtype.
  37836. var subtype = dict.get('Subtype');
  37837. subtype = isName(subtype) ? subtype.name : null;
  37838. // Return the right annotation object based on the subtype and field type.
  37839. var parameters = {
  37840. xref: xref,
  37841. dict: dict,
  37842. ref: isRef(ref) ? ref : null,
  37843. subtype: subtype,
  37844. id: id,
  37845. };
  37846. switch (subtype) {
  37847. case 'Link':
  37848. return new LinkAnnotation(parameters);
  37849. case 'Text':
  37850. return new TextAnnotation(parameters);
  37851. case 'Widget':
  37852. var fieldType = Util.getInheritableProperty(dict, 'FT');
  37853. fieldType = isName(fieldType) ? fieldType.name : null;
  37854. switch (fieldType) {
  37855. case 'Tx':
  37856. return new TextWidgetAnnotation(parameters);
  37857. }
  37858. warn('Unimplemented widget field type "' + fieldType + '", ' +
  37859. 'falling back to base field type.');
  37860. return new WidgetAnnotation(parameters);
  37861. case 'Popup':
  37862. return new PopupAnnotation(parameters);
  37863. case 'Highlight':
  37864. return new HighlightAnnotation(parameters);
  37865. case 'Underline':
  37866. return new UnderlineAnnotation(parameters);
  37867. case 'Squiggly':
  37868. return new SquigglyAnnotation(parameters);
  37869. case 'StrikeOut':
  37870. return new StrikeOutAnnotation(parameters);
  37871. case 'FileAttachment':
  37872. return new FileAttachmentAnnotation(parameters);
  37873. default:
  37874. if (!subtype) {
  37875. warn('Annotation is missing the required /Subtype.');
  37876. } else {
  37877. warn('Unimplemented annotation type "' + subtype + '", ' +
  37878. 'falling back to base annotation.');
  37879. }
  37880. return new Annotation(parameters);
  37881. }
  37882. }
  37883. };
  37884. var Annotation = (function AnnotationClosure() {
  37885. // 12.5.5: Algorithm: Appearance streams
  37886. function getTransformMatrix(rect, bbox, matrix) {
  37887. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  37888. var minX = bounds[0];
  37889. var minY = bounds[1];
  37890. var maxX = bounds[2];
  37891. var maxY = bounds[3];
  37892. if (minX === maxX || minY === maxY) {
  37893. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  37894. // just apply the transform for rect
  37895. return [1, 0, 0, 1, rect[0], rect[1]];
  37896. }
  37897. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  37898. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  37899. return [
  37900. xRatio,
  37901. 0,
  37902. 0,
  37903. yRatio,
  37904. rect[0] - minX * xRatio,
  37905. rect[1] - minY * yRatio
  37906. ];
  37907. }
  37908. function getDefaultAppearance(dict) {
  37909. var appearanceState = dict.get('AP');
  37910. if (!isDict(appearanceState)) {
  37911. return;
  37912. }
  37913. var appearance;
  37914. var appearances = appearanceState.get('N');
  37915. if (isDict(appearances)) {
  37916. var as = dict.get('AS');
  37917. if (as && appearances.has(as.name)) {
  37918. appearance = appearances.get(as.name);
  37919. }
  37920. } else {
  37921. appearance = appearances;
  37922. }
  37923. return appearance;
  37924. }
  37925. function Annotation(params) {
  37926. var dict = params.dict;
  37927. this.setFlags(dict.get('F'));
  37928. this.setRectangle(dict.getArray('Rect'));
  37929. this.setColor(dict.getArray('C'));
  37930. this.setBorderStyle(dict);
  37931. this.appearance = getDefaultAppearance(dict);
  37932. // Expose public properties using a data object.
  37933. this.data = {};
  37934. this.data.id = params.id;
  37935. this.data.subtype = params.subtype;
  37936. this.data.annotationFlags = this.flags;
  37937. this.data.rect = this.rectangle;
  37938. this.data.color = this.color;
  37939. this.data.borderStyle = this.borderStyle;
  37940. this.data.hasAppearance = !!this.appearance;
  37941. }
  37942. Annotation.prototype = {
  37943. /**
  37944. * @private
  37945. */
  37946. _hasFlag: function Annotation_hasFlag(flags, flag) {
  37947. return !!(flags & flag);
  37948. },
  37949. /**
  37950. * @private
  37951. */
  37952. _isViewable: function Annotation_isViewable(flags) {
  37953. return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
  37954. !this._hasFlag(flags, AnnotationFlag.HIDDEN) &&
  37955. !this._hasFlag(flags, AnnotationFlag.NOVIEW);
  37956. },
  37957. /**
  37958. * @private
  37959. */
  37960. _isPrintable: function AnnotationFlag_isPrintable(flags) {
  37961. return this._hasFlag(flags, AnnotationFlag.PRINT) &&
  37962. !this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
  37963. !this._hasFlag(flags, AnnotationFlag.HIDDEN);
  37964. },
  37965. /**
  37966. * @return {boolean}
  37967. */
  37968. get viewable() {
  37969. if (this.flags === 0) {
  37970. return true;
  37971. }
  37972. return this._isViewable(this.flags);
  37973. },
  37974. /**
  37975. * @return {boolean}
  37976. */
  37977. get printable() {
  37978. if (this.flags === 0) {
  37979. return false;
  37980. }
  37981. return this._isPrintable(this.flags);
  37982. },
  37983. /**
  37984. * Set the flags.
  37985. *
  37986. * @public
  37987. * @memberof Annotation
  37988. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  37989. * characteristics
  37990. * @see {@link shared/util.js}
  37991. */
  37992. setFlags: function Annotation_setFlags(flags) {
  37993. this.flags = (isInt(flags) && flags > 0) ? flags : 0;
  37994. },
  37995. /**
  37996. * Check if a provided flag is set.
  37997. *
  37998. * @public
  37999. * @memberof Annotation
  38000. * @param {number} flag - Hexadecimal representation for an annotation
  38001. * characteristic
  38002. * @return {boolean}
  38003. * @see {@link shared/util.js}
  38004. */
  38005. hasFlag: function Annotation_hasFlag(flag) {
  38006. return this._hasFlag(this.flags, flag);
  38007. },
  38008. /**
  38009. * Set the rectangle.
  38010. *
  38011. * @public
  38012. * @memberof Annotation
  38013. * @param {Array} rectangle - The rectangle array with exactly four entries
  38014. */
  38015. setRectangle: function Annotation_setRectangle(rectangle) {
  38016. if (isArray(rectangle) && rectangle.length === 4) {
  38017. this.rectangle = Util.normalizeRect(rectangle);
  38018. } else {
  38019. this.rectangle = [0, 0, 0, 0];
  38020. }
  38021. },
  38022. /**
  38023. * Set the color and take care of color space conversion.
  38024. *
  38025. * @public
  38026. * @memberof Annotation
  38027. * @param {Array} color - The color array containing either 0
  38028. * (transparent), 1 (grayscale), 3 (RGB) or
  38029. * 4 (CMYK) elements
  38030. */
  38031. setColor: function Annotation_setColor(color) {
  38032. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  38033. if (!isArray(color)) {
  38034. this.color = rgbColor;
  38035. return;
  38036. }
  38037. switch (color.length) {
  38038. case 0: // Transparent, which we indicate with a null value
  38039. this.color = null;
  38040. break;
  38041. case 1: // Convert grayscale to RGB
  38042. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  38043. this.color = rgbColor;
  38044. break;
  38045. case 3: // Convert RGB percentages to RGB
  38046. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  38047. this.color = rgbColor;
  38048. break;
  38049. case 4: // Convert CMYK to RGB
  38050. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  38051. this.color = rgbColor;
  38052. break;
  38053. default:
  38054. this.color = rgbColor;
  38055. break;
  38056. }
  38057. },
  38058. /**
  38059. * Set the border style (as AnnotationBorderStyle object).
  38060. *
  38061. * @public
  38062. * @memberof Annotation
  38063. * @param {Dict} borderStyle - The border style dictionary
  38064. */
  38065. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  38066. this.borderStyle = new AnnotationBorderStyle();
  38067. if (!isDict(borderStyle)) {
  38068. return;
  38069. }
  38070. if (borderStyle.has('BS')) {
  38071. var dict = borderStyle.get('BS');
  38072. var dictType = dict.get('Type');
  38073. if (!dictType || isName(dictType, 'Border')) {
  38074. this.borderStyle.setWidth(dict.get('W'));
  38075. this.borderStyle.setStyle(dict.get('S'));
  38076. this.borderStyle.setDashArray(dict.getArray('D'));
  38077. }
  38078. } else if (borderStyle.has('Border')) {
  38079. var array = borderStyle.getArray('Border');
  38080. if (isArray(array) && array.length >= 3) {
  38081. this.borderStyle.setHorizontalCornerRadius(array[0]);
  38082. this.borderStyle.setVerticalCornerRadius(array[1]);
  38083. this.borderStyle.setWidth(array[2]);
  38084. if (array.length === 4) { // Dash array available
  38085. this.borderStyle.setDashArray(array[3]);
  38086. }
  38087. }
  38088. } else {
  38089. // There are no border entries in the dictionary. According to the
  38090. // specification, we should draw a solid border of width 1 in that
  38091. // case, but Adobe Reader did not implement that part of the
  38092. // specification and instead draws no border at all, so we do the same.
  38093. // See also https://github.com/mozilla/pdf.js/issues/6179.
  38094. this.borderStyle.setWidth(0);
  38095. }
  38096. },
  38097. /**
  38098. * Prepare the annotation for working with a popup in the display layer.
  38099. *
  38100. * @private
  38101. * @memberof Annotation
  38102. * @param {Dict} dict - The annotation's data dictionary
  38103. */
  38104. _preparePopup: function Annotation_preparePopup(dict) {
  38105. if (!dict.has('C')) {
  38106. // Fall back to the default background color.
  38107. this.data.color = null;
  38108. }
  38109. this.data.hasPopup = dict.has('Popup');
  38110. this.data.title = stringToPDFString(dict.get('T') || '');
  38111. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  38112. },
  38113. loadResources: function Annotation_loadResources(keys) {
  38114. return new Promise(function (resolve, reject) {
  38115. this.appearance.dict.getAsync('Resources').then(function (resources) {
  38116. if (!resources) {
  38117. resolve();
  38118. return;
  38119. }
  38120. var objectLoader = new ObjectLoader(resources.map,
  38121. keys,
  38122. resources.xref);
  38123. objectLoader.load().then(function() {
  38124. resolve(resources);
  38125. }, reject);
  38126. }, reject);
  38127. }.bind(this));
  38128. },
  38129. getOperatorList: function Annotation_getOperatorList(evaluator, task,
  38130. renderForms) {
  38131. if (!this.appearance) {
  38132. return Promise.resolve(new OperatorList());
  38133. }
  38134. var data = this.data;
  38135. var appearanceDict = this.appearance.dict;
  38136. var resourcesPromise = this.loadResources([
  38137. 'ExtGState',
  38138. 'ColorSpace',
  38139. 'Pattern',
  38140. 'Shading',
  38141. 'XObject',
  38142. 'Font'
  38143. // ProcSet
  38144. // Properties
  38145. ]);
  38146. var bbox = appearanceDict.getArray('BBox') || [0, 0, 1, 1];
  38147. var matrix = appearanceDict.getArray('Matrix') || [1, 0, 0, 1, 0 ,0];
  38148. var transform = getTransformMatrix(data.rect, bbox, matrix);
  38149. var self = this;
  38150. return resourcesPromise.then(function(resources) {
  38151. var opList = new OperatorList();
  38152. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  38153. return evaluator.getOperatorList(self.appearance, task,
  38154. resources, opList).
  38155. then(function () {
  38156. opList.addOp(OPS.endAnnotation, []);
  38157. self.appearance.reset();
  38158. return opList;
  38159. });
  38160. });
  38161. }
  38162. };
  38163. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  38164. annotations, opList, partialEvaluator, task, intent, renderForms) {
  38165. var annotationPromises = [];
  38166. for (var i = 0, n = annotations.length; i < n; ++i) {
  38167. if ((intent === 'display' && annotations[i].viewable) ||
  38168. (intent === 'print' && annotations[i].printable)) {
  38169. annotationPromises.push(
  38170. annotations[i].getOperatorList(partialEvaluator, task, renderForms));
  38171. }
  38172. }
  38173. return Promise.all(annotationPromises).then(function(operatorLists) {
  38174. opList.addOp(OPS.beginAnnotations, []);
  38175. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  38176. opList.addOpList(operatorLists[i]);
  38177. }
  38178. opList.addOp(OPS.endAnnotations, []);
  38179. });
  38180. };
  38181. return Annotation;
  38182. })();
  38183. /**
  38184. * Contains all data regarding an annotation's border style.
  38185. *
  38186. * @class
  38187. */
  38188. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  38189. /**
  38190. * @constructor
  38191. * @private
  38192. */
  38193. function AnnotationBorderStyle() {
  38194. this.width = 1;
  38195. this.style = AnnotationBorderStyleType.SOLID;
  38196. this.dashArray = [3];
  38197. this.horizontalCornerRadius = 0;
  38198. this.verticalCornerRadius = 0;
  38199. }
  38200. AnnotationBorderStyle.prototype = {
  38201. /**
  38202. * Set the width.
  38203. *
  38204. * @public
  38205. * @memberof AnnotationBorderStyle
  38206. * @param {integer} width - The width
  38207. */
  38208. setWidth: function AnnotationBorderStyle_setWidth(width) {
  38209. if (width === (width | 0)) {
  38210. this.width = width;
  38211. }
  38212. },
  38213. /**
  38214. * Set the style.
  38215. *
  38216. * @public
  38217. * @memberof AnnotationBorderStyle
  38218. * @param {Object} style - The style object
  38219. * @see {@link shared/util.js}
  38220. */
  38221. setStyle: function AnnotationBorderStyle_setStyle(style) {
  38222. if (!style) {
  38223. return;
  38224. }
  38225. switch (style.name) {
  38226. case 'S':
  38227. this.style = AnnotationBorderStyleType.SOLID;
  38228. break;
  38229. case 'D':
  38230. this.style = AnnotationBorderStyleType.DASHED;
  38231. break;
  38232. case 'B':
  38233. this.style = AnnotationBorderStyleType.BEVELED;
  38234. break;
  38235. case 'I':
  38236. this.style = AnnotationBorderStyleType.INSET;
  38237. break;
  38238. case 'U':
  38239. this.style = AnnotationBorderStyleType.UNDERLINE;
  38240. break;
  38241. default:
  38242. break;
  38243. }
  38244. },
  38245. /**
  38246. * Set the dash array.
  38247. *
  38248. * @public
  38249. * @memberof AnnotationBorderStyle
  38250. * @param {Array} dashArray - The dash array with at least one element
  38251. */
  38252. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  38253. // We validate the dash array, but we do not use it because CSS does not
  38254. // allow us to change spacing of dashes. For more information, visit
  38255. // http://www.w3.org/TR/css3-background/#the-border-style.
  38256. if (isArray(dashArray) && dashArray.length > 0) {
  38257. // According to the PDF specification: the elements in a dashArray
  38258. // shall be numbers that are nonnegative and not all equal to zero.
  38259. var isValid = true;
  38260. var allZeros = true;
  38261. for (var i = 0, len = dashArray.length; i < len; i++) {
  38262. var element = dashArray[i];
  38263. var validNumber = (+element >= 0);
  38264. if (!validNumber) {
  38265. isValid = false;
  38266. break;
  38267. } else if (element > 0) {
  38268. allZeros = false;
  38269. }
  38270. }
  38271. if (isValid && !allZeros) {
  38272. this.dashArray = dashArray;
  38273. } else {
  38274. this.width = 0; // Adobe behavior when the array is invalid.
  38275. }
  38276. } else if (dashArray) {
  38277. this.width = 0; // Adobe behavior when the array is invalid.
  38278. }
  38279. },
  38280. /**
  38281. * Set the horizontal corner radius (from a Border dictionary).
  38282. *
  38283. * @public
  38284. * @memberof AnnotationBorderStyle
  38285. * @param {integer} radius - The horizontal corner radius
  38286. */
  38287. setHorizontalCornerRadius:
  38288. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  38289. if (radius === (radius | 0)) {
  38290. this.horizontalCornerRadius = radius;
  38291. }
  38292. },
  38293. /**
  38294. * Set the vertical corner radius (from a Border dictionary).
  38295. *
  38296. * @public
  38297. * @memberof AnnotationBorderStyle
  38298. * @param {integer} radius - The vertical corner radius
  38299. */
  38300. setVerticalCornerRadius:
  38301. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  38302. if (radius === (radius | 0)) {
  38303. this.verticalCornerRadius = radius;
  38304. }
  38305. }
  38306. };
  38307. return AnnotationBorderStyle;
  38308. })();
  38309. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  38310. function WidgetAnnotation(params) {
  38311. Annotation.call(this, params);
  38312. var dict = params.dict;
  38313. var data = this.data;
  38314. data.annotationType = AnnotationType.WIDGET;
  38315. data.fieldValue = stringToPDFString(
  38316. Util.getInheritableProperty(dict, 'V') || '');
  38317. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  38318. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  38319. var fieldType = Util.getInheritableProperty(dict, 'FT');
  38320. data.fieldType = isName(fieldType) ? fieldType.name : null;
  38321. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  38322. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff');
  38323. if (!isInt(data.fieldFlags) || data.fieldFlags < 0) {
  38324. data.fieldFlags = 0;
  38325. }
  38326. // Hide signatures because we cannot validate them.
  38327. if (data.fieldType === 'Sig') {
  38328. this.setFlags(AnnotationFlag.HIDDEN);
  38329. }
  38330. // Building the full field name by collecting the field and
  38331. // its ancestors 'T' data and joining them using '.'.
  38332. var fieldName = [];
  38333. var namedItem = dict;
  38334. var ref = params.ref;
  38335. while (namedItem) {
  38336. var parent = namedItem.get('Parent');
  38337. var parentRef = namedItem.getRaw('Parent');
  38338. var name = namedItem.get('T');
  38339. if (name) {
  38340. fieldName.unshift(stringToPDFString(name));
  38341. } else if (parent && ref) {
  38342. // The field name is absent, that means more than one field
  38343. // with the same name may exist. Replacing the empty name
  38344. // with the '`' plus index in the parent's 'Kids' array.
  38345. // This is not in the PDF spec but necessary to id the
  38346. // the input controls.
  38347. var kids = parent.get('Kids');
  38348. var j, jj;
  38349. for (j = 0, jj = kids.length; j < jj; j++) {
  38350. var kidRef = kids[j];
  38351. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  38352. break;
  38353. }
  38354. }
  38355. fieldName.unshift('`' + j);
  38356. }
  38357. namedItem = parent;
  38358. ref = parentRef;
  38359. }
  38360. data.fullName = fieldName.join('.');
  38361. }
  38362. Util.inherit(WidgetAnnotation, Annotation, {
  38363. /**
  38364. * Check if a provided field flag is set.
  38365. *
  38366. * @public
  38367. * @memberof WidgetAnnotation
  38368. * @param {number} flag - Hexadecimal representation for an annotation
  38369. * field characteristic
  38370. * @return {boolean}
  38371. * @see {@link shared/util.js}
  38372. */
  38373. hasFieldFlag: function WidgetAnnotation_hasFieldFlag(flag) {
  38374. return !!(this.data.fieldFlags & flag);
  38375. },
  38376. });
  38377. return WidgetAnnotation;
  38378. })();
  38379. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  38380. function TextWidgetAnnotation(params) {
  38381. WidgetAnnotation.call(this, params);
  38382. // Determine the alignment of text in the field.
  38383. var alignment = Util.getInheritableProperty(params.dict, 'Q');
  38384. if (!isInt(alignment) || alignment < 0 || alignment > 2) {
  38385. alignment = null;
  38386. }
  38387. this.data.textAlignment = alignment;
  38388. // Determine the maximum length of text in the field.
  38389. var maximumLength = Util.getInheritableProperty(params.dict, 'MaxLen');
  38390. if (!isInt(maximumLength) || maximumLength < 0) {
  38391. maximumLength = null;
  38392. }
  38393. this.data.maxLen = maximumLength;
  38394. // Process field flags for the display layer.
  38395. this.data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
  38396. this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
  38397. this.data.comb = this.hasFieldFlag(AnnotationFieldFlag.COMB) &&
  38398. !this.hasFieldFlag(AnnotationFieldFlag.MULTILINE) &&
  38399. !this.hasFieldFlag(AnnotationFieldFlag.PASSWORD) &&
  38400. !this.hasFieldFlag(AnnotationFieldFlag.FILESELECT) &&
  38401. this.data.maxLen !== null;
  38402. }
  38403. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  38404. getOperatorList:
  38405. function TextWidgetAnnotation_getOperatorList(evaluator, task,
  38406. renderForms) {
  38407. var operatorList = new OperatorList();
  38408. // Do not render form elements on the canvas when interactive forms are
  38409. // enabled. The display layer is responsible for rendering them instead.
  38410. if (renderForms) {
  38411. return Promise.resolve(operatorList);
  38412. }
  38413. if (this.appearance) {
  38414. return Annotation.prototype.getOperatorList.call(this, evaluator, task,
  38415. renderForms);
  38416. }
  38417. // Even if there is an appearance stream, ignore it. This is the
  38418. // behaviour used by Adobe Reader.
  38419. if (!this.data.defaultAppearance) {
  38420. return Promise.resolve(operatorList);
  38421. }
  38422. var stream = new Stream(stringToBytes(this.data.defaultAppearance));
  38423. return evaluator.getOperatorList(stream, task, this.fieldResources,
  38424. operatorList).
  38425. then(function () {
  38426. return operatorList;
  38427. });
  38428. }
  38429. });
  38430. return TextWidgetAnnotation;
  38431. })();
  38432. var TextAnnotation = (function TextAnnotationClosure() {
  38433. var DEFAULT_ICON_SIZE = 22; // px
  38434. function TextAnnotation(parameters) {
  38435. Annotation.call(this, parameters);
  38436. this.data.annotationType = AnnotationType.TEXT;
  38437. if (this.data.hasAppearance) {
  38438. this.data.name = 'NoIcon';
  38439. } else {
  38440. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  38441. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  38442. this.data.name = parameters.dict.has('Name') ?
  38443. parameters.dict.get('Name').name : 'Note';
  38444. }
  38445. this._preparePopup(parameters.dict);
  38446. }
  38447. Util.inherit(TextAnnotation, Annotation, {});
  38448. return TextAnnotation;
  38449. })();
  38450. var LinkAnnotation = (function LinkAnnotationClosure() {
  38451. function LinkAnnotation(params) {
  38452. Annotation.call(this, params);
  38453. var dict = params.dict;
  38454. var data = this.data;
  38455. data.annotationType = AnnotationType.LINK;
  38456. var action = dict.get('A'), url, dest;
  38457. if (action && isDict(action)) {
  38458. var linkType = action.get('S').name;
  38459. switch (linkType) {
  38460. case 'URI':
  38461. url = action.get('URI');
  38462. if (isName(url)) {
  38463. // Some bad PDFs do not put parentheses around relative URLs.
  38464. url = '/' + url.name;
  38465. } else if (url) {
  38466. url = addDefaultProtocolToUrl(url);
  38467. }
  38468. // TODO: pdf spec mentions urls can be relative to a Base
  38469. // entry in the dictionary.
  38470. break;
  38471. case 'GoTo':
  38472. dest = action.get('D');
  38473. break;
  38474. case 'GoToR':
  38475. var urlDict = action.get('F');
  38476. if (isDict(urlDict)) {
  38477. // We assume that we found a FileSpec dictionary
  38478. // and fetch the URL without checking any further.
  38479. url = urlDict.get('F') || null;
  38480. } else if (isString(urlDict)) {
  38481. url = urlDict;
  38482. }
  38483. // NOTE: the destination is relative to the *remote* document.
  38484. var remoteDest = action.get('D');
  38485. if (remoteDest) {
  38486. if (isName(remoteDest)) {
  38487. remoteDest = remoteDest.name;
  38488. }
  38489. if (isString(url)) {
  38490. var baseUrl = url.split('#')[0];
  38491. if (isString(remoteDest)) {
  38492. // In practice, a named destination may contain only a number.
  38493. // If that happens, use the '#nameddest=' form to avoid the link
  38494. // redirecting to a page, instead of the correct destination.
  38495. url = baseUrl + '#' +
  38496. (/^\d+$/.test(remoteDest) ? 'nameddest=' : '') + remoteDest;
  38497. } else if (isArray(remoteDest)) {
  38498. url = baseUrl + '#' + JSON.stringify(remoteDest);
  38499. }
  38500. }
  38501. }
  38502. // The 'NewWindow' property, equal to `LinkTarget.BLANK`.
  38503. var newWindow = action.get('NewWindow');
  38504. if (isBool(newWindow)) {
  38505. data.newWindow = newWindow;
  38506. }
  38507. break;
  38508. case 'Named':
  38509. data.action = action.get('N').name;
  38510. break;
  38511. default:
  38512. warn('unrecognized link type: ' + linkType);
  38513. }
  38514. } else if (dict.has('Dest')) { // Simple destination link.
  38515. dest = dict.get('Dest');
  38516. }
  38517. if (url) {
  38518. if (isValidUrl(url, /* allowRelative = */ false)) {
  38519. data.url = tryConvertUrlEncoding(url);
  38520. }
  38521. }
  38522. if (dest) {
  38523. data.dest = isName(dest) ? dest.name : dest;
  38524. }
  38525. }
  38526. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  38527. function addDefaultProtocolToUrl(url) {
  38528. if (isString(url) && url.indexOf('www.') === 0) {
  38529. return ('http://' + url);
  38530. }
  38531. return url;
  38532. }
  38533. function tryConvertUrlEncoding(url) {
  38534. // According to ISO 32000-1:2008, section 12.6.4.7, URIs should be encoded
  38535. // in 7-bit ASCII. Some bad PDFs use UTF-8 encoding, see Bugzilla 1122280.
  38536. try {
  38537. return stringToUTF8String(url);
  38538. } catch (e) {
  38539. return url;
  38540. }
  38541. }
  38542. Util.inherit(LinkAnnotation, Annotation, {});
  38543. return LinkAnnotation;
  38544. })();
  38545. var PopupAnnotation = (function PopupAnnotationClosure() {
  38546. function PopupAnnotation(parameters) {
  38547. Annotation.call(this, parameters);
  38548. this.data.annotationType = AnnotationType.POPUP;
  38549. var dict = parameters.dict;
  38550. var parentItem = dict.get('Parent');
  38551. if (!parentItem) {
  38552. warn('Popup annotation has a missing or invalid parent annotation.');
  38553. return;
  38554. }
  38555. this.data.parentId = dict.getRaw('Parent').toString();
  38556. this.data.title = stringToPDFString(parentItem.get('T') || '');
  38557. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  38558. if (!parentItem.has('C')) {
  38559. // Fall back to the default background color.
  38560. this.data.color = null;
  38561. } else {
  38562. this.setColor(parentItem.getArray('C'));
  38563. this.data.color = this.color;
  38564. }
  38565. // If the Popup annotation is not viewable, but the parent annotation is,
  38566. // that is most likely a bug. Fallback to inherit the flags from the parent
  38567. // annotation (this is consistent with the behaviour in Adobe Reader).
  38568. if (!this.viewable) {
  38569. var parentFlags = parentItem.get('F');
  38570. if (this._isViewable(parentFlags)) {
  38571. this.setFlags(parentFlags);
  38572. }
  38573. }
  38574. }
  38575. Util.inherit(PopupAnnotation, Annotation, {});
  38576. return PopupAnnotation;
  38577. })();
  38578. var HighlightAnnotation = (function HighlightAnnotationClosure() {
  38579. function HighlightAnnotation(parameters) {
  38580. Annotation.call(this, parameters);
  38581. this.data.annotationType = AnnotationType.HIGHLIGHT;
  38582. this._preparePopup(parameters.dict);
  38583. // PDF viewers completely ignore any border styles.
  38584. this.data.borderStyle.setWidth(0);
  38585. }
  38586. Util.inherit(HighlightAnnotation, Annotation, {});
  38587. return HighlightAnnotation;
  38588. })();
  38589. var UnderlineAnnotation = (function UnderlineAnnotationClosure() {
  38590. function UnderlineAnnotation(parameters) {
  38591. Annotation.call(this, parameters);
  38592. this.data.annotationType = AnnotationType.UNDERLINE;
  38593. this._preparePopup(parameters.dict);
  38594. // PDF viewers completely ignore any border styles.
  38595. this.data.borderStyle.setWidth(0);
  38596. }
  38597. Util.inherit(UnderlineAnnotation, Annotation, {});
  38598. return UnderlineAnnotation;
  38599. })();
  38600. var SquigglyAnnotation = (function SquigglyAnnotationClosure() {
  38601. function SquigglyAnnotation(parameters) {
  38602. Annotation.call(this, parameters);
  38603. this.data.annotationType = AnnotationType.SQUIGGLY;
  38604. this._preparePopup(parameters.dict);
  38605. // PDF viewers completely ignore any border styles.
  38606. this.data.borderStyle.setWidth(0);
  38607. }
  38608. Util.inherit(SquigglyAnnotation, Annotation, {});
  38609. return SquigglyAnnotation;
  38610. })();
  38611. var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() {
  38612. function StrikeOutAnnotation(parameters) {
  38613. Annotation.call(this, parameters);
  38614. this.data.annotationType = AnnotationType.STRIKEOUT;
  38615. this._preparePopup(parameters.dict);
  38616. // PDF viewers completely ignore any border styles.
  38617. this.data.borderStyle.setWidth(0);
  38618. }
  38619. Util.inherit(StrikeOutAnnotation, Annotation, {});
  38620. return StrikeOutAnnotation;
  38621. })();
  38622. var FileAttachmentAnnotation = (function FileAttachmentAnnotationClosure() {
  38623. function FileAttachmentAnnotation(parameters) {
  38624. Annotation.call(this, parameters);
  38625. var file = new FileSpec(parameters.dict.get('FS'), parameters.xref);
  38626. this.data.annotationType = AnnotationType.FILEATTACHMENT;
  38627. this.data.file = file.serializable;
  38628. this._preparePopup(parameters.dict);
  38629. }
  38630. Util.inherit(FileAttachmentAnnotation, Annotation, {});
  38631. return FileAttachmentAnnotation;
  38632. })();
  38633. exports.Annotation = Annotation;
  38634. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  38635. exports.AnnotationFactory = AnnotationFactory;
  38636. }));
  38637. (function (root, factory) {
  38638. {
  38639. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  38640. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  38641. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  38642. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  38643. }
  38644. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  38645. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  38646. var MissingDataException = sharedUtil.MissingDataException;
  38647. var Util = sharedUtil.Util;
  38648. var assert = sharedUtil.assert;
  38649. var error = sharedUtil.error;
  38650. var info = sharedUtil.info;
  38651. var isArray = sharedUtil.isArray;
  38652. var isArrayBuffer = sharedUtil.isArrayBuffer;
  38653. var isString = sharedUtil.isString;
  38654. var shadow = sharedUtil.shadow;
  38655. var stringToBytes = sharedUtil.stringToBytes;
  38656. var stringToPDFString = sharedUtil.stringToPDFString;
  38657. var warn = sharedUtil.warn;
  38658. var isSpace = sharedUtil.isSpace;
  38659. var Dict = corePrimitives.Dict;
  38660. var isDict = corePrimitives.isDict;
  38661. var isName = corePrimitives.isName;
  38662. var isStream = corePrimitives.isStream;
  38663. var NullStream = coreStream.NullStream;
  38664. var Stream = coreStream.Stream;
  38665. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  38666. var Catalog = coreObj.Catalog;
  38667. var ObjectLoader = coreObj.ObjectLoader;
  38668. var XRef = coreObj.XRef;
  38669. var Linearization = coreParser.Linearization;
  38670. var calculateMD5 = coreCrypto.calculateMD5;
  38671. var OperatorList = coreEvaluator.OperatorList;
  38672. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  38673. var Annotation = coreAnnotation.Annotation;
  38674. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  38675. var Page = (function PageClosure() {
  38676. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  38677. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  38678. this.pdfManager = pdfManager;
  38679. this.pageIndex = pageIndex;
  38680. this.pageDict = pageDict;
  38681. this.xref = xref;
  38682. this.ref = ref;
  38683. this.fontCache = fontCache;
  38684. this.uniquePrefix = 'p' + this.pageIndex + '_';
  38685. this.idCounters = {
  38686. obj: 0
  38687. };
  38688. this.evaluatorOptions = pdfManager.evaluatorOptions;
  38689. this.resourcesPromise = null;
  38690. }
  38691. Page.prototype = {
  38692. getPageProp: function Page_getPageProp(key) {
  38693. return this.pageDict.get(key);
  38694. },
  38695. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  38696. var dict = this.pageDict, valueArray = null, loopCount = 0;
  38697. var MAX_LOOP_COUNT = 100;
  38698. // Always walk up the entire parent chain, to be able to find
  38699. // e.g. \Resources placed on multiple levels of the tree.
  38700. while (dict) {
  38701. var value = dict.get(key);
  38702. if (value) {
  38703. if (!valueArray) {
  38704. valueArray = [];
  38705. }
  38706. valueArray.push(value);
  38707. }
  38708. if (++loopCount > MAX_LOOP_COUNT) {
  38709. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  38710. break;
  38711. }
  38712. dict = dict.get('Parent');
  38713. }
  38714. if (!valueArray) {
  38715. return Dict.empty;
  38716. }
  38717. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  38718. loopCount > MAX_LOOP_COUNT) {
  38719. return valueArray[0];
  38720. }
  38721. return Dict.merge(this.xref, valueArray);
  38722. },
  38723. get content() {
  38724. return this.getPageProp('Contents');
  38725. },
  38726. get resources() {
  38727. // For robustness: The spec states that a \Resources entry has to be
  38728. // present, but can be empty. Some document omit it still, in this case
  38729. // we return an empty dictionary.
  38730. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  38731. },
  38732. get mediaBox() {
  38733. var obj = this.getInheritedPageProp('MediaBox');
  38734. // Reset invalid media box to letter size.
  38735. if (!isArray(obj) || obj.length !== 4) {
  38736. obj = LETTER_SIZE_MEDIABOX;
  38737. }
  38738. return shadow(this, 'mediaBox', obj);
  38739. },
  38740. get view() {
  38741. var mediaBox = this.mediaBox;
  38742. var cropBox = this.getInheritedPageProp('CropBox');
  38743. if (!isArray(cropBox) || cropBox.length !== 4) {
  38744. return shadow(this, 'view', mediaBox);
  38745. }
  38746. // From the spec, 6th ed., p.963:
  38747. // "The crop, bleed, trim, and art boxes should not ordinarily
  38748. // extend beyond the boundaries of the media box. If they do, they are
  38749. // effectively reduced to their intersection with the media box."
  38750. cropBox = Util.intersect(cropBox, mediaBox);
  38751. if (!cropBox) {
  38752. return shadow(this, 'view', mediaBox);
  38753. }
  38754. return shadow(this, 'view', cropBox);
  38755. },
  38756. get rotate() {
  38757. var rotate = this.getInheritedPageProp('Rotate') || 0;
  38758. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  38759. if (rotate % 90 !== 0) {
  38760. rotate = 0;
  38761. } else if (rotate >= 360) {
  38762. rotate = rotate % 360;
  38763. } else if (rotate < 0) {
  38764. // The spec doesn't cover negatives, assume its counterclockwise
  38765. // rotation. The following is the other implementation of modulo.
  38766. rotate = ((rotate % 360) + 360) % 360;
  38767. }
  38768. return shadow(this, 'rotate', rotate);
  38769. },
  38770. getContentStream: function Page_getContentStream() {
  38771. var content = this.content;
  38772. var stream;
  38773. if (isArray(content)) {
  38774. // fetching items
  38775. var xref = this.xref;
  38776. var i, n = content.length;
  38777. var streams = [];
  38778. for (i = 0; i < n; ++i) {
  38779. streams.push(xref.fetchIfRef(content[i]));
  38780. }
  38781. stream = new StreamsSequenceStream(streams);
  38782. } else if (isStream(content)) {
  38783. stream = content;
  38784. } else {
  38785. // replacing non-existent page content with empty one
  38786. stream = new NullStream();
  38787. }
  38788. return stream;
  38789. },
  38790. loadResources: function Page_loadResources(keys) {
  38791. if (!this.resourcesPromise) {
  38792. // TODO: add async getInheritedPageProp and remove this.
  38793. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  38794. }
  38795. return this.resourcesPromise.then(function resourceSuccess() {
  38796. var objectLoader = new ObjectLoader(this.resources.map,
  38797. keys,
  38798. this.xref);
  38799. return objectLoader.load();
  38800. }.bind(this));
  38801. },
  38802. getOperatorList: function Page_getOperatorList(handler, task, intent,
  38803. renderInteractiveForms) {
  38804. var self = this;
  38805. var pdfManager = this.pdfManager;
  38806. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  38807. []);
  38808. var resourcesPromise = this.loadResources([
  38809. 'ExtGState',
  38810. 'ColorSpace',
  38811. 'Pattern',
  38812. 'Shading',
  38813. 'XObject',
  38814. 'Font'
  38815. // ProcSet
  38816. // Properties
  38817. ]);
  38818. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  38819. handler, this.pageIndex,
  38820. this.uniquePrefix,
  38821. this.idCounters,
  38822. this.fontCache,
  38823. this.evaluatorOptions);
  38824. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  38825. var pageListPromise = dataPromises.then(function(data) {
  38826. var contentStream = data[0];
  38827. var opList = new OperatorList(intent, handler, self.pageIndex);
  38828. handler.send('StartRenderPage', {
  38829. transparency: partialEvaluator.hasBlendModes(self.resources),
  38830. pageIndex: self.pageIndex,
  38831. intent: intent
  38832. });
  38833. return partialEvaluator.getOperatorList(contentStream, task,
  38834. self.resources, opList).then(function () {
  38835. return opList;
  38836. });
  38837. });
  38838. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  38839. return Promise.all([pageListPromise, annotationsPromise]).then(
  38840. function(datas) {
  38841. var pageOpList = datas[0];
  38842. var annotations = datas[1];
  38843. if (annotations.length === 0) {
  38844. pageOpList.flush(true);
  38845. return pageOpList;
  38846. }
  38847. var annotationsReadyPromise = Annotation.appendToOperatorList(
  38848. annotations, pageOpList, partialEvaluator, task, intent,
  38849. renderInteractiveForms);
  38850. return annotationsReadyPromise.then(function () {
  38851. pageOpList.flush(true);
  38852. return pageOpList;
  38853. });
  38854. });
  38855. },
  38856. extractTextContent: function Page_extractTextContent(task,
  38857. normalizeWhitespace,
  38858. combineTextItems) {
  38859. var handler = {
  38860. on: function nullHandlerOn() {},
  38861. send: function nullHandlerSend() {}
  38862. };
  38863. var self = this;
  38864. var pdfManager = this.pdfManager;
  38865. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  38866. []);
  38867. var resourcesPromise = this.loadResources([
  38868. 'ExtGState',
  38869. 'XObject',
  38870. 'Font'
  38871. ]);
  38872. var dataPromises = Promise.all([contentStreamPromise,
  38873. resourcesPromise]);
  38874. return dataPromises.then(function(data) {
  38875. var contentStream = data[0];
  38876. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  38877. handler, self.pageIndex,
  38878. self.uniquePrefix,
  38879. self.idCounters,
  38880. self.fontCache,
  38881. self.evaluatorOptions);
  38882. return partialEvaluator.getTextContent(contentStream,
  38883. task,
  38884. self.resources,
  38885. /* stateManager = */ null,
  38886. normalizeWhitespace,
  38887. combineTextItems);
  38888. });
  38889. },
  38890. getAnnotationsData: function Page_getAnnotationsData(intent) {
  38891. var annotations = this.annotations;
  38892. var annotationsData = [];
  38893. for (var i = 0, n = annotations.length; i < n; ++i) {
  38894. if (intent) {
  38895. if (!(intent === 'display' && annotations[i].viewable) &&
  38896. !(intent === 'print' && annotations[i].printable)) {
  38897. continue;
  38898. }
  38899. }
  38900. annotationsData.push(annotations[i].data);
  38901. }
  38902. return annotationsData;
  38903. },
  38904. get annotations() {
  38905. var annotations = [];
  38906. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  38907. var annotationFactory = new AnnotationFactory();
  38908. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  38909. var annotationRef = annotationRefs[i];
  38910. var annotation = annotationFactory.create(this.xref, annotationRef,
  38911. this.uniquePrefix,
  38912. this.idCounters);
  38913. if (annotation) {
  38914. annotations.push(annotation);
  38915. }
  38916. }
  38917. return shadow(this, 'annotations', annotations);
  38918. }
  38919. };
  38920. return Page;
  38921. })();
  38922. /**
  38923. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  38924. * `PDFDoc`, this one doesn't have any job management code.
  38925. * Right now there exists one PDFDocument on the main thread + one object
  38926. * for each worker. If there is no worker support enabled, there are two
  38927. * `PDFDocument` objects on the main thread created.
  38928. */
  38929. var PDFDocument = (function PDFDocumentClosure() {
  38930. var FINGERPRINT_FIRST_BYTES = 1024;
  38931. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  38932. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  38933. function PDFDocument(pdfManager, arg, password) {
  38934. if (isStream(arg)) {
  38935. init.call(this, pdfManager, arg, password);
  38936. } else if (isArrayBuffer(arg)) {
  38937. init.call(this, pdfManager, new Stream(arg), password);
  38938. } else {
  38939. error('PDFDocument: Unknown argument type');
  38940. }
  38941. }
  38942. function init(pdfManager, stream, password) {
  38943. assert(stream.length > 0, 'stream must have data');
  38944. this.pdfManager = pdfManager;
  38945. this.stream = stream;
  38946. var xref = new XRef(this.stream, password, pdfManager);
  38947. this.xref = xref;
  38948. }
  38949. function find(stream, needle, limit, backwards) {
  38950. var pos = stream.pos;
  38951. var end = stream.end;
  38952. var strBuf = [];
  38953. if (pos + limit > end) {
  38954. limit = end - pos;
  38955. }
  38956. for (var n = 0; n < limit; ++n) {
  38957. strBuf.push(String.fromCharCode(stream.getByte()));
  38958. }
  38959. var str = strBuf.join('');
  38960. stream.pos = pos;
  38961. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  38962. if (index === -1) {
  38963. return false; /* not found */
  38964. }
  38965. stream.pos += index;
  38966. return true; /* found */
  38967. }
  38968. var DocumentInfoValidators = {
  38969. get entries() {
  38970. // Lazily build this since all the validation functions below are not
  38971. // defined until after this file loads.
  38972. return shadow(this, 'entries', {
  38973. Title: isString,
  38974. Author: isString,
  38975. Subject: isString,
  38976. Keywords: isString,
  38977. Creator: isString,
  38978. Producer: isString,
  38979. CreationDate: isString,
  38980. ModDate: isString,
  38981. Trapped: isName
  38982. });
  38983. }
  38984. };
  38985. PDFDocument.prototype = {
  38986. parse: function PDFDocument_parse(recoveryMode) {
  38987. this.setup(recoveryMode);
  38988. var version = this.catalog.catDict.get('Version');
  38989. if (isName(version)) {
  38990. this.pdfFormatVersion = version.name;
  38991. }
  38992. try {
  38993. // checking if AcroForm is present
  38994. this.acroForm = this.catalog.catDict.get('AcroForm');
  38995. if (this.acroForm) {
  38996. this.xfa = this.acroForm.get('XFA');
  38997. var fields = this.acroForm.get('Fields');
  38998. if ((!fields || !isArray(fields) || fields.length === 0) &&
  38999. !this.xfa) {
  39000. // no fields and no XFA -- not a form (?)
  39001. this.acroForm = null;
  39002. }
  39003. }
  39004. } catch (ex) {
  39005. info('Something wrong with AcroForm entry');
  39006. this.acroForm = null;
  39007. }
  39008. },
  39009. get linearization() {
  39010. var linearization = null;
  39011. if (this.stream.length) {
  39012. try {
  39013. linearization = Linearization.create(this.stream);
  39014. } catch (err) {
  39015. if (err instanceof MissingDataException) {
  39016. throw err;
  39017. }
  39018. info(err);
  39019. }
  39020. }
  39021. // shadow the prototype getter with a data property
  39022. return shadow(this, 'linearization', linearization);
  39023. },
  39024. get startXRef() {
  39025. var stream = this.stream;
  39026. var startXRef = 0;
  39027. var linearization = this.linearization;
  39028. if (linearization) {
  39029. // Find end of first obj.
  39030. stream.reset();
  39031. if (find(stream, 'endobj', 1024)) {
  39032. startXRef = stream.pos + 6;
  39033. }
  39034. } else {
  39035. // Find startxref by jumping backward from the end of the file.
  39036. var step = 1024;
  39037. var found = false, pos = stream.end;
  39038. while (!found && pos > 0) {
  39039. pos -= step - 'startxref'.length;
  39040. if (pos < 0) {
  39041. pos = 0;
  39042. }
  39043. stream.pos = pos;
  39044. found = find(stream, 'startxref', step, true);
  39045. }
  39046. if (found) {
  39047. stream.skip(9);
  39048. var ch;
  39049. do {
  39050. ch = stream.getByte();
  39051. } while (isSpace(ch));
  39052. var str = '';
  39053. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  39054. str += String.fromCharCode(ch);
  39055. ch = stream.getByte();
  39056. }
  39057. startXRef = parseInt(str, 10);
  39058. if (isNaN(startXRef)) {
  39059. startXRef = 0;
  39060. }
  39061. }
  39062. }
  39063. // shadow the prototype getter with a data property
  39064. return shadow(this, 'startXRef', startXRef);
  39065. },
  39066. get mainXRefEntriesOffset() {
  39067. var mainXRefEntriesOffset = 0;
  39068. var linearization = this.linearization;
  39069. if (linearization) {
  39070. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  39071. }
  39072. // shadow the prototype getter with a data property
  39073. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  39074. },
  39075. // Find the header, remove leading garbage and setup the stream
  39076. // starting from the header.
  39077. checkHeader: function PDFDocument_checkHeader() {
  39078. var stream = this.stream;
  39079. stream.reset();
  39080. if (find(stream, '%PDF-', 1024)) {
  39081. // Found the header, trim off any garbage before it.
  39082. stream.moveStart();
  39083. // Reading file format version
  39084. var MAX_VERSION_LENGTH = 12;
  39085. var version = '', ch;
  39086. while ((ch = stream.getByte()) > 0x20) { // SPACE
  39087. if (version.length >= MAX_VERSION_LENGTH) {
  39088. break;
  39089. }
  39090. version += String.fromCharCode(ch);
  39091. }
  39092. if (!this.pdfFormatVersion) {
  39093. // removing "%PDF-"-prefix
  39094. this.pdfFormatVersion = version.substring(5);
  39095. }
  39096. return;
  39097. }
  39098. // May not be a PDF file, continue anyway.
  39099. },
  39100. parseStartXRef: function PDFDocument_parseStartXRef() {
  39101. var startXRef = this.startXRef;
  39102. this.xref.setStartXRef(startXRef);
  39103. },
  39104. setup: function PDFDocument_setup(recoveryMode) {
  39105. this.xref.parse(recoveryMode);
  39106. var self = this;
  39107. var pageFactory = {
  39108. createPage: function (pageIndex, dict, ref, fontCache) {
  39109. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  39110. fontCache);
  39111. }
  39112. };
  39113. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  39114. },
  39115. get numPages() {
  39116. var linearization = this.linearization;
  39117. var num = linearization ? linearization.numPages : this.catalog.numPages;
  39118. // shadow the prototype getter
  39119. return shadow(this, 'numPages', num);
  39120. },
  39121. get documentInfo() {
  39122. var docInfo = {
  39123. PDFFormatVersion: this.pdfFormatVersion,
  39124. IsAcroFormPresent: !!this.acroForm,
  39125. IsXFAPresent: !!this.xfa
  39126. };
  39127. var infoDict;
  39128. try {
  39129. infoDict = this.xref.trailer.get('Info');
  39130. } catch (err) {
  39131. info('The document information dictionary is invalid.');
  39132. }
  39133. if (infoDict) {
  39134. var validEntries = DocumentInfoValidators.entries;
  39135. // Only fill the document info with valid entries from the spec.
  39136. for (var key in validEntries) {
  39137. if (infoDict.has(key)) {
  39138. var value = infoDict.get(key);
  39139. // Make sure the value conforms to the spec.
  39140. if (validEntries[key](value)) {
  39141. docInfo[key] = (typeof value !== 'string' ?
  39142. value : stringToPDFString(value));
  39143. } else {
  39144. info('Bad value in document info for "' + key + '"');
  39145. }
  39146. }
  39147. }
  39148. }
  39149. return shadow(this, 'documentInfo', docInfo);
  39150. },
  39151. get fingerprint() {
  39152. var xref = this.xref, hash, fileID = '';
  39153. var idArray = xref.trailer.get('ID');
  39154. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  39155. idArray[0] !== EMPTY_FINGERPRINT) {
  39156. hash = stringToBytes(idArray[0]);
  39157. } else {
  39158. if (this.stream.ensureRange) {
  39159. this.stream.ensureRange(0,
  39160. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  39161. }
  39162. hash = calculateMD5(this.stream.bytes.subarray(0,
  39163. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  39164. }
  39165. for (var i = 0, n = hash.length; i < n; i++) {
  39166. var hex = hash[i].toString(16);
  39167. fileID += hex.length === 1 ? '0' + hex : hex;
  39168. }
  39169. return shadow(this, 'fingerprint', fileID);
  39170. },
  39171. getPage: function PDFDocument_getPage(pageIndex) {
  39172. return this.catalog.getPage(pageIndex);
  39173. },
  39174. cleanup: function PDFDocument_cleanup() {
  39175. return this.catalog.cleanup();
  39176. }
  39177. };
  39178. return PDFDocument;
  39179. })();
  39180. exports.Page = Page;
  39181. exports.PDFDocument = PDFDocument;
  39182. }));
  39183. (function (root, factory) {
  39184. {
  39185. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  39186. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  39187. root.pdfjsCoreDocument);
  39188. }
  39189. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  39190. coreDocument) {
  39191. var NotImplementedException = sharedUtil.NotImplementedException;
  39192. var MissingDataException = sharedUtil.MissingDataException;
  39193. var createPromiseCapability = sharedUtil.createPromiseCapability;
  39194. var Util = sharedUtil.Util;
  39195. var Stream = coreStream.Stream;
  39196. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  39197. var PDFDocument = coreDocument.PDFDocument;
  39198. var BasePdfManager = (function BasePdfManagerClosure() {
  39199. function BasePdfManager() {
  39200. throw new Error('Cannot initialize BaseManagerManager');
  39201. }
  39202. BasePdfManager.prototype = {
  39203. get docId() {
  39204. return this._docId;
  39205. },
  39206. onLoadedStream: function BasePdfManager_onLoadedStream() {
  39207. throw new NotImplementedException();
  39208. },
  39209. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  39210. return this.ensure(this.pdfDocument, prop, args);
  39211. },
  39212. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  39213. return this.ensure(this.pdfDocument.xref, prop, args);
  39214. },
  39215. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  39216. return this.ensure(this.pdfDocument.catalog, prop, args);
  39217. },
  39218. getPage: function BasePdfManager_getPage(pageIndex) {
  39219. return this.pdfDocument.getPage(pageIndex);
  39220. },
  39221. cleanup: function BasePdfManager_cleanup() {
  39222. return this.pdfDocument.cleanup();
  39223. },
  39224. ensure: function BasePdfManager_ensure(obj, prop, args) {
  39225. return new NotImplementedException();
  39226. },
  39227. requestRange: function BasePdfManager_requestRange(begin, end) {
  39228. return new NotImplementedException();
  39229. },
  39230. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  39231. return new NotImplementedException();
  39232. },
  39233. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  39234. return new NotImplementedException();
  39235. },
  39236. updatePassword: function BasePdfManager_updatePassword(password) {
  39237. this.pdfDocument.xref.password = this.password = password;
  39238. if (this._passwordChangedCapability) {
  39239. this._passwordChangedCapability.resolve();
  39240. }
  39241. },
  39242. passwordChanged: function BasePdfManager_passwordChanged() {
  39243. this._passwordChangedCapability = createPromiseCapability();
  39244. return this._passwordChangedCapability.promise;
  39245. },
  39246. terminate: function BasePdfManager_terminate() {
  39247. return new NotImplementedException();
  39248. }
  39249. };
  39250. return BasePdfManager;
  39251. })();
  39252. var LocalPdfManager = (function LocalPdfManagerClosure() {
  39253. function LocalPdfManager(docId, data, password, evaluatorOptions) {
  39254. this._docId = docId;
  39255. this.evaluatorOptions = evaluatorOptions;
  39256. var stream = new Stream(data);
  39257. this.pdfDocument = new PDFDocument(this, stream, password);
  39258. this._loadedStreamCapability = createPromiseCapability();
  39259. this._loadedStreamCapability.resolve(stream);
  39260. }
  39261. Util.inherit(LocalPdfManager, BasePdfManager, {
  39262. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  39263. return new Promise(function (resolve, reject) {
  39264. try {
  39265. var value = obj[prop];
  39266. var result;
  39267. if (typeof value === 'function') {
  39268. result = value.apply(obj, args);
  39269. } else {
  39270. result = value;
  39271. }
  39272. resolve(result);
  39273. } catch (e) {
  39274. reject(e);
  39275. }
  39276. });
  39277. },
  39278. requestRange: function LocalPdfManager_requestRange(begin, end) {
  39279. return Promise.resolve();
  39280. },
  39281. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  39282. return;
  39283. },
  39284. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  39285. return this._loadedStreamCapability.promise;
  39286. },
  39287. terminate: function LocalPdfManager_terminate() {
  39288. return;
  39289. }
  39290. });
  39291. return LocalPdfManager;
  39292. })();
  39293. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  39294. function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions) {
  39295. this._docId = docId;
  39296. this.msgHandler = args.msgHandler;
  39297. this.evaluatorOptions = evaluatorOptions;
  39298. var params = {
  39299. msgHandler: args.msgHandler,
  39300. url: args.url,
  39301. length: args.length,
  39302. disableAutoFetch: args.disableAutoFetch,
  39303. rangeChunkSize: args.rangeChunkSize
  39304. };
  39305. this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
  39306. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  39307. args.password);
  39308. }
  39309. Util.inherit(NetworkPdfManager, BasePdfManager, {
  39310. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  39311. var pdfManager = this;
  39312. return new Promise(function (resolve, reject) {
  39313. function ensureHelper() {
  39314. try {
  39315. var result;
  39316. var value = obj[prop];
  39317. if (typeof value === 'function') {
  39318. result = value.apply(obj, args);
  39319. } else {
  39320. result = value;
  39321. }
  39322. resolve(result);
  39323. } catch(e) {
  39324. if (!(e instanceof MissingDataException)) {
  39325. reject(e);
  39326. return;
  39327. }
  39328. pdfManager.streamManager.requestRange(e.begin, e.end).
  39329. then(ensureHelper, reject);
  39330. }
  39331. }
  39332. ensureHelper();
  39333. });
  39334. },
  39335. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  39336. return this.streamManager.requestRange(begin, end);
  39337. },
  39338. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  39339. this.streamManager.requestAllChunks();
  39340. },
  39341. sendProgressiveData:
  39342. function NetworkPdfManager_sendProgressiveData(chunk) {
  39343. this.streamManager.onReceiveData({ chunk: chunk });
  39344. },
  39345. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  39346. return this.streamManager.onLoadedStream();
  39347. },
  39348. terminate: function NetworkPdfManager_terminate() {
  39349. this.streamManager.abort();
  39350. }
  39351. });
  39352. return NetworkPdfManager;
  39353. })();
  39354. exports.LocalPdfManager = LocalPdfManager;
  39355. exports.NetworkPdfManager = NetworkPdfManager;
  39356. }));
  39357. (function (root, factory) {
  39358. {
  39359. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  39360. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager);
  39361. }
  39362. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager) {
  39363. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  39364. var InvalidPDFException = sharedUtil.InvalidPDFException;
  39365. var MessageHandler = sharedUtil.MessageHandler;
  39366. var MissingPDFException = sharedUtil.MissingPDFException;
  39367. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  39368. var PasswordException = sharedUtil.PasswordException;
  39369. var PasswordResponses = sharedUtil.PasswordResponses;
  39370. var UnknownErrorException = sharedUtil.UnknownErrorException;
  39371. var XRefParseException = sharedUtil.XRefParseException;
  39372. var arrayByteLength = sharedUtil.arrayByteLength;
  39373. var arraysToBytes = sharedUtil.arraysToBytes;
  39374. var assert = sharedUtil.assert;
  39375. var createPromiseCapability = sharedUtil.createPromiseCapability;
  39376. var error = sharedUtil.error;
  39377. var info = sharedUtil.info;
  39378. var warn = sharedUtil.warn;
  39379. var setVerbosityLevel = sharedUtil.setVerbosityLevel;
  39380. var Ref = corePrimitives.Ref;
  39381. var LocalPdfManager = corePdfManager.LocalPdfManager;
  39382. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  39383. var globalScope = sharedUtil.globalScope;
  39384. var WorkerTask = (function WorkerTaskClosure() {
  39385. function WorkerTask(name) {
  39386. this.name = name;
  39387. this.terminated = false;
  39388. this._capability = createPromiseCapability();
  39389. }
  39390. WorkerTask.prototype = {
  39391. get finished() {
  39392. return this._capability.promise;
  39393. },
  39394. finish: function () {
  39395. this._capability.resolve();
  39396. },
  39397. terminate: function () {
  39398. this.terminated = true;
  39399. },
  39400. ensureNotTerminated: function () {
  39401. if (this.terminated) {
  39402. throw new Error('Worker task was terminated');
  39403. }
  39404. }
  39405. };
  39406. return WorkerTask;
  39407. })();
  39408. /** @implements {IPDFStream} */
  39409. var PDFWorkerStream = (function PDFWorkerStreamClosure() {
  39410. function PDFWorkerStream(params, msgHandler) {
  39411. this._queuedChunks = [];
  39412. var initialData = params.initialData;
  39413. if (initialData && initialData.length > 0) {
  39414. this._queuedChunks.push(initialData);
  39415. }
  39416. this._msgHandler = msgHandler;
  39417. this._isRangeSupported = !(params.disableRange);
  39418. this._isStreamingSupported = !(params.disableStream);
  39419. this._contentLength = params.length;
  39420. this._fullRequestReader = null;
  39421. this._rangeReaders = [];
  39422. msgHandler.on('OnDataRange', this._onReceiveData.bind(this));
  39423. msgHandler.on('OnDataProgress', this._onProgress.bind(this));
  39424. }
  39425. PDFWorkerStream.prototype = {
  39426. _onReceiveData: function PDFWorkerStream_onReceiveData(args) {
  39427. if (args.begin === undefined) {
  39428. if (this._fullRequestReader) {
  39429. this._fullRequestReader._enqueue(args.chunk);
  39430. } else {
  39431. this._queuedChunks.push(args.chunk);
  39432. }
  39433. } else {
  39434. var found = this._rangeReaders.some(function (rangeReader) {
  39435. if (rangeReader._begin !== args.begin) {
  39436. return false;
  39437. }
  39438. rangeReader._enqueue(args.chunk);
  39439. return true;
  39440. });
  39441. assert(found);
  39442. }
  39443. },
  39444. _onProgress: function PDFWorkerStream_onProgress(evt) {
  39445. if (this._rangeReaders.length > 0) {
  39446. // Reporting to first range reader.
  39447. var firstReader = this._rangeReaders[0];
  39448. if (firstReader.onProgress) {
  39449. firstReader.onProgress({loaded: evt.loaded});
  39450. }
  39451. }
  39452. },
  39453. _removeRangeReader: function PDFWorkerStream_removeRangeReader(reader) {
  39454. var i = this._rangeReaders.indexOf(reader);
  39455. if (i >= 0) {
  39456. this._rangeReaders.splice(i, 1);
  39457. }
  39458. },
  39459. getFullReader: function PDFWorkerStream_getFullReader() {
  39460. assert(!this._fullRequestReader);
  39461. var queuedChunks = this._queuedChunks;
  39462. this._queuedChunks = null;
  39463. return new PDFWorkerStreamReader(this, queuedChunks);
  39464. },
  39465. getRangeReader: function PDFWorkerStream_getRangeReader(begin, end) {
  39466. var reader = new PDFWorkerStreamRangeReader(this, begin, end);
  39467. this._msgHandler.send('RequestDataRange', { begin: begin, end: end });
  39468. this._rangeReaders.push(reader);
  39469. return reader;
  39470. },
  39471. cancelAllRequests: function PDFWorkerStream_cancelAllRequests(reason) {
  39472. if (this._fullRequestReader) {
  39473. this._fullRequestReader.cancel(reason);
  39474. }
  39475. var readers = this._rangeReaders.slice(0);
  39476. readers.forEach(function (rangeReader) {
  39477. rangeReader.cancel(reason);
  39478. });
  39479. }
  39480. };
  39481. /** @implements {IPDFStreamReader} */
  39482. function PDFWorkerStreamReader(stream, queuedChunks) {
  39483. this._stream = stream;
  39484. this._done = false;
  39485. this._queuedChunks = queuedChunks || [];
  39486. this._requests = [];
  39487. this._headersReady = Promise.resolve();
  39488. stream._fullRequestReader = this;
  39489. this.onProgress = null; // not used
  39490. }
  39491. PDFWorkerStreamReader.prototype = {
  39492. _enqueue: function PDFWorkerStreamReader_enqueue(chunk) {
  39493. if (this._done) {
  39494. return; // ignore new data
  39495. }
  39496. if (this._requests.length > 0) {
  39497. var requestCapability = this._requests.shift();
  39498. requestCapability.resolve({value: chunk, done: false});
  39499. return;
  39500. }
  39501. this._queuedChunks.push(chunk);
  39502. },
  39503. get headersReady() {
  39504. return this._headersReady;
  39505. },
  39506. get isRangeSupported() {
  39507. return this._stream._isRangeSupported;
  39508. },
  39509. get isStreamingSupported() {
  39510. return this._stream._isStreamingSupported;
  39511. },
  39512. get contentLength() {
  39513. return this._stream._contentLength;
  39514. },
  39515. read: function PDFWorkerStreamReader_read() {
  39516. if (this._queuedChunks.length > 0) {
  39517. var chunk = this._queuedChunks.shift();
  39518. return Promise.resolve({value: chunk, done: false});
  39519. }
  39520. if (this._done) {
  39521. return Promise.resolve({value: undefined, done: true});
  39522. }
  39523. var requestCapability = createPromiseCapability();
  39524. this._requests.push(requestCapability);
  39525. return requestCapability.promise;
  39526. },
  39527. cancel: function PDFWorkerStreamReader_cancel(reason) {
  39528. this._done = true;
  39529. this._requests.forEach(function (requestCapability) {
  39530. requestCapability.resolve({value: undefined, done: true});
  39531. });
  39532. this._requests = [];
  39533. }
  39534. };
  39535. /** @implements {IPDFStreamRangeReader} */
  39536. function PDFWorkerStreamRangeReader(stream, begin, end) {
  39537. this._stream = stream;
  39538. this._begin = begin;
  39539. this._end = end;
  39540. this._queuedChunk = null;
  39541. this._requests = [];
  39542. this._done = false;
  39543. this.onProgress = null;
  39544. }
  39545. PDFWorkerStreamRangeReader.prototype = {
  39546. _enqueue: function PDFWorkerStreamRangeReader_enqueue(chunk) {
  39547. if (this._done) {
  39548. return; // ignore new data
  39549. }
  39550. if (this._requests.length === 0) {
  39551. this._queuedChunk = chunk;
  39552. } else {
  39553. var requestsCapability = this._requests.shift();
  39554. requestsCapability.resolve({value: chunk, done: false});
  39555. this._requests.forEach(function (requestCapability) {
  39556. requestCapability.resolve({value: undefined, done: true});
  39557. });
  39558. this._requests = [];
  39559. }
  39560. this._done = true;
  39561. this._stream._removeRangeReader(this);
  39562. },
  39563. get isStreamingSupported() {
  39564. return false;
  39565. },
  39566. read: function PDFWorkerStreamRangeReader_read() {
  39567. if (this._queuedChunk) {
  39568. return Promise.resolve({value: this._queuedChunk, done: false});
  39569. }
  39570. if (this._done) {
  39571. return Promise.resolve({value: undefined, done: true});
  39572. }
  39573. var requestCapability = createPromiseCapability();
  39574. this._requests.push(requestCapability);
  39575. return requestCapability.promise;
  39576. },
  39577. cancel: function PDFWorkerStreamRangeReader_cancel(reason) {
  39578. this._done = true;
  39579. this._requests.forEach(function (requestCapability) {
  39580. requestCapability.resolve({value: undefined, done: true});
  39581. });
  39582. this._requests = [];
  39583. this._stream._removeRangeReader(this);
  39584. }
  39585. };
  39586. return PDFWorkerStream;
  39587. })();
  39588. /** @type IPDFStream */
  39589. var PDFNetworkStream;
  39590. /**
  39591. * Sets PDFNetworkStream class to be used as alternative PDF data transport.
  39592. * @param {IPDFStream} cls - the PDF data transport.
  39593. */
  39594. function setPDFNetworkStreamClass(cls) {
  39595. PDFNetworkStream = cls;
  39596. }
  39597. var WorkerMessageHandler = {
  39598. setup: function wphSetup(handler, port) {
  39599. var testMessageProcessed = false;
  39600. handler.on('test', function wphSetupTest(data) {
  39601. if (testMessageProcessed) {
  39602. return; // we already processed 'test' message once
  39603. }
  39604. testMessageProcessed = true;
  39605. // check if Uint8Array can be sent to worker
  39606. if (!(data instanceof Uint8Array)) {
  39607. handler.send('test', 'main', false);
  39608. return;
  39609. }
  39610. // making sure postMessage transfers are working
  39611. var supportTransfers = data[0] === 255;
  39612. handler.postMessageTransfers = supportTransfers;
  39613. // check if the response property is supported by xhr
  39614. var xhr = new XMLHttpRequest();
  39615. var responseExists = 'response' in xhr;
  39616. // check if the property is actually implemented
  39617. try {
  39618. var dummy = xhr.responseType;
  39619. } catch (e) {
  39620. responseExists = false;
  39621. }
  39622. if (!responseExists) {
  39623. handler.send('test', false);
  39624. return;
  39625. }
  39626. handler.send('test', {
  39627. supportTypedArray: true,
  39628. supportTransfers: supportTransfers
  39629. });
  39630. });
  39631. handler.on('configure', function wphConfigure(data) {
  39632. setVerbosityLevel(data.verbosity);
  39633. });
  39634. handler.on('GetDocRequest', function wphSetupDoc(data) {
  39635. return WorkerMessageHandler.createDocumentHandler(data, port);
  39636. });
  39637. },
  39638. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  39639. // This context is actually holds references on pdfManager and handler,
  39640. // until the latter is destroyed.
  39641. var pdfManager;
  39642. var terminated = false;
  39643. var cancelXHRs = null;
  39644. var WorkerTasks = [];
  39645. var docId = docParams.docId;
  39646. var workerHandlerName = docParams.docId + '_worker';
  39647. var handler = new MessageHandler(workerHandlerName, docId, port);
  39648. // Ensure that postMessage transfers are correctly enabled/disabled,
  39649. // to prevent "DataCloneError" in older versions of IE (see issue 6957).
  39650. handler.postMessageTransfers = docParams.postMessageTransfers;
  39651. function ensureNotTerminated() {
  39652. if (terminated) {
  39653. throw new Error('Worker was terminated');
  39654. }
  39655. }
  39656. function startWorkerTask(task) {
  39657. WorkerTasks.push(task);
  39658. }
  39659. function finishWorkerTask(task) {
  39660. task.finish();
  39661. var i = WorkerTasks.indexOf(task);
  39662. WorkerTasks.splice(i, 1);
  39663. }
  39664. function loadDocument(recoveryMode) {
  39665. var loadDocumentCapability = createPromiseCapability();
  39666. var parseSuccess = function parseSuccess() {
  39667. var numPagesPromise = pdfManager.ensureDoc('numPages');
  39668. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  39669. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  39670. Promise.all([numPagesPromise, fingerprintPromise,
  39671. encryptedPromise]).then(function onDocReady(results) {
  39672. var doc = {
  39673. numPages: results[0],
  39674. fingerprint: results[1],
  39675. encrypted: !!results[2],
  39676. };
  39677. loadDocumentCapability.resolve(doc);
  39678. },
  39679. parseFailure);
  39680. };
  39681. var parseFailure = function parseFailure(e) {
  39682. loadDocumentCapability.reject(e);
  39683. };
  39684. pdfManager.ensureDoc('checkHeader', []).then(function() {
  39685. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  39686. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  39687. parseSuccess, parseFailure);
  39688. }, parseFailure);
  39689. }, parseFailure);
  39690. return loadDocumentCapability.promise;
  39691. }
  39692. function getPdfManager(data, evaluatorOptions) {
  39693. var pdfManagerCapability = createPromiseCapability();
  39694. var pdfManager;
  39695. var source = data.source;
  39696. if (source.data) {
  39697. try {
  39698. pdfManager = new LocalPdfManager(docId, source.data, source.password,
  39699. evaluatorOptions);
  39700. pdfManagerCapability.resolve(pdfManager);
  39701. } catch (ex) {
  39702. pdfManagerCapability.reject(ex);
  39703. }
  39704. return pdfManagerCapability.promise;
  39705. }
  39706. var pdfStream;
  39707. try {
  39708. if (source.chunkedViewerLoading) {
  39709. pdfStream = new PDFWorkerStream(source, handler);
  39710. } else {
  39711. assert(PDFNetworkStream, 'pdfjs/core/network module is not loaded');
  39712. pdfStream = new PDFNetworkStream(data);
  39713. }
  39714. } catch (ex) {
  39715. pdfManagerCapability.reject(ex);
  39716. return pdfManagerCapability.promise;
  39717. }
  39718. var fullRequest = pdfStream.getFullReader();
  39719. fullRequest.headersReady.then(function () {
  39720. if (!fullRequest.isStreamingSupported ||
  39721. !fullRequest.isRangeSupported) {
  39722. // If stream or range are disabled, it's our only way to report
  39723. // loading progress.
  39724. fullRequest.onProgress = function (evt) {
  39725. handler.send('DocProgress', {
  39726. loaded: evt.loaded,
  39727. total: evt.total
  39728. });
  39729. };
  39730. }
  39731. if (!fullRequest.isRangeSupported) {
  39732. return;
  39733. }
  39734. // We don't need auto-fetch when streaming is enabled.
  39735. var disableAutoFetch = source.disableAutoFetch ||
  39736. fullRequest.isStreamingSupported;
  39737. pdfManager = new NetworkPdfManager(docId, pdfStream, {
  39738. msgHandler: handler,
  39739. url: source.url,
  39740. password: source.password,
  39741. length: fullRequest.contentLength,
  39742. disableAutoFetch: disableAutoFetch,
  39743. rangeChunkSize: source.rangeChunkSize
  39744. }, evaluatorOptions);
  39745. pdfManagerCapability.resolve(pdfManager);
  39746. cancelXHRs = null;
  39747. }).catch(function (reason) {
  39748. pdfManagerCapability.reject(reason);
  39749. cancelXHRs = null;
  39750. });
  39751. var cachedChunks = [], loaded = 0;
  39752. var flushChunks = function () {
  39753. var pdfFile = arraysToBytes(cachedChunks);
  39754. if (source.length && pdfFile.length !== source.length) {
  39755. warn('reported HTTP length is different from actual');
  39756. }
  39757. // the data is array, instantiating directly from it
  39758. try {
  39759. pdfManager = new LocalPdfManager(docId, pdfFile, source.password,
  39760. evaluatorOptions);
  39761. pdfManagerCapability.resolve(pdfManager);
  39762. } catch (ex) {
  39763. pdfManagerCapability.reject(ex);
  39764. }
  39765. cachedChunks = [];
  39766. };
  39767. var readPromise = new Promise(function (resolve, reject) {
  39768. var readChunk = function (chunk) {
  39769. try {
  39770. ensureNotTerminated();
  39771. if (chunk.done) {
  39772. if (!pdfManager) {
  39773. flushChunks();
  39774. }
  39775. cancelXHRs = null;
  39776. return;
  39777. }
  39778. var data = chunk.value;
  39779. loaded += arrayByteLength(data);
  39780. if (!fullRequest.isStreamingSupported) {
  39781. handler.send('DocProgress', {
  39782. loaded: loaded,
  39783. total: Math.max(loaded, fullRequest.contentLength || 0)
  39784. });
  39785. }
  39786. if (pdfManager) {
  39787. pdfManager.sendProgressiveData(data);
  39788. } else {
  39789. cachedChunks.push(data);
  39790. }
  39791. fullRequest.read().then(readChunk, reject);
  39792. } catch (e) {
  39793. reject(e);
  39794. }
  39795. };
  39796. fullRequest.read().then(readChunk, reject);
  39797. });
  39798. readPromise.catch(function (e) {
  39799. pdfManagerCapability.reject(e);
  39800. cancelXHRs = null;
  39801. });
  39802. cancelXHRs = function () {
  39803. pdfStream.cancelAllRequests('abort');
  39804. };
  39805. return pdfManagerCapability.promise;
  39806. }
  39807. var setupDoc = function(data) {
  39808. var onSuccess = function(doc) {
  39809. ensureNotTerminated();
  39810. handler.send('GetDoc', { pdfInfo: doc });
  39811. };
  39812. var onFailure = function(e) {
  39813. if (e instanceof PasswordException) {
  39814. if (e.code === PasswordResponses.NEED_PASSWORD) {
  39815. handler.send('NeedPassword', e);
  39816. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  39817. handler.send('IncorrectPassword', e);
  39818. }
  39819. } else if (e instanceof InvalidPDFException) {
  39820. handler.send('InvalidPDF', e);
  39821. } else if (e instanceof MissingPDFException) {
  39822. handler.send('MissingPDF', e);
  39823. } else if (e instanceof UnexpectedResponseException) {
  39824. handler.send('UnexpectedResponse', e);
  39825. } else {
  39826. handler.send('UnknownError',
  39827. new UnknownErrorException(e.message, e.toString()));
  39828. }
  39829. };
  39830. ensureNotTerminated();
  39831. var cMapOptions = {
  39832. url: data.cMapUrl === undefined ? null : data.cMapUrl,
  39833. packed: data.cMapPacked === true
  39834. };
  39835. var evaluatorOptions = {
  39836. forceDataSchema: data.disableCreateObjectURL,
  39837. maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize,
  39838. disableFontFace: data.disableFontFace,
  39839. cMapOptions: cMapOptions
  39840. };
  39841. getPdfManager(data, evaluatorOptions).then(function (newPdfManager) {
  39842. if (terminated) {
  39843. // We were in a process of setting up the manager, but it got
  39844. // terminated in the middle.
  39845. newPdfManager.terminate();
  39846. throw new Error('Worker was terminated');
  39847. }
  39848. pdfManager = newPdfManager;
  39849. handler.send('PDFManagerReady', null);
  39850. pdfManager.onLoadedStream().then(function(stream) {
  39851. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  39852. });
  39853. }).then(function pdfManagerReady() {
  39854. ensureNotTerminated();
  39855. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  39856. ensureNotTerminated();
  39857. // Try again with recoveryMode == true
  39858. if (!(ex instanceof XRefParseException)) {
  39859. if (ex instanceof PasswordException) {
  39860. // after password exception prepare to receive a new password
  39861. // to repeat loading
  39862. pdfManager.passwordChanged().then(pdfManagerReady);
  39863. }
  39864. onFailure(ex);
  39865. return;
  39866. }
  39867. pdfManager.requestLoadedStream();
  39868. pdfManager.onLoadedStream().then(function() {
  39869. ensureNotTerminated();
  39870. loadDocument(true).then(onSuccess, onFailure);
  39871. });
  39872. }, onFailure);
  39873. }, onFailure);
  39874. };
  39875. handler.on('GetPage', function wphSetupGetPage(data) {
  39876. return pdfManager.getPage(data.pageIndex).then(function(page) {
  39877. var rotatePromise = pdfManager.ensure(page, 'rotate');
  39878. var refPromise = pdfManager.ensure(page, 'ref');
  39879. var viewPromise = pdfManager.ensure(page, 'view');
  39880. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  39881. function(results) {
  39882. return {
  39883. rotate: results[0],
  39884. ref: results[1],
  39885. view: results[2]
  39886. };
  39887. });
  39888. });
  39889. });
  39890. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  39891. var ref = new Ref(data.ref.num, data.ref.gen);
  39892. var catalog = pdfManager.pdfDocument.catalog;
  39893. return catalog.getPageIndex(ref);
  39894. });
  39895. handler.on('GetDestinations',
  39896. function wphSetupGetDestinations(data) {
  39897. return pdfManager.ensureCatalog('destinations');
  39898. }
  39899. );
  39900. handler.on('GetDestination',
  39901. function wphSetupGetDestination(data) {
  39902. return pdfManager.ensureCatalog('getDestination', [data.id]);
  39903. }
  39904. );
  39905. handler.on('GetPageLabels',
  39906. function wphSetupGetPageLabels(data) {
  39907. return pdfManager.ensureCatalog('pageLabels');
  39908. }
  39909. );
  39910. handler.on('GetAttachments',
  39911. function wphSetupGetAttachments(data) {
  39912. return pdfManager.ensureCatalog('attachments');
  39913. }
  39914. );
  39915. handler.on('GetJavaScript',
  39916. function wphSetupGetJavaScript(data) {
  39917. return pdfManager.ensureCatalog('javaScript');
  39918. }
  39919. );
  39920. handler.on('GetOutline',
  39921. function wphSetupGetOutline(data) {
  39922. return pdfManager.ensureCatalog('documentOutline');
  39923. }
  39924. );
  39925. handler.on('GetMetadata',
  39926. function wphSetupGetMetadata(data) {
  39927. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  39928. pdfManager.ensureCatalog('metadata')]);
  39929. }
  39930. );
  39931. handler.on('GetData', function wphSetupGetData(data) {
  39932. pdfManager.requestLoadedStream();
  39933. return pdfManager.onLoadedStream().then(function(stream) {
  39934. return stream.bytes;
  39935. });
  39936. });
  39937. handler.on('GetStats',
  39938. function wphSetupGetStats(data) {
  39939. return pdfManager.pdfDocument.xref.stats;
  39940. }
  39941. );
  39942. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  39943. pdfManager.updatePassword(data);
  39944. });
  39945. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  39946. return pdfManager.getPage(data.pageIndex).then(function(page) {
  39947. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  39948. });
  39949. });
  39950. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  39951. var pageIndex = data.pageIndex;
  39952. pdfManager.getPage(pageIndex).then(function(page) {
  39953. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  39954. startWorkerTask(task);
  39955. var pageNum = pageIndex + 1;
  39956. var start = Date.now();
  39957. // Pre compile the pdf page and fetch the fonts/images.
  39958. page.getOperatorList(handler, task, data.intent,
  39959. data.renderInteractiveForms).then(
  39960. function(operatorList) {
  39961. finishWorkerTask(task);
  39962. info('page=' + pageNum + ' - getOperatorList: time=' +
  39963. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  39964. }, function(e) {
  39965. finishWorkerTask(task);
  39966. if (task.terminated) {
  39967. return; // ignoring errors from the terminated thread
  39968. }
  39969. // For compatibility with older behavior, generating unknown
  39970. // unsupported feature notification on errors.
  39971. handler.send('UnsupportedFeature',
  39972. {featureId: UNSUPPORTED_FEATURES.unknown});
  39973. var minimumStackMessage =
  39974. 'worker.js: while trying to getPage() and getOperatorList()';
  39975. var wrappedException;
  39976. // Turn the error into an obj that can be serialized
  39977. if (typeof e === 'string') {
  39978. wrappedException = {
  39979. message: e,
  39980. stack: minimumStackMessage
  39981. };
  39982. } else if (typeof e === 'object') {
  39983. wrappedException = {
  39984. message: e.message || e.toString(),
  39985. stack: e.stack || minimumStackMessage
  39986. };
  39987. } else {
  39988. wrappedException = {
  39989. message: 'Unknown exception type: ' + (typeof e),
  39990. stack: minimumStackMessage
  39991. };
  39992. }
  39993. handler.send('PageError', {
  39994. pageNum: pageNum,
  39995. error: wrappedException,
  39996. intent: data.intent
  39997. });
  39998. });
  39999. });
  40000. }, this);
  40001. handler.on('GetTextContent', function wphExtractText(data) {
  40002. var pageIndex = data.pageIndex;
  40003. var normalizeWhitespace = data.normalizeWhitespace;
  40004. var combineTextItems = data.combineTextItems;
  40005. return pdfManager.getPage(pageIndex).then(function(page) {
  40006. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  40007. startWorkerTask(task);
  40008. var pageNum = pageIndex + 1;
  40009. var start = Date.now();
  40010. return page.extractTextContent(task, normalizeWhitespace,
  40011. combineTextItems).then(
  40012. function(textContent) {
  40013. finishWorkerTask(task);
  40014. info('text indexing: page=' + pageNum + ' - time=' +
  40015. (Date.now() - start) + 'ms');
  40016. return textContent;
  40017. }, function (reason) {
  40018. finishWorkerTask(task);
  40019. if (task.terminated) {
  40020. return; // ignoring errors from the terminated thread
  40021. }
  40022. throw reason;
  40023. });
  40024. });
  40025. });
  40026. handler.on('Cleanup', function wphCleanup(data) {
  40027. return pdfManager.cleanup();
  40028. });
  40029. handler.on('Terminate', function wphTerminate(data) {
  40030. terminated = true;
  40031. if (pdfManager) {
  40032. pdfManager.terminate();
  40033. pdfManager = null;
  40034. }
  40035. if (cancelXHRs) {
  40036. cancelXHRs();
  40037. }
  40038. var waitOn = [];
  40039. WorkerTasks.forEach(function (task) {
  40040. waitOn.push(task.finished);
  40041. task.terminate();
  40042. });
  40043. return Promise.all(waitOn).then(function () {
  40044. // Notice that even if we destroying handler, resolved response promise
  40045. // must be sent back.
  40046. handler.destroy();
  40047. handler = null;
  40048. });
  40049. });
  40050. handler.on('Ready', function wphReady(data) {
  40051. setupDoc(docParams);
  40052. docParams = null; // we don't need docParams anymore -- saving memory.
  40053. });
  40054. return workerHandlerName;
  40055. }
  40056. };
  40057. function initializeWorker() {
  40058. if (!('console' in globalScope)) {
  40059. var consoleTimer = {};
  40060. var workerConsole = {
  40061. log: function log() {
  40062. var args = Array.prototype.slice.call(arguments);
  40063. globalScope.postMessage({
  40064. targetName: 'main',
  40065. action: 'console_log',
  40066. data: args
  40067. });
  40068. },
  40069. error: function error() {
  40070. var args = Array.prototype.slice.call(arguments);
  40071. globalScope.postMessage({
  40072. targetName: 'main',
  40073. action: 'console_error',
  40074. data: args
  40075. });
  40076. throw 'pdf.js execution error';
  40077. },
  40078. time: function time(name) {
  40079. consoleTimer[name] = Date.now();
  40080. },
  40081. timeEnd: function timeEnd(name) {
  40082. var time = consoleTimer[name];
  40083. if (!time) {
  40084. error('Unknown timer name ' + name);
  40085. }
  40086. this.log('Timer:', name, Date.now() - time);
  40087. }
  40088. };
  40089. globalScope.console = workerConsole;
  40090. }
  40091. var handler = new MessageHandler('worker', 'main', self);
  40092. WorkerMessageHandler.setup(handler, self);
  40093. handler.send('ready', null);
  40094. }
  40095. // Worker thread (and not node.js)?
  40096. if (typeof window === 'undefined' &&
  40097. !(typeof module !== 'undefined' && module.require)) {
  40098. initializeWorker();
  40099. }
  40100. exports.setPDFNetworkStreamClass = setPDFNetworkStreamClass;
  40101. exports.WorkerTask = WorkerTask;
  40102. exports.WorkerMessageHandler = WorkerMessageHandler;
  40103. }));
  40104. var NetworkManager = (function NetworkManagerClosure() {
  40105. var OK_RESPONSE = 200;
  40106. var PARTIAL_CONTENT_RESPONSE = 206;
  40107. function NetworkManager(url, args) {
  40108. this.url = url;
  40109. args = args || {};
  40110. this.isHttp = /^https?:/i.test(url);
  40111. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  40112. this.withCredentials = args.withCredentials || false;
  40113. this.getXhr = args.getXhr ||
  40114. function NetworkManager_getXhr() {
  40115. return new XMLHttpRequest();
  40116. };
  40117. this.currXhrId = 0;
  40118. this.pendingRequests = Object.create(null);
  40119. this.loadedRequests = Object.create(null);
  40120. }
  40121. function getArrayBuffer(xhr) {
  40122. var data = xhr.response;
  40123. if (typeof data !== 'string') {
  40124. return data;
  40125. }
  40126. var length = data.length;
  40127. var array = new Uint8Array(length);
  40128. for (var i = 0; i < length; i++) {
  40129. array[i] = data.charCodeAt(i) & 0xFF;
  40130. }
  40131. return array.buffer;
  40132. }
  40133. var supportsMozChunked = (function supportsMozChunkedClosure() {
  40134. try {
  40135. var x = new XMLHttpRequest();
  40136. // Firefox 37- required .open() to be called before setting responseType.
  40137. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  40138. // Even though the URL is not visited, .open() could fail if the URL is
  40139. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  40140. // When this error occurs, this feature detection method will mistakenly
  40141. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  40142. x.open('GET', 'https://example.com');
  40143. x.responseType = 'moz-chunked-arraybuffer';
  40144. return x.responseType === 'moz-chunked-arraybuffer';
  40145. } catch (e) {
  40146. return false;
  40147. }
  40148. })();
  40149. NetworkManager.prototype = {
  40150. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  40151. var args = {
  40152. begin: begin,
  40153. end: end
  40154. };
  40155. for (var prop in listeners) {
  40156. args[prop] = listeners[prop];
  40157. }
  40158. return this.request(args);
  40159. },
  40160. requestFull: function NetworkManager_requestFull(listeners) {
  40161. return this.request(listeners);
  40162. },
  40163. request: function NetworkManager_request(args) {
  40164. var xhr = this.getXhr();
  40165. var xhrId = this.currXhrId++;
  40166. var pendingRequest = this.pendingRequests[xhrId] = {
  40167. xhr: xhr
  40168. };
  40169. xhr.open('GET', this.url);
  40170. xhr.withCredentials = this.withCredentials;
  40171. for (var property in this.httpHeaders) {
  40172. var value = this.httpHeaders[property];
  40173. if (typeof value === 'undefined') {
  40174. continue;
  40175. }
  40176. xhr.setRequestHeader(property, value);
  40177. }
  40178. if (this.isHttp && 'begin' in args && 'end' in args) {
  40179. var rangeStr = args.begin + '-' + (args.end - 1);
  40180. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  40181. pendingRequest.expectedStatus = 206;
  40182. } else {
  40183. pendingRequest.expectedStatus = 200;
  40184. }
  40185. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  40186. if (useMozChunkedLoading) {
  40187. xhr.responseType = 'moz-chunked-arraybuffer';
  40188. pendingRequest.onProgressiveData = args.onProgressiveData;
  40189. pendingRequest.mozChunked = true;
  40190. } else {
  40191. xhr.responseType = 'arraybuffer';
  40192. }
  40193. if (args.onError) {
  40194. xhr.onerror = function(evt) {
  40195. args.onError(xhr.status);
  40196. };
  40197. }
  40198. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  40199. xhr.onprogress = this.onProgress.bind(this, xhrId);
  40200. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  40201. pendingRequest.onDone = args.onDone;
  40202. pendingRequest.onError = args.onError;
  40203. pendingRequest.onProgress = args.onProgress;
  40204. xhr.send(null);
  40205. return xhrId;
  40206. },
  40207. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  40208. var pendingRequest = this.pendingRequests[xhrId];
  40209. if (!pendingRequest) {
  40210. // Maybe abortRequest was called...
  40211. return;
  40212. }
  40213. if (pendingRequest.mozChunked) {
  40214. var chunk = getArrayBuffer(pendingRequest.xhr);
  40215. pendingRequest.onProgressiveData(chunk);
  40216. }
  40217. var onProgress = pendingRequest.onProgress;
  40218. if (onProgress) {
  40219. onProgress(evt);
  40220. }
  40221. },
  40222. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  40223. var pendingRequest = this.pendingRequests[xhrId];
  40224. if (!pendingRequest) {
  40225. // Maybe abortRequest was called...
  40226. return;
  40227. }
  40228. var xhr = pendingRequest.xhr;
  40229. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  40230. pendingRequest.onHeadersReceived();
  40231. delete pendingRequest.onHeadersReceived;
  40232. }
  40233. if (xhr.readyState !== 4) {
  40234. return;
  40235. }
  40236. if (!(xhrId in this.pendingRequests)) {
  40237. // The XHR request might have been aborted in onHeadersReceived()
  40238. // callback, in which case we should abort request
  40239. return;
  40240. }
  40241. delete this.pendingRequests[xhrId];
  40242. // success status == 0 can be on ftp, file and other protocols
  40243. if (xhr.status === 0 && this.isHttp) {
  40244. if (pendingRequest.onError) {
  40245. pendingRequest.onError(xhr.status);
  40246. }
  40247. return;
  40248. }
  40249. var xhrStatus = xhr.status || OK_RESPONSE;
  40250. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  40251. // "A server MAY ignore the Range header". This means it's possible to
  40252. // get a 200 rather than a 206 response from a range request.
  40253. var ok_response_on_range_request =
  40254. xhrStatus === OK_RESPONSE &&
  40255. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  40256. if (!ok_response_on_range_request &&
  40257. xhrStatus !== pendingRequest.expectedStatus) {
  40258. if (pendingRequest.onError) {
  40259. pendingRequest.onError(xhr.status);
  40260. }
  40261. return;
  40262. }
  40263. this.loadedRequests[xhrId] = true;
  40264. var chunk = getArrayBuffer(xhr);
  40265. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  40266. var rangeHeader = xhr.getResponseHeader('Content-Range');
  40267. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  40268. var begin = parseInt(matches[1], 10);
  40269. pendingRequest.onDone({
  40270. begin: begin,
  40271. chunk: chunk
  40272. });
  40273. } else if (pendingRequest.onProgressiveData) {
  40274. pendingRequest.onDone(null);
  40275. } else if (chunk) {
  40276. pendingRequest.onDone({
  40277. begin: 0,
  40278. chunk: chunk
  40279. });
  40280. } else if (pendingRequest.onError) {
  40281. pendingRequest.onError(xhr.status);
  40282. }
  40283. },
  40284. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  40285. for (var xhrId in this.pendingRequests) {
  40286. return true;
  40287. }
  40288. return false;
  40289. },
  40290. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  40291. return this.pendingRequests[xhrId].xhr;
  40292. },
  40293. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  40294. return !!(this.pendingRequests[xhrId].onProgressiveData);
  40295. },
  40296. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  40297. return xhrId in this.pendingRequests;
  40298. },
  40299. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  40300. return xhrId in this.loadedRequests;
  40301. },
  40302. abortAllRequests: function NetworkManager_abortAllRequests() {
  40303. for (var xhrId in this.pendingRequests) {
  40304. this.abortRequest(xhrId | 0);
  40305. }
  40306. },
  40307. abortRequest: function NetworkManager_abortRequest(xhrId) {
  40308. var xhr = this.pendingRequests[xhrId].xhr;
  40309. delete this.pendingRequests[xhrId];
  40310. xhr.abort();
  40311. }
  40312. };
  40313. return NetworkManager;
  40314. })();
  40315. (function (root, factory) {
  40316. {
  40317. factory((root.pdfjsCoreNetwork = {}), root.pdfjsSharedUtil,
  40318. root.pdfjsCoreWorker);
  40319. }
  40320. }(this, function (exports, sharedUtil, coreWorker) {
  40321. var assert = sharedUtil.assert;
  40322. var createPromiseCapability = sharedUtil.createPromiseCapability;
  40323. var isInt = sharedUtil.isInt;
  40324. var MissingPDFException = sharedUtil.MissingPDFException;
  40325. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  40326. /** @implements {IPDFStream} */
  40327. function PDFNetworkStream(options) {
  40328. this._options = options;
  40329. var source = options.source;
  40330. this._manager = new NetworkManager(source.url, {
  40331. httpHeaders: source.httpHeaders,
  40332. withCredentials: source.withCredentials
  40333. });
  40334. this._rangeChunkSize = source.rangeChunkSize;
  40335. this._fullRequestReader = null;
  40336. this._rangeRequestReaders = [];
  40337. }
  40338. PDFNetworkStream.prototype = {
  40339. _onRangeRequestReaderClosed:
  40340. function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
  40341. var i = this._rangeRequestReaders.indexOf(reader);
  40342. if (i >= 0) {
  40343. this._rangeRequestReaders.splice(i, 1);
  40344. }
  40345. },
  40346. getFullReader: function PDFNetworkStream_getFullReader() {
  40347. assert(!this._fullRequestReader);
  40348. this._fullRequestReader =
  40349. new PDFNetworkStreamFullRequestReader(this._manager, this._options);
  40350. return this._fullRequestReader;
  40351. },
  40352. getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
  40353. var reader = new PDFNetworkStreamRangeRequestReader(this._manager,
  40354. begin, end);
  40355. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  40356. this._rangeRequestReaders.push(reader);
  40357. return reader;
  40358. },
  40359. cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
  40360. if (this._fullRequestReader) {
  40361. this._fullRequestReader.cancel(reason);
  40362. }
  40363. var readers = this._rangeRequestReaders.slice(0);
  40364. readers.forEach(function (reader) {
  40365. reader.cancel(reason);
  40366. });
  40367. }
  40368. };
  40369. /** @implements {IPDFStreamReader} */
  40370. function PDFNetworkStreamFullRequestReader(manager, options) {
  40371. this._manager = manager;
  40372. var source = options.source;
  40373. var args = {
  40374. onHeadersReceived: this._onHeadersReceived.bind(this),
  40375. onProgressiveData: source.disableStream ? null :
  40376. this._onProgressiveData.bind(this),
  40377. onDone: this._onDone.bind(this),
  40378. onError: this._onError.bind(this),
  40379. onProgress: this._onProgress.bind(this)
  40380. };
  40381. this._url = source.url;
  40382. this._fullRequestId = manager.requestFull(args);
  40383. this._headersReceivedCapability = createPromiseCapability();
  40384. this._disableRange = options.disableRange || false;
  40385. this._contentLength = source.length; // optional
  40386. this._rangeChunkSize = source.rangeChunkSize;
  40387. if (!this._rangeChunkSize && !this._disableRange) {
  40388. this._disableRange = true;
  40389. }
  40390. this._isStreamingSupported = false;
  40391. this._isRangeSupported = false;
  40392. this._cachedChunks = [];
  40393. this._requests = [];
  40394. this._done = false;
  40395. this._storedError = undefined;
  40396. this.onProgress = null;
  40397. }
  40398. PDFNetworkStreamFullRequestReader.prototype = {
  40399. _validateRangeRequestCapabilities: function
  40400. PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() {
  40401. if (this._disableRange) {
  40402. return false;
  40403. }
  40404. var networkManager = this._manager;
  40405. var fullRequestXhrId = this._fullRequestId;
  40406. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  40407. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  40408. return false;
  40409. }
  40410. var contentEncoding =
  40411. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  40412. if (contentEncoding !== 'identity') {
  40413. return false;
  40414. }
  40415. var length = fullRequestXhr.getResponseHeader('Content-Length');
  40416. length = parseInt(length, 10);
  40417. if (!isInt(length)) {
  40418. return false;
  40419. }
  40420. this._contentLength = length; // setting right content length
  40421. if (length <= 2 * this._rangeChunkSize) {
  40422. // The file size is smaller than the size of two chunks, so it does
  40423. // not make any sense to abort the request and retry with a range
  40424. // request.
  40425. return false;
  40426. }
  40427. return true;
  40428. },
  40429. _onHeadersReceived:
  40430. function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
  40431. if (this._validateRangeRequestCapabilities()) {
  40432. this._isRangeSupported = true;
  40433. }
  40434. var networkManager = this._manager;
  40435. var fullRequestXhrId = this._fullRequestId;
  40436. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  40437. // We can continue fetching when progressive loading is enabled,
  40438. // and we don't need the autoFetch feature.
  40439. this._isStreamingSupported = true;
  40440. } else if (this._isRangeSupported) {
  40441. // NOTE: by cancelling the full request, and then issuing range
  40442. // requests, there will be an issue for sites where you can only
  40443. // request the pdf once. However, if this is the case, then the
  40444. // server should not be returning that it can support range
  40445. // requests.
  40446. networkManager.abortRequest(fullRequestXhrId);
  40447. }
  40448. this._headersReceivedCapability.resolve();
  40449. },
  40450. _onProgressiveData:
  40451. function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
  40452. if (this._requests.length > 0) {
  40453. var requestCapability = this._requests.shift();
  40454. requestCapability.resolve({value: chunk, done: false});
  40455. } else {
  40456. this._cachedChunks.push(chunk);
  40457. }
  40458. },
  40459. _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
  40460. if (args) {
  40461. this._onProgressiveData(args.chunk);
  40462. }
  40463. this._done = true;
  40464. if (this._cachedChunks.length > 0) {
  40465. return;
  40466. }
  40467. this._requests.forEach(function (requestCapability) {
  40468. requestCapability.resolve({value: undefined, done: true});
  40469. });
  40470. this._requests = [];
  40471. },
  40472. _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
  40473. var url = this._url;
  40474. var exception;
  40475. if (status === 404 || status === 0 && /^file:/.test(url)) {
  40476. exception = new MissingPDFException('Missing PDF "' + url + '".');
  40477. } else {
  40478. exception = new UnexpectedResponseException(
  40479. 'Unexpected server response (' + status +
  40480. ') while retrieving PDF "' + url + '".', status);
  40481. }
  40482. this._storedError = exception;
  40483. this._headersReceivedCapability.reject(exception);
  40484. this._requests.forEach(function (requestCapability) {
  40485. requestCapability.reject(exception);
  40486. });
  40487. this._requests = [];
  40488. this._cachedChunks = [];
  40489. },
  40490. _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
  40491. if (this.onProgress) {
  40492. this.onProgress({
  40493. loaded: data.loaded,
  40494. total: data.lengthComputable ? data.total : this._contentLength
  40495. });
  40496. }
  40497. },
  40498. get isRangeSupported() {
  40499. return this._isRangeSupported;
  40500. },
  40501. get isStreamingSupported() {
  40502. return this._isStreamingSupported;
  40503. },
  40504. get contentLength() {
  40505. return this._contentLength;
  40506. },
  40507. get headersReady() {
  40508. return this._headersReceivedCapability.promise;
  40509. },
  40510. read: function PDFNetworkStreamFullRequestReader_read() {
  40511. if (this._storedError) {
  40512. return Promise.reject(this._storedError);
  40513. }
  40514. if (this._cachedChunks.length > 0) {
  40515. var chunk = this._cachedChunks.shift();
  40516. return Promise.resolve(chunk);
  40517. }
  40518. if (this._done) {
  40519. return Promise.resolve({value: undefined, done: true});
  40520. }
  40521. var requestCapability = createPromiseCapability();
  40522. this._requests.push(requestCapability);
  40523. return requestCapability.promise;
  40524. },
  40525. cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
  40526. this._done = true;
  40527. this._headersReceivedCapability.reject(reason);
  40528. this._requests.forEach(function (requestCapability) {
  40529. requestCapability.resolve({value: undefined, done: true});
  40530. });
  40531. this._requests = [];
  40532. if (this._manager.isPendingRequest(this._fullRequestId)) {
  40533. this._manager.abortRequest(this._fullRequestId);
  40534. }
  40535. this._fullRequestReader = null;
  40536. }
  40537. };
  40538. /** @implements {IPDFStreamRangeReader} */
  40539. function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
  40540. this._manager = manager;
  40541. var args = {
  40542. onDone: this._onDone.bind(this),
  40543. onProgress: this._onProgress.bind(this)
  40544. };
  40545. this._requestId = manager.requestRange(begin, end, args);
  40546. this._requests = [];
  40547. this._queuedChunk = null;
  40548. this._done = false;
  40549. this.onProgress = null;
  40550. this.onClosed = null;
  40551. }
  40552. PDFNetworkStreamRangeRequestReader.prototype = {
  40553. _close: function PDFNetworkStreamRangeRequestReader_close() {
  40554. if (this.onClosed) {
  40555. this.onClosed(this);
  40556. }
  40557. },
  40558. _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
  40559. var chunk = data.chunk;
  40560. if (this._requests.length > 0) {
  40561. var requestCapability = this._requests.shift();
  40562. requestCapability.resolve({value: chunk, done: false});
  40563. } else {
  40564. this._queuedChunk = chunk;
  40565. }
  40566. this._done = true;
  40567. this._requests.forEach(function (requestCapability) {
  40568. requestCapability.resolve({value: undefined, done: true});
  40569. });
  40570. this._requests = [];
  40571. this._close();
  40572. },
  40573. _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
  40574. if (!this.isStreamingSupported && this.onProgress) {
  40575. this.onProgress({
  40576. loaded: evt.loaded
  40577. });
  40578. }
  40579. },
  40580. get isStreamingSupported() {
  40581. return false; // TODO allow progressive range bytes loading
  40582. },
  40583. read: function PDFNetworkStreamRangeRequestReader_read() {
  40584. if (this._queuedChunk !== null) {
  40585. var chunk = this._queuedChunk;
  40586. this._queuedChunk = null;
  40587. return Promise.resolve({value: chunk, done: false});
  40588. }
  40589. if (this._done) {
  40590. return Promise.resolve({value: undefined, done: true});
  40591. }
  40592. var requestCapability = createPromiseCapability();
  40593. this._requests.push(requestCapability);
  40594. return requestCapability.promise;
  40595. },
  40596. cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
  40597. this._done = true;
  40598. this._requests.forEach(function (requestCapability) {
  40599. requestCapability.resolve({value: undefined, done: true});
  40600. });
  40601. this._requests = [];
  40602. if (this._manager.isPendingRequest(this._requestId)) {
  40603. this._manager.abortRequest(this._requestId);
  40604. }
  40605. this._close();
  40606. }
  40607. };
  40608. coreWorker.setPDFNetworkStreamClass(PDFNetworkStream);
  40609. exports.PDFNetworkStream = PDFNetworkStream;
  40610. exports.NetworkManager = NetworkManager;
  40611. }));
  40612. }).call(pdfjsLibs);
  40613. exports.WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
  40614. }));