pdf.worker.js 1.4 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500
  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.492';
  30. var pdfjsBuild = 'a9a3396';
  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 JpegImageClosure() {
  10633. var dctZigZag = new Uint8Array([
  10634. 0,
  10635. 1, 8,
  10636. 16, 9, 2,
  10637. 3, 10, 17, 24,
  10638. 32, 25, 18, 11, 4,
  10639. 5, 12, 19, 26, 33, 40,
  10640. 48, 41, 34, 27, 20, 13, 6,
  10641. 7, 14, 21, 28, 35, 42, 49, 56,
  10642. 57, 50, 43, 36, 29, 22, 15,
  10643. 23, 30, 37, 44, 51, 58,
  10644. 59, 52, 45, 38, 31,
  10645. 39, 46, 53, 60,
  10646. 61, 54, 47,
  10647. 55, 62,
  10648. 63
  10649. ]);
  10650. var dctCos1 = 4017; // cos(pi/16)
  10651. var dctSin1 = 799; // sin(pi/16)
  10652. var dctCos3 = 3406; // cos(3*pi/16)
  10653. var dctSin3 = 2276; // sin(3*pi/16)
  10654. var dctCos6 = 1567; // cos(6*pi/16)
  10655. var dctSin6 = 3784; // sin(6*pi/16)
  10656. var dctSqrt2 = 5793; // sqrt(2)
  10657. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  10658. function JpegImage() {
  10659. this.decodeTransform = null;
  10660. this.colorTransform = -1;
  10661. }
  10662. function buildHuffmanTable(codeLengths, values) {
  10663. var k = 0, code = [], i, j, length = 16;
  10664. while (length > 0 && !codeLengths[length - 1]) {
  10665. length--;
  10666. }
  10667. code.push({children: [], index: 0});
  10668. var p = code[0], q;
  10669. for (i = 0; i < length; i++) {
  10670. for (j = 0; j < codeLengths[i]; j++) {
  10671. p = code.pop();
  10672. p.children[p.index] = values[k];
  10673. while (p.index > 0) {
  10674. p = code.pop();
  10675. }
  10676. p.index++;
  10677. code.push(p);
  10678. while (code.length <= i) {
  10679. code.push(q = {children: [], index: 0});
  10680. p.children[p.index] = q.children;
  10681. p = q;
  10682. }
  10683. k++;
  10684. }
  10685. if (i + 1 < length) {
  10686. // p here points to last code
  10687. code.push(q = {children: [], index: 0});
  10688. p.children[p.index] = q.children;
  10689. p = q;
  10690. }
  10691. }
  10692. return code[0].children;
  10693. }
  10694. function getBlockBufferOffset(component, row, col) {
  10695. return 64 * ((component.blocksPerLine + 1) * row + col);
  10696. }
  10697. function decodeScan(data, offset, frame, components, resetInterval,
  10698. spectralStart, spectralEnd, successivePrev, successive) {
  10699. var mcusPerLine = frame.mcusPerLine;
  10700. var progressive = frame.progressive;
  10701. var startOffset = offset, bitsData = 0, bitsCount = 0;
  10702. function readBit() {
  10703. if (bitsCount > 0) {
  10704. bitsCount--;
  10705. return (bitsData >> bitsCount) & 1;
  10706. }
  10707. bitsData = data[offset++];
  10708. if (bitsData === 0xFF) {
  10709. var nextByte = data[offset++];
  10710. if (nextByte) {
  10711. error('JPEG error: unexpected marker ' +
  10712. ((bitsData << 8) | nextByte).toString(16));
  10713. }
  10714. // unstuff 0
  10715. }
  10716. bitsCount = 7;
  10717. return bitsData >>> 7;
  10718. }
  10719. function decodeHuffman(tree) {
  10720. var node = tree;
  10721. while (true) {
  10722. node = node[readBit()];
  10723. if (typeof node === 'number') {
  10724. return node;
  10725. }
  10726. if (typeof node !== 'object') {
  10727. error('JPEG error: invalid huffman sequence');
  10728. }
  10729. }
  10730. }
  10731. function receive(length) {
  10732. var n = 0;
  10733. while (length > 0) {
  10734. n = (n << 1) | readBit();
  10735. length--;
  10736. }
  10737. return n;
  10738. }
  10739. function receiveAndExtend(length) {
  10740. if (length === 1) {
  10741. return readBit() === 1 ? 1 : -1;
  10742. }
  10743. var n = receive(length);
  10744. if (n >= 1 << (length - 1)) {
  10745. return n;
  10746. }
  10747. return n + (-1 << length) + 1;
  10748. }
  10749. function decodeBaseline(component, offset) {
  10750. var t = decodeHuffman(component.huffmanTableDC);
  10751. var diff = t === 0 ? 0 : receiveAndExtend(t);
  10752. component.blockData[offset] = (component.pred += diff);
  10753. var k = 1;
  10754. while (k < 64) {
  10755. var rs = decodeHuffman(component.huffmanTableAC);
  10756. var s = rs & 15, r = rs >> 4;
  10757. if (s === 0) {
  10758. if (r < 15) {
  10759. break;
  10760. }
  10761. k += 16;
  10762. continue;
  10763. }
  10764. k += r;
  10765. var z = dctZigZag[k];
  10766. component.blockData[offset + z] = receiveAndExtend(s);
  10767. k++;
  10768. }
  10769. }
  10770. function decodeDCFirst(component, offset) {
  10771. var t = decodeHuffman(component.huffmanTableDC);
  10772. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  10773. component.blockData[offset] = (component.pred += diff);
  10774. }
  10775. function decodeDCSuccessive(component, offset) {
  10776. component.blockData[offset] |= readBit() << successive;
  10777. }
  10778. var eobrun = 0;
  10779. function decodeACFirst(component, offset) {
  10780. if (eobrun > 0) {
  10781. eobrun--;
  10782. return;
  10783. }
  10784. var k = spectralStart, e = spectralEnd;
  10785. while (k <= e) {
  10786. var rs = decodeHuffman(component.huffmanTableAC);
  10787. var s = rs & 15, r = rs >> 4;
  10788. if (s === 0) {
  10789. if (r < 15) {
  10790. eobrun = receive(r) + (1 << r) - 1;
  10791. break;
  10792. }
  10793. k += 16;
  10794. continue;
  10795. }
  10796. k += r;
  10797. var z = dctZigZag[k];
  10798. component.blockData[offset + z] =
  10799. receiveAndExtend(s) * (1 << successive);
  10800. k++;
  10801. }
  10802. }
  10803. var successiveACState = 0, successiveACNextValue;
  10804. function decodeACSuccessive(component, offset) {
  10805. var k = spectralStart;
  10806. var e = spectralEnd;
  10807. var r = 0;
  10808. var s;
  10809. var rs;
  10810. while (k <= e) {
  10811. var z = dctZigZag[k];
  10812. switch (successiveACState) {
  10813. case 0: // initial state
  10814. rs = decodeHuffman(component.huffmanTableAC);
  10815. s = rs & 15;
  10816. r = rs >> 4;
  10817. if (s === 0) {
  10818. if (r < 15) {
  10819. eobrun = receive(r) + (1 << r);
  10820. successiveACState = 4;
  10821. } else {
  10822. r = 16;
  10823. successiveACState = 1;
  10824. }
  10825. } else {
  10826. if (s !== 1) {
  10827. error('JPEG error: invalid ACn encoding');
  10828. }
  10829. successiveACNextValue = receiveAndExtend(s);
  10830. successiveACState = r ? 2 : 3;
  10831. }
  10832. continue;
  10833. case 1: // skipping r zero items
  10834. case 2:
  10835. if (component.blockData[offset + z]) {
  10836. component.blockData[offset + z] += (readBit() << successive);
  10837. } else {
  10838. r--;
  10839. if (r === 0) {
  10840. successiveACState = successiveACState === 2 ? 3 : 0;
  10841. }
  10842. }
  10843. break;
  10844. case 3: // set value for a zero item
  10845. if (component.blockData[offset + z]) {
  10846. component.blockData[offset + z] += (readBit() << successive);
  10847. } else {
  10848. component.blockData[offset + z] =
  10849. successiveACNextValue << successive;
  10850. successiveACState = 0;
  10851. }
  10852. break;
  10853. case 4: // eob
  10854. if (component.blockData[offset + z]) {
  10855. component.blockData[offset + z] += (readBit() << successive);
  10856. }
  10857. break;
  10858. }
  10859. k++;
  10860. }
  10861. if (successiveACState === 4) {
  10862. eobrun--;
  10863. if (eobrun === 0) {
  10864. successiveACState = 0;
  10865. }
  10866. }
  10867. }
  10868. function decodeMcu(component, decode, mcu, row, col) {
  10869. var mcuRow = (mcu / mcusPerLine) | 0;
  10870. var mcuCol = mcu % mcusPerLine;
  10871. var blockRow = mcuRow * component.v + row;
  10872. var blockCol = mcuCol * component.h + col;
  10873. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  10874. decode(component, offset);
  10875. }
  10876. function decodeBlock(component, decode, mcu) {
  10877. var blockRow = (mcu / component.blocksPerLine) | 0;
  10878. var blockCol = mcu % component.blocksPerLine;
  10879. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  10880. decode(component, offset);
  10881. }
  10882. var componentsLength = components.length;
  10883. var component, i, j, k, n;
  10884. var decodeFn;
  10885. if (progressive) {
  10886. if (spectralStart === 0) {
  10887. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  10888. } else {
  10889. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  10890. }
  10891. } else {
  10892. decodeFn = decodeBaseline;
  10893. }
  10894. var mcu = 0, marker;
  10895. var mcuExpected;
  10896. if (componentsLength === 1) {
  10897. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  10898. } else {
  10899. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  10900. }
  10901. if (!resetInterval) {
  10902. resetInterval = mcuExpected;
  10903. }
  10904. var h, v;
  10905. while (mcu < mcuExpected) {
  10906. // reset interval stuff
  10907. for (i = 0; i < componentsLength; i++) {
  10908. components[i].pred = 0;
  10909. }
  10910. eobrun = 0;
  10911. if (componentsLength === 1) {
  10912. component = components[0];
  10913. for (n = 0; n < resetInterval; n++) {
  10914. decodeBlock(component, decodeFn, mcu);
  10915. mcu++;
  10916. }
  10917. } else {
  10918. for (n = 0; n < resetInterval; n++) {
  10919. for (i = 0; i < componentsLength; i++) {
  10920. component = components[i];
  10921. h = component.h;
  10922. v = component.v;
  10923. for (j = 0; j < v; j++) {
  10924. for (k = 0; k < h; k++) {
  10925. decodeMcu(component, decodeFn, mcu, j, k);
  10926. }
  10927. }
  10928. }
  10929. mcu++;
  10930. }
  10931. }
  10932. // find marker
  10933. bitsCount = 0;
  10934. marker = (data[offset] << 8) | data[offset + 1];
  10935. if (marker <= 0xFF00) {
  10936. error('JPEG error: marker was not found');
  10937. }
  10938. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  10939. offset += 2;
  10940. } else {
  10941. break;
  10942. }
  10943. }
  10944. return offset - startOffset;
  10945. }
  10946. // A port of poppler's IDCT method which in turn is taken from:
  10947. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  10948. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  10949. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  10950. // 988-991.
  10951. function quantizeAndInverse(component, blockBufferOffset, p) {
  10952. var qt = component.quantizationTable, blockData = component.blockData;
  10953. var v0, v1, v2, v3, v4, v5, v6, v7;
  10954. var p0, p1, p2, p3, p4, p5, p6, p7;
  10955. var t;
  10956. if (!qt) {
  10957. error('JPEG error: missing required Quantization Table.');
  10958. }
  10959. // inverse DCT on rows
  10960. for (var row = 0; row < 64; row += 8) {
  10961. // gather block data
  10962. p0 = blockData[blockBufferOffset + row];
  10963. p1 = blockData[blockBufferOffset + row + 1];
  10964. p2 = blockData[blockBufferOffset + row + 2];
  10965. p3 = blockData[blockBufferOffset + row + 3];
  10966. p4 = blockData[blockBufferOffset + row + 4];
  10967. p5 = blockData[blockBufferOffset + row + 5];
  10968. p6 = blockData[blockBufferOffset + row + 6];
  10969. p7 = blockData[blockBufferOffset + row + 7];
  10970. // dequant p0
  10971. p0 *= qt[row];
  10972. // check for all-zero AC coefficients
  10973. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  10974. t = (dctSqrt2 * p0 + 512) >> 10;
  10975. p[row] = t;
  10976. p[row + 1] = t;
  10977. p[row + 2] = t;
  10978. p[row + 3] = t;
  10979. p[row + 4] = t;
  10980. p[row + 5] = t;
  10981. p[row + 6] = t;
  10982. p[row + 7] = t;
  10983. continue;
  10984. }
  10985. // dequant p1 ... p7
  10986. p1 *= qt[row + 1];
  10987. p2 *= qt[row + 2];
  10988. p3 *= qt[row + 3];
  10989. p4 *= qt[row + 4];
  10990. p5 *= qt[row + 5];
  10991. p6 *= qt[row + 6];
  10992. p7 *= qt[row + 7];
  10993. // stage 4
  10994. v0 = (dctSqrt2 * p0 + 128) >> 8;
  10995. v1 = (dctSqrt2 * p4 + 128) >> 8;
  10996. v2 = p2;
  10997. v3 = p6;
  10998. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  10999. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  11000. v5 = p3 << 4;
  11001. v6 = p5 << 4;
  11002. // stage 3
  11003. v0 = (v0 + v1 + 1) >> 1;
  11004. v1 = v0 - v1;
  11005. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  11006. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  11007. v3 = t;
  11008. v4 = (v4 + v6 + 1) >> 1;
  11009. v6 = v4 - v6;
  11010. v7 = (v7 + v5 + 1) >> 1;
  11011. v5 = v7 - v5;
  11012. // stage 2
  11013. v0 = (v0 + v3 + 1) >> 1;
  11014. v3 = v0 - v3;
  11015. v1 = (v1 + v2 + 1) >> 1;
  11016. v2 = v1 - v2;
  11017. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  11018. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  11019. v7 = t;
  11020. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  11021. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  11022. v6 = t;
  11023. // stage 1
  11024. p[row] = v0 + v7;
  11025. p[row + 7] = v0 - v7;
  11026. p[row + 1] = v1 + v6;
  11027. p[row + 6] = v1 - v6;
  11028. p[row + 2] = v2 + v5;
  11029. p[row + 5] = v2 - v5;
  11030. p[row + 3] = v3 + v4;
  11031. p[row + 4] = v3 - v4;
  11032. }
  11033. // inverse DCT on columns
  11034. for (var col = 0; col < 8; ++col) {
  11035. p0 = p[col];
  11036. p1 = p[col + 8];
  11037. p2 = p[col + 16];
  11038. p3 = p[col + 24];
  11039. p4 = p[col + 32];
  11040. p5 = p[col + 40];
  11041. p6 = p[col + 48];
  11042. p7 = p[col + 56];
  11043. // check for all-zero AC coefficients
  11044. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  11045. t = (dctSqrt2 * p0 + 8192) >> 14;
  11046. // convert to 8 bit
  11047. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  11048. blockData[blockBufferOffset + col] = t;
  11049. blockData[blockBufferOffset + col + 8] = t;
  11050. blockData[blockBufferOffset + col + 16] = t;
  11051. blockData[blockBufferOffset + col + 24] = t;
  11052. blockData[blockBufferOffset + col + 32] = t;
  11053. blockData[blockBufferOffset + col + 40] = t;
  11054. blockData[blockBufferOffset + col + 48] = t;
  11055. blockData[blockBufferOffset + col + 56] = t;
  11056. continue;
  11057. }
  11058. // stage 4
  11059. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  11060. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  11061. v2 = p2;
  11062. v3 = p6;
  11063. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  11064. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  11065. v5 = p3;
  11066. v6 = p5;
  11067. // stage 3
  11068. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  11069. // converting to UInt8 range later.
  11070. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  11071. v1 = v0 - v1;
  11072. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  11073. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  11074. v3 = t;
  11075. v4 = (v4 + v6 + 1) >> 1;
  11076. v6 = v4 - v6;
  11077. v7 = (v7 + v5 + 1) >> 1;
  11078. v5 = v7 - v5;
  11079. // stage 2
  11080. v0 = (v0 + v3 + 1) >> 1;
  11081. v3 = v0 - v3;
  11082. v1 = (v1 + v2 + 1) >> 1;
  11083. v2 = v1 - v2;
  11084. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  11085. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  11086. v7 = t;
  11087. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  11088. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  11089. v6 = t;
  11090. // stage 1
  11091. p0 = v0 + v7;
  11092. p7 = v0 - v7;
  11093. p1 = v1 + v6;
  11094. p6 = v1 - v6;
  11095. p2 = v2 + v5;
  11096. p5 = v2 - v5;
  11097. p3 = v3 + v4;
  11098. p4 = v3 - v4;
  11099. // convert to 8-bit integers
  11100. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  11101. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  11102. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  11103. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  11104. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  11105. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  11106. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  11107. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  11108. // store block data
  11109. blockData[blockBufferOffset + col] = p0;
  11110. blockData[blockBufferOffset + col + 8] = p1;
  11111. blockData[blockBufferOffset + col + 16] = p2;
  11112. blockData[blockBufferOffset + col + 24] = p3;
  11113. blockData[blockBufferOffset + col + 32] = p4;
  11114. blockData[blockBufferOffset + col + 40] = p5;
  11115. blockData[blockBufferOffset + col + 48] = p6;
  11116. blockData[blockBufferOffset + col + 56] = p7;
  11117. }
  11118. }
  11119. function buildComponentData(frame, component) {
  11120. var blocksPerLine = component.blocksPerLine;
  11121. var blocksPerColumn = component.blocksPerColumn;
  11122. var computationBuffer = new Int16Array(64);
  11123. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  11124. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  11125. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  11126. quantizeAndInverse(component, offset, computationBuffer);
  11127. }
  11128. }
  11129. return component.blockData;
  11130. }
  11131. function clamp0to255(a) {
  11132. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  11133. }
  11134. JpegImage.prototype = {
  11135. parse: function parse(data) {
  11136. function readUint16() {
  11137. var value = (data[offset] << 8) | data[offset + 1];
  11138. offset += 2;
  11139. return value;
  11140. }
  11141. function readDataBlock() {
  11142. var length = readUint16();
  11143. var array = data.subarray(offset, offset + length - 2);
  11144. offset += array.length;
  11145. return array;
  11146. }
  11147. function prepareComponents(frame) {
  11148. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  11149. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  11150. for (var i = 0; i < frame.components.length; i++) {
  11151. component = frame.components[i];
  11152. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  11153. component.h / frame.maxH);
  11154. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  11155. component.v / frame.maxV);
  11156. var blocksPerLineForMcu = mcusPerLine * component.h;
  11157. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  11158. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  11159. (blocksPerLineForMcu + 1);
  11160. component.blockData = new Int16Array(blocksBufferSize);
  11161. component.blocksPerLine = blocksPerLine;
  11162. component.blocksPerColumn = blocksPerColumn;
  11163. }
  11164. frame.mcusPerLine = mcusPerLine;
  11165. frame.mcusPerColumn = mcusPerColumn;
  11166. }
  11167. var offset = 0;
  11168. var jfif = null;
  11169. var adobe = null;
  11170. var frame, resetInterval;
  11171. var quantizationTables = [];
  11172. var huffmanTablesAC = [], huffmanTablesDC = [];
  11173. var fileMarker = readUint16();
  11174. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  11175. error('JPEG error: SOI not found');
  11176. }
  11177. fileMarker = readUint16();
  11178. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  11179. var i, j, l;
  11180. switch(fileMarker) {
  11181. case 0xFFE0: // APP0 (Application Specific)
  11182. case 0xFFE1: // APP1
  11183. case 0xFFE2: // APP2
  11184. case 0xFFE3: // APP3
  11185. case 0xFFE4: // APP4
  11186. case 0xFFE5: // APP5
  11187. case 0xFFE6: // APP6
  11188. case 0xFFE7: // APP7
  11189. case 0xFFE8: // APP8
  11190. case 0xFFE9: // APP9
  11191. case 0xFFEA: // APP10
  11192. case 0xFFEB: // APP11
  11193. case 0xFFEC: // APP12
  11194. case 0xFFED: // APP13
  11195. case 0xFFEE: // APP14
  11196. case 0xFFEF: // APP15
  11197. case 0xFFFE: // COM (Comment)
  11198. var appData = readDataBlock();
  11199. if (fileMarker === 0xFFE0) {
  11200. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  11201. appData[2] === 0x49 && appData[3] === 0x46 &&
  11202. appData[4] === 0) { // 'JFIF\x00'
  11203. jfif = {
  11204. version: { major: appData[5], minor: appData[6] },
  11205. densityUnits: appData[7],
  11206. xDensity: (appData[8] << 8) | appData[9],
  11207. yDensity: (appData[10] << 8) | appData[11],
  11208. thumbWidth: appData[12],
  11209. thumbHeight: appData[13],
  11210. thumbData: appData.subarray(14, 14 +
  11211. 3 * appData[12] * appData[13])
  11212. };
  11213. }
  11214. }
  11215. // TODO APP1 - Exif
  11216. if (fileMarker === 0xFFEE) {
  11217. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  11218. appData[2] === 0x6F && appData[3] === 0x62 &&
  11219. appData[4] === 0x65) { // 'Adobe'
  11220. adobe = {
  11221. version: (appData[5] << 8) | appData[6],
  11222. flags0: (appData[7] << 8) | appData[8],
  11223. flags1: (appData[9] << 8) | appData[10],
  11224. transformCode: appData[11]
  11225. };
  11226. }
  11227. }
  11228. break;
  11229. case 0xFFDB: // DQT (Define Quantization Tables)
  11230. var quantizationTablesLength = readUint16();
  11231. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  11232. var z;
  11233. while (offset < quantizationTablesEnd) {
  11234. var quantizationTableSpec = data[offset++];
  11235. var tableData = new Uint16Array(64);
  11236. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  11237. for (j = 0; j < 64; j++) {
  11238. z = dctZigZag[j];
  11239. tableData[z] = data[offset++];
  11240. }
  11241. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  11242. for (j = 0; j < 64; j++) {
  11243. z = dctZigZag[j];
  11244. tableData[z] = readUint16();
  11245. }
  11246. } else {
  11247. error('JPEG error: DQT - invalid table spec');
  11248. }
  11249. quantizationTables[quantizationTableSpec & 15] = tableData;
  11250. }
  11251. break;
  11252. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  11253. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  11254. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  11255. if (frame) {
  11256. error('JPEG error: Only single frame JPEGs supported');
  11257. }
  11258. readUint16(); // skip data length
  11259. frame = {};
  11260. frame.extended = (fileMarker === 0xFFC1);
  11261. frame.progressive = (fileMarker === 0xFFC2);
  11262. frame.precision = data[offset++];
  11263. frame.scanLines = readUint16();
  11264. frame.samplesPerLine = readUint16();
  11265. frame.components = [];
  11266. frame.componentIds = {};
  11267. var componentsCount = data[offset++], componentId;
  11268. var maxH = 0, maxV = 0;
  11269. for (i = 0; i < componentsCount; i++) {
  11270. componentId = data[offset];
  11271. var h = data[offset + 1] >> 4;
  11272. var v = data[offset + 1] & 15;
  11273. if (maxH < h) {
  11274. maxH = h;
  11275. }
  11276. if (maxV < v) {
  11277. maxV = v;
  11278. }
  11279. var qId = data[offset + 2];
  11280. l = frame.components.push({
  11281. h: h,
  11282. v: v,
  11283. quantizationId: qId,
  11284. quantizationTable: null, // See comment below.
  11285. });
  11286. frame.componentIds[componentId] = l - 1;
  11287. offset += 3;
  11288. }
  11289. frame.maxH = maxH;
  11290. frame.maxV = maxV;
  11291. prepareComponents(frame);
  11292. break;
  11293. case 0xFFC4: // DHT (Define Huffman Tables)
  11294. var huffmanLength = readUint16();
  11295. for (i = 2; i < huffmanLength;) {
  11296. var huffmanTableSpec = data[offset++];
  11297. var codeLengths = new Uint8Array(16);
  11298. var codeLengthSum = 0;
  11299. for (j = 0; j < 16; j++, offset++) {
  11300. codeLengthSum += (codeLengths[j] = data[offset]);
  11301. }
  11302. var huffmanValues = new Uint8Array(codeLengthSum);
  11303. for (j = 0; j < codeLengthSum; j++, offset++) {
  11304. huffmanValues[j] = data[offset];
  11305. }
  11306. i += 17 + codeLengthSum;
  11307. ((huffmanTableSpec >> 4) === 0 ?
  11308. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  11309. buildHuffmanTable(codeLengths, huffmanValues);
  11310. }
  11311. break;
  11312. case 0xFFDD: // DRI (Define Restart Interval)
  11313. readUint16(); // skip data length
  11314. resetInterval = readUint16();
  11315. break;
  11316. case 0xFFDA: // SOS (Start of Scan)
  11317. var scanLength = readUint16();
  11318. var selectorsCount = data[offset++];
  11319. var components = [], component;
  11320. for (i = 0; i < selectorsCount; i++) {
  11321. var componentIndex = frame.componentIds[data[offset++]];
  11322. component = frame.components[componentIndex];
  11323. var tableSpec = data[offset++];
  11324. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  11325. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  11326. components.push(component);
  11327. }
  11328. var spectralStart = data[offset++];
  11329. var spectralEnd = data[offset++];
  11330. var successiveApproximation = data[offset++];
  11331. var processed = decodeScan(data, offset,
  11332. frame, components, resetInterval,
  11333. spectralStart, spectralEnd,
  11334. successiveApproximation >> 4, successiveApproximation & 15);
  11335. offset += processed;
  11336. break;
  11337. case 0xFFFF: // Fill bytes
  11338. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  11339. offset--;
  11340. }
  11341. break;
  11342. default:
  11343. if (data[offset - 3] === 0xFF &&
  11344. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  11345. // could be incorrect encoding -- last 0xFF byte of the previous
  11346. // block was eaten by the encoder
  11347. offset -= 3;
  11348. break;
  11349. }
  11350. error('JPEG error: unknown marker ' + fileMarker.toString(16));
  11351. }
  11352. fileMarker = readUint16();
  11353. }
  11354. this.width = frame.samplesPerLine;
  11355. this.height = frame.scanLines;
  11356. this.jfif = jfif;
  11357. this.adobe = adobe;
  11358. this.components = [];
  11359. for (i = 0; i < frame.components.length; i++) {
  11360. component = frame.components[i];
  11361. // Prevent errors when DQT markers are placed after SOF{n} markers,
  11362. // by assigning the `quantizationTable` entry after the entire image
  11363. // has been parsed (fixes issue7406.pdf).
  11364. var quantizationTable = quantizationTables[component.quantizationId];
  11365. if (quantizationTable) {
  11366. component.quantizationTable = quantizationTable;
  11367. }
  11368. this.components.push({
  11369. output: buildComponentData(frame, component),
  11370. scaleX: component.h / frame.maxH,
  11371. scaleY: component.v / frame.maxV,
  11372. blocksPerLine: component.blocksPerLine,
  11373. blocksPerColumn: component.blocksPerColumn
  11374. });
  11375. }
  11376. this.numComponents = this.components.length;
  11377. },
  11378. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  11379. var scaleX = this.width / width, scaleY = this.height / height;
  11380. var component, componentScaleX, componentScaleY, blocksPerScanline;
  11381. var x, y, i, j, k;
  11382. var index;
  11383. var offset = 0;
  11384. var output;
  11385. var numComponents = this.components.length;
  11386. var dataLength = width * height * numComponents;
  11387. var data = new Uint8Array(dataLength);
  11388. var xScaleBlockOffset = new Uint32Array(width);
  11389. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  11390. for (i = 0; i < numComponents; i++) {
  11391. component = this.components[i];
  11392. componentScaleX = component.scaleX * scaleX;
  11393. componentScaleY = component.scaleY * scaleY;
  11394. offset = i;
  11395. output = component.output;
  11396. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  11397. // precalculate the xScaleBlockOffset
  11398. for (x = 0; x < width; x++) {
  11399. j = 0 | (x * componentScaleX);
  11400. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  11401. }
  11402. // linearize the blocks of the component
  11403. for (y = 0; y < height; y++) {
  11404. j = 0 | (y * componentScaleY);
  11405. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  11406. for (x = 0; x < width; x++) {
  11407. data[offset] = output[index + xScaleBlockOffset[x]];
  11408. offset += numComponents;
  11409. }
  11410. }
  11411. }
  11412. // decodeTransform contains pairs of multiplier (-256..256) and additive
  11413. var transform = this.decodeTransform;
  11414. if (transform) {
  11415. for (i = 0; i < dataLength;) {
  11416. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  11417. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  11418. }
  11419. }
  11420. }
  11421. return data;
  11422. },
  11423. _isColorConversionNeeded: function isColorConversionNeeded() {
  11424. if (this.adobe && this.adobe.transformCode) {
  11425. // The adobe transform marker overrides any previous setting
  11426. return true;
  11427. } else if (this.numComponents === 3) {
  11428. if (!this.adobe && this.colorTransform === 0) {
  11429. // If the Adobe transform marker is not present and the image
  11430. // dictionary has a 'ColorTransform' entry, explicitly set to `0`,
  11431. // then the colours should *not* be transformed.
  11432. return false;
  11433. }
  11434. return true;
  11435. } else { // `this.numComponents !== 3`
  11436. if (!this.adobe && this.colorTransform === 1) {
  11437. // If the Adobe transform marker is not present and the image
  11438. // dictionary has a 'ColorTransform' entry, explicitly set to `1`,
  11439. // then the colours should be transformed.
  11440. return true;
  11441. }
  11442. return false;
  11443. }
  11444. },
  11445. _convertYccToRgb: function convertYccToRgb(data) {
  11446. var Y, Cb, Cr;
  11447. for (var i = 0, length = data.length; i < length; i += 3) {
  11448. Y = data[i ];
  11449. Cb = data[i + 1];
  11450. Cr = data[i + 2];
  11451. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  11452. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  11453. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  11454. }
  11455. return data;
  11456. },
  11457. _convertYcckToRgb: function convertYcckToRgb(data) {
  11458. var Y, Cb, Cr, k;
  11459. var offset = 0;
  11460. for (var i = 0, length = data.length; i < length; i += 4) {
  11461. Y = data[i];
  11462. Cb = data[i + 1];
  11463. Cr = data[i + 2];
  11464. k = data[i + 3];
  11465. var r = -122.67195406894 +
  11466. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  11467. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  11468. 0.154362151871126) +
  11469. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  11470. 0.00477271405408747 * k + 1.53380253221734) +
  11471. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  11472. 0.48357088451265) +
  11473. k * (-0.000336197177618394 * k + 0.484791561490776);
  11474. var g = 107.268039397724 +
  11475. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  11476. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  11477. 0.176491792462875) +
  11478. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  11479. 0.000770482631801132 * k - 0.151051492775562) +
  11480. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  11481. 0.25802910206845) +
  11482. k * (-0.000318913117588328 * k - 0.213742400323665);
  11483. var b = -20.810012546947 +
  11484. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  11485. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  11486. 0.814272968359295) +
  11487. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  11488. 0.000560833691242812 * k - 0.195152027534049) +
  11489. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  11490. 0.116935020465145) +
  11491. k * (-0.000343531996510555 * k + 0.24165260232407);
  11492. data[offset++] = clamp0to255(r);
  11493. data[offset++] = clamp0to255(g);
  11494. data[offset++] = clamp0to255(b);
  11495. }
  11496. return data;
  11497. },
  11498. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  11499. var Y, Cb, Cr;
  11500. for (var i = 0, length = data.length; i < length; i += 4) {
  11501. Y = data[i];
  11502. Cb = data[i + 1];
  11503. Cr = data[i + 2];
  11504. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  11505. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  11506. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  11507. // K in data[i + 3] is unchanged
  11508. }
  11509. return data;
  11510. },
  11511. _convertCmykToRgb: function convertCmykToRgb(data) {
  11512. var c, m, y, k;
  11513. var offset = 0;
  11514. var min = -255 * 255 * 255;
  11515. var scale = 1 / 255 / 255;
  11516. for (var i = 0, length = data.length; i < length; i += 4) {
  11517. c = data[i];
  11518. m = data[i + 1];
  11519. y = data[i + 2];
  11520. k = data[i + 3];
  11521. var r =
  11522. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  11523. 18.82290502165302 * y + 212.25662451639585 * k -
  11524. 72734.4411664936) +
  11525. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  11526. 17.873870861415444 * k - 1401.7366389350734) +
  11527. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  11528. 4465.541406466231) -
  11529. k * (21.86122147463605 * k + 48317.86113160301);
  11530. var g =
  11531. c * (8.841041422036149 * c + 60.118027045597366 * m +
  11532. 6.871425592049007 * y + 31.159100130055922 * k -
  11533. 20220.756542821975) +
  11534. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  11535. 131.35250912493976 * k - 48691.05921601825) +
  11536. y * (4.444339102852739 * y + 9.8632861493405 * k -
  11537. 6341.191035517494) -
  11538. k * (20.737325471181034 * k + 47890.15695978492);
  11539. var b =
  11540. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  11541. 30.89978309703729 * y - 0.23883238689178934 * k -
  11542. 3616.812083916688) +
  11543. m * (10.49593273432072 * m + 63.02378494754052 * y +
  11544. 50.606957656360734 * k - 28620.90484698408) +
  11545. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  11546. 49363.43385999684) -
  11547. k * (22.33816807309886 * k + 45932.16563550634);
  11548. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  11549. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  11550. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  11551. }
  11552. return data;
  11553. },
  11554. getData: function getData(width, height, forceRGBoutput) {
  11555. if (this.numComponents > 4) {
  11556. error('JPEG error: Unsupported color mode');
  11557. }
  11558. // type of data: Uint8Array(width * height * numComponents)
  11559. var data = this._getLinearizedBlockData(width, height);
  11560. if (this.numComponents === 1 && forceRGBoutput) {
  11561. var dataLength = data.length;
  11562. var rgbData = new Uint8Array(dataLength * 3);
  11563. var offset = 0;
  11564. for (var i = 0; i < dataLength; i++) {
  11565. var grayColor = data[i];
  11566. rgbData[offset++] = grayColor;
  11567. rgbData[offset++] = grayColor;
  11568. rgbData[offset++] = grayColor;
  11569. }
  11570. return rgbData;
  11571. } else if (this.numComponents === 3 && this._isColorConversionNeeded()) {
  11572. return this._convertYccToRgb(data);
  11573. } else if (this.numComponents === 4) {
  11574. if (this._isColorConversionNeeded()) {
  11575. if (forceRGBoutput) {
  11576. return this._convertYcckToRgb(data);
  11577. } else {
  11578. return this._convertYcckToCmyk(data);
  11579. }
  11580. } else if (forceRGBoutput) {
  11581. return this._convertCmykToRgb(data);
  11582. }
  11583. }
  11584. return data;
  11585. }
  11586. };
  11587. return JpegImage;
  11588. })();
  11589. exports.JpegImage = JpegImage;
  11590. }));
  11591. (function (root, factory) {
  11592. {
  11593. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  11594. root.pdfjsCoreArithmeticDecoder);
  11595. }
  11596. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  11597. var info = sharedUtil.info;
  11598. var warn = sharedUtil.warn;
  11599. var error = sharedUtil.error;
  11600. var log2 = sharedUtil.log2;
  11601. var readUint16 = sharedUtil.readUint16;
  11602. var readUint32 = sharedUtil.readUint32;
  11603. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  11604. var JpxImage = (function JpxImageClosure() {
  11605. // Table E.1
  11606. var SubbandsGainLog2 = {
  11607. 'LL': 0,
  11608. 'LH': 1,
  11609. 'HL': 1,
  11610. 'HH': 2
  11611. };
  11612. function JpxImage() {
  11613. this.failOnCorruptedImage = false;
  11614. }
  11615. JpxImage.prototype = {
  11616. parse: function JpxImage_parse(data) {
  11617. var head = readUint16(data, 0);
  11618. // No box header, immediate start of codestream (SOC)
  11619. if (head === 0xFF4F) {
  11620. this.parseCodestream(data, 0, data.length);
  11621. return;
  11622. }
  11623. var position = 0, length = data.length;
  11624. while (position < length) {
  11625. var headerSize = 8;
  11626. var lbox = readUint32(data, position);
  11627. var tbox = readUint32(data, position + 4);
  11628. position += headerSize;
  11629. if (lbox === 1) {
  11630. // XLBox: read UInt64 according to spec.
  11631. // JavaScript's int precision of 53 bit should be sufficient here.
  11632. lbox = readUint32(data, position) * 4294967296 +
  11633. readUint32(data, position + 4);
  11634. position += 8;
  11635. headerSize += 8;
  11636. }
  11637. if (lbox === 0) {
  11638. lbox = length - position + headerSize;
  11639. }
  11640. if (lbox < headerSize) {
  11641. error('JPX Error: Invalid box field size');
  11642. }
  11643. var dataLength = lbox - headerSize;
  11644. var jumpDataLength = true;
  11645. switch (tbox) {
  11646. case 0x6A703268: // 'jp2h'
  11647. jumpDataLength = false; // parsing child boxes
  11648. break;
  11649. case 0x636F6C72: // 'colr'
  11650. // Colorspaces are not used, the CS from the PDF is used.
  11651. var method = data[position];
  11652. if (method === 1) {
  11653. // enumerated colorspace
  11654. var colorspace = readUint32(data, position + 3);
  11655. switch (colorspace) {
  11656. case 16: // this indicates a sRGB colorspace
  11657. case 17: // this indicates a grayscale colorspace
  11658. case 18: // this indicates a YUV colorspace
  11659. break;
  11660. default:
  11661. warn('Unknown colorspace ' + colorspace);
  11662. break;
  11663. }
  11664. } else if (method === 2) {
  11665. info('ICC profile not supported');
  11666. }
  11667. break;
  11668. case 0x6A703263: // 'jp2c'
  11669. this.parseCodestream(data, position, position + dataLength);
  11670. break;
  11671. case 0x6A502020: // 'jP\024\024'
  11672. if (0x0d0a870a !== readUint32(data, position)) {
  11673. warn('Invalid JP2 signature');
  11674. }
  11675. break;
  11676. // The following header types are valid but currently not used:
  11677. case 0x6A501A1A: // 'jP\032\032'
  11678. case 0x66747970: // 'ftyp'
  11679. case 0x72726571: // 'rreq'
  11680. case 0x72657320: // 'res '
  11681. case 0x69686472: // 'ihdr'
  11682. break;
  11683. default:
  11684. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  11685. (tbox >> 16) & 0xFF,
  11686. (tbox >> 8) & 0xFF,
  11687. tbox & 0xFF);
  11688. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  11689. break;
  11690. }
  11691. if (jumpDataLength) {
  11692. position += dataLength;
  11693. }
  11694. }
  11695. },
  11696. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  11697. var newByte = stream.getByte();
  11698. while (newByte >= 0) {
  11699. var oldByte = newByte;
  11700. newByte = stream.getByte();
  11701. var code = (oldByte << 8) | newByte;
  11702. // Image and tile size (SIZ)
  11703. if (code === 0xFF51) {
  11704. stream.skip(4);
  11705. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  11706. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  11707. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  11708. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  11709. stream.skip(16);
  11710. var Csiz = stream.getUint16(); // Byte 36
  11711. this.width = Xsiz - XOsiz;
  11712. this.height = Ysiz - YOsiz;
  11713. this.componentsCount = Csiz;
  11714. // Results are always returned as Uint8Arrays
  11715. this.bitsPerComponent = 8;
  11716. return;
  11717. }
  11718. }
  11719. error('JPX Error: No size marker found in JPX stream');
  11720. },
  11721. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  11722. var context = {};
  11723. var doNotRecover = false;
  11724. try {
  11725. var position = start;
  11726. while (position + 1 < end) {
  11727. var code = readUint16(data, position);
  11728. position += 2;
  11729. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  11730. switch (code) {
  11731. case 0xFF4F: // Start of codestream (SOC)
  11732. context.mainHeader = true;
  11733. break;
  11734. case 0xFFD9: // End of codestream (EOC)
  11735. break;
  11736. case 0xFF51: // Image and tile size (SIZ)
  11737. length = readUint16(data, position);
  11738. var siz = {};
  11739. siz.Xsiz = readUint32(data, position + 4);
  11740. siz.Ysiz = readUint32(data, position + 8);
  11741. siz.XOsiz = readUint32(data, position + 12);
  11742. siz.YOsiz = readUint32(data, position + 16);
  11743. siz.XTsiz = readUint32(data, position + 20);
  11744. siz.YTsiz = readUint32(data, position + 24);
  11745. siz.XTOsiz = readUint32(data, position + 28);
  11746. siz.YTOsiz = readUint32(data, position + 32);
  11747. var componentsCount = readUint16(data, position + 36);
  11748. siz.Csiz = componentsCount;
  11749. var components = [];
  11750. j = position + 38;
  11751. for (var i = 0; i < componentsCount; i++) {
  11752. var component = {
  11753. precision: (data[j] & 0x7F) + 1,
  11754. isSigned: !!(data[j] & 0x80),
  11755. XRsiz: data[j + 1],
  11756. YRsiz: data[j + 1]
  11757. };
  11758. calculateComponentDimensions(component, siz);
  11759. components.push(component);
  11760. }
  11761. context.SIZ = siz;
  11762. context.components = components;
  11763. calculateTileGrids(context, components);
  11764. context.QCC = [];
  11765. context.COC = [];
  11766. break;
  11767. case 0xFF5C: // Quantization default (QCD)
  11768. length = readUint16(data, position);
  11769. var qcd = {};
  11770. j = position + 2;
  11771. sqcd = data[j++];
  11772. switch (sqcd & 0x1F) {
  11773. case 0:
  11774. spqcdSize = 8;
  11775. scalarExpounded = true;
  11776. break;
  11777. case 1:
  11778. spqcdSize = 16;
  11779. scalarExpounded = false;
  11780. break;
  11781. case 2:
  11782. spqcdSize = 16;
  11783. scalarExpounded = true;
  11784. break;
  11785. default:
  11786. throw new Error('Invalid SQcd value ' + sqcd);
  11787. }
  11788. qcd.noQuantization = (spqcdSize === 8);
  11789. qcd.scalarExpounded = scalarExpounded;
  11790. qcd.guardBits = sqcd >> 5;
  11791. spqcds = [];
  11792. while (j < length + position) {
  11793. var spqcd = {};
  11794. if (spqcdSize === 8) {
  11795. spqcd.epsilon = data[j++] >> 3;
  11796. spqcd.mu = 0;
  11797. } else {
  11798. spqcd.epsilon = data[j] >> 3;
  11799. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  11800. j += 2;
  11801. }
  11802. spqcds.push(spqcd);
  11803. }
  11804. qcd.SPqcds = spqcds;
  11805. if (context.mainHeader) {
  11806. context.QCD = qcd;
  11807. } else {
  11808. context.currentTile.QCD = qcd;
  11809. context.currentTile.QCC = [];
  11810. }
  11811. break;
  11812. case 0xFF5D: // Quantization component (QCC)
  11813. length = readUint16(data, position);
  11814. var qcc = {};
  11815. j = position + 2;
  11816. var cqcc;
  11817. if (context.SIZ.Csiz < 257) {
  11818. cqcc = data[j++];
  11819. } else {
  11820. cqcc = readUint16(data, j);
  11821. j += 2;
  11822. }
  11823. sqcd = data[j++];
  11824. switch (sqcd & 0x1F) {
  11825. case 0:
  11826. spqcdSize = 8;
  11827. scalarExpounded = true;
  11828. break;
  11829. case 1:
  11830. spqcdSize = 16;
  11831. scalarExpounded = false;
  11832. break;
  11833. case 2:
  11834. spqcdSize = 16;
  11835. scalarExpounded = true;
  11836. break;
  11837. default:
  11838. throw new Error('Invalid SQcd value ' + sqcd);
  11839. }
  11840. qcc.noQuantization = (spqcdSize === 8);
  11841. qcc.scalarExpounded = scalarExpounded;
  11842. qcc.guardBits = sqcd >> 5;
  11843. spqcds = [];
  11844. while (j < (length + position)) {
  11845. spqcd = {};
  11846. if (spqcdSize === 8) {
  11847. spqcd.epsilon = data[j++] >> 3;
  11848. spqcd.mu = 0;
  11849. } else {
  11850. spqcd.epsilon = data[j] >> 3;
  11851. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  11852. j += 2;
  11853. }
  11854. spqcds.push(spqcd);
  11855. }
  11856. qcc.SPqcds = spqcds;
  11857. if (context.mainHeader) {
  11858. context.QCC[cqcc] = qcc;
  11859. } else {
  11860. context.currentTile.QCC[cqcc] = qcc;
  11861. }
  11862. break;
  11863. case 0xFF52: // Coding style default (COD)
  11864. length = readUint16(data, position);
  11865. var cod = {};
  11866. j = position + 2;
  11867. var scod = data[j++];
  11868. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  11869. cod.sopMarkerUsed = !!(scod & 2);
  11870. cod.ephMarkerUsed = !!(scod & 4);
  11871. cod.progressionOrder = data[j++];
  11872. cod.layersCount = readUint16(data, j);
  11873. j += 2;
  11874. cod.multipleComponentTransform = data[j++];
  11875. cod.decompositionLevelsCount = data[j++];
  11876. cod.xcb = (data[j++] & 0xF) + 2;
  11877. cod.ycb = (data[j++] & 0xF) + 2;
  11878. var blockStyle = data[j++];
  11879. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  11880. cod.resetContextProbabilities = !!(blockStyle & 2);
  11881. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  11882. cod.verticalyStripe = !!(blockStyle & 8);
  11883. cod.predictableTermination = !!(blockStyle & 16);
  11884. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  11885. cod.reversibleTransformation = data[j++];
  11886. if (cod.entropyCoderWithCustomPrecincts) {
  11887. var precinctsSizes = [];
  11888. while (j < length + position) {
  11889. var precinctsSize = data[j++];
  11890. precinctsSizes.push({
  11891. PPx: precinctsSize & 0xF,
  11892. PPy: precinctsSize >> 4
  11893. });
  11894. }
  11895. cod.precinctsSizes = precinctsSizes;
  11896. }
  11897. var unsupported = [];
  11898. if (cod.selectiveArithmeticCodingBypass) {
  11899. unsupported.push('selectiveArithmeticCodingBypass');
  11900. }
  11901. if (cod.resetContextProbabilities) {
  11902. unsupported.push('resetContextProbabilities');
  11903. }
  11904. if (cod.terminationOnEachCodingPass) {
  11905. unsupported.push('terminationOnEachCodingPass');
  11906. }
  11907. if (cod.verticalyStripe) {
  11908. unsupported.push('verticalyStripe');
  11909. }
  11910. if (cod.predictableTermination) {
  11911. unsupported.push('predictableTermination');
  11912. }
  11913. if (unsupported.length > 0) {
  11914. doNotRecover = true;
  11915. throw new Error('Unsupported COD options (' +
  11916. unsupported.join(', ') + ')');
  11917. }
  11918. if (context.mainHeader) {
  11919. context.COD = cod;
  11920. } else {
  11921. context.currentTile.COD = cod;
  11922. context.currentTile.COC = [];
  11923. }
  11924. break;
  11925. case 0xFF90: // Start of tile-part (SOT)
  11926. length = readUint16(data, position);
  11927. tile = {};
  11928. tile.index = readUint16(data, position + 2);
  11929. tile.length = readUint32(data, position + 4);
  11930. tile.dataEnd = tile.length + position - 2;
  11931. tile.partIndex = data[position + 8];
  11932. tile.partsCount = data[position + 9];
  11933. context.mainHeader = false;
  11934. if (tile.partIndex === 0) {
  11935. // reset component specific settings
  11936. tile.COD = context.COD;
  11937. tile.COC = context.COC.slice(0); // clone of the global COC
  11938. tile.QCD = context.QCD;
  11939. tile.QCC = context.QCC.slice(0); // clone of the global COC
  11940. }
  11941. context.currentTile = tile;
  11942. break;
  11943. case 0xFF93: // Start of data (SOD)
  11944. tile = context.currentTile;
  11945. if (tile.partIndex === 0) {
  11946. initializeTile(context, tile.index);
  11947. buildPackets(context);
  11948. }
  11949. // moving to the end of the data
  11950. length = tile.dataEnd - position;
  11951. parseTilePackets(context, data, position, length);
  11952. break;
  11953. case 0xFF55: // Tile-part lengths, main header (TLM)
  11954. case 0xFF57: // Packet length, main header (PLM)
  11955. case 0xFF58: // Packet length, tile-part header (PLT)
  11956. case 0xFF64: // Comment (COM)
  11957. length = readUint16(data, position);
  11958. // skipping content
  11959. break;
  11960. case 0xFF53: // Coding style component (COC)
  11961. throw new Error('Codestream code 0xFF53 (COC) is ' +
  11962. 'not implemented');
  11963. default:
  11964. throw new Error('Unknown codestream code: ' + code.toString(16));
  11965. }
  11966. position += length;
  11967. }
  11968. } catch (e) {
  11969. if (doNotRecover || this.failOnCorruptedImage) {
  11970. error('JPX Error: ' + e.message);
  11971. } else {
  11972. warn('JPX: Trying to recover from: ' + e.message);
  11973. }
  11974. }
  11975. this.tiles = transformComponents(context);
  11976. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  11977. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  11978. this.componentsCount = context.SIZ.Csiz;
  11979. }
  11980. };
  11981. function calculateComponentDimensions(component, siz) {
  11982. // Section B.2 Component mapping
  11983. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  11984. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  11985. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  11986. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  11987. component.width = component.x1 - component.x0;
  11988. component.height = component.y1 - component.y0;
  11989. }
  11990. function calculateTileGrids(context, components) {
  11991. var siz = context.SIZ;
  11992. // Section B.3 Division into tile and tile-components
  11993. var tile, tiles = [];
  11994. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  11995. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  11996. for (var q = 0; q < numYtiles; q++) {
  11997. for (var p = 0; p < numXtiles; p++) {
  11998. tile = {};
  11999. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  12000. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  12001. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  12002. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  12003. tile.width = tile.tx1 - tile.tx0;
  12004. tile.height = tile.ty1 - tile.ty0;
  12005. tile.components = [];
  12006. tiles.push(tile);
  12007. }
  12008. }
  12009. context.tiles = tiles;
  12010. var componentsCount = siz.Csiz;
  12011. for (var i = 0, ii = componentsCount; i < ii; i++) {
  12012. var component = components[i];
  12013. for (var j = 0, jj = tiles.length; j < jj; j++) {
  12014. var tileComponent = {};
  12015. tile = tiles[j];
  12016. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  12017. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  12018. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  12019. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  12020. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  12021. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  12022. tile.components[i] = tileComponent;
  12023. }
  12024. }
  12025. }
  12026. function getBlocksDimensions(context, component, r) {
  12027. var codOrCoc = component.codingStyleParameters;
  12028. var result = {};
  12029. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  12030. result.PPx = 15;
  12031. result.PPy = 15;
  12032. } else {
  12033. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  12034. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  12035. }
  12036. // calculate codeblock size as described in section B.7
  12037. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  12038. Math.min(codOrCoc.xcb, result.PPx));
  12039. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  12040. Math.min(codOrCoc.ycb, result.PPy));
  12041. return result;
  12042. }
  12043. function buildPrecincts(context, resolution, dimensions) {
  12044. // Section B.6 Division resolution to precincts
  12045. var precinctWidth = 1 << dimensions.PPx;
  12046. var precinctHeight = 1 << dimensions.PPy;
  12047. // Jasper introduces codeblock groups for mapping each subband codeblocks
  12048. // to precincts. Precinct partition divides a resolution according to width
  12049. // and height parameters. The subband that belongs to the resolution level
  12050. // has a different size than the level, unless it is the zero resolution.
  12051. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  12052. // The precinct partitioning for a particular subband is derived from a
  12053. // partitioning of its parent LL band (i.e., the LL band at the next higher
  12054. // resolution level)... The LL band associated with each resolution level is
  12055. // divided into precincts... Each of the resulting precinct regions is then
  12056. // mapped into its child subbands (if any) at the next lower resolution
  12057. // level. This is accomplished by using the coordinate transformation
  12058. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  12059. // coordinates of a point in the LL band and child subband, respectively.
  12060. var isZeroRes = resolution.resLevel === 0;
  12061. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  12062. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  12063. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  12064. Math.ceil(resolution.trx1 / precinctWidth) -
  12065. Math.floor(resolution.trx0 / precinctWidth) : 0);
  12066. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  12067. Math.ceil(resolution.try1 / precinctHeight) -
  12068. Math.floor(resolution.try0 / precinctHeight) : 0);
  12069. var numprecincts = numprecinctswide * numprecinctshigh;
  12070. resolution.precinctParameters = {
  12071. precinctWidth: precinctWidth,
  12072. precinctHeight: precinctHeight,
  12073. numprecinctswide: numprecinctswide,
  12074. numprecinctshigh: numprecinctshigh,
  12075. numprecincts: numprecincts,
  12076. precinctWidthInSubband: precinctWidthInSubband,
  12077. precinctHeightInSubband: precinctHeightInSubband
  12078. };
  12079. }
  12080. function buildCodeblocks(context, subband, dimensions) {
  12081. // Section B.7 Division sub-band into code-blocks
  12082. var xcb_ = dimensions.xcb_;
  12083. var ycb_ = dimensions.ycb_;
  12084. var codeblockWidth = 1 << xcb_;
  12085. var codeblockHeight = 1 << ycb_;
  12086. var cbx0 = subband.tbx0 >> xcb_;
  12087. var cby0 = subband.tby0 >> ycb_;
  12088. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  12089. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  12090. var precinctParameters = subband.resolution.precinctParameters;
  12091. var codeblocks = [];
  12092. var precincts = [];
  12093. var i, j, codeblock, precinctNumber;
  12094. for (j = cby0; j < cby1; j++) {
  12095. for (i = cbx0; i < cbx1; i++) {
  12096. codeblock = {
  12097. cbx: i,
  12098. cby: j,
  12099. tbx0: codeblockWidth * i,
  12100. tby0: codeblockHeight * j,
  12101. tbx1: codeblockWidth * (i + 1),
  12102. tby1: codeblockHeight * (j + 1)
  12103. };
  12104. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  12105. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  12106. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  12107. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  12108. // Calculate precinct number for this codeblock, codeblock position
  12109. // should be relative to its subband, use actual dimension and position
  12110. // See comment about codeblock group width and height
  12111. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  12112. precinctParameters.precinctWidthInSubband);
  12113. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  12114. precinctParameters.precinctHeightInSubband);
  12115. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  12116. codeblock.precinctNumber = precinctNumber;
  12117. codeblock.subbandType = subband.type;
  12118. codeblock.Lblock = 3;
  12119. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  12120. codeblock.tby1_ <= codeblock.tby0_) {
  12121. continue;
  12122. }
  12123. codeblocks.push(codeblock);
  12124. // building precinct for the sub-band
  12125. var precinct = precincts[precinctNumber];
  12126. if (precinct !== undefined) {
  12127. if (i < precinct.cbxMin) {
  12128. precinct.cbxMin = i;
  12129. } else if (i > precinct.cbxMax) {
  12130. precinct.cbxMax = i;
  12131. }
  12132. if (j < precinct.cbyMin) {
  12133. precinct.cbxMin = j;
  12134. } else if (j > precinct.cbyMax) {
  12135. precinct.cbyMax = j;
  12136. }
  12137. } else {
  12138. precincts[precinctNumber] = precinct = {
  12139. cbxMin: i,
  12140. cbyMin: j,
  12141. cbxMax: i,
  12142. cbyMax: j
  12143. };
  12144. }
  12145. codeblock.precinct = precinct;
  12146. }
  12147. }
  12148. subband.codeblockParameters = {
  12149. codeblockWidth: xcb_,
  12150. codeblockHeight: ycb_,
  12151. numcodeblockwide: cbx1 - cbx0 + 1,
  12152. numcodeblockhigh: cby1 - cby0 + 1
  12153. };
  12154. subband.codeblocks = codeblocks;
  12155. subband.precincts = precincts;
  12156. }
  12157. function createPacket(resolution, precinctNumber, layerNumber) {
  12158. var precinctCodeblocks = [];
  12159. // Section B.10.8 Order of info in packet
  12160. var subbands = resolution.subbands;
  12161. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  12162. for (var i = 0, ii = subbands.length; i < ii; i++) {
  12163. var subband = subbands[i];
  12164. var codeblocks = subband.codeblocks;
  12165. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  12166. var codeblock = codeblocks[j];
  12167. if (codeblock.precinctNumber !== precinctNumber) {
  12168. continue;
  12169. }
  12170. precinctCodeblocks.push(codeblock);
  12171. }
  12172. }
  12173. return {
  12174. layerNumber: layerNumber,
  12175. codeblocks: precinctCodeblocks
  12176. };
  12177. }
  12178. function LayerResolutionComponentPositionIterator(context) {
  12179. var siz = context.SIZ;
  12180. var tileIndex = context.currentTile.index;
  12181. var tile = context.tiles[tileIndex];
  12182. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12183. var componentsCount = siz.Csiz;
  12184. var maxDecompositionLevelsCount = 0;
  12185. for (var q = 0; q < componentsCount; q++) {
  12186. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12187. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12188. }
  12189. var l = 0, r = 0, i = 0, k = 0;
  12190. this.nextPacket = function JpxImage_nextPacket() {
  12191. // Section B.12.1.1 Layer-resolution-component-position
  12192. for (; l < layersCount; l++) {
  12193. for (; r <= maxDecompositionLevelsCount; r++) {
  12194. for (; i < componentsCount; i++) {
  12195. var component = tile.components[i];
  12196. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12197. continue;
  12198. }
  12199. var resolution = component.resolutions[r];
  12200. var numprecincts = resolution.precinctParameters.numprecincts;
  12201. for (; k < numprecincts;) {
  12202. var packet = createPacket(resolution, k, l);
  12203. k++;
  12204. return packet;
  12205. }
  12206. k = 0;
  12207. }
  12208. i = 0;
  12209. }
  12210. r = 0;
  12211. }
  12212. error('JPX Error: Out of packets');
  12213. };
  12214. }
  12215. function ResolutionLayerComponentPositionIterator(context) {
  12216. var siz = context.SIZ;
  12217. var tileIndex = context.currentTile.index;
  12218. var tile = context.tiles[tileIndex];
  12219. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12220. var componentsCount = siz.Csiz;
  12221. var maxDecompositionLevelsCount = 0;
  12222. for (var q = 0; q < componentsCount; q++) {
  12223. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12224. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12225. }
  12226. var r = 0, l = 0, i = 0, k = 0;
  12227. this.nextPacket = function JpxImage_nextPacket() {
  12228. // Section B.12.1.2 Resolution-layer-component-position
  12229. for (; r <= maxDecompositionLevelsCount; r++) {
  12230. for (; l < layersCount; l++) {
  12231. for (; i < componentsCount; i++) {
  12232. var component = tile.components[i];
  12233. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12234. continue;
  12235. }
  12236. var resolution = component.resolutions[r];
  12237. var numprecincts = resolution.precinctParameters.numprecincts;
  12238. for (; k < numprecincts;) {
  12239. var packet = createPacket(resolution, k, l);
  12240. k++;
  12241. return packet;
  12242. }
  12243. k = 0;
  12244. }
  12245. i = 0;
  12246. }
  12247. l = 0;
  12248. }
  12249. error('JPX Error: Out of packets');
  12250. };
  12251. }
  12252. function ResolutionPositionComponentLayerIterator(context) {
  12253. var siz = context.SIZ;
  12254. var tileIndex = context.currentTile.index;
  12255. var tile = context.tiles[tileIndex];
  12256. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12257. var componentsCount = siz.Csiz;
  12258. var l, r, c, p;
  12259. var maxDecompositionLevelsCount = 0;
  12260. for (c = 0; c < componentsCount; c++) {
  12261. var component = tile.components[c];
  12262. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12263. component.codingStyleParameters.decompositionLevelsCount);
  12264. }
  12265. var maxNumPrecinctsInLevel = new Int32Array(
  12266. maxDecompositionLevelsCount + 1);
  12267. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  12268. var maxNumPrecincts = 0;
  12269. for (c = 0; c < componentsCount; ++c) {
  12270. var resolutions = tile.components[c].resolutions;
  12271. if (r < resolutions.length) {
  12272. maxNumPrecincts = Math.max(maxNumPrecincts,
  12273. resolutions[r].precinctParameters.numprecincts);
  12274. }
  12275. }
  12276. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  12277. }
  12278. l = 0;
  12279. r = 0;
  12280. c = 0;
  12281. p = 0;
  12282. this.nextPacket = function JpxImage_nextPacket() {
  12283. // Section B.12.1.3 Resolution-position-component-layer
  12284. for (; r <= maxDecompositionLevelsCount; r++) {
  12285. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  12286. for (; c < componentsCount; c++) {
  12287. var component = tile.components[c];
  12288. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12289. continue;
  12290. }
  12291. var resolution = component.resolutions[r];
  12292. var numprecincts = resolution.precinctParameters.numprecincts;
  12293. if (p >= numprecincts) {
  12294. continue;
  12295. }
  12296. for (; l < layersCount;) {
  12297. var packet = createPacket(resolution, p, l);
  12298. l++;
  12299. return packet;
  12300. }
  12301. l = 0;
  12302. }
  12303. c = 0;
  12304. }
  12305. p = 0;
  12306. }
  12307. error('JPX Error: Out of packets');
  12308. };
  12309. }
  12310. function PositionComponentResolutionLayerIterator(context) {
  12311. var siz = context.SIZ;
  12312. var tileIndex = context.currentTile.index;
  12313. var tile = context.tiles[tileIndex];
  12314. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12315. var componentsCount = siz.Csiz;
  12316. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12317. var precinctsIterationSizes = precinctsSizes;
  12318. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12319. this.nextPacket = function JpxImage_nextPacket() {
  12320. // Section B.12.1.4 Position-component-resolution-layer
  12321. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12322. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12323. for (; c < componentsCount; c++) {
  12324. var component = tile.components[c];
  12325. var decompositionLevelsCount =
  12326. component.codingStyleParameters.decompositionLevelsCount;
  12327. for (; r <= decompositionLevelsCount; r++) {
  12328. var resolution = component.resolutions[r];
  12329. var sizeInImageScale =
  12330. precinctsSizes.components[c].resolutions[r];
  12331. var k = getPrecinctIndexIfExist(
  12332. px,
  12333. py,
  12334. sizeInImageScale,
  12335. precinctsIterationSizes,
  12336. resolution);
  12337. if (k === null) {
  12338. continue;
  12339. }
  12340. for (; l < layersCount;) {
  12341. var packet = createPacket(resolution, k, l);
  12342. l++;
  12343. return packet;
  12344. }
  12345. l = 0;
  12346. }
  12347. r = 0;
  12348. }
  12349. c = 0;
  12350. }
  12351. px = 0;
  12352. }
  12353. error('JPX Error: Out of packets');
  12354. };
  12355. }
  12356. function ComponentPositionResolutionLayerIterator(context) {
  12357. var siz = context.SIZ;
  12358. var tileIndex = context.currentTile.index;
  12359. var tile = context.tiles[tileIndex];
  12360. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12361. var componentsCount = siz.Csiz;
  12362. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12363. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12364. this.nextPacket = function JpxImage_nextPacket() {
  12365. // Section B.12.1.5 Component-position-resolution-layer
  12366. for (; c < componentsCount; ++c) {
  12367. var component = tile.components[c];
  12368. var precinctsIterationSizes = precinctsSizes.components[c];
  12369. var decompositionLevelsCount =
  12370. component.codingStyleParameters.decompositionLevelsCount;
  12371. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12372. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12373. for (; r <= decompositionLevelsCount; r++) {
  12374. var resolution = component.resolutions[r];
  12375. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  12376. var k = getPrecinctIndexIfExist(
  12377. px,
  12378. py,
  12379. sizeInImageScale,
  12380. precinctsIterationSizes,
  12381. resolution);
  12382. if (k === null) {
  12383. continue;
  12384. }
  12385. for (; l < layersCount;) {
  12386. var packet = createPacket(resolution, k, l);
  12387. l++;
  12388. return packet;
  12389. }
  12390. l = 0;
  12391. }
  12392. r = 0;
  12393. }
  12394. px = 0;
  12395. }
  12396. py = 0;
  12397. }
  12398. error('JPX Error: Out of packets');
  12399. };
  12400. }
  12401. function getPrecinctIndexIfExist(
  12402. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  12403. var posX = pxIndex * precinctIterationSizes.minWidth;
  12404. var posY = pyIndex * precinctIterationSizes.minHeight;
  12405. if (posX % sizeInImageScale.width !== 0 ||
  12406. posY % sizeInImageScale.height !== 0) {
  12407. return null;
  12408. }
  12409. var startPrecinctRowIndex =
  12410. (posY / sizeInImageScale.width) *
  12411. resolution.precinctParameters.numprecinctswide;
  12412. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  12413. }
  12414. function getPrecinctSizesInImageScale(tile) {
  12415. var componentsCount = tile.components.length;
  12416. var minWidth = Number.MAX_VALUE;
  12417. var minHeight = Number.MAX_VALUE;
  12418. var maxNumWide = 0;
  12419. var maxNumHigh = 0;
  12420. var sizePerComponent = new Array(componentsCount);
  12421. for (var c = 0; c < componentsCount; c++) {
  12422. var component = tile.components[c];
  12423. var decompositionLevelsCount =
  12424. component.codingStyleParameters.decompositionLevelsCount;
  12425. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  12426. var minWidthCurrentComponent = Number.MAX_VALUE;
  12427. var minHeightCurrentComponent = Number.MAX_VALUE;
  12428. var maxNumWideCurrentComponent = 0;
  12429. var maxNumHighCurrentComponent = 0;
  12430. var scale = 1;
  12431. for (var r = decompositionLevelsCount; r >= 0; --r) {
  12432. var resolution = component.resolutions[r];
  12433. var widthCurrentResolution =
  12434. scale * resolution.precinctParameters.precinctWidth;
  12435. var heightCurrentResolution =
  12436. scale * resolution.precinctParameters.precinctHeight;
  12437. minWidthCurrentComponent = Math.min(
  12438. minWidthCurrentComponent,
  12439. widthCurrentResolution);
  12440. minHeightCurrentComponent = Math.min(
  12441. minHeightCurrentComponent,
  12442. heightCurrentResolution);
  12443. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  12444. resolution.precinctParameters.numprecinctswide);
  12445. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  12446. resolution.precinctParameters.numprecinctshigh);
  12447. sizePerResolution[r] = {
  12448. width: widthCurrentResolution,
  12449. height: heightCurrentResolution
  12450. };
  12451. scale <<= 1;
  12452. }
  12453. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  12454. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  12455. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  12456. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  12457. sizePerComponent[c] = {
  12458. resolutions: sizePerResolution,
  12459. minWidth: minWidthCurrentComponent,
  12460. minHeight: minHeightCurrentComponent,
  12461. maxNumWide: maxNumWideCurrentComponent,
  12462. maxNumHigh: maxNumHighCurrentComponent
  12463. };
  12464. }
  12465. return {
  12466. components: sizePerComponent,
  12467. minWidth: minWidth,
  12468. minHeight: minHeight,
  12469. maxNumWide: maxNumWide,
  12470. maxNumHigh: maxNumHigh
  12471. };
  12472. }
  12473. function buildPackets(context) {
  12474. var siz = context.SIZ;
  12475. var tileIndex = context.currentTile.index;
  12476. var tile = context.tiles[tileIndex];
  12477. var componentsCount = siz.Csiz;
  12478. // Creating resolutions and sub-bands for each component
  12479. for (var c = 0; c < componentsCount; c++) {
  12480. var component = tile.components[c];
  12481. var decompositionLevelsCount =
  12482. component.codingStyleParameters.decompositionLevelsCount;
  12483. // Section B.5 Resolution levels and sub-bands
  12484. var resolutions = [];
  12485. var subbands = [];
  12486. for (var r = 0; r <= decompositionLevelsCount; r++) {
  12487. var blocksDimensions = getBlocksDimensions(context, component, r);
  12488. var resolution = {};
  12489. var scale = 1 << (decompositionLevelsCount - r);
  12490. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  12491. resolution.try0 = Math.ceil(component.tcy0 / scale);
  12492. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  12493. resolution.try1 = Math.ceil(component.tcy1 / scale);
  12494. resolution.resLevel = r;
  12495. buildPrecincts(context, resolution, blocksDimensions);
  12496. resolutions.push(resolution);
  12497. var subband;
  12498. if (r === 0) {
  12499. // one sub-band (LL) with last decomposition
  12500. subband = {};
  12501. subband.type = 'LL';
  12502. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  12503. subband.tby0 = Math.ceil(component.tcy0 / scale);
  12504. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  12505. subband.tby1 = Math.ceil(component.tcy1 / scale);
  12506. subband.resolution = resolution;
  12507. buildCodeblocks(context, subband, blocksDimensions);
  12508. subbands.push(subband);
  12509. resolution.subbands = [subband];
  12510. } else {
  12511. var bscale = 1 << (decompositionLevelsCount - r + 1);
  12512. var resolutionSubbands = [];
  12513. // three sub-bands (HL, LH and HH) with rest of decompositions
  12514. subband = {};
  12515. subband.type = 'HL';
  12516. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  12517. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  12518. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  12519. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  12520. subband.resolution = resolution;
  12521. buildCodeblocks(context, subband, blocksDimensions);
  12522. subbands.push(subband);
  12523. resolutionSubbands.push(subband);
  12524. subband = {};
  12525. subband.type = 'LH';
  12526. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  12527. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  12528. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  12529. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  12530. subband.resolution = resolution;
  12531. buildCodeblocks(context, subband, blocksDimensions);
  12532. subbands.push(subband);
  12533. resolutionSubbands.push(subband);
  12534. subband = {};
  12535. subband.type = 'HH';
  12536. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  12537. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  12538. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  12539. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  12540. subband.resolution = resolution;
  12541. buildCodeblocks(context, subband, blocksDimensions);
  12542. subbands.push(subband);
  12543. resolutionSubbands.push(subband);
  12544. resolution.subbands = resolutionSubbands;
  12545. }
  12546. }
  12547. component.resolutions = resolutions;
  12548. component.subbands = subbands;
  12549. }
  12550. // Generate the packets sequence
  12551. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  12552. switch (progressionOrder) {
  12553. case 0:
  12554. tile.packetsIterator =
  12555. new LayerResolutionComponentPositionIterator(context);
  12556. break;
  12557. case 1:
  12558. tile.packetsIterator =
  12559. new ResolutionLayerComponentPositionIterator(context);
  12560. break;
  12561. case 2:
  12562. tile.packetsIterator =
  12563. new ResolutionPositionComponentLayerIterator(context);
  12564. break;
  12565. case 3:
  12566. tile.packetsIterator =
  12567. new PositionComponentResolutionLayerIterator(context);
  12568. break;
  12569. case 4:
  12570. tile.packetsIterator =
  12571. new ComponentPositionResolutionLayerIterator(context);
  12572. break;
  12573. default:
  12574. error('JPX Error: Unsupported progression order ' + progressionOrder);
  12575. }
  12576. }
  12577. function parseTilePackets(context, data, offset, dataLength) {
  12578. var position = 0;
  12579. var buffer, bufferSize = 0, skipNextBit = false;
  12580. function readBits(count) {
  12581. while (bufferSize < count) {
  12582. var b = data[offset + position];
  12583. position++;
  12584. if (skipNextBit) {
  12585. buffer = (buffer << 7) | b;
  12586. bufferSize += 7;
  12587. skipNextBit = false;
  12588. } else {
  12589. buffer = (buffer << 8) | b;
  12590. bufferSize += 8;
  12591. }
  12592. if (b === 0xFF) {
  12593. skipNextBit = true;
  12594. }
  12595. }
  12596. bufferSize -= count;
  12597. return (buffer >>> bufferSize) & ((1 << count) - 1);
  12598. }
  12599. function skipMarkerIfEqual(value) {
  12600. if (data[offset + position - 1] === 0xFF &&
  12601. data[offset + position] === value) {
  12602. skipBytes(1);
  12603. return true;
  12604. } else if (data[offset + position] === 0xFF &&
  12605. data[offset + position + 1] === value) {
  12606. skipBytes(2);
  12607. return true;
  12608. }
  12609. return false;
  12610. }
  12611. function skipBytes(count) {
  12612. position += count;
  12613. }
  12614. function alignToByte() {
  12615. bufferSize = 0;
  12616. if (skipNextBit) {
  12617. position++;
  12618. skipNextBit = false;
  12619. }
  12620. }
  12621. function readCodingpasses() {
  12622. if (readBits(1) === 0) {
  12623. return 1;
  12624. }
  12625. if (readBits(1) === 0) {
  12626. return 2;
  12627. }
  12628. var value = readBits(2);
  12629. if (value < 3) {
  12630. return value + 3;
  12631. }
  12632. value = readBits(5);
  12633. if (value < 31) {
  12634. return value + 6;
  12635. }
  12636. value = readBits(7);
  12637. return value + 37;
  12638. }
  12639. var tileIndex = context.currentTile.index;
  12640. var tile = context.tiles[tileIndex];
  12641. var sopMarkerUsed = context.COD.sopMarkerUsed;
  12642. var ephMarkerUsed = context.COD.ephMarkerUsed;
  12643. var packetsIterator = tile.packetsIterator;
  12644. while (position < dataLength) {
  12645. alignToByte();
  12646. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  12647. // Skip also marker segment length and packet sequence ID
  12648. skipBytes(4);
  12649. }
  12650. var packet = packetsIterator.nextPacket();
  12651. if (!readBits(1)) {
  12652. continue;
  12653. }
  12654. var layerNumber = packet.layerNumber;
  12655. var queue = [], codeblock;
  12656. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  12657. codeblock = packet.codeblocks[i];
  12658. var precinct = codeblock.precinct;
  12659. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  12660. var codeblockRow = codeblock.cby - precinct.cbyMin;
  12661. var codeblockIncluded = false;
  12662. var firstTimeInclusion = false;
  12663. var valueReady;
  12664. if (codeblock['included'] !== undefined) {
  12665. codeblockIncluded = !!readBits(1);
  12666. } else {
  12667. // reading inclusion tree
  12668. precinct = codeblock.precinct;
  12669. var inclusionTree, zeroBitPlanesTree;
  12670. if (precinct['inclusionTree'] !== undefined) {
  12671. inclusionTree = precinct.inclusionTree;
  12672. } else {
  12673. // building inclusion and zero bit-planes trees
  12674. var width = precinct.cbxMax - precinct.cbxMin + 1;
  12675. var height = precinct.cbyMax - precinct.cbyMin + 1;
  12676. inclusionTree = new InclusionTree(width, height, layerNumber);
  12677. zeroBitPlanesTree = new TagTree(width, height);
  12678. precinct.inclusionTree = inclusionTree;
  12679. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  12680. }
  12681. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  12682. while (true) {
  12683. if (readBits(1)) {
  12684. valueReady = !inclusionTree.nextLevel();
  12685. if (valueReady) {
  12686. codeblock.included = true;
  12687. codeblockIncluded = firstTimeInclusion = true;
  12688. break;
  12689. }
  12690. } else {
  12691. inclusionTree.incrementValue(layerNumber);
  12692. break;
  12693. }
  12694. }
  12695. }
  12696. }
  12697. if (!codeblockIncluded) {
  12698. continue;
  12699. }
  12700. if (firstTimeInclusion) {
  12701. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  12702. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  12703. while (true) {
  12704. if (readBits(1)) {
  12705. valueReady = !zeroBitPlanesTree.nextLevel();
  12706. if (valueReady) {
  12707. break;
  12708. }
  12709. } else {
  12710. zeroBitPlanesTree.incrementValue();
  12711. }
  12712. }
  12713. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  12714. }
  12715. var codingpasses = readCodingpasses();
  12716. while (readBits(1)) {
  12717. codeblock.Lblock++;
  12718. }
  12719. var codingpassesLog2 = log2(codingpasses);
  12720. // rounding down log2
  12721. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  12722. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  12723. var codedDataLength = readBits(bits);
  12724. queue.push({
  12725. codeblock: codeblock,
  12726. codingpasses: codingpasses,
  12727. dataLength: codedDataLength
  12728. });
  12729. }
  12730. alignToByte();
  12731. if (ephMarkerUsed) {
  12732. skipMarkerIfEqual(0x92);
  12733. }
  12734. while (queue.length > 0) {
  12735. var packetItem = queue.shift();
  12736. codeblock = packetItem.codeblock;
  12737. if (codeblock['data'] === undefined) {
  12738. codeblock.data = [];
  12739. }
  12740. codeblock.data.push({
  12741. data: data,
  12742. start: offset + position,
  12743. end: offset + position + packetItem.dataLength,
  12744. codingpasses: packetItem.codingpasses
  12745. });
  12746. position += packetItem.dataLength;
  12747. }
  12748. }
  12749. return position;
  12750. }
  12751. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  12752. delta, mb, reversible, segmentationSymbolUsed) {
  12753. var x0 = subband.tbx0;
  12754. var y0 = subband.tby0;
  12755. var width = subband.tbx1 - subband.tbx0;
  12756. var codeblocks = subband.codeblocks;
  12757. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  12758. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  12759. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  12760. var codeblock = codeblocks[i];
  12761. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  12762. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  12763. if (blockWidth === 0 || blockHeight === 0) {
  12764. continue;
  12765. }
  12766. if (codeblock['data'] === undefined) {
  12767. continue;
  12768. }
  12769. var bitModel, currentCodingpassType;
  12770. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  12771. codeblock.zeroBitPlanes, mb);
  12772. currentCodingpassType = 2; // first bit plane starts from cleanup
  12773. // collect data
  12774. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  12775. var j, jj, dataItem;
  12776. for (j = 0, jj = data.length; j < jj; j++) {
  12777. dataItem = data[j];
  12778. totalLength += dataItem.end - dataItem.start;
  12779. codingpasses += dataItem.codingpasses;
  12780. }
  12781. var encodedData = new Uint8Array(totalLength);
  12782. var position = 0;
  12783. for (j = 0, jj = data.length; j < jj; j++) {
  12784. dataItem = data[j];
  12785. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  12786. encodedData.set(chunk, position);
  12787. position += chunk.length;
  12788. }
  12789. // decoding the item
  12790. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  12791. bitModel.setDecoder(decoder);
  12792. for (j = 0; j < codingpasses; j++) {
  12793. switch (currentCodingpassType) {
  12794. case 0:
  12795. bitModel.runSignificancePropagationPass();
  12796. break;
  12797. case 1:
  12798. bitModel.runMagnitudeRefinementPass();
  12799. break;
  12800. case 2:
  12801. bitModel.runCleanupPass();
  12802. if (segmentationSymbolUsed) {
  12803. bitModel.checkSegmentationSymbol();
  12804. }
  12805. break;
  12806. }
  12807. currentCodingpassType = (currentCodingpassType + 1) % 3;
  12808. }
  12809. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  12810. var sign = bitModel.coefficentsSign;
  12811. var magnitude = bitModel.coefficentsMagnitude;
  12812. var bitsDecoded = bitModel.bitsDecoded;
  12813. var magnitudeCorrection = reversible ? 0 : 0.5;
  12814. var k, n, nb;
  12815. position = 0;
  12816. // Do the interleaving of Section F.3.3 here, so we do not need
  12817. // to copy later. LL level is not interleaved, just copied.
  12818. var interleave = (subband.type !== 'LL');
  12819. for (j = 0; j < blockHeight; j++) {
  12820. var row = (offset / width) | 0; // row in the non-interleaved subband
  12821. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  12822. for (k = 0; k < blockWidth; k++) {
  12823. n = magnitude[position];
  12824. if (n !== 0) {
  12825. n = (n + magnitudeCorrection) * delta;
  12826. if (sign[position] !== 0) {
  12827. n = -n;
  12828. }
  12829. nb = bitsDecoded[position];
  12830. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  12831. if (reversible && (nb >= mb)) {
  12832. coefficients[pos] = n;
  12833. } else {
  12834. coefficients[pos] = n * (1 << (mb - nb));
  12835. }
  12836. }
  12837. offset++;
  12838. position++;
  12839. }
  12840. offset += width - blockWidth;
  12841. }
  12842. }
  12843. }
  12844. function transformTile(context, tile, c) {
  12845. var component = tile.components[c];
  12846. var codingStyleParameters = component.codingStyleParameters;
  12847. var quantizationParameters = component.quantizationParameters;
  12848. var decompositionLevelsCount =
  12849. codingStyleParameters.decompositionLevelsCount;
  12850. var spqcds = quantizationParameters.SPqcds;
  12851. var scalarExpounded = quantizationParameters.scalarExpounded;
  12852. var guardBits = quantizationParameters.guardBits;
  12853. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  12854. var precision = context.components[c].precision;
  12855. var reversible = codingStyleParameters.reversibleTransformation;
  12856. var transform = (reversible ? new ReversibleTransform() :
  12857. new IrreversibleTransform());
  12858. var subbandCoefficients = [];
  12859. var b = 0;
  12860. for (var i = 0; i <= decompositionLevelsCount; i++) {
  12861. var resolution = component.resolutions[i];
  12862. var width = resolution.trx1 - resolution.trx0;
  12863. var height = resolution.try1 - resolution.try0;
  12864. // Allocate space for the whole sublevel.
  12865. var coefficients = new Float32Array(width * height);
  12866. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  12867. var mu, epsilon;
  12868. if (!scalarExpounded) {
  12869. // formula E-5
  12870. mu = spqcds[0].mu;
  12871. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  12872. } else {
  12873. mu = spqcds[b].mu;
  12874. epsilon = spqcds[b].epsilon;
  12875. b++;
  12876. }
  12877. var subband = resolution.subbands[j];
  12878. var gainLog2 = SubbandsGainLog2[subband.type];
  12879. // calculate quantization coefficient (Section E.1.1.1)
  12880. var delta = (reversible ? 1 :
  12881. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  12882. var mb = (guardBits + epsilon - 1);
  12883. // In the first resolution level, copyCoefficients will fill the
  12884. // whole array with coefficients. In the succeeding passes,
  12885. // copyCoefficients will consecutively fill in the values that belong
  12886. // to the interleaved positions of the HL, LH, and HH coefficients.
  12887. // The LL coefficients will then be interleaved in Transform.iterate().
  12888. copyCoefficients(coefficients, width, height, subband, delta, mb,
  12889. reversible, segmentationSymbolUsed);
  12890. }
  12891. subbandCoefficients.push({
  12892. width: width,
  12893. height: height,
  12894. items: coefficients
  12895. });
  12896. }
  12897. var result = transform.calculate(subbandCoefficients,
  12898. component.tcx0, component.tcy0);
  12899. return {
  12900. left: component.tcx0,
  12901. top: component.tcy0,
  12902. width: result.width,
  12903. height: result.height,
  12904. items: result.items
  12905. };
  12906. }
  12907. function transformComponents(context) {
  12908. var siz = context.SIZ;
  12909. var components = context.components;
  12910. var componentsCount = siz.Csiz;
  12911. var resultImages = [];
  12912. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  12913. var tile = context.tiles[i];
  12914. var transformedTiles = [];
  12915. var c;
  12916. for (c = 0; c < componentsCount; c++) {
  12917. transformedTiles[c] = transformTile(context, tile, c);
  12918. }
  12919. var tile0 = transformedTiles[0];
  12920. var out = new Uint8Array(tile0.items.length * componentsCount);
  12921. var result = {
  12922. left: tile0.left,
  12923. top: tile0.top,
  12924. width: tile0.width,
  12925. height: tile0.height,
  12926. items: out
  12927. };
  12928. // Section G.2.2 Inverse multi component transform
  12929. var shift, offset, max, min, maxK;
  12930. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  12931. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  12932. var fourComponents = componentsCount === 4;
  12933. var y0items = transformedTiles[0].items;
  12934. var y1items = transformedTiles[1].items;
  12935. var y2items = transformedTiles[2].items;
  12936. var y3items = fourComponents ? transformedTiles[3].items : null;
  12937. // HACK: The multiple component transform formulas below assume that
  12938. // all components have the same precision. With this in mind, we
  12939. // compute shift and offset only once.
  12940. shift = components[0].precision - 8;
  12941. offset = (128 << shift) + 0.5;
  12942. max = 255 * (1 << shift);
  12943. maxK = max * 0.5;
  12944. min = -maxK;
  12945. var component0 = tile.components[0];
  12946. var alpha01 = componentsCount - 3;
  12947. jj = y0items.length;
  12948. if (!component0.codingStyleParameters.reversibleTransformation) {
  12949. // inverse irreversible multiple component transform
  12950. for (j = 0; j < jj; j++, pos += alpha01) {
  12951. y0 = y0items[j] + offset;
  12952. y1 = y1items[j];
  12953. y2 = y2items[j];
  12954. r = y0 + 1.402 * y2;
  12955. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  12956. b = y0 + 1.772 * y1;
  12957. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  12958. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  12959. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  12960. }
  12961. } else {
  12962. // inverse reversible multiple component transform
  12963. for (j = 0; j < jj; j++, pos += alpha01) {
  12964. y0 = y0items[j] + offset;
  12965. y1 = y1items[j];
  12966. y2 = y2items[j];
  12967. g = y0 - ((y2 + y1) >> 2);
  12968. r = g + y2;
  12969. b = g + y1;
  12970. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  12971. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  12972. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  12973. }
  12974. }
  12975. if (fourComponents) {
  12976. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  12977. k = y3items[j];
  12978. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  12979. }
  12980. }
  12981. } else { // no multi-component transform
  12982. for (c = 0; c < componentsCount; c++) {
  12983. var items = transformedTiles[c].items;
  12984. shift = components[c].precision - 8;
  12985. offset = (128 << shift) + 0.5;
  12986. max = (127.5 * (1 << shift));
  12987. min = -max;
  12988. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  12989. val = items[j];
  12990. out[pos] = val <= min ? 0 :
  12991. val >= max ? 255 : (val + offset) >> shift;
  12992. pos += componentsCount;
  12993. }
  12994. }
  12995. }
  12996. resultImages.push(result);
  12997. }
  12998. return resultImages;
  12999. }
  13000. function initializeTile(context, tileIndex) {
  13001. var siz = context.SIZ;
  13002. var componentsCount = siz.Csiz;
  13003. var tile = context.tiles[tileIndex];
  13004. for (var c = 0; c < componentsCount; c++) {
  13005. var component = tile.components[c];
  13006. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  13007. context.currentTile.QCC[c] : context.currentTile.QCD);
  13008. component.quantizationParameters = qcdOrQcc;
  13009. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  13010. context.currentTile.COC[c] : context.currentTile.COD);
  13011. component.codingStyleParameters = codOrCoc;
  13012. }
  13013. tile.codingStyleDefaultParameters = context.currentTile.COD;
  13014. }
  13015. // Section B.10.2 Tag trees
  13016. var TagTree = (function TagTreeClosure() {
  13017. function TagTree(width, height) {
  13018. var levelsLength = log2(Math.max(width, height)) + 1;
  13019. this.levels = [];
  13020. for (var i = 0; i < levelsLength; i++) {
  13021. var level = {
  13022. width: width,
  13023. height: height,
  13024. items: []
  13025. };
  13026. this.levels.push(level);
  13027. width = Math.ceil(width / 2);
  13028. height = Math.ceil(height / 2);
  13029. }
  13030. }
  13031. TagTree.prototype = {
  13032. reset: function TagTree_reset(i, j) {
  13033. var currentLevel = 0, value = 0, level;
  13034. while (currentLevel < this.levels.length) {
  13035. level = this.levels[currentLevel];
  13036. var index = i + j * level.width;
  13037. if (level.items[index] !== undefined) {
  13038. value = level.items[index];
  13039. break;
  13040. }
  13041. level.index = index;
  13042. i >>= 1;
  13043. j >>= 1;
  13044. currentLevel++;
  13045. }
  13046. currentLevel--;
  13047. level = this.levels[currentLevel];
  13048. level.items[level.index] = value;
  13049. this.currentLevel = currentLevel;
  13050. delete this.value;
  13051. },
  13052. incrementValue: function TagTree_incrementValue() {
  13053. var level = this.levels[this.currentLevel];
  13054. level.items[level.index]++;
  13055. },
  13056. nextLevel: function TagTree_nextLevel() {
  13057. var currentLevel = this.currentLevel;
  13058. var level = this.levels[currentLevel];
  13059. var value = level.items[level.index];
  13060. currentLevel--;
  13061. if (currentLevel < 0) {
  13062. this.value = value;
  13063. return false;
  13064. }
  13065. this.currentLevel = currentLevel;
  13066. level = this.levels[currentLevel];
  13067. level.items[level.index] = value;
  13068. return true;
  13069. }
  13070. };
  13071. return TagTree;
  13072. })();
  13073. var InclusionTree = (function InclusionTreeClosure() {
  13074. function InclusionTree(width, height, defaultValue) {
  13075. var levelsLength = log2(Math.max(width, height)) + 1;
  13076. this.levels = [];
  13077. for (var i = 0; i < levelsLength; i++) {
  13078. var items = new Uint8Array(width * height);
  13079. for (var j = 0, jj = items.length; j < jj; j++) {
  13080. items[j] = defaultValue;
  13081. }
  13082. var level = {
  13083. width: width,
  13084. height: height,
  13085. items: items
  13086. };
  13087. this.levels.push(level);
  13088. width = Math.ceil(width / 2);
  13089. height = Math.ceil(height / 2);
  13090. }
  13091. }
  13092. InclusionTree.prototype = {
  13093. reset: function InclusionTree_reset(i, j, stopValue) {
  13094. var currentLevel = 0;
  13095. while (currentLevel < this.levels.length) {
  13096. var level = this.levels[currentLevel];
  13097. var index = i + j * level.width;
  13098. level.index = index;
  13099. var value = level.items[index];
  13100. if (value === 0xFF) {
  13101. break;
  13102. }
  13103. if (value > stopValue) {
  13104. this.currentLevel = currentLevel;
  13105. // already know about this one, propagating the value to top levels
  13106. this.propagateValues();
  13107. return false;
  13108. }
  13109. i >>= 1;
  13110. j >>= 1;
  13111. currentLevel++;
  13112. }
  13113. this.currentLevel = currentLevel - 1;
  13114. return true;
  13115. },
  13116. incrementValue: function InclusionTree_incrementValue(stopValue) {
  13117. var level = this.levels[this.currentLevel];
  13118. level.items[level.index] = stopValue + 1;
  13119. this.propagateValues();
  13120. },
  13121. propagateValues: function InclusionTree_propagateValues() {
  13122. var levelIndex = this.currentLevel;
  13123. var level = this.levels[levelIndex];
  13124. var currentValue = level.items[level.index];
  13125. while (--levelIndex >= 0) {
  13126. level = this.levels[levelIndex];
  13127. level.items[level.index] = currentValue;
  13128. }
  13129. },
  13130. nextLevel: function InclusionTree_nextLevel() {
  13131. var currentLevel = this.currentLevel;
  13132. var level = this.levels[currentLevel];
  13133. var value = level.items[level.index];
  13134. level.items[level.index] = 0xFF;
  13135. currentLevel--;
  13136. if (currentLevel < 0) {
  13137. return false;
  13138. }
  13139. this.currentLevel = currentLevel;
  13140. level = this.levels[currentLevel];
  13141. level.items[level.index] = value;
  13142. return true;
  13143. }
  13144. };
  13145. return InclusionTree;
  13146. })();
  13147. // Section D. Coefficient bit modeling
  13148. var BitModel = (function BitModelClosure() {
  13149. var UNIFORM_CONTEXT = 17;
  13150. var RUNLENGTH_CONTEXT = 18;
  13151. // Table D-1
  13152. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  13153. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  13154. var LLAndLHContextsLabel = new Uint8Array([
  13155. 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,
  13156. 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,
  13157. 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
  13158. ]);
  13159. var HLContextLabel = new Uint8Array([
  13160. 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,
  13161. 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,
  13162. 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
  13163. ]);
  13164. var HHContextLabel = new Uint8Array([
  13165. 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,
  13166. 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,
  13167. 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
  13168. ]);
  13169. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  13170. this.width = width;
  13171. this.height = height;
  13172. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  13173. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  13174. var coefficientCount = width * height;
  13175. // coefficients outside the encoding region treated as insignificant
  13176. // add border state cells for significanceState
  13177. this.neighborsSignificance = new Uint8Array(coefficientCount);
  13178. this.coefficentsSign = new Uint8Array(coefficientCount);
  13179. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  13180. mb > 6 ? new Uint16Array(coefficientCount) :
  13181. new Uint8Array(coefficientCount);
  13182. this.processingFlags = new Uint8Array(coefficientCount);
  13183. var bitsDecoded = new Uint8Array(coefficientCount);
  13184. if (zeroBitPlanes !== 0) {
  13185. for (var i = 0; i < coefficientCount; i++) {
  13186. bitsDecoded[i] = zeroBitPlanes;
  13187. }
  13188. }
  13189. this.bitsDecoded = bitsDecoded;
  13190. this.reset();
  13191. }
  13192. BitModel.prototype = {
  13193. setDecoder: function BitModel_setDecoder(decoder) {
  13194. this.decoder = decoder;
  13195. },
  13196. reset: function BitModel_reset() {
  13197. // We have 17 contexts that are accessed via context labels,
  13198. // plus the uniform and runlength context.
  13199. this.contexts = new Int8Array(19);
  13200. // Contexts are packed into 1 byte:
  13201. // highest 7 bits carry the index, lowest bit carries mps
  13202. this.contexts[0] = (4 << 1) | 0;
  13203. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  13204. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  13205. },
  13206. setNeighborsSignificance:
  13207. function BitModel_setNeighborsSignificance(row, column, index) {
  13208. var neighborsSignificance = this.neighborsSignificance;
  13209. var width = this.width, height = this.height;
  13210. var left = (column > 0);
  13211. var right = (column + 1 < width);
  13212. var i;
  13213. if (row > 0) {
  13214. i = index - width;
  13215. if (left) {
  13216. neighborsSignificance[i - 1] += 0x10;
  13217. }
  13218. if (right) {
  13219. neighborsSignificance[i + 1] += 0x10;
  13220. }
  13221. neighborsSignificance[i] += 0x04;
  13222. }
  13223. if (row + 1 < height) {
  13224. i = index + width;
  13225. if (left) {
  13226. neighborsSignificance[i - 1] += 0x10;
  13227. }
  13228. if (right) {
  13229. neighborsSignificance[i + 1] += 0x10;
  13230. }
  13231. neighborsSignificance[i] += 0x04;
  13232. }
  13233. if (left) {
  13234. neighborsSignificance[index - 1] += 0x01;
  13235. }
  13236. if (right) {
  13237. neighborsSignificance[index + 1] += 0x01;
  13238. }
  13239. neighborsSignificance[index] |= 0x80;
  13240. },
  13241. runSignificancePropagationPass:
  13242. function BitModel_runSignificancePropagationPass() {
  13243. var decoder = this.decoder;
  13244. var width = this.width, height = this.height;
  13245. var coefficentsMagnitude = this.coefficentsMagnitude;
  13246. var coefficentsSign = this.coefficentsSign;
  13247. var neighborsSignificance = this.neighborsSignificance;
  13248. var processingFlags = this.processingFlags;
  13249. var contexts = this.contexts;
  13250. var labels = this.contextLabelTable;
  13251. var bitsDecoded = this.bitsDecoded;
  13252. var processedInverseMask = ~1;
  13253. var processedMask = 1;
  13254. var firstMagnitudeBitMask = 2;
  13255. for (var i0 = 0; i0 < height; i0 += 4) {
  13256. for (var j = 0; j < width; j++) {
  13257. var index = i0 * width + j;
  13258. for (var i1 = 0; i1 < 4; i1++, index += width) {
  13259. var i = i0 + i1;
  13260. if (i >= height) {
  13261. break;
  13262. }
  13263. // clear processed flag first
  13264. processingFlags[index] &= processedInverseMask;
  13265. if (coefficentsMagnitude[index] ||
  13266. !neighborsSignificance[index]) {
  13267. continue;
  13268. }
  13269. var contextLabel = labels[neighborsSignificance[index]];
  13270. var decision = decoder.readBit(contexts, contextLabel);
  13271. if (decision) {
  13272. var sign = this.decodeSignBit(i, j, index);
  13273. coefficentsSign[index] = sign;
  13274. coefficentsMagnitude[index] = 1;
  13275. this.setNeighborsSignificance(i, j, index);
  13276. processingFlags[index] |= firstMagnitudeBitMask;
  13277. }
  13278. bitsDecoded[index]++;
  13279. processingFlags[index] |= processedMask;
  13280. }
  13281. }
  13282. }
  13283. },
  13284. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  13285. var width = this.width, height = this.height;
  13286. var coefficentsMagnitude = this.coefficentsMagnitude;
  13287. var coefficentsSign = this.coefficentsSign;
  13288. var contribution, sign0, sign1, significance1;
  13289. var contextLabel, decoded;
  13290. // calculate horizontal contribution
  13291. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  13292. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  13293. sign1 = coefficentsSign[index + 1];
  13294. if (significance1) {
  13295. sign0 = coefficentsSign[index - 1];
  13296. contribution = 1 - sign1 - sign0;
  13297. } else {
  13298. contribution = 1 - sign1 - sign1;
  13299. }
  13300. } else if (significance1) {
  13301. sign0 = coefficentsSign[index - 1];
  13302. contribution = 1 - sign0 - sign0;
  13303. } else {
  13304. contribution = 0;
  13305. }
  13306. var horizontalContribution = 3 * contribution;
  13307. // calculate vertical contribution and combine with the horizontal
  13308. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  13309. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  13310. sign1 = coefficentsSign[index + width];
  13311. if (significance1) {
  13312. sign0 = coefficentsSign[index - width];
  13313. contribution = 1 - sign1 - sign0 + horizontalContribution;
  13314. } else {
  13315. contribution = 1 - sign1 - sign1 + horizontalContribution;
  13316. }
  13317. } else if (significance1) {
  13318. sign0 = coefficentsSign[index - width];
  13319. contribution = 1 - sign0 - sign0 + horizontalContribution;
  13320. } else {
  13321. contribution = horizontalContribution;
  13322. }
  13323. if (contribution >= 0) {
  13324. contextLabel = 9 + contribution;
  13325. decoded = this.decoder.readBit(this.contexts, contextLabel);
  13326. } else {
  13327. contextLabel = 9 - contribution;
  13328. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  13329. }
  13330. return decoded;
  13331. },
  13332. runMagnitudeRefinementPass:
  13333. function BitModel_runMagnitudeRefinementPass() {
  13334. var decoder = this.decoder;
  13335. var width = this.width, height = this.height;
  13336. var coefficentsMagnitude = this.coefficentsMagnitude;
  13337. var neighborsSignificance = this.neighborsSignificance;
  13338. var contexts = this.contexts;
  13339. var bitsDecoded = this.bitsDecoded;
  13340. var processingFlags = this.processingFlags;
  13341. var processedMask = 1;
  13342. var firstMagnitudeBitMask = 2;
  13343. var length = width * height;
  13344. var width4 = width * 4;
  13345. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  13346. indexNext = Math.min(length, index0 + width4);
  13347. for (var j = 0; j < width; j++) {
  13348. for (var index = index0 + j; index < indexNext; index += width) {
  13349. // significant but not those that have just become
  13350. if (!coefficentsMagnitude[index] ||
  13351. (processingFlags[index] & processedMask) !== 0) {
  13352. continue;
  13353. }
  13354. var contextLabel = 16;
  13355. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  13356. processingFlags[index] ^= firstMagnitudeBitMask;
  13357. // first refinement
  13358. var significance = neighborsSignificance[index] & 127;
  13359. contextLabel = significance === 0 ? 15 : 14;
  13360. }
  13361. var bit = decoder.readBit(contexts, contextLabel);
  13362. coefficentsMagnitude[index] =
  13363. (coefficentsMagnitude[index] << 1) | bit;
  13364. bitsDecoded[index]++;
  13365. processingFlags[index] |= processedMask;
  13366. }
  13367. }
  13368. }
  13369. },
  13370. runCleanupPass: function BitModel_runCleanupPass() {
  13371. var decoder = this.decoder;
  13372. var width = this.width, height = this.height;
  13373. var neighborsSignificance = this.neighborsSignificance;
  13374. var coefficentsMagnitude = this.coefficentsMagnitude;
  13375. var coefficentsSign = this.coefficentsSign;
  13376. var contexts = this.contexts;
  13377. var labels = this.contextLabelTable;
  13378. var bitsDecoded = this.bitsDecoded;
  13379. var processingFlags = this.processingFlags;
  13380. var processedMask = 1;
  13381. var firstMagnitudeBitMask = 2;
  13382. var oneRowDown = width;
  13383. var twoRowsDown = width * 2;
  13384. var threeRowsDown = width * 3;
  13385. var iNext;
  13386. for (var i0 = 0; i0 < height; i0 = iNext) {
  13387. iNext = Math.min(i0 + 4, height);
  13388. var indexBase = i0 * width;
  13389. var checkAllEmpty = i0 + 3 < height;
  13390. for (var j = 0; j < width; j++) {
  13391. var index0 = indexBase + j;
  13392. // using the property: labels[neighborsSignificance[index]] === 0
  13393. // when neighborsSignificance[index] === 0
  13394. var allEmpty = (checkAllEmpty &&
  13395. processingFlags[index0] === 0 &&
  13396. processingFlags[index0 + oneRowDown] === 0 &&
  13397. processingFlags[index0 + twoRowsDown] === 0 &&
  13398. processingFlags[index0 + threeRowsDown] === 0 &&
  13399. neighborsSignificance[index0] === 0 &&
  13400. neighborsSignificance[index0 + oneRowDown] === 0 &&
  13401. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  13402. neighborsSignificance[index0 + threeRowsDown] === 0);
  13403. var i1 = 0, index = index0;
  13404. var i = i0, sign;
  13405. if (allEmpty) {
  13406. var hasSignificantCoefficent =
  13407. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  13408. if (!hasSignificantCoefficent) {
  13409. bitsDecoded[index0]++;
  13410. bitsDecoded[index0 + oneRowDown]++;
  13411. bitsDecoded[index0 + twoRowsDown]++;
  13412. bitsDecoded[index0 + threeRowsDown]++;
  13413. continue; // next column
  13414. }
  13415. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  13416. decoder.readBit(contexts, UNIFORM_CONTEXT);
  13417. if (i1 !== 0) {
  13418. i = i0 + i1;
  13419. index += i1 * width;
  13420. }
  13421. sign = this.decodeSignBit(i, j, index);
  13422. coefficentsSign[index] = sign;
  13423. coefficentsMagnitude[index] = 1;
  13424. this.setNeighborsSignificance(i, j, index);
  13425. processingFlags[index] |= firstMagnitudeBitMask;
  13426. index = index0;
  13427. for (var i2 = i0; i2 <= i; i2++, index += width) {
  13428. bitsDecoded[index]++;
  13429. }
  13430. i1++;
  13431. }
  13432. for (i = i0 + i1; i < iNext; i++, index += width) {
  13433. if (coefficentsMagnitude[index] ||
  13434. (processingFlags[index] & processedMask) !== 0) {
  13435. continue;
  13436. }
  13437. var contextLabel = labels[neighborsSignificance[index]];
  13438. var decision = decoder.readBit(contexts, contextLabel);
  13439. if (decision === 1) {
  13440. sign = this.decodeSignBit(i, j, index);
  13441. coefficentsSign[index] = sign;
  13442. coefficentsMagnitude[index] = 1;
  13443. this.setNeighborsSignificance(i, j, index);
  13444. processingFlags[index] |= firstMagnitudeBitMask;
  13445. }
  13446. bitsDecoded[index]++;
  13447. }
  13448. }
  13449. }
  13450. },
  13451. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  13452. var decoder = this.decoder;
  13453. var contexts = this.contexts;
  13454. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  13455. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  13456. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  13457. decoder.readBit(contexts, UNIFORM_CONTEXT);
  13458. if (symbol !== 0xA) {
  13459. error('JPX Error: Invalid segmentation symbol');
  13460. }
  13461. }
  13462. };
  13463. return BitModel;
  13464. })();
  13465. // Section F, Discrete wavelet transformation
  13466. var Transform = (function TransformClosure() {
  13467. function Transform() {}
  13468. Transform.prototype.calculate =
  13469. function transformCalculate(subbands, u0, v0) {
  13470. var ll = subbands[0];
  13471. for (var i = 1, ii = subbands.length; i < ii; i++) {
  13472. ll = this.iterate(ll, subbands[i], u0, v0);
  13473. }
  13474. return ll;
  13475. };
  13476. Transform.prototype.extend = function extend(buffer, offset, size) {
  13477. // Section F.3.7 extending... using max extension of 4
  13478. var i1 = offset - 1, j1 = offset + 1;
  13479. var i2 = offset + size - 2, j2 = offset + size;
  13480. buffer[i1--] = buffer[j1++];
  13481. buffer[j2++] = buffer[i2--];
  13482. buffer[i1--] = buffer[j1++];
  13483. buffer[j2++] = buffer[i2--];
  13484. buffer[i1--] = buffer[j1++];
  13485. buffer[j2++] = buffer[i2--];
  13486. buffer[i1] = buffer[j1];
  13487. buffer[j2] = buffer[i2];
  13488. };
  13489. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  13490. u0, v0) {
  13491. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  13492. var width = hl_lh_hh.width;
  13493. var height = hl_lh_hh.height;
  13494. var items = hl_lh_hh.items;
  13495. var i, j, k, l, u, v;
  13496. // Interleave LL according to Section F.3.3
  13497. for (k = 0, i = 0; i < llHeight; i++) {
  13498. l = i * 2 * width;
  13499. for (j = 0; j < llWidth; j++, k++, l += 2) {
  13500. items[l] = llItems[k];
  13501. }
  13502. }
  13503. // The LL band is not needed anymore.
  13504. llItems = ll.items = null;
  13505. var bufferPadding = 4;
  13506. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  13507. // Section F.3.4 HOR_SR
  13508. if (width === 1) {
  13509. // if width = 1, when u0 even keep items as is, when odd divide by 2
  13510. if ((u0 & 1) !== 0) {
  13511. for (v = 0, k = 0; v < height; v++, k += width) {
  13512. items[k] *= 0.5;
  13513. }
  13514. }
  13515. } else {
  13516. for (v = 0, k = 0; v < height; v++, k += width) {
  13517. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  13518. this.extend(rowBuffer, bufferPadding, width);
  13519. this.filter(rowBuffer, bufferPadding, width);
  13520. items.set(
  13521. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  13522. k);
  13523. }
  13524. }
  13525. // Accesses to the items array can take long, because it may not fit into
  13526. // CPU cache and has to be fetched from main memory. Since subsequent
  13527. // accesses to the items array are not local when reading columns, we
  13528. // have a cache miss every time. To reduce cache misses, get up to
  13529. // 'numBuffers' items at a time and store them into the individual
  13530. // buffers. The colBuffers should be small enough to fit into CPU cache.
  13531. var numBuffers = 16;
  13532. var colBuffers = [];
  13533. for (i = 0; i < numBuffers; i++) {
  13534. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  13535. }
  13536. var b, currentBuffer = 0;
  13537. ll = bufferPadding + height;
  13538. // Section F.3.5 VER_SR
  13539. if (height === 1) {
  13540. // if height = 1, when v0 even keep items as is, when odd divide by 2
  13541. if ((v0 & 1) !== 0) {
  13542. for (u = 0; u < width; u++) {
  13543. items[u] *= 0.5;
  13544. }
  13545. }
  13546. } else {
  13547. for (u = 0; u < width; u++) {
  13548. // if we ran out of buffers, copy several image columns at once
  13549. if (currentBuffer === 0) {
  13550. numBuffers = Math.min(width - u, numBuffers);
  13551. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  13552. for (b = 0; b < numBuffers; b++) {
  13553. colBuffers[b][l] = items[k + b];
  13554. }
  13555. }
  13556. currentBuffer = numBuffers;
  13557. }
  13558. currentBuffer--;
  13559. var buffer = colBuffers[currentBuffer];
  13560. this.extend(buffer, bufferPadding, height);
  13561. this.filter(buffer, bufferPadding, height);
  13562. // If this is last buffer in this group of buffers, flush all buffers.
  13563. if (currentBuffer === 0) {
  13564. k = u - numBuffers + 1;
  13565. for (l = bufferPadding; l < ll; k += width, l++) {
  13566. for (b = 0; b < numBuffers; b++) {
  13567. items[k + b] = colBuffers[b][l];
  13568. }
  13569. }
  13570. }
  13571. }
  13572. }
  13573. return {
  13574. width: width,
  13575. height: height,
  13576. items: items
  13577. };
  13578. };
  13579. return Transform;
  13580. })();
  13581. // Section 3.8.2 Irreversible 9-7 filter
  13582. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  13583. function IrreversibleTransform() {
  13584. Transform.call(this);
  13585. }
  13586. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  13587. IrreversibleTransform.prototype.filter =
  13588. function irreversibleTransformFilter(x, offset, length) {
  13589. var len = length >> 1;
  13590. offset = offset | 0;
  13591. var j, n, current, next;
  13592. var alpha = -1.586134342059924;
  13593. var beta = -0.052980118572961;
  13594. var gamma = 0.882911075530934;
  13595. var delta = 0.443506852043971;
  13596. var K = 1.230174104914001;
  13597. var K_ = 1 / K;
  13598. // step 1 is combined with step 3
  13599. // step 2
  13600. j = offset - 3;
  13601. for (n = len + 4; n--; j += 2) {
  13602. x[j] *= K_;
  13603. }
  13604. // step 1 & 3
  13605. j = offset - 2;
  13606. current = delta * x[j -1];
  13607. for (n = len + 3; n--; j += 2) {
  13608. next = delta * x[j + 1];
  13609. x[j] = K * x[j] - current - next;
  13610. if (n--) {
  13611. j += 2;
  13612. current = delta * x[j + 1];
  13613. x[j] = K * x[j] - current - next;
  13614. } else {
  13615. break;
  13616. }
  13617. }
  13618. // step 4
  13619. j = offset - 1;
  13620. current = gamma * x[j - 1];
  13621. for (n = len + 2; n--; j += 2) {
  13622. next = gamma * x[j + 1];
  13623. x[j] -= current + next;
  13624. if (n--) {
  13625. j += 2;
  13626. current = gamma * x[j + 1];
  13627. x[j] -= current + next;
  13628. } else {
  13629. break;
  13630. }
  13631. }
  13632. // step 5
  13633. j = offset;
  13634. current = beta * x[j - 1];
  13635. for (n = len + 1; n--; j += 2) {
  13636. next = beta * x[j + 1];
  13637. x[j] -= current + next;
  13638. if (n--) {
  13639. j += 2;
  13640. current = beta * x[j + 1];
  13641. x[j] -= current + next;
  13642. } else {
  13643. break;
  13644. }
  13645. }
  13646. // step 6
  13647. if (len !== 0) {
  13648. j = offset + 1;
  13649. current = alpha * x[j - 1];
  13650. for (n = len; n--; j += 2) {
  13651. next = alpha * x[j + 1];
  13652. x[j] -= current + next;
  13653. if (n--) {
  13654. j += 2;
  13655. current = alpha * x[j + 1];
  13656. x[j] -= current + next;
  13657. } else {
  13658. break;
  13659. }
  13660. }
  13661. }
  13662. };
  13663. return IrreversibleTransform;
  13664. })();
  13665. // Section 3.8.1 Reversible 5-3 filter
  13666. var ReversibleTransform = (function ReversibleTransformClosure() {
  13667. function ReversibleTransform() {
  13668. Transform.call(this);
  13669. }
  13670. ReversibleTransform.prototype = Object.create(Transform.prototype);
  13671. ReversibleTransform.prototype.filter =
  13672. function reversibleTransformFilter(x, offset, length) {
  13673. var len = length >> 1;
  13674. offset = offset | 0;
  13675. var j, n;
  13676. for (j = offset, n = len + 1; n--; j += 2) {
  13677. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  13678. }
  13679. for (j = offset + 1, n = len; n--; j += 2) {
  13680. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  13681. }
  13682. };
  13683. return ReversibleTransform;
  13684. })();
  13685. return JpxImage;
  13686. })();
  13687. exports.JpxImage = JpxImage;
  13688. }));
  13689. (function (root, factory) {
  13690. {
  13691. factory((root.pdfjsCoreMetrics = {}), root.pdfjsSharedUtil);
  13692. }
  13693. }(this, function (exports, sharedUtil) {
  13694. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  13695. // The Metrics object contains glyph widths (in glyph space units).
  13696. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  13697. // space unit corresponds to 1/1000th of text space unit.
  13698. var getMetrics = getLookupTableFactory(function (t) {
  13699. t['Courier'] = 600;
  13700. t['Courier-Bold'] = 600;
  13701. t['Courier-BoldOblique'] = 600;
  13702. t['Courier-Oblique'] = 600;
  13703. t['Helvetica'] = getLookupTableFactory(function (t) {
  13704. t['space'] = 278;
  13705. t['exclam'] = 278;
  13706. t['quotedbl'] = 355;
  13707. t['numbersign'] = 556;
  13708. t['dollar'] = 556;
  13709. t['percent'] = 889;
  13710. t['ampersand'] = 667;
  13711. t['quoteright'] = 222;
  13712. t['parenleft'] = 333;
  13713. t['parenright'] = 333;
  13714. t['asterisk'] = 389;
  13715. t['plus'] = 584;
  13716. t['comma'] = 278;
  13717. t['hyphen'] = 333;
  13718. t['period'] = 278;
  13719. t['slash'] = 278;
  13720. t['zero'] = 556;
  13721. t['one'] = 556;
  13722. t['two'] = 556;
  13723. t['three'] = 556;
  13724. t['four'] = 556;
  13725. t['five'] = 556;
  13726. t['six'] = 556;
  13727. t['seven'] = 556;
  13728. t['eight'] = 556;
  13729. t['nine'] = 556;
  13730. t['colon'] = 278;
  13731. t['semicolon'] = 278;
  13732. t['less'] = 584;
  13733. t['equal'] = 584;
  13734. t['greater'] = 584;
  13735. t['question'] = 556;
  13736. t['at'] = 1015;
  13737. t['A'] = 667;
  13738. t['B'] = 667;
  13739. t['C'] = 722;
  13740. t['D'] = 722;
  13741. t['E'] = 667;
  13742. t['F'] = 611;
  13743. t['G'] = 778;
  13744. t['H'] = 722;
  13745. t['I'] = 278;
  13746. t['J'] = 500;
  13747. t['K'] = 667;
  13748. t['L'] = 556;
  13749. t['M'] = 833;
  13750. t['N'] = 722;
  13751. t['O'] = 778;
  13752. t['P'] = 667;
  13753. t['Q'] = 778;
  13754. t['R'] = 722;
  13755. t['S'] = 667;
  13756. t['T'] = 611;
  13757. t['U'] = 722;
  13758. t['V'] = 667;
  13759. t['W'] = 944;
  13760. t['X'] = 667;
  13761. t['Y'] = 667;
  13762. t['Z'] = 611;
  13763. t['bracketleft'] = 278;
  13764. t['backslash'] = 278;
  13765. t['bracketright'] = 278;
  13766. t['asciicircum'] = 469;
  13767. t['underscore'] = 556;
  13768. t['quoteleft'] = 222;
  13769. t['a'] = 556;
  13770. t['b'] = 556;
  13771. t['c'] = 500;
  13772. t['d'] = 556;
  13773. t['e'] = 556;
  13774. t['f'] = 278;
  13775. t['g'] = 556;
  13776. t['h'] = 556;
  13777. t['i'] = 222;
  13778. t['j'] = 222;
  13779. t['k'] = 500;
  13780. t['l'] = 222;
  13781. t['m'] = 833;
  13782. t['n'] = 556;
  13783. t['o'] = 556;
  13784. t['p'] = 556;
  13785. t['q'] = 556;
  13786. t['r'] = 333;
  13787. t['s'] = 500;
  13788. t['t'] = 278;
  13789. t['u'] = 556;
  13790. t['v'] = 500;
  13791. t['w'] = 722;
  13792. t['x'] = 500;
  13793. t['y'] = 500;
  13794. t['z'] = 500;
  13795. t['braceleft'] = 334;
  13796. t['bar'] = 260;
  13797. t['braceright'] = 334;
  13798. t['asciitilde'] = 584;
  13799. t['exclamdown'] = 333;
  13800. t['cent'] = 556;
  13801. t['sterling'] = 556;
  13802. t['fraction'] = 167;
  13803. t['yen'] = 556;
  13804. t['florin'] = 556;
  13805. t['section'] = 556;
  13806. t['currency'] = 556;
  13807. t['quotesingle'] = 191;
  13808. t['quotedblleft'] = 333;
  13809. t['guillemotleft'] = 556;
  13810. t['guilsinglleft'] = 333;
  13811. t['guilsinglright'] = 333;
  13812. t['fi'] = 500;
  13813. t['fl'] = 500;
  13814. t['endash'] = 556;
  13815. t['dagger'] = 556;
  13816. t['daggerdbl'] = 556;
  13817. t['periodcentered'] = 278;
  13818. t['paragraph'] = 537;
  13819. t['bullet'] = 350;
  13820. t['quotesinglbase'] = 222;
  13821. t['quotedblbase'] = 333;
  13822. t['quotedblright'] = 333;
  13823. t['guillemotright'] = 556;
  13824. t['ellipsis'] = 1000;
  13825. t['perthousand'] = 1000;
  13826. t['questiondown'] = 611;
  13827. t['grave'] = 333;
  13828. t['acute'] = 333;
  13829. t['circumflex'] = 333;
  13830. t['tilde'] = 333;
  13831. t['macron'] = 333;
  13832. t['breve'] = 333;
  13833. t['dotaccent'] = 333;
  13834. t['dieresis'] = 333;
  13835. t['ring'] = 333;
  13836. t['cedilla'] = 333;
  13837. t['hungarumlaut'] = 333;
  13838. t['ogonek'] = 333;
  13839. t['caron'] = 333;
  13840. t['emdash'] = 1000;
  13841. t['AE'] = 1000;
  13842. t['ordfeminine'] = 370;
  13843. t['Lslash'] = 556;
  13844. t['Oslash'] = 778;
  13845. t['OE'] = 1000;
  13846. t['ordmasculine'] = 365;
  13847. t['ae'] = 889;
  13848. t['dotlessi'] = 278;
  13849. t['lslash'] = 222;
  13850. t['oslash'] = 611;
  13851. t['oe'] = 944;
  13852. t['germandbls'] = 611;
  13853. t['Idieresis'] = 278;
  13854. t['eacute'] = 556;
  13855. t['abreve'] = 556;
  13856. t['uhungarumlaut'] = 556;
  13857. t['ecaron'] = 556;
  13858. t['Ydieresis'] = 667;
  13859. t['divide'] = 584;
  13860. t['Yacute'] = 667;
  13861. t['Acircumflex'] = 667;
  13862. t['aacute'] = 556;
  13863. t['Ucircumflex'] = 722;
  13864. t['yacute'] = 500;
  13865. t['scommaaccent'] = 500;
  13866. t['ecircumflex'] = 556;
  13867. t['Uring'] = 722;
  13868. t['Udieresis'] = 722;
  13869. t['aogonek'] = 556;
  13870. t['Uacute'] = 722;
  13871. t['uogonek'] = 556;
  13872. t['Edieresis'] = 667;
  13873. t['Dcroat'] = 722;
  13874. t['commaaccent'] = 250;
  13875. t['copyright'] = 737;
  13876. t['Emacron'] = 667;
  13877. t['ccaron'] = 500;
  13878. t['aring'] = 556;
  13879. t['Ncommaaccent'] = 722;
  13880. t['lacute'] = 222;
  13881. t['agrave'] = 556;
  13882. t['Tcommaaccent'] = 611;
  13883. t['Cacute'] = 722;
  13884. t['atilde'] = 556;
  13885. t['Edotaccent'] = 667;
  13886. t['scaron'] = 500;
  13887. t['scedilla'] = 500;
  13888. t['iacute'] = 278;
  13889. t['lozenge'] = 471;
  13890. t['Rcaron'] = 722;
  13891. t['Gcommaaccent'] = 778;
  13892. t['ucircumflex'] = 556;
  13893. t['acircumflex'] = 556;
  13894. t['Amacron'] = 667;
  13895. t['rcaron'] = 333;
  13896. t['ccedilla'] = 500;
  13897. t['Zdotaccent'] = 611;
  13898. t['Thorn'] = 667;
  13899. t['Omacron'] = 778;
  13900. t['Racute'] = 722;
  13901. t['Sacute'] = 667;
  13902. t['dcaron'] = 643;
  13903. t['Umacron'] = 722;
  13904. t['uring'] = 556;
  13905. t['threesuperior'] = 333;
  13906. t['Ograve'] = 778;
  13907. t['Agrave'] = 667;
  13908. t['Abreve'] = 667;
  13909. t['multiply'] = 584;
  13910. t['uacute'] = 556;
  13911. t['Tcaron'] = 611;
  13912. t['partialdiff'] = 476;
  13913. t['ydieresis'] = 500;
  13914. t['Nacute'] = 722;
  13915. t['icircumflex'] = 278;
  13916. t['Ecircumflex'] = 667;
  13917. t['adieresis'] = 556;
  13918. t['edieresis'] = 556;
  13919. t['cacute'] = 500;
  13920. t['nacute'] = 556;
  13921. t['umacron'] = 556;
  13922. t['Ncaron'] = 722;
  13923. t['Iacute'] = 278;
  13924. t['plusminus'] = 584;
  13925. t['brokenbar'] = 260;
  13926. t['registered'] = 737;
  13927. t['Gbreve'] = 778;
  13928. t['Idotaccent'] = 278;
  13929. t['summation'] = 600;
  13930. t['Egrave'] = 667;
  13931. t['racute'] = 333;
  13932. t['omacron'] = 556;
  13933. t['Zacute'] = 611;
  13934. t['Zcaron'] = 611;
  13935. t['greaterequal'] = 549;
  13936. t['Eth'] = 722;
  13937. t['Ccedilla'] = 722;
  13938. t['lcommaaccent'] = 222;
  13939. t['tcaron'] = 317;
  13940. t['eogonek'] = 556;
  13941. t['Uogonek'] = 722;
  13942. t['Aacute'] = 667;
  13943. t['Adieresis'] = 667;
  13944. t['egrave'] = 556;
  13945. t['zacute'] = 500;
  13946. t['iogonek'] = 222;
  13947. t['Oacute'] = 778;
  13948. t['oacute'] = 556;
  13949. t['amacron'] = 556;
  13950. t['sacute'] = 500;
  13951. t['idieresis'] = 278;
  13952. t['Ocircumflex'] = 778;
  13953. t['Ugrave'] = 722;
  13954. t['Delta'] = 612;
  13955. t['thorn'] = 556;
  13956. t['twosuperior'] = 333;
  13957. t['Odieresis'] = 778;
  13958. t['mu'] = 556;
  13959. t['igrave'] = 278;
  13960. t['ohungarumlaut'] = 556;
  13961. t['Eogonek'] = 667;
  13962. t['dcroat'] = 556;
  13963. t['threequarters'] = 834;
  13964. t['Scedilla'] = 667;
  13965. t['lcaron'] = 299;
  13966. t['Kcommaaccent'] = 667;
  13967. t['Lacute'] = 556;
  13968. t['trademark'] = 1000;
  13969. t['edotaccent'] = 556;
  13970. t['Igrave'] = 278;
  13971. t['Imacron'] = 278;
  13972. t['Lcaron'] = 556;
  13973. t['onehalf'] = 834;
  13974. t['lessequal'] = 549;
  13975. t['ocircumflex'] = 556;
  13976. t['ntilde'] = 556;
  13977. t['Uhungarumlaut'] = 722;
  13978. t['Eacute'] = 667;
  13979. t['emacron'] = 556;
  13980. t['gbreve'] = 556;
  13981. t['onequarter'] = 834;
  13982. t['Scaron'] = 667;
  13983. t['Scommaaccent'] = 667;
  13984. t['Ohungarumlaut'] = 778;
  13985. t['degree'] = 400;
  13986. t['ograve'] = 556;
  13987. t['Ccaron'] = 722;
  13988. t['ugrave'] = 556;
  13989. t['radical'] = 453;
  13990. t['Dcaron'] = 722;
  13991. t['rcommaaccent'] = 333;
  13992. t['Ntilde'] = 722;
  13993. t['otilde'] = 556;
  13994. t['Rcommaaccent'] = 722;
  13995. t['Lcommaaccent'] = 556;
  13996. t['Atilde'] = 667;
  13997. t['Aogonek'] = 667;
  13998. t['Aring'] = 667;
  13999. t['Otilde'] = 778;
  14000. t['zdotaccent'] = 500;
  14001. t['Ecaron'] = 667;
  14002. t['Iogonek'] = 278;
  14003. t['kcommaaccent'] = 500;
  14004. t['minus'] = 584;
  14005. t['Icircumflex'] = 278;
  14006. t['ncaron'] = 556;
  14007. t['tcommaaccent'] = 278;
  14008. t['logicalnot'] = 584;
  14009. t['odieresis'] = 556;
  14010. t['udieresis'] = 556;
  14011. t['notequal'] = 549;
  14012. t['gcommaaccent'] = 556;
  14013. t['eth'] = 556;
  14014. t['zcaron'] = 500;
  14015. t['ncommaaccent'] = 556;
  14016. t['onesuperior'] = 333;
  14017. t['imacron'] = 278;
  14018. t['Euro'] = 556;
  14019. });
  14020. t['Helvetica-Bold'] = getLookupTableFactory(function (t) {
  14021. t['space'] = 278;
  14022. t['exclam'] = 333;
  14023. t['quotedbl'] = 474;
  14024. t['numbersign'] = 556;
  14025. t['dollar'] = 556;
  14026. t['percent'] = 889;
  14027. t['ampersand'] = 722;
  14028. t['quoteright'] = 278;
  14029. t['parenleft'] = 333;
  14030. t['parenright'] = 333;
  14031. t['asterisk'] = 389;
  14032. t['plus'] = 584;
  14033. t['comma'] = 278;
  14034. t['hyphen'] = 333;
  14035. t['period'] = 278;
  14036. t['slash'] = 278;
  14037. t['zero'] = 556;
  14038. t['one'] = 556;
  14039. t['two'] = 556;
  14040. t['three'] = 556;
  14041. t['four'] = 556;
  14042. t['five'] = 556;
  14043. t['six'] = 556;
  14044. t['seven'] = 556;
  14045. t['eight'] = 556;
  14046. t['nine'] = 556;
  14047. t['colon'] = 333;
  14048. t['semicolon'] = 333;
  14049. t['less'] = 584;
  14050. t['equal'] = 584;
  14051. t['greater'] = 584;
  14052. t['question'] = 611;
  14053. t['at'] = 975;
  14054. t['A'] = 722;
  14055. t['B'] = 722;
  14056. t['C'] = 722;
  14057. t['D'] = 722;
  14058. t['E'] = 667;
  14059. t['F'] = 611;
  14060. t['G'] = 778;
  14061. t['H'] = 722;
  14062. t['I'] = 278;
  14063. t['J'] = 556;
  14064. t['K'] = 722;
  14065. t['L'] = 611;
  14066. t['M'] = 833;
  14067. t['N'] = 722;
  14068. t['O'] = 778;
  14069. t['P'] = 667;
  14070. t['Q'] = 778;
  14071. t['R'] = 722;
  14072. t['S'] = 667;
  14073. t['T'] = 611;
  14074. t['U'] = 722;
  14075. t['V'] = 667;
  14076. t['W'] = 944;
  14077. t['X'] = 667;
  14078. t['Y'] = 667;
  14079. t['Z'] = 611;
  14080. t['bracketleft'] = 333;
  14081. t['backslash'] = 278;
  14082. t['bracketright'] = 333;
  14083. t['asciicircum'] = 584;
  14084. t['underscore'] = 556;
  14085. t['quoteleft'] = 278;
  14086. t['a'] = 556;
  14087. t['b'] = 611;
  14088. t['c'] = 556;
  14089. t['d'] = 611;
  14090. t['e'] = 556;
  14091. t['f'] = 333;
  14092. t['g'] = 611;
  14093. t['h'] = 611;
  14094. t['i'] = 278;
  14095. t['j'] = 278;
  14096. t['k'] = 556;
  14097. t['l'] = 278;
  14098. t['m'] = 889;
  14099. t['n'] = 611;
  14100. t['o'] = 611;
  14101. t['p'] = 611;
  14102. t['q'] = 611;
  14103. t['r'] = 389;
  14104. t['s'] = 556;
  14105. t['t'] = 333;
  14106. t['u'] = 611;
  14107. t['v'] = 556;
  14108. t['w'] = 778;
  14109. t['x'] = 556;
  14110. t['y'] = 556;
  14111. t['z'] = 500;
  14112. t['braceleft'] = 389;
  14113. t['bar'] = 280;
  14114. t['braceright'] = 389;
  14115. t['asciitilde'] = 584;
  14116. t['exclamdown'] = 333;
  14117. t['cent'] = 556;
  14118. t['sterling'] = 556;
  14119. t['fraction'] = 167;
  14120. t['yen'] = 556;
  14121. t['florin'] = 556;
  14122. t['section'] = 556;
  14123. t['currency'] = 556;
  14124. t['quotesingle'] = 238;
  14125. t['quotedblleft'] = 500;
  14126. t['guillemotleft'] = 556;
  14127. t['guilsinglleft'] = 333;
  14128. t['guilsinglright'] = 333;
  14129. t['fi'] = 611;
  14130. t['fl'] = 611;
  14131. t['endash'] = 556;
  14132. t['dagger'] = 556;
  14133. t['daggerdbl'] = 556;
  14134. t['periodcentered'] = 278;
  14135. t['paragraph'] = 556;
  14136. t['bullet'] = 350;
  14137. t['quotesinglbase'] = 278;
  14138. t['quotedblbase'] = 500;
  14139. t['quotedblright'] = 500;
  14140. t['guillemotright'] = 556;
  14141. t['ellipsis'] = 1000;
  14142. t['perthousand'] = 1000;
  14143. t['questiondown'] = 611;
  14144. t['grave'] = 333;
  14145. t['acute'] = 333;
  14146. t['circumflex'] = 333;
  14147. t['tilde'] = 333;
  14148. t['macron'] = 333;
  14149. t['breve'] = 333;
  14150. t['dotaccent'] = 333;
  14151. t['dieresis'] = 333;
  14152. t['ring'] = 333;
  14153. t['cedilla'] = 333;
  14154. t['hungarumlaut'] = 333;
  14155. t['ogonek'] = 333;
  14156. t['caron'] = 333;
  14157. t['emdash'] = 1000;
  14158. t['AE'] = 1000;
  14159. t['ordfeminine'] = 370;
  14160. t['Lslash'] = 611;
  14161. t['Oslash'] = 778;
  14162. t['OE'] = 1000;
  14163. t['ordmasculine'] = 365;
  14164. t['ae'] = 889;
  14165. t['dotlessi'] = 278;
  14166. t['lslash'] = 278;
  14167. t['oslash'] = 611;
  14168. t['oe'] = 944;
  14169. t['germandbls'] = 611;
  14170. t['Idieresis'] = 278;
  14171. t['eacute'] = 556;
  14172. t['abreve'] = 556;
  14173. t['uhungarumlaut'] = 611;
  14174. t['ecaron'] = 556;
  14175. t['Ydieresis'] = 667;
  14176. t['divide'] = 584;
  14177. t['Yacute'] = 667;
  14178. t['Acircumflex'] = 722;
  14179. t['aacute'] = 556;
  14180. t['Ucircumflex'] = 722;
  14181. t['yacute'] = 556;
  14182. t['scommaaccent'] = 556;
  14183. t['ecircumflex'] = 556;
  14184. t['Uring'] = 722;
  14185. t['Udieresis'] = 722;
  14186. t['aogonek'] = 556;
  14187. t['Uacute'] = 722;
  14188. t['uogonek'] = 611;
  14189. t['Edieresis'] = 667;
  14190. t['Dcroat'] = 722;
  14191. t['commaaccent'] = 250;
  14192. t['copyright'] = 737;
  14193. t['Emacron'] = 667;
  14194. t['ccaron'] = 556;
  14195. t['aring'] = 556;
  14196. t['Ncommaaccent'] = 722;
  14197. t['lacute'] = 278;
  14198. t['agrave'] = 556;
  14199. t['Tcommaaccent'] = 611;
  14200. t['Cacute'] = 722;
  14201. t['atilde'] = 556;
  14202. t['Edotaccent'] = 667;
  14203. t['scaron'] = 556;
  14204. t['scedilla'] = 556;
  14205. t['iacute'] = 278;
  14206. t['lozenge'] = 494;
  14207. t['Rcaron'] = 722;
  14208. t['Gcommaaccent'] = 778;
  14209. t['ucircumflex'] = 611;
  14210. t['acircumflex'] = 556;
  14211. t['Amacron'] = 722;
  14212. t['rcaron'] = 389;
  14213. t['ccedilla'] = 556;
  14214. t['Zdotaccent'] = 611;
  14215. t['Thorn'] = 667;
  14216. t['Omacron'] = 778;
  14217. t['Racute'] = 722;
  14218. t['Sacute'] = 667;
  14219. t['dcaron'] = 743;
  14220. t['Umacron'] = 722;
  14221. t['uring'] = 611;
  14222. t['threesuperior'] = 333;
  14223. t['Ograve'] = 778;
  14224. t['Agrave'] = 722;
  14225. t['Abreve'] = 722;
  14226. t['multiply'] = 584;
  14227. t['uacute'] = 611;
  14228. t['Tcaron'] = 611;
  14229. t['partialdiff'] = 494;
  14230. t['ydieresis'] = 556;
  14231. t['Nacute'] = 722;
  14232. t['icircumflex'] = 278;
  14233. t['Ecircumflex'] = 667;
  14234. t['adieresis'] = 556;
  14235. t['edieresis'] = 556;
  14236. t['cacute'] = 556;
  14237. t['nacute'] = 611;
  14238. t['umacron'] = 611;
  14239. t['Ncaron'] = 722;
  14240. t['Iacute'] = 278;
  14241. t['plusminus'] = 584;
  14242. t['brokenbar'] = 280;
  14243. t['registered'] = 737;
  14244. t['Gbreve'] = 778;
  14245. t['Idotaccent'] = 278;
  14246. t['summation'] = 600;
  14247. t['Egrave'] = 667;
  14248. t['racute'] = 389;
  14249. t['omacron'] = 611;
  14250. t['Zacute'] = 611;
  14251. t['Zcaron'] = 611;
  14252. t['greaterequal'] = 549;
  14253. t['Eth'] = 722;
  14254. t['Ccedilla'] = 722;
  14255. t['lcommaaccent'] = 278;
  14256. t['tcaron'] = 389;
  14257. t['eogonek'] = 556;
  14258. t['Uogonek'] = 722;
  14259. t['Aacute'] = 722;
  14260. t['Adieresis'] = 722;
  14261. t['egrave'] = 556;
  14262. t['zacute'] = 500;
  14263. t['iogonek'] = 278;
  14264. t['Oacute'] = 778;
  14265. t['oacute'] = 611;
  14266. t['amacron'] = 556;
  14267. t['sacute'] = 556;
  14268. t['idieresis'] = 278;
  14269. t['Ocircumflex'] = 778;
  14270. t['Ugrave'] = 722;
  14271. t['Delta'] = 612;
  14272. t['thorn'] = 611;
  14273. t['twosuperior'] = 333;
  14274. t['Odieresis'] = 778;
  14275. t['mu'] = 611;
  14276. t['igrave'] = 278;
  14277. t['ohungarumlaut'] = 611;
  14278. t['Eogonek'] = 667;
  14279. t['dcroat'] = 611;
  14280. t['threequarters'] = 834;
  14281. t['Scedilla'] = 667;
  14282. t['lcaron'] = 400;
  14283. t['Kcommaaccent'] = 722;
  14284. t['Lacute'] = 611;
  14285. t['trademark'] = 1000;
  14286. t['edotaccent'] = 556;
  14287. t['Igrave'] = 278;
  14288. t['Imacron'] = 278;
  14289. t['Lcaron'] = 611;
  14290. t['onehalf'] = 834;
  14291. t['lessequal'] = 549;
  14292. t['ocircumflex'] = 611;
  14293. t['ntilde'] = 611;
  14294. t['Uhungarumlaut'] = 722;
  14295. t['Eacute'] = 667;
  14296. t['emacron'] = 556;
  14297. t['gbreve'] = 611;
  14298. t['onequarter'] = 834;
  14299. t['Scaron'] = 667;
  14300. t['Scommaaccent'] = 667;
  14301. t['Ohungarumlaut'] = 778;
  14302. t['degree'] = 400;
  14303. t['ograve'] = 611;
  14304. t['Ccaron'] = 722;
  14305. t['ugrave'] = 611;
  14306. t['radical'] = 549;
  14307. t['Dcaron'] = 722;
  14308. t['rcommaaccent'] = 389;
  14309. t['Ntilde'] = 722;
  14310. t['otilde'] = 611;
  14311. t['Rcommaaccent'] = 722;
  14312. t['Lcommaaccent'] = 611;
  14313. t['Atilde'] = 722;
  14314. t['Aogonek'] = 722;
  14315. t['Aring'] = 722;
  14316. t['Otilde'] = 778;
  14317. t['zdotaccent'] = 500;
  14318. t['Ecaron'] = 667;
  14319. t['Iogonek'] = 278;
  14320. t['kcommaaccent'] = 556;
  14321. t['minus'] = 584;
  14322. t['Icircumflex'] = 278;
  14323. t['ncaron'] = 611;
  14324. t['tcommaaccent'] = 333;
  14325. t['logicalnot'] = 584;
  14326. t['odieresis'] = 611;
  14327. t['udieresis'] = 611;
  14328. t['notequal'] = 549;
  14329. t['gcommaaccent'] = 611;
  14330. t['eth'] = 611;
  14331. t['zcaron'] = 500;
  14332. t['ncommaaccent'] = 611;
  14333. t['onesuperior'] = 333;
  14334. t['imacron'] = 278;
  14335. t['Euro'] = 556;
  14336. });
  14337. t['Helvetica-BoldOblique'] = getLookupTableFactory(function (t) {
  14338. t['space'] = 278;
  14339. t['exclam'] = 333;
  14340. t['quotedbl'] = 474;
  14341. t['numbersign'] = 556;
  14342. t['dollar'] = 556;
  14343. t['percent'] = 889;
  14344. t['ampersand'] = 722;
  14345. t['quoteright'] = 278;
  14346. t['parenleft'] = 333;
  14347. t['parenright'] = 333;
  14348. t['asterisk'] = 389;
  14349. t['plus'] = 584;
  14350. t['comma'] = 278;
  14351. t['hyphen'] = 333;
  14352. t['period'] = 278;
  14353. t['slash'] = 278;
  14354. t['zero'] = 556;
  14355. t['one'] = 556;
  14356. t['two'] = 556;
  14357. t['three'] = 556;
  14358. t['four'] = 556;
  14359. t['five'] = 556;
  14360. t['six'] = 556;
  14361. t['seven'] = 556;
  14362. t['eight'] = 556;
  14363. t['nine'] = 556;
  14364. t['colon'] = 333;
  14365. t['semicolon'] = 333;
  14366. t['less'] = 584;
  14367. t['equal'] = 584;
  14368. t['greater'] = 584;
  14369. t['question'] = 611;
  14370. t['at'] = 975;
  14371. t['A'] = 722;
  14372. t['B'] = 722;
  14373. t['C'] = 722;
  14374. t['D'] = 722;
  14375. t['E'] = 667;
  14376. t['F'] = 611;
  14377. t['G'] = 778;
  14378. t['H'] = 722;
  14379. t['I'] = 278;
  14380. t['J'] = 556;
  14381. t['K'] = 722;
  14382. t['L'] = 611;
  14383. t['M'] = 833;
  14384. t['N'] = 722;
  14385. t['O'] = 778;
  14386. t['P'] = 667;
  14387. t['Q'] = 778;
  14388. t['R'] = 722;
  14389. t['S'] = 667;
  14390. t['T'] = 611;
  14391. t['U'] = 722;
  14392. t['V'] = 667;
  14393. t['W'] = 944;
  14394. t['X'] = 667;
  14395. t['Y'] = 667;
  14396. t['Z'] = 611;
  14397. t['bracketleft'] = 333;
  14398. t['backslash'] = 278;
  14399. t['bracketright'] = 333;
  14400. t['asciicircum'] = 584;
  14401. t['underscore'] = 556;
  14402. t['quoteleft'] = 278;
  14403. t['a'] = 556;
  14404. t['b'] = 611;
  14405. t['c'] = 556;
  14406. t['d'] = 611;
  14407. t['e'] = 556;
  14408. t['f'] = 333;
  14409. t['g'] = 611;
  14410. t['h'] = 611;
  14411. t['i'] = 278;
  14412. t['j'] = 278;
  14413. t['k'] = 556;
  14414. t['l'] = 278;
  14415. t['m'] = 889;
  14416. t['n'] = 611;
  14417. t['o'] = 611;
  14418. t['p'] = 611;
  14419. t['q'] = 611;
  14420. t['r'] = 389;
  14421. t['s'] = 556;
  14422. t['t'] = 333;
  14423. t['u'] = 611;
  14424. t['v'] = 556;
  14425. t['w'] = 778;
  14426. t['x'] = 556;
  14427. t['y'] = 556;
  14428. t['z'] = 500;
  14429. t['braceleft'] = 389;
  14430. t['bar'] = 280;
  14431. t['braceright'] = 389;
  14432. t['asciitilde'] = 584;
  14433. t['exclamdown'] = 333;
  14434. t['cent'] = 556;
  14435. t['sterling'] = 556;
  14436. t['fraction'] = 167;
  14437. t['yen'] = 556;
  14438. t['florin'] = 556;
  14439. t['section'] = 556;
  14440. t['currency'] = 556;
  14441. t['quotesingle'] = 238;
  14442. t['quotedblleft'] = 500;
  14443. t['guillemotleft'] = 556;
  14444. t['guilsinglleft'] = 333;
  14445. t['guilsinglright'] = 333;
  14446. t['fi'] = 611;
  14447. t['fl'] = 611;
  14448. t['endash'] = 556;
  14449. t['dagger'] = 556;
  14450. t['daggerdbl'] = 556;
  14451. t['periodcentered'] = 278;
  14452. t['paragraph'] = 556;
  14453. t['bullet'] = 350;
  14454. t['quotesinglbase'] = 278;
  14455. t['quotedblbase'] = 500;
  14456. t['quotedblright'] = 500;
  14457. t['guillemotright'] = 556;
  14458. t['ellipsis'] = 1000;
  14459. t['perthousand'] = 1000;
  14460. t['questiondown'] = 611;
  14461. t['grave'] = 333;
  14462. t['acute'] = 333;
  14463. t['circumflex'] = 333;
  14464. t['tilde'] = 333;
  14465. t['macron'] = 333;
  14466. t['breve'] = 333;
  14467. t['dotaccent'] = 333;
  14468. t['dieresis'] = 333;
  14469. t['ring'] = 333;
  14470. t['cedilla'] = 333;
  14471. t['hungarumlaut'] = 333;
  14472. t['ogonek'] = 333;
  14473. t['caron'] = 333;
  14474. t['emdash'] = 1000;
  14475. t['AE'] = 1000;
  14476. t['ordfeminine'] = 370;
  14477. t['Lslash'] = 611;
  14478. t['Oslash'] = 778;
  14479. t['OE'] = 1000;
  14480. t['ordmasculine'] = 365;
  14481. t['ae'] = 889;
  14482. t['dotlessi'] = 278;
  14483. t['lslash'] = 278;
  14484. t['oslash'] = 611;
  14485. t['oe'] = 944;
  14486. t['germandbls'] = 611;
  14487. t['Idieresis'] = 278;
  14488. t['eacute'] = 556;
  14489. t['abreve'] = 556;
  14490. t['uhungarumlaut'] = 611;
  14491. t['ecaron'] = 556;
  14492. t['Ydieresis'] = 667;
  14493. t['divide'] = 584;
  14494. t['Yacute'] = 667;
  14495. t['Acircumflex'] = 722;
  14496. t['aacute'] = 556;
  14497. t['Ucircumflex'] = 722;
  14498. t['yacute'] = 556;
  14499. t['scommaaccent'] = 556;
  14500. t['ecircumflex'] = 556;
  14501. t['Uring'] = 722;
  14502. t['Udieresis'] = 722;
  14503. t['aogonek'] = 556;
  14504. t['Uacute'] = 722;
  14505. t['uogonek'] = 611;
  14506. t['Edieresis'] = 667;
  14507. t['Dcroat'] = 722;
  14508. t['commaaccent'] = 250;
  14509. t['copyright'] = 737;
  14510. t['Emacron'] = 667;
  14511. t['ccaron'] = 556;
  14512. t['aring'] = 556;
  14513. t['Ncommaaccent'] = 722;
  14514. t['lacute'] = 278;
  14515. t['agrave'] = 556;
  14516. t['Tcommaaccent'] = 611;
  14517. t['Cacute'] = 722;
  14518. t['atilde'] = 556;
  14519. t['Edotaccent'] = 667;
  14520. t['scaron'] = 556;
  14521. t['scedilla'] = 556;
  14522. t['iacute'] = 278;
  14523. t['lozenge'] = 494;
  14524. t['Rcaron'] = 722;
  14525. t['Gcommaaccent'] = 778;
  14526. t['ucircumflex'] = 611;
  14527. t['acircumflex'] = 556;
  14528. t['Amacron'] = 722;
  14529. t['rcaron'] = 389;
  14530. t['ccedilla'] = 556;
  14531. t['Zdotaccent'] = 611;
  14532. t['Thorn'] = 667;
  14533. t['Omacron'] = 778;
  14534. t['Racute'] = 722;
  14535. t['Sacute'] = 667;
  14536. t['dcaron'] = 743;
  14537. t['Umacron'] = 722;
  14538. t['uring'] = 611;
  14539. t['threesuperior'] = 333;
  14540. t['Ograve'] = 778;
  14541. t['Agrave'] = 722;
  14542. t['Abreve'] = 722;
  14543. t['multiply'] = 584;
  14544. t['uacute'] = 611;
  14545. t['Tcaron'] = 611;
  14546. t['partialdiff'] = 494;
  14547. t['ydieresis'] = 556;
  14548. t['Nacute'] = 722;
  14549. t['icircumflex'] = 278;
  14550. t['Ecircumflex'] = 667;
  14551. t['adieresis'] = 556;
  14552. t['edieresis'] = 556;
  14553. t['cacute'] = 556;
  14554. t['nacute'] = 611;
  14555. t['umacron'] = 611;
  14556. t['Ncaron'] = 722;
  14557. t['Iacute'] = 278;
  14558. t['plusminus'] = 584;
  14559. t['brokenbar'] = 280;
  14560. t['registered'] = 737;
  14561. t['Gbreve'] = 778;
  14562. t['Idotaccent'] = 278;
  14563. t['summation'] = 600;
  14564. t['Egrave'] = 667;
  14565. t['racute'] = 389;
  14566. t['omacron'] = 611;
  14567. t['Zacute'] = 611;
  14568. t['Zcaron'] = 611;
  14569. t['greaterequal'] = 549;
  14570. t['Eth'] = 722;
  14571. t['Ccedilla'] = 722;
  14572. t['lcommaaccent'] = 278;
  14573. t['tcaron'] = 389;
  14574. t['eogonek'] = 556;
  14575. t['Uogonek'] = 722;
  14576. t['Aacute'] = 722;
  14577. t['Adieresis'] = 722;
  14578. t['egrave'] = 556;
  14579. t['zacute'] = 500;
  14580. t['iogonek'] = 278;
  14581. t['Oacute'] = 778;
  14582. t['oacute'] = 611;
  14583. t['amacron'] = 556;
  14584. t['sacute'] = 556;
  14585. t['idieresis'] = 278;
  14586. t['Ocircumflex'] = 778;
  14587. t['Ugrave'] = 722;
  14588. t['Delta'] = 612;
  14589. t['thorn'] = 611;
  14590. t['twosuperior'] = 333;
  14591. t['Odieresis'] = 778;
  14592. t['mu'] = 611;
  14593. t['igrave'] = 278;
  14594. t['ohungarumlaut'] = 611;
  14595. t['Eogonek'] = 667;
  14596. t['dcroat'] = 611;
  14597. t['threequarters'] = 834;
  14598. t['Scedilla'] = 667;
  14599. t['lcaron'] = 400;
  14600. t['Kcommaaccent'] = 722;
  14601. t['Lacute'] = 611;
  14602. t['trademark'] = 1000;
  14603. t['edotaccent'] = 556;
  14604. t['Igrave'] = 278;
  14605. t['Imacron'] = 278;
  14606. t['Lcaron'] = 611;
  14607. t['onehalf'] = 834;
  14608. t['lessequal'] = 549;
  14609. t['ocircumflex'] = 611;
  14610. t['ntilde'] = 611;
  14611. t['Uhungarumlaut'] = 722;
  14612. t['Eacute'] = 667;
  14613. t['emacron'] = 556;
  14614. t['gbreve'] = 611;
  14615. t['onequarter'] = 834;
  14616. t['Scaron'] = 667;
  14617. t['Scommaaccent'] = 667;
  14618. t['Ohungarumlaut'] = 778;
  14619. t['degree'] = 400;
  14620. t['ograve'] = 611;
  14621. t['Ccaron'] = 722;
  14622. t['ugrave'] = 611;
  14623. t['radical'] = 549;
  14624. t['Dcaron'] = 722;
  14625. t['rcommaaccent'] = 389;
  14626. t['Ntilde'] = 722;
  14627. t['otilde'] = 611;
  14628. t['Rcommaaccent'] = 722;
  14629. t['Lcommaaccent'] = 611;
  14630. t['Atilde'] = 722;
  14631. t['Aogonek'] = 722;
  14632. t['Aring'] = 722;
  14633. t['Otilde'] = 778;
  14634. t['zdotaccent'] = 500;
  14635. t['Ecaron'] = 667;
  14636. t['Iogonek'] = 278;
  14637. t['kcommaaccent'] = 556;
  14638. t['minus'] = 584;
  14639. t['Icircumflex'] = 278;
  14640. t['ncaron'] = 611;
  14641. t['tcommaaccent'] = 333;
  14642. t['logicalnot'] = 584;
  14643. t['odieresis'] = 611;
  14644. t['udieresis'] = 611;
  14645. t['notequal'] = 549;
  14646. t['gcommaaccent'] = 611;
  14647. t['eth'] = 611;
  14648. t['zcaron'] = 500;
  14649. t['ncommaaccent'] = 611;
  14650. t['onesuperior'] = 333;
  14651. t['imacron'] = 278;
  14652. t['Euro'] = 556;
  14653. });
  14654. t['Helvetica-Oblique'] = getLookupTableFactory(function (t) {
  14655. t['space'] = 278;
  14656. t['exclam'] = 278;
  14657. t['quotedbl'] = 355;
  14658. t['numbersign'] = 556;
  14659. t['dollar'] = 556;
  14660. t['percent'] = 889;
  14661. t['ampersand'] = 667;
  14662. t['quoteright'] = 222;
  14663. t['parenleft'] = 333;
  14664. t['parenright'] = 333;
  14665. t['asterisk'] = 389;
  14666. t['plus'] = 584;
  14667. t['comma'] = 278;
  14668. t['hyphen'] = 333;
  14669. t['period'] = 278;
  14670. t['slash'] = 278;
  14671. t['zero'] = 556;
  14672. t['one'] = 556;
  14673. t['two'] = 556;
  14674. t['three'] = 556;
  14675. t['four'] = 556;
  14676. t['five'] = 556;
  14677. t['six'] = 556;
  14678. t['seven'] = 556;
  14679. t['eight'] = 556;
  14680. t['nine'] = 556;
  14681. t['colon'] = 278;
  14682. t['semicolon'] = 278;
  14683. t['less'] = 584;
  14684. t['equal'] = 584;
  14685. t['greater'] = 584;
  14686. t['question'] = 556;
  14687. t['at'] = 1015;
  14688. t['A'] = 667;
  14689. t['B'] = 667;
  14690. t['C'] = 722;
  14691. t['D'] = 722;
  14692. t['E'] = 667;
  14693. t['F'] = 611;
  14694. t['G'] = 778;
  14695. t['H'] = 722;
  14696. t['I'] = 278;
  14697. t['J'] = 500;
  14698. t['K'] = 667;
  14699. t['L'] = 556;
  14700. t['M'] = 833;
  14701. t['N'] = 722;
  14702. t['O'] = 778;
  14703. t['P'] = 667;
  14704. t['Q'] = 778;
  14705. t['R'] = 722;
  14706. t['S'] = 667;
  14707. t['T'] = 611;
  14708. t['U'] = 722;
  14709. t['V'] = 667;
  14710. t['W'] = 944;
  14711. t['X'] = 667;
  14712. t['Y'] = 667;
  14713. t['Z'] = 611;
  14714. t['bracketleft'] = 278;
  14715. t['backslash'] = 278;
  14716. t['bracketright'] = 278;
  14717. t['asciicircum'] = 469;
  14718. t['underscore'] = 556;
  14719. t['quoteleft'] = 222;
  14720. t['a'] = 556;
  14721. t['b'] = 556;
  14722. t['c'] = 500;
  14723. t['d'] = 556;
  14724. t['e'] = 556;
  14725. t['f'] = 278;
  14726. t['g'] = 556;
  14727. t['h'] = 556;
  14728. t['i'] = 222;
  14729. t['j'] = 222;
  14730. t['k'] = 500;
  14731. t['l'] = 222;
  14732. t['m'] = 833;
  14733. t['n'] = 556;
  14734. t['o'] = 556;
  14735. t['p'] = 556;
  14736. t['q'] = 556;
  14737. t['r'] = 333;
  14738. t['s'] = 500;
  14739. t['t'] = 278;
  14740. t['u'] = 556;
  14741. t['v'] = 500;
  14742. t['w'] = 722;
  14743. t['x'] = 500;
  14744. t['y'] = 500;
  14745. t['z'] = 500;
  14746. t['braceleft'] = 334;
  14747. t['bar'] = 260;
  14748. t['braceright'] = 334;
  14749. t['asciitilde'] = 584;
  14750. t['exclamdown'] = 333;
  14751. t['cent'] = 556;
  14752. t['sterling'] = 556;
  14753. t['fraction'] = 167;
  14754. t['yen'] = 556;
  14755. t['florin'] = 556;
  14756. t['section'] = 556;
  14757. t['currency'] = 556;
  14758. t['quotesingle'] = 191;
  14759. t['quotedblleft'] = 333;
  14760. t['guillemotleft'] = 556;
  14761. t['guilsinglleft'] = 333;
  14762. t['guilsinglright'] = 333;
  14763. t['fi'] = 500;
  14764. t['fl'] = 500;
  14765. t['endash'] = 556;
  14766. t['dagger'] = 556;
  14767. t['daggerdbl'] = 556;
  14768. t['periodcentered'] = 278;
  14769. t['paragraph'] = 537;
  14770. t['bullet'] = 350;
  14771. t['quotesinglbase'] = 222;
  14772. t['quotedblbase'] = 333;
  14773. t['quotedblright'] = 333;
  14774. t['guillemotright'] = 556;
  14775. t['ellipsis'] = 1000;
  14776. t['perthousand'] = 1000;
  14777. t['questiondown'] = 611;
  14778. t['grave'] = 333;
  14779. t['acute'] = 333;
  14780. t['circumflex'] = 333;
  14781. t['tilde'] = 333;
  14782. t['macron'] = 333;
  14783. t['breve'] = 333;
  14784. t['dotaccent'] = 333;
  14785. t['dieresis'] = 333;
  14786. t['ring'] = 333;
  14787. t['cedilla'] = 333;
  14788. t['hungarumlaut'] = 333;
  14789. t['ogonek'] = 333;
  14790. t['caron'] = 333;
  14791. t['emdash'] = 1000;
  14792. t['AE'] = 1000;
  14793. t['ordfeminine'] = 370;
  14794. t['Lslash'] = 556;
  14795. t['Oslash'] = 778;
  14796. t['OE'] = 1000;
  14797. t['ordmasculine'] = 365;
  14798. t['ae'] = 889;
  14799. t['dotlessi'] = 278;
  14800. t['lslash'] = 222;
  14801. t['oslash'] = 611;
  14802. t['oe'] = 944;
  14803. t['germandbls'] = 611;
  14804. t['Idieresis'] = 278;
  14805. t['eacute'] = 556;
  14806. t['abreve'] = 556;
  14807. t['uhungarumlaut'] = 556;
  14808. t['ecaron'] = 556;
  14809. t['Ydieresis'] = 667;
  14810. t['divide'] = 584;
  14811. t['Yacute'] = 667;
  14812. t['Acircumflex'] = 667;
  14813. t['aacute'] = 556;
  14814. t['Ucircumflex'] = 722;
  14815. t['yacute'] = 500;
  14816. t['scommaaccent'] = 500;
  14817. t['ecircumflex'] = 556;
  14818. t['Uring'] = 722;
  14819. t['Udieresis'] = 722;
  14820. t['aogonek'] = 556;
  14821. t['Uacute'] = 722;
  14822. t['uogonek'] = 556;
  14823. t['Edieresis'] = 667;
  14824. t['Dcroat'] = 722;
  14825. t['commaaccent'] = 250;
  14826. t['copyright'] = 737;
  14827. t['Emacron'] = 667;
  14828. t['ccaron'] = 500;
  14829. t['aring'] = 556;
  14830. t['Ncommaaccent'] = 722;
  14831. t['lacute'] = 222;
  14832. t['agrave'] = 556;
  14833. t['Tcommaaccent'] = 611;
  14834. t['Cacute'] = 722;
  14835. t['atilde'] = 556;
  14836. t['Edotaccent'] = 667;
  14837. t['scaron'] = 500;
  14838. t['scedilla'] = 500;
  14839. t['iacute'] = 278;
  14840. t['lozenge'] = 471;
  14841. t['Rcaron'] = 722;
  14842. t['Gcommaaccent'] = 778;
  14843. t['ucircumflex'] = 556;
  14844. t['acircumflex'] = 556;
  14845. t['Amacron'] = 667;
  14846. t['rcaron'] = 333;
  14847. t['ccedilla'] = 500;
  14848. t['Zdotaccent'] = 611;
  14849. t['Thorn'] = 667;
  14850. t['Omacron'] = 778;
  14851. t['Racute'] = 722;
  14852. t['Sacute'] = 667;
  14853. t['dcaron'] = 643;
  14854. t['Umacron'] = 722;
  14855. t['uring'] = 556;
  14856. t['threesuperior'] = 333;
  14857. t['Ograve'] = 778;
  14858. t['Agrave'] = 667;
  14859. t['Abreve'] = 667;
  14860. t['multiply'] = 584;
  14861. t['uacute'] = 556;
  14862. t['Tcaron'] = 611;
  14863. t['partialdiff'] = 476;
  14864. t['ydieresis'] = 500;
  14865. t['Nacute'] = 722;
  14866. t['icircumflex'] = 278;
  14867. t['Ecircumflex'] = 667;
  14868. t['adieresis'] = 556;
  14869. t['edieresis'] = 556;
  14870. t['cacute'] = 500;
  14871. t['nacute'] = 556;
  14872. t['umacron'] = 556;
  14873. t['Ncaron'] = 722;
  14874. t['Iacute'] = 278;
  14875. t['plusminus'] = 584;
  14876. t['brokenbar'] = 260;
  14877. t['registered'] = 737;
  14878. t['Gbreve'] = 778;
  14879. t['Idotaccent'] = 278;
  14880. t['summation'] = 600;
  14881. t['Egrave'] = 667;
  14882. t['racute'] = 333;
  14883. t['omacron'] = 556;
  14884. t['Zacute'] = 611;
  14885. t['Zcaron'] = 611;
  14886. t['greaterequal'] = 549;
  14887. t['Eth'] = 722;
  14888. t['Ccedilla'] = 722;
  14889. t['lcommaaccent'] = 222;
  14890. t['tcaron'] = 317;
  14891. t['eogonek'] = 556;
  14892. t['Uogonek'] = 722;
  14893. t['Aacute'] = 667;
  14894. t['Adieresis'] = 667;
  14895. t['egrave'] = 556;
  14896. t['zacute'] = 500;
  14897. t['iogonek'] = 222;
  14898. t['Oacute'] = 778;
  14899. t['oacute'] = 556;
  14900. t['amacron'] = 556;
  14901. t['sacute'] = 500;
  14902. t['idieresis'] = 278;
  14903. t['Ocircumflex'] = 778;
  14904. t['Ugrave'] = 722;
  14905. t['Delta'] = 612;
  14906. t['thorn'] = 556;
  14907. t['twosuperior'] = 333;
  14908. t['Odieresis'] = 778;
  14909. t['mu'] = 556;
  14910. t['igrave'] = 278;
  14911. t['ohungarumlaut'] = 556;
  14912. t['Eogonek'] = 667;
  14913. t['dcroat'] = 556;
  14914. t['threequarters'] = 834;
  14915. t['Scedilla'] = 667;
  14916. t['lcaron'] = 299;
  14917. t['Kcommaaccent'] = 667;
  14918. t['Lacute'] = 556;
  14919. t['trademark'] = 1000;
  14920. t['edotaccent'] = 556;
  14921. t['Igrave'] = 278;
  14922. t['Imacron'] = 278;
  14923. t['Lcaron'] = 556;
  14924. t['onehalf'] = 834;
  14925. t['lessequal'] = 549;
  14926. t['ocircumflex'] = 556;
  14927. t['ntilde'] = 556;
  14928. t['Uhungarumlaut'] = 722;
  14929. t['Eacute'] = 667;
  14930. t['emacron'] = 556;
  14931. t['gbreve'] = 556;
  14932. t['onequarter'] = 834;
  14933. t['Scaron'] = 667;
  14934. t['Scommaaccent'] = 667;
  14935. t['Ohungarumlaut'] = 778;
  14936. t['degree'] = 400;
  14937. t['ograve'] = 556;
  14938. t['Ccaron'] = 722;
  14939. t['ugrave'] = 556;
  14940. t['radical'] = 453;
  14941. t['Dcaron'] = 722;
  14942. t['rcommaaccent'] = 333;
  14943. t['Ntilde'] = 722;
  14944. t['otilde'] = 556;
  14945. t['Rcommaaccent'] = 722;
  14946. t['Lcommaaccent'] = 556;
  14947. t['Atilde'] = 667;
  14948. t['Aogonek'] = 667;
  14949. t['Aring'] = 667;
  14950. t['Otilde'] = 778;
  14951. t['zdotaccent'] = 500;
  14952. t['Ecaron'] = 667;
  14953. t['Iogonek'] = 278;
  14954. t['kcommaaccent'] = 500;
  14955. t['minus'] = 584;
  14956. t['Icircumflex'] = 278;
  14957. t['ncaron'] = 556;
  14958. t['tcommaaccent'] = 278;
  14959. t['logicalnot'] = 584;
  14960. t['odieresis'] = 556;
  14961. t['udieresis'] = 556;
  14962. t['notequal'] = 549;
  14963. t['gcommaaccent'] = 556;
  14964. t['eth'] = 556;
  14965. t['zcaron'] = 500;
  14966. t['ncommaaccent'] = 556;
  14967. t['onesuperior'] = 333;
  14968. t['imacron'] = 278;
  14969. t['Euro'] = 556;
  14970. });
  14971. t['Symbol'] = getLookupTableFactory(function (t) {
  14972. t['space'] = 250;
  14973. t['exclam'] = 333;
  14974. t['universal'] = 713;
  14975. t['numbersign'] = 500;
  14976. t['existential'] = 549;
  14977. t['percent'] = 833;
  14978. t['ampersand'] = 778;
  14979. t['suchthat'] = 439;
  14980. t['parenleft'] = 333;
  14981. t['parenright'] = 333;
  14982. t['asteriskmath'] = 500;
  14983. t['plus'] = 549;
  14984. t['comma'] = 250;
  14985. t['minus'] = 549;
  14986. t['period'] = 250;
  14987. t['slash'] = 278;
  14988. t['zero'] = 500;
  14989. t['one'] = 500;
  14990. t['two'] = 500;
  14991. t['three'] = 500;
  14992. t['four'] = 500;
  14993. t['five'] = 500;
  14994. t['six'] = 500;
  14995. t['seven'] = 500;
  14996. t['eight'] = 500;
  14997. t['nine'] = 500;
  14998. t['colon'] = 278;
  14999. t['semicolon'] = 278;
  15000. t['less'] = 549;
  15001. t['equal'] = 549;
  15002. t['greater'] = 549;
  15003. t['question'] = 444;
  15004. t['congruent'] = 549;
  15005. t['Alpha'] = 722;
  15006. t['Beta'] = 667;
  15007. t['Chi'] = 722;
  15008. t['Delta'] = 612;
  15009. t['Epsilon'] = 611;
  15010. t['Phi'] = 763;
  15011. t['Gamma'] = 603;
  15012. t['Eta'] = 722;
  15013. t['Iota'] = 333;
  15014. t['theta1'] = 631;
  15015. t['Kappa'] = 722;
  15016. t['Lambda'] = 686;
  15017. t['Mu'] = 889;
  15018. t['Nu'] = 722;
  15019. t['Omicron'] = 722;
  15020. t['Pi'] = 768;
  15021. t['Theta'] = 741;
  15022. t['Rho'] = 556;
  15023. t['Sigma'] = 592;
  15024. t['Tau'] = 611;
  15025. t['Upsilon'] = 690;
  15026. t['sigma1'] = 439;
  15027. t['Omega'] = 768;
  15028. t['Xi'] = 645;
  15029. t['Psi'] = 795;
  15030. t['Zeta'] = 611;
  15031. t['bracketleft'] = 333;
  15032. t['therefore'] = 863;
  15033. t['bracketright'] = 333;
  15034. t['perpendicular'] = 658;
  15035. t['underscore'] = 500;
  15036. t['radicalex'] = 500;
  15037. t['alpha'] = 631;
  15038. t['beta'] = 549;
  15039. t['chi'] = 549;
  15040. t['delta'] = 494;
  15041. t['epsilon'] = 439;
  15042. t['phi'] = 521;
  15043. t['gamma'] = 411;
  15044. t['eta'] = 603;
  15045. t['iota'] = 329;
  15046. t['phi1'] = 603;
  15047. t['kappa'] = 549;
  15048. t['lambda'] = 549;
  15049. t['mu'] = 576;
  15050. t['nu'] = 521;
  15051. t['omicron'] = 549;
  15052. t['pi'] = 549;
  15053. t['theta'] = 521;
  15054. t['rho'] = 549;
  15055. t['sigma'] = 603;
  15056. t['tau'] = 439;
  15057. t['upsilon'] = 576;
  15058. t['omega1'] = 713;
  15059. t['omega'] = 686;
  15060. t['xi'] = 493;
  15061. t['psi'] = 686;
  15062. t['zeta'] = 494;
  15063. t['braceleft'] = 480;
  15064. t['bar'] = 200;
  15065. t['braceright'] = 480;
  15066. t['similar'] = 549;
  15067. t['Euro'] = 750;
  15068. t['Upsilon1'] = 620;
  15069. t['minute'] = 247;
  15070. t['lessequal'] = 549;
  15071. t['fraction'] = 167;
  15072. t['infinity'] = 713;
  15073. t['florin'] = 500;
  15074. t['club'] = 753;
  15075. t['diamond'] = 753;
  15076. t['heart'] = 753;
  15077. t['spade'] = 753;
  15078. t['arrowboth'] = 1042;
  15079. t['arrowleft'] = 987;
  15080. t['arrowup'] = 603;
  15081. t['arrowright'] = 987;
  15082. t['arrowdown'] = 603;
  15083. t['degree'] = 400;
  15084. t['plusminus'] = 549;
  15085. t['second'] = 411;
  15086. t['greaterequal'] = 549;
  15087. t['multiply'] = 549;
  15088. t['proportional'] = 713;
  15089. t['partialdiff'] = 494;
  15090. t['bullet'] = 460;
  15091. t['divide'] = 549;
  15092. t['notequal'] = 549;
  15093. t['equivalence'] = 549;
  15094. t['approxequal'] = 549;
  15095. t['ellipsis'] = 1000;
  15096. t['arrowvertex'] = 603;
  15097. t['arrowhorizex'] = 1000;
  15098. t['carriagereturn'] = 658;
  15099. t['aleph'] = 823;
  15100. t['Ifraktur'] = 686;
  15101. t['Rfraktur'] = 795;
  15102. t['weierstrass'] = 987;
  15103. t['circlemultiply'] = 768;
  15104. t['circleplus'] = 768;
  15105. t['emptyset'] = 823;
  15106. t['intersection'] = 768;
  15107. t['union'] = 768;
  15108. t['propersuperset'] = 713;
  15109. t['reflexsuperset'] = 713;
  15110. t['notsubset'] = 713;
  15111. t['propersubset'] = 713;
  15112. t['reflexsubset'] = 713;
  15113. t['element'] = 713;
  15114. t['notelement'] = 713;
  15115. t['angle'] = 768;
  15116. t['gradient'] = 713;
  15117. t['registerserif'] = 790;
  15118. t['copyrightserif'] = 790;
  15119. t['trademarkserif'] = 890;
  15120. t['product'] = 823;
  15121. t['radical'] = 549;
  15122. t['dotmath'] = 250;
  15123. t['logicalnot'] = 713;
  15124. t['logicaland'] = 603;
  15125. t['logicalor'] = 603;
  15126. t['arrowdblboth'] = 1042;
  15127. t['arrowdblleft'] = 987;
  15128. t['arrowdblup'] = 603;
  15129. t['arrowdblright'] = 987;
  15130. t['arrowdbldown'] = 603;
  15131. t['lozenge'] = 494;
  15132. t['angleleft'] = 329;
  15133. t['registersans'] = 790;
  15134. t['copyrightsans'] = 790;
  15135. t['trademarksans'] = 786;
  15136. t['summation'] = 713;
  15137. t['parenlefttp'] = 384;
  15138. t['parenleftex'] = 384;
  15139. t['parenleftbt'] = 384;
  15140. t['bracketlefttp'] = 384;
  15141. t['bracketleftex'] = 384;
  15142. t['bracketleftbt'] = 384;
  15143. t['bracelefttp'] = 494;
  15144. t['braceleftmid'] = 494;
  15145. t['braceleftbt'] = 494;
  15146. t['braceex'] = 494;
  15147. t['angleright'] = 329;
  15148. t['integral'] = 274;
  15149. t['integraltp'] = 686;
  15150. t['integralex'] = 686;
  15151. t['integralbt'] = 686;
  15152. t['parenrighttp'] = 384;
  15153. t['parenrightex'] = 384;
  15154. t['parenrightbt'] = 384;
  15155. t['bracketrighttp'] = 384;
  15156. t['bracketrightex'] = 384;
  15157. t['bracketrightbt'] = 384;
  15158. t['bracerighttp'] = 494;
  15159. t['bracerightmid'] = 494;
  15160. t['bracerightbt'] = 494;
  15161. t['apple'] = 790;
  15162. });
  15163. t['Times-Roman'] = getLookupTableFactory(function (t) {
  15164. t['space'] = 250;
  15165. t['exclam'] = 333;
  15166. t['quotedbl'] = 408;
  15167. t['numbersign'] = 500;
  15168. t['dollar'] = 500;
  15169. t['percent'] = 833;
  15170. t['ampersand'] = 778;
  15171. t['quoteright'] = 333;
  15172. t['parenleft'] = 333;
  15173. t['parenright'] = 333;
  15174. t['asterisk'] = 500;
  15175. t['plus'] = 564;
  15176. t['comma'] = 250;
  15177. t['hyphen'] = 333;
  15178. t['period'] = 250;
  15179. t['slash'] = 278;
  15180. t['zero'] = 500;
  15181. t['one'] = 500;
  15182. t['two'] = 500;
  15183. t['three'] = 500;
  15184. t['four'] = 500;
  15185. t['five'] = 500;
  15186. t['six'] = 500;
  15187. t['seven'] = 500;
  15188. t['eight'] = 500;
  15189. t['nine'] = 500;
  15190. t['colon'] = 278;
  15191. t['semicolon'] = 278;
  15192. t['less'] = 564;
  15193. t['equal'] = 564;
  15194. t['greater'] = 564;
  15195. t['question'] = 444;
  15196. t['at'] = 921;
  15197. t['A'] = 722;
  15198. t['B'] = 667;
  15199. t['C'] = 667;
  15200. t['D'] = 722;
  15201. t['E'] = 611;
  15202. t['F'] = 556;
  15203. t['G'] = 722;
  15204. t['H'] = 722;
  15205. t['I'] = 333;
  15206. t['J'] = 389;
  15207. t['K'] = 722;
  15208. t['L'] = 611;
  15209. t['M'] = 889;
  15210. t['N'] = 722;
  15211. t['O'] = 722;
  15212. t['P'] = 556;
  15213. t['Q'] = 722;
  15214. t['R'] = 667;
  15215. t['S'] = 556;
  15216. t['T'] = 611;
  15217. t['U'] = 722;
  15218. t['V'] = 722;
  15219. t['W'] = 944;
  15220. t['X'] = 722;
  15221. t['Y'] = 722;
  15222. t['Z'] = 611;
  15223. t['bracketleft'] = 333;
  15224. t['backslash'] = 278;
  15225. t['bracketright'] = 333;
  15226. t['asciicircum'] = 469;
  15227. t['underscore'] = 500;
  15228. t['quoteleft'] = 333;
  15229. t['a'] = 444;
  15230. t['b'] = 500;
  15231. t['c'] = 444;
  15232. t['d'] = 500;
  15233. t['e'] = 444;
  15234. t['f'] = 333;
  15235. t['g'] = 500;
  15236. t['h'] = 500;
  15237. t['i'] = 278;
  15238. t['j'] = 278;
  15239. t['k'] = 500;
  15240. t['l'] = 278;
  15241. t['m'] = 778;
  15242. t['n'] = 500;
  15243. t['o'] = 500;
  15244. t['p'] = 500;
  15245. t['q'] = 500;
  15246. t['r'] = 333;
  15247. t['s'] = 389;
  15248. t['t'] = 278;
  15249. t['u'] = 500;
  15250. t['v'] = 500;
  15251. t['w'] = 722;
  15252. t['x'] = 500;
  15253. t['y'] = 500;
  15254. t['z'] = 444;
  15255. t['braceleft'] = 480;
  15256. t['bar'] = 200;
  15257. t['braceright'] = 480;
  15258. t['asciitilde'] = 541;
  15259. t['exclamdown'] = 333;
  15260. t['cent'] = 500;
  15261. t['sterling'] = 500;
  15262. t['fraction'] = 167;
  15263. t['yen'] = 500;
  15264. t['florin'] = 500;
  15265. t['section'] = 500;
  15266. t['currency'] = 500;
  15267. t['quotesingle'] = 180;
  15268. t['quotedblleft'] = 444;
  15269. t['guillemotleft'] = 500;
  15270. t['guilsinglleft'] = 333;
  15271. t['guilsinglright'] = 333;
  15272. t['fi'] = 556;
  15273. t['fl'] = 556;
  15274. t['endash'] = 500;
  15275. t['dagger'] = 500;
  15276. t['daggerdbl'] = 500;
  15277. t['periodcentered'] = 250;
  15278. t['paragraph'] = 453;
  15279. t['bullet'] = 350;
  15280. t['quotesinglbase'] = 333;
  15281. t['quotedblbase'] = 444;
  15282. t['quotedblright'] = 444;
  15283. t['guillemotright'] = 500;
  15284. t['ellipsis'] = 1000;
  15285. t['perthousand'] = 1000;
  15286. t['questiondown'] = 444;
  15287. t['grave'] = 333;
  15288. t['acute'] = 333;
  15289. t['circumflex'] = 333;
  15290. t['tilde'] = 333;
  15291. t['macron'] = 333;
  15292. t['breve'] = 333;
  15293. t['dotaccent'] = 333;
  15294. t['dieresis'] = 333;
  15295. t['ring'] = 333;
  15296. t['cedilla'] = 333;
  15297. t['hungarumlaut'] = 333;
  15298. t['ogonek'] = 333;
  15299. t['caron'] = 333;
  15300. t['emdash'] = 1000;
  15301. t['AE'] = 889;
  15302. t['ordfeminine'] = 276;
  15303. t['Lslash'] = 611;
  15304. t['Oslash'] = 722;
  15305. t['OE'] = 889;
  15306. t['ordmasculine'] = 310;
  15307. t['ae'] = 667;
  15308. t['dotlessi'] = 278;
  15309. t['lslash'] = 278;
  15310. t['oslash'] = 500;
  15311. t['oe'] = 722;
  15312. t['germandbls'] = 500;
  15313. t['Idieresis'] = 333;
  15314. t['eacute'] = 444;
  15315. t['abreve'] = 444;
  15316. t['uhungarumlaut'] = 500;
  15317. t['ecaron'] = 444;
  15318. t['Ydieresis'] = 722;
  15319. t['divide'] = 564;
  15320. t['Yacute'] = 722;
  15321. t['Acircumflex'] = 722;
  15322. t['aacute'] = 444;
  15323. t['Ucircumflex'] = 722;
  15324. t['yacute'] = 500;
  15325. t['scommaaccent'] = 389;
  15326. t['ecircumflex'] = 444;
  15327. t['Uring'] = 722;
  15328. t['Udieresis'] = 722;
  15329. t['aogonek'] = 444;
  15330. t['Uacute'] = 722;
  15331. t['uogonek'] = 500;
  15332. t['Edieresis'] = 611;
  15333. t['Dcroat'] = 722;
  15334. t['commaaccent'] = 250;
  15335. t['copyright'] = 760;
  15336. t['Emacron'] = 611;
  15337. t['ccaron'] = 444;
  15338. t['aring'] = 444;
  15339. t['Ncommaaccent'] = 722;
  15340. t['lacute'] = 278;
  15341. t['agrave'] = 444;
  15342. t['Tcommaaccent'] = 611;
  15343. t['Cacute'] = 667;
  15344. t['atilde'] = 444;
  15345. t['Edotaccent'] = 611;
  15346. t['scaron'] = 389;
  15347. t['scedilla'] = 389;
  15348. t['iacute'] = 278;
  15349. t['lozenge'] = 471;
  15350. t['Rcaron'] = 667;
  15351. t['Gcommaaccent'] = 722;
  15352. t['ucircumflex'] = 500;
  15353. t['acircumflex'] = 444;
  15354. t['Amacron'] = 722;
  15355. t['rcaron'] = 333;
  15356. t['ccedilla'] = 444;
  15357. t['Zdotaccent'] = 611;
  15358. t['Thorn'] = 556;
  15359. t['Omacron'] = 722;
  15360. t['Racute'] = 667;
  15361. t['Sacute'] = 556;
  15362. t['dcaron'] = 588;
  15363. t['Umacron'] = 722;
  15364. t['uring'] = 500;
  15365. t['threesuperior'] = 300;
  15366. t['Ograve'] = 722;
  15367. t['Agrave'] = 722;
  15368. t['Abreve'] = 722;
  15369. t['multiply'] = 564;
  15370. t['uacute'] = 500;
  15371. t['Tcaron'] = 611;
  15372. t['partialdiff'] = 476;
  15373. t['ydieresis'] = 500;
  15374. t['Nacute'] = 722;
  15375. t['icircumflex'] = 278;
  15376. t['Ecircumflex'] = 611;
  15377. t['adieresis'] = 444;
  15378. t['edieresis'] = 444;
  15379. t['cacute'] = 444;
  15380. t['nacute'] = 500;
  15381. t['umacron'] = 500;
  15382. t['Ncaron'] = 722;
  15383. t['Iacute'] = 333;
  15384. t['plusminus'] = 564;
  15385. t['brokenbar'] = 200;
  15386. t['registered'] = 760;
  15387. t['Gbreve'] = 722;
  15388. t['Idotaccent'] = 333;
  15389. t['summation'] = 600;
  15390. t['Egrave'] = 611;
  15391. t['racute'] = 333;
  15392. t['omacron'] = 500;
  15393. t['Zacute'] = 611;
  15394. t['Zcaron'] = 611;
  15395. t['greaterequal'] = 549;
  15396. t['Eth'] = 722;
  15397. t['Ccedilla'] = 667;
  15398. t['lcommaaccent'] = 278;
  15399. t['tcaron'] = 326;
  15400. t['eogonek'] = 444;
  15401. t['Uogonek'] = 722;
  15402. t['Aacute'] = 722;
  15403. t['Adieresis'] = 722;
  15404. t['egrave'] = 444;
  15405. t['zacute'] = 444;
  15406. t['iogonek'] = 278;
  15407. t['Oacute'] = 722;
  15408. t['oacute'] = 500;
  15409. t['amacron'] = 444;
  15410. t['sacute'] = 389;
  15411. t['idieresis'] = 278;
  15412. t['Ocircumflex'] = 722;
  15413. t['Ugrave'] = 722;
  15414. t['Delta'] = 612;
  15415. t['thorn'] = 500;
  15416. t['twosuperior'] = 300;
  15417. t['Odieresis'] = 722;
  15418. t['mu'] = 500;
  15419. t['igrave'] = 278;
  15420. t['ohungarumlaut'] = 500;
  15421. t['Eogonek'] = 611;
  15422. t['dcroat'] = 500;
  15423. t['threequarters'] = 750;
  15424. t['Scedilla'] = 556;
  15425. t['lcaron'] = 344;
  15426. t['Kcommaaccent'] = 722;
  15427. t['Lacute'] = 611;
  15428. t['trademark'] = 980;
  15429. t['edotaccent'] = 444;
  15430. t['Igrave'] = 333;
  15431. t['Imacron'] = 333;
  15432. t['Lcaron'] = 611;
  15433. t['onehalf'] = 750;
  15434. t['lessequal'] = 549;
  15435. t['ocircumflex'] = 500;
  15436. t['ntilde'] = 500;
  15437. t['Uhungarumlaut'] = 722;
  15438. t['Eacute'] = 611;
  15439. t['emacron'] = 444;
  15440. t['gbreve'] = 500;
  15441. t['onequarter'] = 750;
  15442. t['Scaron'] = 556;
  15443. t['Scommaaccent'] = 556;
  15444. t['Ohungarumlaut'] = 722;
  15445. t['degree'] = 400;
  15446. t['ograve'] = 500;
  15447. t['Ccaron'] = 667;
  15448. t['ugrave'] = 500;
  15449. t['radical'] = 453;
  15450. t['Dcaron'] = 722;
  15451. t['rcommaaccent'] = 333;
  15452. t['Ntilde'] = 722;
  15453. t['otilde'] = 500;
  15454. t['Rcommaaccent'] = 667;
  15455. t['Lcommaaccent'] = 611;
  15456. t['Atilde'] = 722;
  15457. t['Aogonek'] = 722;
  15458. t['Aring'] = 722;
  15459. t['Otilde'] = 722;
  15460. t['zdotaccent'] = 444;
  15461. t['Ecaron'] = 611;
  15462. t['Iogonek'] = 333;
  15463. t['kcommaaccent'] = 500;
  15464. t['minus'] = 564;
  15465. t['Icircumflex'] = 333;
  15466. t['ncaron'] = 500;
  15467. t['tcommaaccent'] = 278;
  15468. t['logicalnot'] = 564;
  15469. t['odieresis'] = 500;
  15470. t['udieresis'] = 500;
  15471. t['notequal'] = 549;
  15472. t['gcommaaccent'] = 500;
  15473. t['eth'] = 500;
  15474. t['zcaron'] = 444;
  15475. t['ncommaaccent'] = 500;
  15476. t['onesuperior'] = 300;
  15477. t['imacron'] = 278;
  15478. t['Euro'] = 500;
  15479. });
  15480. t['Times-Bold'] = getLookupTableFactory(function (t) {
  15481. t['space'] = 250;
  15482. t['exclam'] = 333;
  15483. t['quotedbl'] = 555;
  15484. t['numbersign'] = 500;
  15485. t['dollar'] = 500;
  15486. t['percent'] = 1000;
  15487. t['ampersand'] = 833;
  15488. t['quoteright'] = 333;
  15489. t['parenleft'] = 333;
  15490. t['parenright'] = 333;
  15491. t['asterisk'] = 500;
  15492. t['plus'] = 570;
  15493. t['comma'] = 250;
  15494. t['hyphen'] = 333;
  15495. t['period'] = 250;
  15496. t['slash'] = 278;
  15497. t['zero'] = 500;
  15498. t['one'] = 500;
  15499. t['two'] = 500;
  15500. t['three'] = 500;
  15501. t['four'] = 500;
  15502. t['five'] = 500;
  15503. t['six'] = 500;
  15504. t['seven'] = 500;
  15505. t['eight'] = 500;
  15506. t['nine'] = 500;
  15507. t['colon'] = 333;
  15508. t['semicolon'] = 333;
  15509. t['less'] = 570;
  15510. t['equal'] = 570;
  15511. t['greater'] = 570;
  15512. t['question'] = 500;
  15513. t['at'] = 930;
  15514. t['A'] = 722;
  15515. t['B'] = 667;
  15516. t['C'] = 722;
  15517. t['D'] = 722;
  15518. t['E'] = 667;
  15519. t['F'] = 611;
  15520. t['G'] = 778;
  15521. t['H'] = 778;
  15522. t['I'] = 389;
  15523. t['J'] = 500;
  15524. t['K'] = 778;
  15525. t['L'] = 667;
  15526. t['M'] = 944;
  15527. t['N'] = 722;
  15528. t['O'] = 778;
  15529. t['P'] = 611;
  15530. t['Q'] = 778;
  15531. t['R'] = 722;
  15532. t['S'] = 556;
  15533. t['T'] = 667;
  15534. t['U'] = 722;
  15535. t['V'] = 722;
  15536. t['W'] = 1000;
  15537. t['X'] = 722;
  15538. t['Y'] = 722;
  15539. t['Z'] = 667;
  15540. t['bracketleft'] = 333;
  15541. t['backslash'] = 278;
  15542. t['bracketright'] = 333;
  15543. t['asciicircum'] = 581;
  15544. t['underscore'] = 500;
  15545. t['quoteleft'] = 333;
  15546. t['a'] = 500;
  15547. t['b'] = 556;
  15548. t['c'] = 444;
  15549. t['d'] = 556;
  15550. t['e'] = 444;
  15551. t['f'] = 333;
  15552. t['g'] = 500;
  15553. t['h'] = 556;
  15554. t['i'] = 278;
  15555. t['j'] = 333;
  15556. t['k'] = 556;
  15557. t['l'] = 278;
  15558. t['m'] = 833;
  15559. t['n'] = 556;
  15560. t['o'] = 500;
  15561. t['p'] = 556;
  15562. t['q'] = 556;
  15563. t['r'] = 444;
  15564. t['s'] = 389;
  15565. t['t'] = 333;
  15566. t['u'] = 556;
  15567. t['v'] = 500;
  15568. t['w'] = 722;
  15569. t['x'] = 500;
  15570. t['y'] = 500;
  15571. t['z'] = 444;
  15572. t['braceleft'] = 394;
  15573. t['bar'] = 220;
  15574. t['braceright'] = 394;
  15575. t['asciitilde'] = 520;
  15576. t['exclamdown'] = 333;
  15577. t['cent'] = 500;
  15578. t['sterling'] = 500;
  15579. t['fraction'] = 167;
  15580. t['yen'] = 500;
  15581. t['florin'] = 500;
  15582. t['section'] = 500;
  15583. t['currency'] = 500;
  15584. t['quotesingle'] = 278;
  15585. t['quotedblleft'] = 500;
  15586. t['guillemotleft'] = 500;
  15587. t['guilsinglleft'] = 333;
  15588. t['guilsinglright'] = 333;
  15589. t['fi'] = 556;
  15590. t['fl'] = 556;
  15591. t['endash'] = 500;
  15592. t['dagger'] = 500;
  15593. t['daggerdbl'] = 500;
  15594. t['periodcentered'] = 250;
  15595. t['paragraph'] = 540;
  15596. t['bullet'] = 350;
  15597. t['quotesinglbase'] = 333;
  15598. t['quotedblbase'] = 500;
  15599. t['quotedblright'] = 500;
  15600. t['guillemotright'] = 500;
  15601. t['ellipsis'] = 1000;
  15602. t['perthousand'] = 1000;
  15603. t['questiondown'] = 500;
  15604. t['grave'] = 333;
  15605. t['acute'] = 333;
  15606. t['circumflex'] = 333;
  15607. t['tilde'] = 333;
  15608. t['macron'] = 333;
  15609. t['breve'] = 333;
  15610. t['dotaccent'] = 333;
  15611. t['dieresis'] = 333;
  15612. t['ring'] = 333;
  15613. t['cedilla'] = 333;
  15614. t['hungarumlaut'] = 333;
  15615. t['ogonek'] = 333;
  15616. t['caron'] = 333;
  15617. t['emdash'] = 1000;
  15618. t['AE'] = 1000;
  15619. t['ordfeminine'] = 300;
  15620. t['Lslash'] = 667;
  15621. t['Oslash'] = 778;
  15622. t['OE'] = 1000;
  15623. t['ordmasculine'] = 330;
  15624. t['ae'] = 722;
  15625. t['dotlessi'] = 278;
  15626. t['lslash'] = 278;
  15627. t['oslash'] = 500;
  15628. t['oe'] = 722;
  15629. t['germandbls'] = 556;
  15630. t['Idieresis'] = 389;
  15631. t['eacute'] = 444;
  15632. t['abreve'] = 500;
  15633. t['uhungarumlaut'] = 556;
  15634. t['ecaron'] = 444;
  15635. t['Ydieresis'] = 722;
  15636. t['divide'] = 570;
  15637. t['Yacute'] = 722;
  15638. t['Acircumflex'] = 722;
  15639. t['aacute'] = 500;
  15640. t['Ucircumflex'] = 722;
  15641. t['yacute'] = 500;
  15642. t['scommaaccent'] = 389;
  15643. t['ecircumflex'] = 444;
  15644. t['Uring'] = 722;
  15645. t['Udieresis'] = 722;
  15646. t['aogonek'] = 500;
  15647. t['Uacute'] = 722;
  15648. t['uogonek'] = 556;
  15649. t['Edieresis'] = 667;
  15650. t['Dcroat'] = 722;
  15651. t['commaaccent'] = 250;
  15652. t['copyright'] = 747;
  15653. t['Emacron'] = 667;
  15654. t['ccaron'] = 444;
  15655. t['aring'] = 500;
  15656. t['Ncommaaccent'] = 722;
  15657. t['lacute'] = 278;
  15658. t['agrave'] = 500;
  15659. t['Tcommaaccent'] = 667;
  15660. t['Cacute'] = 722;
  15661. t['atilde'] = 500;
  15662. t['Edotaccent'] = 667;
  15663. t['scaron'] = 389;
  15664. t['scedilla'] = 389;
  15665. t['iacute'] = 278;
  15666. t['lozenge'] = 494;
  15667. t['Rcaron'] = 722;
  15668. t['Gcommaaccent'] = 778;
  15669. t['ucircumflex'] = 556;
  15670. t['acircumflex'] = 500;
  15671. t['Amacron'] = 722;
  15672. t['rcaron'] = 444;
  15673. t['ccedilla'] = 444;
  15674. t['Zdotaccent'] = 667;
  15675. t['Thorn'] = 611;
  15676. t['Omacron'] = 778;
  15677. t['Racute'] = 722;
  15678. t['Sacute'] = 556;
  15679. t['dcaron'] = 672;
  15680. t['Umacron'] = 722;
  15681. t['uring'] = 556;
  15682. t['threesuperior'] = 300;
  15683. t['Ograve'] = 778;
  15684. t['Agrave'] = 722;
  15685. t['Abreve'] = 722;
  15686. t['multiply'] = 570;
  15687. t['uacute'] = 556;
  15688. t['Tcaron'] = 667;
  15689. t['partialdiff'] = 494;
  15690. t['ydieresis'] = 500;
  15691. t['Nacute'] = 722;
  15692. t['icircumflex'] = 278;
  15693. t['Ecircumflex'] = 667;
  15694. t['adieresis'] = 500;
  15695. t['edieresis'] = 444;
  15696. t['cacute'] = 444;
  15697. t['nacute'] = 556;
  15698. t['umacron'] = 556;
  15699. t['Ncaron'] = 722;
  15700. t['Iacute'] = 389;
  15701. t['plusminus'] = 570;
  15702. t['brokenbar'] = 220;
  15703. t['registered'] = 747;
  15704. t['Gbreve'] = 778;
  15705. t['Idotaccent'] = 389;
  15706. t['summation'] = 600;
  15707. t['Egrave'] = 667;
  15708. t['racute'] = 444;
  15709. t['omacron'] = 500;
  15710. t['Zacute'] = 667;
  15711. t['Zcaron'] = 667;
  15712. t['greaterequal'] = 549;
  15713. t['Eth'] = 722;
  15714. t['Ccedilla'] = 722;
  15715. t['lcommaaccent'] = 278;
  15716. t['tcaron'] = 416;
  15717. t['eogonek'] = 444;
  15718. t['Uogonek'] = 722;
  15719. t['Aacute'] = 722;
  15720. t['Adieresis'] = 722;
  15721. t['egrave'] = 444;
  15722. t['zacute'] = 444;
  15723. t['iogonek'] = 278;
  15724. t['Oacute'] = 778;
  15725. t['oacute'] = 500;
  15726. t['amacron'] = 500;
  15727. t['sacute'] = 389;
  15728. t['idieresis'] = 278;
  15729. t['Ocircumflex'] = 778;
  15730. t['Ugrave'] = 722;
  15731. t['Delta'] = 612;
  15732. t['thorn'] = 556;
  15733. t['twosuperior'] = 300;
  15734. t['Odieresis'] = 778;
  15735. t['mu'] = 556;
  15736. t['igrave'] = 278;
  15737. t['ohungarumlaut'] = 500;
  15738. t['Eogonek'] = 667;
  15739. t['dcroat'] = 556;
  15740. t['threequarters'] = 750;
  15741. t['Scedilla'] = 556;
  15742. t['lcaron'] = 394;
  15743. t['Kcommaaccent'] = 778;
  15744. t['Lacute'] = 667;
  15745. t['trademark'] = 1000;
  15746. t['edotaccent'] = 444;
  15747. t['Igrave'] = 389;
  15748. t['Imacron'] = 389;
  15749. t['Lcaron'] = 667;
  15750. t['onehalf'] = 750;
  15751. t['lessequal'] = 549;
  15752. t['ocircumflex'] = 500;
  15753. t['ntilde'] = 556;
  15754. t['Uhungarumlaut'] = 722;
  15755. t['Eacute'] = 667;
  15756. t['emacron'] = 444;
  15757. t['gbreve'] = 500;
  15758. t['onequarter'] = 750;
  15759. t['Scaron'] = 556;
  15760. t['Scommaaccent'] = 556;
  15761. t['Ohungarumlaut'] = 778;
  15762. t['degree'] = 400;
  15763. t['ograve'] = 500;
  15764. t['Ccaron'] = 722;
  15765. t['ugrave'] = 556;
  15766. t['radical'] = 549;
  15767. t['Dcaron'] = 722;
  15768. t['rcommaaccent'] = 444;
  15769. t['Ntilde'] = 722;
  15770. t['otilde'] = 500;
  15771. t['Rcommaaccent'] = 722;
  15772. t['Lcommaaccent'] = 667;
  15773. t['Atilde'] = 722;
  15774. t['Aogonek'] = 722;
  15775. t['Aring'] = 722;
  15776. t['Otilde'] = 778;
  15777. t['zdotaccent'] = 444;
  15778. t['Ecaron'] = 667;
  15779. t['Iogonek'] = 389;
  15780. t['kcommaaccent'] = 556;
  15781. t['minus'] = 570;
  15782. t['Icircumflex'] = 389;
  15783. t['ncaron'] = 556;
  15784. t['tcommaaccent'] = 333;
  15785. t['logicalnot'] = 570;
  15786. t['odieresis'] = 500;
  15787. t['udieresis'] = 556;
  15788. t['notequal'] = 549;
  15789. t['gcommaaccent'] = 500;
  15790. t['eth'] = 500;
  15791. t['zcaron'] = 444;
  15792. t['ncommaaccent'] = 556;
  15793. t['onesuperior'] = 300;
  15794. t['imacron'] = 278;
  15795. t['Euro'] = 500;
  15796. });
  15797. t['Times-BoldItalic'] = getLookupTableFactory(function (t) {
  15798. t['space'] = 250;
  15799. t['exclam'] = 389;
  15800. t['quotedbl'] = 555;
  15801. t['numbersign'] = 500;
  15802. t['dollar'] = 500;
  15803. t['percent'] = 833;
  15804. t['ampersand'] = 778;
  15805. t['quoteright'] = 333;
  15806. t['parenleft'] = 333;
  15807. t['parenright'] = 333;
  15808. t['asterisk'] = 500;
  15809. t['plus'] = 570;
  15810. t['comma'] = 250;
  15811. t['hyphen'] = 333;
  15812. t['period'] = 250;
  15813. t['slash'] = 278;
  15814. t['zero'] = 500;
  15815. t['one'] = 500;
  15816. t['two'] = 500;
  15817. t['three'] = 500;
  15818. t['four'] = 500;
  15819. t['five'] = 500;
  15820. t['six'] = 500;
  15821. t['seven'] = 500;
  15822. t['eight'] = 500;
  15823. t['nine'] = 500;
  15824. t['colon'] = 333;
  15825. t['semicolon'] = 333;
  15826. t['less'] = 570;
  15827. t['equal'] = 570;
  15828. t['greater'] = 570;
  15829. t['question'] = 500;
  15830. t['at'] = 832;
  15831. t['A'] = 667;
  15832. t['B'] = 667;
  15833. t['C'] = 667;
  15834. t['D'] = 722;
  15835. t['E'] = 667;
  15836. t['F'] = 667;
  15837. t['G'] = 722;
  15838. t['H'] = 778;
  15839. t['I'] = 389;
  15840. t['J'] = 500;
  15841. t['K'] = 667;
  15842. t['L'] = 611;
  15843. t['M'] = 889;
  15844. t['N'] = 722;
  15845. t['O'] = 722;
  15846. t['P'] = 611;
  15847. t['Q'] = 722;
  15848. t['R'] = 667;
  15849. t['S'] = 556;
  15850. t['T'] = 611;
  15851. t['U'] = 722;
  15852. t['V'] = 667;
  15853. t['W'] = 889;
  15854. t['X'] = 667;
  15855. t['Y'] = 611;
  15856. t['Z'] = 611;
  15857. t['bracketleft'] = 333;
  15858. t['backslash'] = 278;
  15859. t['bracketright'] = 333;
  15860. t['asciicircum'] = 570;
  15861. t['underscore'] = 500;
  15862. t['quoteleft'] = 333;
  15863. t['a'] = 500;
  15864. t['b'] = 500;
  15865. t['c'] = 444;
  15866. t['d'] = 500;
  15867. t['e'] = 444;
  15868. t['f'] = 333;
  15869. t['g'] = 500;
  15870. t['h'] = 556;
  15871. t['i'] = 278;
  15872. t['j'] = 278;
  15873. t['k'] = 500;
  15874. t['l'] = 278;
  15875. t['m'] = 778;
  15876. t['n'] = 556;
  15877. t['o'] = 500;
  15878. t['p'] = 500;
  15879. t['q'] = 500;
  15880. t['r'] = 389;
  15881. t['s'] = 389;
  15882. t['t'] = 278;
  15883. t['u'] = 556;
  15884. t['v'] = 444;
  15885. t['w'] = 667;
  15886. t['x'] = 500;
  15887. t['y'] = 444;
  15888. t['z'] = 389;
  15889. t['braceleft'] = 348;
  15890. t['bar'] = 220;
  15891. t['braceright'] = 348;
  15892. t['asciitilde'] = 570;
  15893. t['exclamdown'] = 389;
  15894. t['cent'] = 500;
  15895. t['sterling'] = 500;
  15896. t['fraction'] = 167;
  15897. t['yen'] = 500;
  15898. t['florin'] = 500;
  15899. t['section'] = 500;
  15900. t['currency'] = 500;
  15901. t['quotesingle'] = 278;
  15902. t['quotedblleft'] = 500;
  15903. t['guillemotleft'] = 500;
  15904. t['guilsinglleft'] = 333;
  15905. t['guilsinglright'] = 333;
  15906. t['fi'] = 556;
  15907. t['fl'] = 556;
  15908. t['endash'] = 500;
  15909. t['dagger'] = 500;
  15910. t['daggerdbl'] = 500;
  15911. t['periodcentered'] = 250;
  15912. t['paragraph'] = 500;
  15913. t['bullet'] = 350;
  15914. t['quotesinglbase'] = 333;
  15915. t['quotedblbase'] = 500;
  15916. t['quotedblright'] = 500;
  15917. t['guillemotright'] = 500;
  15918. t['ellipsis'] = 1000;
  15919. t['perthousand'] = 1000;
  15920. t['questiondown'] = 500;
  15921. t['grave'] = 333;
  15922. t['acute'] = 333;
  15923. t['circumflex'] = 333;
  15924. t['tilde'] = 333;
  15925. t['macron'] = 333;
  15926. t['breve'] = 333;
  15927. t['dotaccent'] = 333;
  15928. t['dieresis'] = 333;
  15929. t['ring'] = 333;
  15930. t['cedilla'] = 333;
  15931. t['hungarumlaut'] = 333;
  15932. t['ogonek'] = 333;
  15933. t['caron'] = 333;
  15934. t['emdash'] = 1000;
  15935. t['AE'] = 944;
  15936. t['ordfeminine'] = 266;
  15937. t['Lslash'] = 611;
  15938. t['Oslash'] = 722;
  15939. t['OE'] = 944;
  15940. t['ordmasculine'] = 300;
  15941. t['ae'] = 722;
  15942. t['dotlessi'] = 278;
  15943. t['lslash'] = 278;
  15944. t['oslash'] = 500;
  15945. t['oe'] = 722;
  15946. t['germandbls'] = 500;
  15947. t['Idieresis'] = 389;
  15948. t['eacute'] = 444;
  15949. t['abreve'] = 500;
  15950. t['uhungarumlaut'] = 556;
  15951. t['ecaron'] = 444;
  15952. t['Ydieresis'] = 611;
  15953. t['divide'] = 570;
  15954. t['Yacute'] = 611;
  15955. t['Acircumflex'] = 667;
  15956. t['aacute'] = 500;
  15957. t['Ucircumflex'] = 722;
  15958. t['yacute'] = 444;
  15959. t['scommaaccent'] = 389;
  15960. t['ecircumflex'] = 444;
  15961. t['Uring'] = 722;
  15962. t['Udieresis'] = 722;
  15963. t['aogonek'] = 500;
  15964. t['Uacute'] = 722;
  15965. t['uogonek'] = 556;
  15966. t['Edieresis'] = 667;
  15967. t['Dcroat'] = 722;
  15968. t['commaaccent'] = 250;
  15969. t['copyright'] = 747;
  15970. t['Emacron'] = 667;
  15971. t['ccaron'] = 444;
  15972. t['aring'] = 500;
  15973. t['Ncommaaccent'] = 722;
  15974. t['lacute'] = 278;
  15975. t['agrave'] = 500;
  15976. t['Tcommaaccent'] = 611;
  15977. t['Cacute'] = 667;
  15978. t['atilde'] = 500;
  15979. t['Edotaccent'] = 667;
  15980. t['scaron'] = 389;
  15981. t['scedilla'] = 389;
  15982. t['iacute'] = 278;
  15983. t['lozenge'] = 494;
  15984. t['Rcaron'] = 667;
  15985. t['Gcommaaccent'] = 722;
  15986. t['ucircumflex'] = 556;
  15987. t['acircumflex'] = 500;
  15988. t['Amacron'] = 667;
  15989. t['rcaron'] = 389;
  15990. t['ccedilla'] = 444;
  15991. t['Zdotaccent'] = 611;
  15992. t['Thorn'] = 611;
  15993. t['Omacron'] = 722;
  15994. t['Racute'] = 667;
  15995. t['Sacute'] = 556;
  15996. t['dcaron'] = 608;
  15997. t['Umacron'] = 722;
  15998. t['uring'] = 556;
  15999. t['threesuperior'] = 300;
  16000. t['Ograve'] = 722;
  16001. t['Agrave'] = 667;
  16002. t['Abreve'] = 667;
  16003. t['multiply'] = 570;
  16004. t['uacute'] = 556;
  16005. t['Tcaron'] = 611;
  16006. t['partialdiff'] = 494;
  16007. t['ydieresis'] = 444;
  16008. t['Nacute'] = 722;
  16009. t['icircumflex'] = 278;
  16010. t['Ecircumflex'] = 667;
  16011. t['adieresis'] = 500;
  16012. t['edieresis'] = 444;
  16013. t['cacute'] = 444;
  16014. t['nacute'] = 556;
  16015. t['umacron'] = 556;
  16016. t['Ncaron'] = 722;
  16017. t['Iacute'] = 389;
  16018. t['plusminus'] = 570;
  16019. t['brokenbar'] = 220;
  16020. t['registered'] = 747;
  16021. t['Gbreve'] = 722;
  16022. t['Idotaccent'] = 389;
  16023. t['summation'] = 600;
  16024. t['Egrave'] = 667;
  16025. t['racute'] = 389;
  16026. t['omacron'] = 500;
  16027. t['Zacute'] = 611;
  16028. t['Zcaron'] = 611;
  16029. t['greaterequal'] = 549;
  16030. t['Eth'] = 722;
  16031. t['Ccedilla'] = 667;
  16032. t['lcommaaccent'] = 278;
  16033. t['tcaron'] = 366;
  16034. t['eogonek'] = 444;
  16035. t['Uogonek'] = 722;
  16036. t['Aacute'] = 667;
  16037. t['Adieresis'] = 667;
  16038. t['egrave'] = 444;
  16039. t['zacute'] = 389;
  16040. t['iogonek'] = 278;
  16041. t['Oacute'] = 722;
  16042. t['oacute'] = 500;
  16043. t['amacron'] = 500;
  16044. t['sacute'] = 389;
  16045. t['idieresis'] = 278;
  16046. t['Ocircumflex'] = 722;
  16047. t['Ugrave'] = 722;
  16048. t['Delta'] = 612;
  16049. t['thorn'] = 500;
  16050. t['twosuperior'] = 300;
  16051. t['Odieresis'] = 722;
  16052. t['mu'] = 576;
  16053. t['igrave'] = 278;
  16054. t['ohungarumlaut'] = 500;
  16055. t['Eogonek'] = 667;
  16056. t['dcroat'] = 500;
  16057. t['threequarters'] = 750;
  16058. t['Scedilla'] = 556;
  16059. t['lcaron'] = 382;
  16060. t['Kcommaaccent'] = 667;
  16061. t['Lacute'] = 611;
  16062. t['trademark'] = 1000;
  16063. t['edotaccent'] = 444;
  16064. t['Igrave'] = 389;
  16065. t['Imacron'] = 389;
  16066. t['Lcaron'] = 611;
  16067. t['onehalf'] = 750;
  16068. t['lessequal'] = 549;
  16069. t['ocircumflex'] = 500;
  16070. t['ntilde'] = 556;
  16071. t['Uhungarumlaut'] = 722;
  16072. t['Eacute'] = 667;
  16073. t['emacron'] = 444;
  16074. t['gbreve'] = 500;
  16075. t['onequarter'] = 750;
  16076. t['Scaron'] = 556;
  16077. t['Scommaaccent'] = 556;
  16078. t['Ohungarumlaut'] = 722;
  16079. t['degree'] = 400;
  16080. t['ograve'] = 500;
  16081. t['Ccaron'] = 667;
  16082. t['ugrave'] = 556;
  16083. t['radical'] = 549;
  16084. t['Dcaron'] = 722;
  16085. t['rcommaaccent'] = 389;
  16086. t['Ntilde'] = 722;
  16087. t['otilde'] = 500;
  16088. t['Rcommaaccent'] = 667;
  16089. t['Lcommaaccent'] = 611;
  16090. t['Atilde'] = 667;
  16091. t['Aogonek'] = 667;
  16092. t['Aring'] = 667;
  16093. t['Otilde'] = 722;
  16094. t['zdotaccent'] = 389;
  16095. t['Ecaron'] = 667;
  16096. t['Iogonek'] = 389;
  16097. t['kcommaaccent'] = 500;
  16098. t['minus'] = 606;
  16099. t['Icircumflex'] = 389;
  16100. t['ncaron'] = 556;
  16101. t['tcommaaccent'] = 278;
  16102. t['logicalnot'] = 606;
  16103. t['odieresis'] = 500;
  16104. t['udieresis'] = 556;
  16105. t['notequal'] = 549;
  16106. t['gcommaaccent'] = 500;
  16107. t['eth'] = 500;
  16108. t['zcaron'] = 389;
  16109. t['ncommaaccent'] = 556;
  16110. t['onesuperior'] = 300;
  16111. t['imacron'] = 278;
  16112. t['Euro'] = 500;
  16113. });
  16114. t['Times-Italic'] = getLookupTableFactory(function (t) {
  16115. t['space'] = 250;
  16116. t['exclam'] = 333;
  16117. t['quotedbl'] = 420;
  16118. t['numbersign'] = 500;
  16119. t['dollar'] = 500;
  16120. t['percent'] = 833;
  16121. t['ampersand'] = 778;
  16122. t['quoteright'] = 333;
  16123. t['parenleft'] = 333;
  16124. t['parenright'] = 333;
  16125. t['asterisk'] = 500;
  16126. t['plus'] = 675;
  16127. t['comma'] = 250;
  16128. t['hyphen'] = 333;
  16129. t['period'] = 250;
  16130. t['slash'] = 278;
  16131. t['zero'] = 500;
  16132. t['one'] = 500;
  16133. t['two'] = 500;
  16134. t['three'] = 500;
  16135. t['four'] = 500;
  16136. t['five'] = 500;
  16137. t['six'] = 500;
  16138. t['seven'] = 500;
  16139. t['eight'] = 500;
  16140. t['nine'] = 500;
  16141. t['colon'] = 333;
  16142. t['semicolon'] = 333;
  16143. t['less'] = 675;
  16144. t['equal'] = 675;
  16145. t['greater'] = 675;
  16146. t['question'] = 500;
  16147. t['at'] = 920;
  16148. t['A'] = 611;
  16149. t['B'] = 611;
  16150. t['C'] = 667;
  16151. t['D'] = 722;
  16152. t['E'] = 611;
  16153. t['F'] = 611;
  16154. t['G'] = 722;
  16155. t['H'] = 722;
  16156. t['I'] = 333;
  16157. t['J'] = 444;
  16158. t['K'] = 667;
  16159. t['L'] = 556;
  16160. t['M'] = 833;
  16161. t['N'] = 667;
  16162. t['O'] = 722;
  16163. t['P'] = 611;
  16164. t['Q'] = 722;
  16165. t['R'] = 611;
  16166. t['S'] = 500;
  16167. t['T'] = 556;
  16168. t['U'] = 722;
  16169. t['V'] = 611;
  16170. t['W'] = 833;
  16171. t['X'] = 611;
  16172. t['Y'] = 556;
  16173. t['Z'] = 556;
  16174. t['bracketleft'] = 389;
  16175. t['backslash'] = 278;
  16176. t['bracketright'] = 389;
  16177. t['asciicircum'] = 422;
  16178. t['underscore'] = 500;
  16179. t['quoteleft'] = 333;
  16180. t['a'] = 500;
  16181. t['b'] = 500;
  16182. t['c'] = 444;
  16183. t['d'] = 500;
  16184. t['e'] = 444;
  16185. t['f'] = 278;
  16186. t['g'] = 500;
  16187. t['h'] = 500;
  16188. t['i'] = 278;
  16189. t['j'] = 278;
  16190. t['k'] = 444;
  16191. t['l'] = 278;
  16192. t['m'] = 722;
  16193. t['n'] = 500;
  16194. t['o'] = 500;
  16195. t['p'] = 500;
  16196. t['q'] = 500;
  16197. t['r'] = 389;
  16198. t['s'] = 389;
  16199. t['t'] = 278;
  16200. t['u'] = 500;
  16201. t['v'] = 444;
  16202. t['w'] = 667;
  16203. t['x'] = 444;
  16204. t['y'] = 444;
  16205. t['z'] = 389;
  16206. t['braceleft'] = 400;
  16207. t['bar'] = 275;
  16208. t['braceright'] = 400;
  16209. t['asciitilde'] = 541;
  16210. t['exclamdown'] = 389;
  16211. t['cent'] = 500;
  16212. t['sterling'] = 500;
  16213. t['fraction'] = 167;
  16214. t['yen'] = 500;
  16215. t['florin'] = 500;
  16216. t['section'] = 500;
  16217. t['currency'] = 500;
  16218. t['quotesingle'] = 214;
  16219. t['quotedblleft'] = 556;
  16220. t['guillemotleft'] = 500;
  16221. t['guilsinglleft'] = 333;
  16222. t['guilsinglright'] = 333;
  16223. t['fi'] = 500;
  16224. t['fl'] = 500;
  16225. t['endash'] = 500;
  16226. t['dagger'] = 500;
  16227. t['daggerdbl'] = 500;
  16228. t['periodcentered'] = 250;
  16229. t['paragraph'] = 523;
  16230. t['bullet'] = 350;
  16231. t['quotesinglbase'] = 333;
  16232. t['quotedblbase'] = 556;
  16233. t['quotedblright'] = 556;
  16234. t['guillemotright'] = 500;
  16235. t['ellipsis'] = 889;
  16236. t['perthousand'] = 1000;
  16237. t['questiondown'] = 500;
  16238. t['grave'] = 333;
  16239. t['acute'] = 333;
  16240. t['circumflex'] = 333;
  16241. t['tilde'] = 333;
  16242. t['macron'] = 333;
  16243. t['breve'] = 333;
  16244. t['dotaccent'] = 333;
  16245. t['dieresis'] = 333;
  16246. t['ring'] = 333;
  16247. t['cedilla'] = 333;
  16248. t['hungarumlaut'] = 333;
  16249. t['ogonek'] = 333;
  16250. t['caron'] = 333;
  16251. t['emdash'] = 889;
  16252. t['AE'] = 889;
  16253. t['ordfeminine'] = 276;
  16254. t['Lslash'] = 556;
  16255. t['Oslash'] = 722;
  16256. t['OE'] = 944;
  16257. t['ordmasculine'] = 310;
  16258. t['ae'] = 667;
  16259. t['dotlessi'] = 278;
  16260. t['lslash'] = 278;
  16261. t['oslash'] = 500;
  16262. t['oe'] = 667;
  16263. t['germandbls'] = 500;
  16264. t['Idieresis'] = 333;
  16265. t['eacute'] = 444;
  16266. t['abreve'] = 500;
  16267. t['uhungarumlaut'] = 500;
  16268. t['ecaron'] = 444;
  16269. t['Ydieresis'] = 556;
  16270. t['divide'] = 675;
  16271. t['Yacute'] = 556;
  16272. t['Acircumflex'] = 611;
  16273. t['aacute'] = 500;
  16274. t['Ucircumflex'] = 722;
  16275. t['yacute'] = 444;
  16276. t['scommaaccent'] = 389;
  16277. t['ecircumflex'] = 444;
  16278. t['Uring'] = 722;
  16279. t['Udieresis'] = 722;
  16280. t['aogonek'] = 500;
  16281. t['Uacute'] = 722;
  16282. t['uogonek'] = 500;
  16283. t['Edieresis'] = 611;
  16284. t['Dcroat'] = 722;
  16285. t['commaaccent'] = 250;
  16286. t['copyright'] = 760;
  16287. t['Emacron'] = 611;
  16288. t['ccaron'] = 444;
  16289. t['aring'] = 500;
  16290. t['Ncommaaccent'] = 667;
  16291. t['lacute'] = 278;
  16292. t['agrave'] = 500;
  16293. t['Tcommaaccent'] = 556;
  16294. t['Cacute'] = 667;
  16295. t['atilde'] = 500;
  16296. t['Edotaccent'] = 611;
  16297. t['scaron'] = 389;
  16298. t['scedilla'] = 389;
  16299. t['iacute'] = 278;
  16300. t['lozenge'] = 471;
  16301. t['Rcaron'] = 611;
  16302. t['Gcommaaccent'] = 722;
  16303. t['ucircumflex'] = 500;
  16304. t['acircumflex'] = 500;
  16305. t['Amacron'] = 611;
  16306. t['rcaron'] = 389;
  16307. t['ccedilla'] = 444;
  16308. t['Zdotaccent'] = 556;
  16309. t['Thorn'] = 611;
  16310. t['Omacron'] = 722;
  16311. t['Racute'] = 611;
  16312. t['Sacute'] = 500;
  16313. t['dcaron'] = 544;
  16314. t['Umacron'] = 722;
  16315. t['uring'] = 500;
  16316. t['threesuperior'] = 300;
  16317. t['Ograve'] = 722;
  16318. t['Agrave'] = 611;
  16319. t['Abreve'] = 611;
  16320. t['multiply'] = 675;
  16321. t['uacute'] = 500;
  16322. t['Tcaron'] = 556;
  16323. t['partialdiff'] = 476;
  16324. t['ydieresis'] = 444;
  16325. t['Nacute'] = 667;
  16326. t['icircumflex'] = 278;
  16327. t['Ecircumflex'] = 611;
  16328. t['adieresis'] = 500;
  16329. t['edieresis'] = 444;
  16330. t['cacute'] = 444;
  16331. t['nacute'] = 500;
  16332. t['umacron'] = 500;
  16333. t['Ncaron'] = 667;
  16334. t['Iacute'] = 333;
  16335. t['plusminus'] = 675;
  16336. t['brokenbar'] = 275;
  16337. t['registered'] = 760;
  16338. t['Gbreve'] = 722;
  16339. t['Idotaccent'] = 333;
  16340. t['summation'] = 600;
  16341. t['Egrave'] = 611;
  16342. t['racute'] = 389;
  16343. t['omacron'] = 500;
  16344. t['Zacute'] = 556;
  16345. t['Zcaron'] = 556;
  16346. t['greaterequal'] = 549;
  16347. t['Eth'] = 722;
  16348. t['Ccedilla'] = 667;
  16349. t['lcommaaccent'] = 278;
  16350. t['tcaron'] = 300;
  16351. t['eogonek'] = 444;
  16352. t['Uogonek'] = 722;
  16353. t['Aacute'] = 611;
  16354. t['Adieresis'] = 611;
  16355. t['egrave'] = 444;
  16356. t['zacute'] = 389;
  16357. t['iogonek'] = 278;
  16358. t['Oacute'] = 722;
  16359. t['oacute'] = 500;
  16360. t['amacron'] = 500;
  16361. t['sacute'] = 389;
  16362. t['idieresis'] = 278;
  16363. t['Ocircumflex'] = 722;
  16364. t['Ugrave'] = 722;
  16365. t['Delta'] = 612;
  16366. t['thorn'] = 500;
  16367. t['twosuperior'] = 300;
  16368. t['Odieresis'] = 722;
  16369. t['mu'] = 500;
  16370. t['igrave'] = 278;
  16371. t['ohungarumlaut'] = 500;
  16372. t['Eogonek'] = 611;
  16373. t['dcroat'] = 500;
  16374. t['threequarters'] = 750;
  16375. t['Scedilla'] = 500;
  16376. t['lcaron'] = 300;
  16377. t['Kcommaaccent'] = 667;
  16378. t['Lacute'] = 556;
  16379. t['trademark'] = 980;
  16380. t['edotaccent'] = 444;
  16381. t['Igrave'] = 333;
  16382. t['Imacron'] = 333;
  16383. t['Lcaron'] = 611;
  16384. t['onehalf'] = 750;
  16385. t['lessequal'] = 549;
  16386. t['ocircumflex'] = 500;
  16387. t['ntilde'] = 500;
  16388. t['Uhungarumlaut'] = 722;
  16389. t['Eacute'] = 611;
  16390. t['emacron'] = 444;
  16391. t['gbreve'] = 500;
  16392. t['onequarter'] = 750;
  16393. t['Scaron'] = 500;
  16394. t['Scommaaccent'] = 500;
  16395. t['Ohungarumlaut'] = 722;
  16396. t['degree'] = 400;
  16397. t['ograve'] = 500;
  16398. t['Ccaron'] = 667;
  16399. t['ugrave'] = 500;
  16400. t['radical'] = 453;
  16401. t['Dcaron'] = 722;
  16402. t['rcommaaccent'] = 389;
  16403. t['Ntilde'] = 667;
  16404. t['otilde'] = 500;
  16405. t['Rcommaaccent'] = 611;
  16406. t['Lcommaaccent'] = 556;
  16407. t['Atilde'] = 611;
  16408. t['Aogonek'] = 611;
  16409. t['Aring'] = 611;
  16410. t['Otilde'] = 722;
  16411. t['zdotaccent'] = 389;
  16412. t['Ecaron'] = 611;
  16413. t['Iogonek'] = 333;
  16414. t['kcommaaccent'] = 444;
  16415. t['minus'] = 675;
  16416. t['Icircumflex'] = 333;
  16417. t['ncaron'] = 500;
  16418. t['tcommaaccent'] = 278;
  16419. t['logicalnot'] = 675;
  16420. t['odieresis'] = 500;
  16421. t['udieresis'] = 500;
  16422. t['notequal'] = 549;
  16423. t['gcommaaccent'] = 500;
  16424. t['eth'] = 500;
  16425. t['zcaron'] = 389;
  16426. t['ncommaaccent'] = 500;
  16427. t['onesuperior'] = 300;
  16428. t['imacron'] = 278;
  16429. t['Euro'] = 500;
  16430. });
  16431. t['ZapfDingbats'] = getLookupTableFactory(function (t) {
  16432. t['space'] = 278;
  16433. t['a1'] = 974;
  16434. t['a2'] = 961;
  16435. t['a202'] = 974;
  16436. t['a3'] = 980;
  16437. t['a4'] = 719;
  16438. t['a5'] = 789;
  16439. t['a119'] = 790;
  16440. t['a118'] = 791;
  16441. t['a117'] = 690;
  16442. t['a11'] = 960;
  16443. t['a12'] = 939;
  16444. t['a13'] = 549;
  16445. t['a14'] = 855;
  16446. t['a15'] = 911;
  16447. t['a16'] = 933;
  16448. t['a105'] = 911;
  16449. t['a17'] = 945;
  16450. t['a18'] = 974;
  16451. t['a19'] = 755;
  16452. t['a20'] = 846;
  16453. t['a21'] = 762;
  16454. t['a22'] = 761;
  16455. t['a23'] = 571;
  16456. t['a24'] = 677;
  16457. t['a25'] = 763;
  16458. t['a26'] = 760;
  16459. t['a27'] = 759;
  16460. t['a28'] = 754;
  16461. t['a6'] = 494;
  16462. t['a7'] = 552;
  16463. t['a8'] = 537;
  16464. t['a9'] = 577;
  16465. t['a10'] = 692;
  16466. t['a29'] = 786;
  16467. t['a30'] = 788;
  16468. t['a31'] = 788;
  16469. t['a32'] = 790;
  16470. t['a33'] = 793;
  16471. t['a34'] = 794;
  16472. t['a35'] = 816;
  16473. t['a36'] = 823;
  16474. t['a37'] = 789;
  16475. t['a38'] = 841;
  16476. t['a39'] = 823;
  16477. t['a40'] = 833;
  16478. t['a41'] = 816;
  16479. t['a42'] = 831;
  16480. t['a43'] = 923;
  16481. t['a44'] = 744;
  16482. t['a45'] = 723;
  16483. t['a46'] = 749;
  16484. t['a47'] = 790;
  16485. t['a48'] = 792;
  16486. t['a49'] = 695;
  16487. t['a50'] = 776;
  16488. t['a51'] = 768;
  16489. t['a52'] = 792;
  16490. t['a53'] = 759;
  16491. t['a54'] = 707;
  16492. t['a55'] = 708;
  16493. t['a56'] = 682;
  16494. t['a57'] = 701;
  16495. t['a58'] = 826;
  16496. t['a59'] = 815;
  16497. t['a60'] = 789;
  16498. t['a61'] = 789;
  16499. t['a62'] = 707;
  16500. t['a63'] = 687;
  16501. t['a64'] = 696;
  16502. t['a65'] = 689;
  16503. t['a66'] = 786;
  16504. t['a67'] = 787;
  16505. t['a68'] = 713;
  16506. t['a69'] = 791;
  16507. t['a70'] = 785;
  16508. t['a71'] = 791;
  16509. t['a72'] = 873;
  16510. t['a73'] = 761;
  16511. t['a74'] = 762;
  16512. t['a203'] = 762;
  16513. t['a75'] = 759;
  16514. t['a204'] = 759;
  16515. t['a76'] = 892;
  16516. t['a77'] = 892;
  16517. t['a78'] = 788;
  16518. t['a79'] = 784;
  16519. t['a81'] = 438;
  16520. t['a82'] = 138;
  16521. t['a83'] = 277;
  16522. t['a84'] = 415;
  16523. t['a97'] = 392;
  16524. t['a98'] = 392;
  16525. t['a99'] = 668;
  16526. t['a100'] = 668;
  16527. t['a89'] = 390;
  16528. t['a90'] = 390;
  16529. t['a93'] = 317;
  16530. t['a94'] = 317;
  16531. t['a91'] = 276;
  16532. t['a92'] = 276;
  16533. t['a205'] = 509;
  16534. t['a85'] = 509;
  16535. t['a206'] = 410;
  16536. t['a86'] = 410;
  16537. t['a87'] = 234;
  16538. t['a88'] = 234;
  16539. t['a95'] = 334;
  16540. t['a96'] = 334;
  16541. t['a101'] = 732;
  16542. t['a102'] = 544;
  16543. t['a103'] = 544;
  16544. t['a104'] = 910;
  16545. t['a106'] = 667;
  16546. t['a107'] = 760;
  16547. t['a108'] = 760;
  16548. t['a112'] = 776;
  16549. t['a111'] = 595;
  16550. t['a110'] = 694;
  16551. t['a109'] = 626;
  16552. t['a120'] = 788;
  16553. t['a121'] = 788;
  16554. t['a122'] = 788;
  16555. t['a123'] = 788;
  16556. t['a124'] = 788;
  16557. t['a125'] = 788;
  16558. t['a126'] = 788;
  16559. t['a127'] = 788;
  16560. t['a128'] = 788;
  16561. t['a129'] = 788;
  16562. t['a130'] = 788;
  16563. t['a131'] = 788;
  16564. t['a132'] = 788;
  16565. t['a133'] = 788;
  16566. t['a134'] = 788;
  16567. t['a135'] = 788;
  16568. t['a136'] = 788;
  16569. t['a137'] = 788;
  16570. t['a138'] = 788;
  16571. t['a139'] = 788;
  16572. t['a140'] = 788;
  16573. t['a141'] = 788;
  16574. t['a142'] = 788;
  16575. t['a143'] = 788;
  16576. t['a144'] = 788;
  16577. t['a145'] = 788;
  16578. t['a146'] = 788;
  16579. t['a147'] = 788;
  16580. t['a148'] = 788;
  16581. t['a149'] = 788;
  16582. t['a150'] = 788;
  16583. t['a151'] = 788;
  16584. t['a152'] = 788;
  16585. t['a153'] = 788;
  16586. t['a154'] = 788;
  16587. t['a155'] = 788;
  16588. t['a156'] = 788;
  16589. t['a157'] = 788;
  16590. t['a158'] = 788;
  16591. t['a159'] = 788;
  16592. t['a160'] = 894;
  16593. t['a161'] = 838;
  16594. t['a163'] = 1016;
  16595. t['a164'] = 458;
  16596. t['a196'] = 748;
  16597. t['a165'] = 924;
  16598. t['a192'] = 748;
  16599. t['a166'] = 918;
  16600. t['a167'] = 927;
  16601. t['a168'] = 928;
  16602. t['a169'] = 928;
  16603. t['a170'] = 834;
  16604. t['a171'] = 873;
  16605. t['a172'] = 828;
  16606. t['a173'] = 924;
  16607. t['a162'] = 924;
  16608. t['a174'] = 917;
  16609. t['a175'] = 930;
  16610. t['a176'] = 931;
  16611. t['a177'] = 463;
  16612. t['a178'] = 883;
  16613. t['a179'] = 836;
  16614. t['a193'] = 836;
  16615. t['a180'] = 867;
  16616. t['a199'] = 867;
  16617. t['a181'] = 696;
  16618. t['a200'] = 696;
  16619. t['a182'] = 874;
  16620. t['a201'] = 874;
  16621. t['a183'] = 760;
  16622. t['a184'] = 946;
  16623. t['a197'] = 771;
  16624. t['a185'] = 865;
  16625. t['a194'] = 771;
  16626. t['a198'] = 888;
  16627. t['a186'] = 967;
  16628. t['a195'] = 888;
  16629. t['a187'] = 831;
  16630. t['a188'] = 873;
  16631. t['a189'] = 927;
  16632. t['a190'] = 970;
  16633. t['a191'] = 918;
  16634. });
  16635. });
  16636. exports.getMetrics = getMetrics;
  16637. }));
  16638. (function (root, factory) {
  16639. {
  16640. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  16641. }
  16642. }(this, function (exports, sharedUtil) {
  16643. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  16644. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  16645. // Workaround for missing math precision in JS.
  16646. var MASK_HIGH = 0xffff0000;
  16647. var MASK_LOW = 0xffff;
  16648. function MurmurHash3_64 (seed) {
  16649. var SEED = 0xc3d2e1f0;
  16650. this.h1 = seed ? seed & 0xffffffff : SEED;
  16651. this.h2 = seed ? seed & 0xffffffff : SEED;
  16652. }
  16653. var alwaysUseUint32ArrayView = false;
  16654. // old webkits have issues with non-aligned arrays
  16655. try {
  16656. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  16657. } catch (e) {
  16658. alwaysUseUint32ArrayView = true;
  16659. }
  16660. MurmurHash3_64.prototype = {
  16661. update: function MurmurHash3_64_update(input) {
  16662. var useUint32ArrayView = alwaysUseUint32ArrayView;
  16663. var i;
  16664. if (typeof input === 'string') {
  16665. var data = new Uint8Array(input.length * 2);
  16666. var length = 0;
  16667. for (i = 0; i < input.length; i++) {
  16668. var code = input.charCodeAt(i);
  16669. if (code <= 0xff) {
  16670. data[length++] = code;
  16671. }
  16672. else {
  16673. data[length++] = code >>> 8;
  16674. data[length++] = code & 0xff;
  16675. }
  16676. }
  16677. } else if (input instanceof Uint8Array) {
  16678. data = input;
  16679. length = data.length;
  16680. } else if (typeof input === 'object' && ('length' in input)) {
  16681. // processing regular arrays as well, e.g. for IE9
  16682. data = input;
  16683. length = data.length;
  16684. useUint32ArrayView = true;
  16685. } else {
  16686. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  16687. 'Input must be a string or array.');
  16688. }
  16689. var blockCounts = length >> 2;
  16690. var tailLength = length - blockCounts * 4;
  16691. // we don't care about endianness here
  16692. var dataUint32 = useUint32ArrayView ?
  16693. new Uint32ArrayView(data, blockCounts) :
  16694. new Uint32Array(data.buffer, 0, blockCounts);
  16695. var k1 = 0;
  16696. var k2 = 0;
  16697. var h1 = this.h1;
  16698. var h2 = this.h2;
  16699. var C1 = 0xcc9e2d51;
  16700. var C2 = 0x1b873593;
  16701. var C1_LOW = C1 & MASK_LOW;
  16702. var C2_LOW = C2 & MASK_LOW;
  16703. for (i = 0; i < blockCounts; i++) {
  16704. if (i & 1) {
  16705. k1 = dataUint32[i];
  16706. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  16707. k1 = k1 << 15 | k1 >>> 17;
  16708. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  16709. h1 ^= k1;
  16710. h1 = h1 << 13 | h1 >>> 19;
  16711. h1 = h1 * 5 + 0xe6546b64;
  16712. } else {
  16713. k2 = dataUint32[i];
  16714. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  16715. k2 = k2 << 15 | k2 >>> 17;
  16716. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  16717. h2 ^= k2;
  16718. h2 = h2 << 13 | h2 >>> 19;
  16719. h2 = h2 * 5 + 0xe6546b64;
  16720. }
  16721. }
  16722. k1 = 0;
  16723. switch (tailLength) {
  16724. case 3:
  16725. k1 ^= data[blockCounts * 4 + 2] << 16;
  16726. /* falls through */
  16727. case 2:
  16728. k1 ^= data[blockCounts * 4 + 1] << 8;
  16729. /* falls through */
  16730. case 1:
  16731. k1 ^= data[blockCounts * 4];
  16732. /* falls through */
  16733. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  16734. k1 = k1 << 15 | k1 >>> 17;
  16735. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  16736. if (blockCounts & 1) {
  16737. h1 ^= k1;
  16738. } else {
  16739. h2 ^= k1;
  16740. }
  16741. }
  16742. this.h1 = h1;
  16743. this.h2 = h2;
  16744. return this;
  16745. },
  16746. hexdigest: function MurmurHash3_64_hexdigest () {
  16747. var h1 = this.h1;
  16748. var h2 = this.h2;
  16749. h1 ^= h2 >>> 1;
  16750. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  16751. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  16752. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  16753. h1 ^= h2 >>> 1;
  16754. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  16755. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  16756. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  16757. h1 ^= h2 >>> 1;
  16758. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  16759. var hex = (arr[i] >>> 0).toString(16);
  16760. while (hex.length < 8) {
  16761. hex = '0' + hex;
  16762. }
  16763. str += hex;
  16764. }
  16765. return str;
  16766. }
  16767. };
  16768. return MurmurHash3_64;
  16769. })();
  16770. exports.MurmurHash3_64 = MurmurHash3_64;
  16771. }));
  16772. (function (root, factory) {
  16773. {
  16774. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  16775. }
  16776. }(this, function (exports, sharedUtil) {
  16777. var isArray = sharedUtil.isArray;
  16778. var Name = (function NameClosure() {
  16779. function Name(name) {
  16780. this.name = name;
  16781. }
  16782. Name.prototype = {};
  16783. var nameCache = Object.create(null);
  16784. Name.get = function Name_get(name) {
  16785. var nameValue = nameCache[name];
  16786. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  16787. };
  16788. return Name;
  16789. })();
  16790. var Cmd = (function CmdClosure() {
  16791. function Cmd(cmd) {
  16792. this.cmd = cmd;
  16793. }
  16794. Cmd.prototype = {};
  16795. var cmdCache = Object.create(null);
  16796. Cmd.get = function Cmd_get(cmd) {
  16797. var cmdValue = cmdCache[cmd];
  16798. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  16799. };
  16800. return Cmd;
  16801. })();
  16802. var Dict = (function DictClosure() {
  16803. var nonSerializable = function nonSerializableClosure() {
  16804. return nonSerializable; // creating closure on some variable
  16805. };
  16806. // xref is optional
  16807. function Dict(xref) {
  16808. // Map should only be used internally, use functions below to access.
  16809. this.map = Object.create(null);
  16810. this.xref = xref;
  16811. this.objId = null;
  16812. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  16813. }
  16814. Dict.prototype = {
  16815. assignXref: function Dict_assignXref(newXref) {
  16816. this.xref = newXref;
  16817. },
  16818. // automatically dereferences Ref objects
  16819. get: function Dict_get(key1, key2, key3) {
  16820. var value;
  16821. var xref = this.xref;
  16822. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  16823. typeof key2 === 'undefined') {
  16824. return xref ? xref.fetchIfRef(value) : value;
  16825. }
  16826. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  16827. typeof key3 === 'undefined') {
  16828. return xref ? xref.fetchIfRef(value) : value;
  16829. }
  16830. value = this.map[key3] || null;
  16831. return xref ? xref.fetchIfRef(value) : value;
  16832. },
  16833. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  16834. getAsync: function Dict_getAsync(key1, key2, key3) {
  16835. var value;
  16836. var xref = this.xref;
  16837. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  16838. typeof key2 === 'undefined') {
  16839. if (xref) {
  16840. return xref.fetchIfRefAsync(value);
  16841. }
  16842. return Promise.resolve(value);
  16843. }
  16844. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  16845. typeof key3 === 'undefined') {
  16846. if (xref) {
  16847. return xref.fetchIfRefAsync(value);
  16848. }
  16849. return Promise.resolve(value);
  16850. }
  16851. value = this.map[key3] || null;
  16852. if (xref) {
  16853. return xref.fetchIfRefAsync(value);
  16854. }
  16855. return Promise.resolve(value);
  16856. },
  16857. // Same as get(), but dereferences all elements if the result is an Array.
  16858. getArray: function Dict_getArray(key1, key2, key3) {
  16859. var value = this.get(key1, key2, key3);
  16860. var xref = this.xref;
  16861. if (!isArray(value) || !xref) {
  16862. return value;
  16863. }
  16864. value = value.slice(); // Ensure that we don't modify the Dict data.
  16865. for (var i = 0, ii = value.length; i < ii; i++) {
  16866. if (!isRef(value[i])) {
  16867. continue;
  16868. }
  16869. value[i] = xref.fetch(value[i]);
  16870. }
  16871. return value;
  16872. },
  16873. // no dereferencing
  16874. getRaw: function Dict_getRaw(key) {
  16875. return this.map[key];
  16876. },
  16877. getKeys: function Dict_getKeys() {
  16878. return Object.keys(this.map);
  16879. },
  16880. set: function Dict_set(key, value) {
  16881. this.map[key] = value;
  16882. },
  16883. has: function Dict_has(key) {
  16884. return key in this.map;
  16885. },
  16886. forEach: function Dict_forEach(callback) {
  16887. for (var key in this.map) {
  16888. callback(key, this.get(key));
  16889. }
  16890. }
  16891. };
  16892. Dict.empty = new Dict(null);
  16893. Dict.merge = function Dict_merge(xref, dictArray) {
  16894. var mergedDict = new Dict(xref);
  16895. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  16896. var dict = dictArray[i];
  16897. if (!isDict(dict)) {
  16898. continue;
  16899. }
  16900. for (var keyName in dict.map) {
  16901. if (mergedDict.map[keyName]) {
  16902. continue;
  16903. }
  16904. mergedDict.map[keyName] = dict.map[keyName];
  16905. }
  16906. }
  16907. return mergedDict;
  16908. };
  16909. return Dict;
  16910. })();
  16911. var Ref = (function RefClosure() {
  16912. function Ref(num, gen) {
  16913. this.num = num;
  16914. this.gen = gen;
  16915. }
  16916. Ref.prototype = {
  16917. toString: function Ref_toString() {
  16918. // This function is hot, so we make the string as compact as possible.
  16919. // |this.gen| is almost always zero, so we treat that case specially.
  16920. var str = this.num + 'R';
  16921. if (this.gen !== 0) {
  16922. str += this.gen;
  16923. }
  16924. return str;
  16925. }
  16926. };
  16927. return Ref;
  16928. })();
  16929. // The reference is identified by number and generation.
  16930. // This structure stores only one instance of the reference.
  16931. var RefSet = (function RefSetClosure() {
  16932. function RefSet() {
  16933. this.dict = Object.create(null);
  16934. }
  16935. RefSet.prototype = {
  16936. has: function RefSet_has(ref) {
  16937. return ref.toString() in this.dict;
  16938. },
  16939. put: function RefSet_put(ref) {
  16940. this.dict[ref.toString()] = true;
  16941. },
  16942. remove: function RefSet_remove(ref) {
  16943. delete this.dict[ref.toString()];
  16944. }
  16945. };
  16946. return RefSet;
  16947. })();
  16948. var RefSetCache = (function RefSetCacheClosure() {
  16949. function RefSetCache() {
  16950. this.dict = Object.create(null);
  16951. }
  16952. RefSetCache.prototype = {
  16953. get: function RefSetCache_get(ref) {
  16954. return this.dict[ref.toString()];
  16955. },
  16956. has: function RefSetCache_has(ref) {
  16957. return ref.toString() in this.dict;
  16958. },
  16959. put: function RefSetCache_put(ref, obj) {
  16960. this.dict[ref.toString()] = obj;
  16961. },
  16962. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  16963. this.dict[ref.toString()] = this.get(aliasRef);
  16964. },
  16965. forEach: function RefSetCache_forEach(fn, thisArg) {
  16966. for (var i in this.dict) {
  16967. fn.call(thisArg, this.dict[i]);
  16968. }
  16969. },
  16970. clear: function RefSetCache_clear() {
  16971. this.dict = Object.create(null);
  16972. }
  16973. };
  16974. return RefSetCache;
  16975. })();
  16976. function isName(v, name) {
  16977. return v instanceof Name && (name === undefined || v.name === name);
  16978. }
  16979. function isCmd(v, cmd) {
  16980. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  16981. }
  16982. function isDict(v, type) {
  16983. return v instanceof Dict &&
  16984. (type === undefined || isName(v.get('Type'), type));
  16985. }
  16986. function isRef(v) {
  16987. return v instanceof Ref;
  16988. }
  16989. function isRefsEqual(v1, v2) {
  16990. return v1.num === v2.num && v1.gen === v2.gen;
  16991. }
  16992. function isStream(v) {
  16993. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  16994. }
  16995. exports.Cmd = Cmd;
  16996. exports.Dict = Dict;
  16997. exports.Name = Name;
  16998. exports.Ref = Ref;
  16999. exports.RefSet = RefSet;
  17000. exports.RefSetCache = RefSetCache;
  17001. exports.isCmd = isCmd;
  17002. exports.isDict = isDict;
  17003. exports.isName = isName;
  17004. exports.isRef = isRef;
  17005. exports.isRefsEqual = isRefsEqual;
  17006. exports.isStream = isStream;
  17007. }));
  17008. (function (root, factory) {
  17009. {
  17010. factory((root.pdfjsCoreStandardFonts = {}), root.pdfjsSharedUtil);
  17011. }
  17012. }(this, function (exports, sharedUtil) {
  17013. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  17014. /**
  17015. * Hold a map of decoded fonts and of the standard fourteen Type1
  17016. * fonts and their acronyms.
  17017. */
  17018. var getStdFontMap = getLookupTableFactory(function (t) {
  17019. t['ArialNarrow'] = 'Helvetica';
  17020. t['ArialNarrow-Bold'] = 'Helvetica-Bold';
  17021. t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique';
  17022. t['ArialNarrow-Italic'] = 'Helvetica-Oblique';
  17023. t['ArialBlack'] = 'Helvetica';
  17024. t['ArialBlack-Bold'] = 'Helvetica-Bold';
  17025. t['ArialBlack-BoldItalic'] = 'Helvetica-BoldOblique';
  17026. t['ArialBlack-Italic'] = 'Helvetica-Oblique';
  17027. t['Arial'] = 'Helvetica';
  17028. t['Arial-Bold'] = 'Helvetica-Bold';
  17029. t['Arial-BoldItalic'] = 'Helvetica-BoldOblique';
  17030. t['Arial-Italic'] = 'Helvetica-Oblique';
  17031. t['Arial-BoldItalicMT'] = 'Helvetica-BoldOblique';
  17032. t['Arial-BoldMT'] = 'Helvetica-Bold';
  17033. t['Arial-ItalicMT'] = 'Helvetica-Oblique';
  17034. t['ArialMT'] = 'Helvetica';
  17035. t['Courier-Bold'] = 'Courier-Bold';
  17036. t['Courier-BoldItalic'] = 'Courier-BoldOblique';
  17037. t['Courier-Italic'] = 'Courier-Oblique';
  17038. t['CourierNew'] = 'Courier';
  17039. t['CourierNew-Bold'] = 'Courier-Bold';
  17040. t['CourierNew-BoldItalic'] = 'Courier-BoldOblique';
  17041. t['CourierNew-Italic'] = 'Courier-Oblique';
  17042. t['CourierNewPS-BoldItalicMT'] = 'Courier-BoldOblique';
  17043. t['CourierNewPS-BoldMT'] = 'Courier-Bold';
  17044. t['CourierNewPS-ItalicMT'] = 'Courier-Oblique';
  17045. t['CourierNewPSMT'] = 'Courier';
  17046. t['Helvetica'] = 'Helvetica';
  17047. t['Helvetica-Bold'] = 'Helvetica-Bold';
  17048. t['Helvetica-BoldItalic'] = 'Helvetica-BoldOblique';
  17049. t['Helvetica-BoldOblique'] = 'Helvetica-BoldOblique';
  17050. t['Helvetica-Italic'] = 'Helvetica-Oblique';
  17051. t['Helvetica-Oblique'] = 'Helvetica-Oblique';
  17052. t['Symbol-Bold'] = 'Symbol';
  17053. t['Symbol-BoldItalic'] = 'Symbol';
  17054. t['Symbol-Italic'] = 'Symbol';
  17055. t['TimesNewRoman'] = 'Times-Roman';
  17056. t['TimesNewRoman-Bold'] = 'Times-Bold';
  17057. t['TimesNewRoman-BoldItalic'] = 'Times-BoldItalic';
  17058. t['TimesNewRoman-Italic'] = 'Times-Italic';
  17059. t['TimesNewRomanPS'] = 'Times-Roman';
  17060. t['TimesNewRomanPS-Bold'] = 'Times-Bold';
  17061. t['TimesNewRomanPS-BoldItalic'] = 'Times-BoldItalic';
  17062. t['TimesNewRomanPS-BoldItalicMT'] = 'Times-BoldItalic';
  17063. t['TimesNewRomanPS-BoldMT'] = 'Times-Bold';
  17064. t['TimesNewRomanPS-Italic'] = 'Times-Italic';
  17065. t['TimesNewRomanPS-ItalicMT'] = 'Times-Italic';
  17066. t['TimesNewRomanPSMT'] = 'Times-Roman';
  17067. t['TimesNewRomanPSMT-Bold'] = 'Times-Bold';
  17068. t['TimesNewRomanPSMT-BoldItalic'] = 'Times-BoldItalic';
  17069. t['TimesNewRomanPSMT-Italic'] = 'Times-Italic';
  17070. });
  17071. /**
  17072. * Holds the map of the non-standard fonts that might be included as
  17073. * a standard fonts without glyph data.
  17074. */
  17075. var getNonStdFontMap = getLookupTableFactory(function (t) {
  17076. t['CenturyGothic'] = 'Helvetica';
  17077. t['CenturyGothic-Bold'] = 'Helvetica-Bold';
  17078. t['CenturyGothic-BoldItalic'] = 'Helvetica-BoldOblique';
  17079. t['CenturyGothic-Italic'] = 'Helvetica-Oblique';
  17080. t['ComicSansMS'] = 'Comic Sans MS';
  17081. t['ComicSansMS-Bold'] = 'Comic Sans MS-Bold';
  17082. t['ComicSansMS-BoldItalic'] = 'Comic Sans MS-BoldItalic';
  17083. t['ComicSansMS-Italic'] = 'Comic Sans MS-Italic';
  17084. t['LucidaConsole'] = 'Courier';
  17085. t['LucidaConsole-Bold'] = 'Courier-Bold';
  17086. t['LucidaConsole-BoldItalic'] = 'Courier-BoldOblique';
  17087. t['LucidaConsole-Italic'] = 'Courier-Oblique';
  17088. t['MS-Gothic'] = 'MS Gothic';
  17089. t['MS-Gothic-Bold'] = 'MS Gothic-Bold';
  17090. t['MS-Gothic-BoldItalic'] = 'MS Gothic-BoldItalic';
  17091. t['MS-Gothic-Italic'] = 'MS Gothic-Italic';
  17092. t['MS-Mincho'] = 'MS Mincho';
  17093. t['MS-Mincho-Bold'] = 'MS Mincho-Bold';
  17094. t['MS-Mincho-BoldItalic'] = 'MS Mincho-BoldItalic';
  17095. t['MS-Mincho-Italic'] = 'MS Mincho-Italic';
  17096. t['MS-PGothic'] = 'MS PGothic';
  17097. t['MS-PGothic-Bold'] = 'MS PGothic-Bold';
  17098. t['MS-PGothic-BoldItalic'] = 'MS PGothic-BoldItalic';
  17099. t['MS-PGothic-Italic'] = 'MS PGothic-Italic';
  17100. t['MS-PMincho'] = 'MS PMincho';
  17101. t['MS-PMincho-Bold'] = 'MS PMincho-Bold';
  17102. t['MS-PMincho-BoldItalic'] = 'MS PMincho-BoldItalic';
  17103. t['MS-PMincho-Italic'] = 'MS PMincho-Italic';
  17104. t['Wingdings'] = 'ZapfDingbats';
  17105. });
  17106. var getSerifFonts = getLookupTableFactory(function (t) {
  17107. t['Adobe Jenson'] = true;
  17108. t['Adobe Text'] = true;
  17109. t['Albertus'] = true;
  17110. t['Aldus'] = true;
  17111. t['Alexandria'] = true;
  17112. t['Algerian'] = true;
  17113. t['American Typewriter'] = true;
  17114. t['Antiqua'] = true;
  17115. t['Apex'] = true;
  17116. t['Arno'] = true;
  17117. t['Aster'] = true;
  17118. t['Aurora'] = true;
  17119. t['Baskerville'] = true;
  17120. t['Bell'] = true;
  17121. t['Bembo'] = true;
  17122. t['Bembo Schoolbook'] = true;
  17123. t['Benguiat'] = true;
  17124. t['Berkeley Old Style'] = true;
  17125. t['Bernhard Modern'] = true;
  17126. t['Berthold City'] = true;
  17127. t['Bodoni'] = true;
  17128. t['Bauer Bodoni'] = true;
  17129. t['Book Antiqua'] = true;
  17130. t['Bookman'] = true;
  17131. t['Bordeaux Roman'] = true;
  17132. t['Californian FB'] = true;
  17133. t['Calisto'] = true;
  17134. t['Calvert'] = true;
  17135. t['Capitals'] = true;
  17136. t['Cambria'] = true;
  17137. t['Cartier'] = true;
  17138. t['Caslon'] = true;
  17139. t['Catull'] = true;
  17140. t['Centaur'] = true;
  17141. t['Century Old Style'] = true;
  17142. t['Century Schoolbook'] = true;
  17143. t['Chaparral'] = true;
  17144. t['Charis SIL'] = true;
  17145. t['Cheltenham'] = true;
  17146. t['Cholla Slab'] = true;
  17147. t['Clarendon'] = true;
  17148. t['Clearface'] = true;
  17149. t['Cochin'] = true;
  17150. t['Colonna'] = true;
  17151. t['Computer Modern'] = true;
  17152. t['Concrete Roman'] = true;
  17153. t['Constantia'] = true;
  17154. t['Cooper Black'] = true;
  17155. t['Corona'] = true;
  17156. t['Ecotype'] = true;
  17157. t['Egyptienne'] = true;
  17158. t['Elephant'] = true;
  17159. t['Excelsior'] = true;
  17160. t['Fairfield'] = true;
  17161. t['FF Scala'] = true;
  17162. t['Folkard'] = true;
  17163. t['Footlight'] = true;
  17164. t['FreeSerif'] = true;
  17165. t['Friz Quadrata'] = true;
  17166. t['Garamond'] = true;
  17167. t['Gentium'] = true;
  17168. t['Georgia'] = true;
  17169. t['Gloucester'] = true;
  17170. t['Goudy Old Style'] = true;
  17171. t['Goudy Schoolbook'] = true;
  17172. t['Goudy Pro Font'] = true;
  17173. t['Granjon'] = true;
  17174. t['Guardian Egyptian'] = true;
  17175. t['Heather'] = true;
  17176. t['Hercules'] = true;
  17177. t['High Tower Text'] = true;
  17178. t['Hiroshige'] = true;
  17179. t['Hoefler Text'] = true;
  17180. t['Humana Serif'] = true;
  17181. t['Imprint'] = true;
  17182. t['Ionic No. 5'] = true;
  17183. t['Janson'] = true;
  17184. t['Joanna'] = true;
  17185. t['Korinna'] = true;
  17186. t['Lexicon'] = true;
  17187. t['Liberation Serif'] = true;
  17188. t['Linux Libertine'] = true;
  17189. t['Literaturnaya'] = true;
  17190. t['Lucida'] = true;
  17191. t['Lucida Bright'] = true;
  17192. t['Melior'] = true;
  17193. t['Memphis'] = true;
  17194. t['Miller'] = true;
  17195. t['Minion'] = true;
  17196. t['Modern'] = true;
  17197. t['Mona Lisa'] = true;
  17198. t['Mrs Eaves'] = true;
  17199. t['MS Serif'] = true;
  17200. t['Museo Slab'] = true;
  17201. t['New York'] = true;
  17202. t['Nimbus Roman'] = true;
  17203. t['NPS Rawlinson Roadway'] = true;
  17204. t['Palatino'] = true;
  17205. t['Perpetua'] = true;
  17206. t['Plantin'] = true;
  17207. t['Plantin Schoolbook'] = true;
  17208. t['Playbill'] = true;
  17209. t['Poor Richard'] = true;
  17210. t['Rawlinson Roadway'] = true;
  17211. t['Renault'] = true;
  17212. t['Requiem'] = true;
  17213. t['Rockwell'] = true;
  17214. t['Roman'] = true;
  17215. t['Rotis Serif'] = true;
  17216. t['Sabon'] = true;
  17217. t['Scala'] = true;
  17218. t['Seagull'] = true;
  17219. t['Sistina'] = true;
  17220. t['Souvenir'] = true;
  17221. t['STIX'] = true;
  17222. t['Stone Informal'] = true;
  17223. t['Stone Serif'] = true;
  17224. t['Sylfaen'] = true;
  17225. t['Times'] = true;
  17226. t['Trajan'] = true;
  17227. t['Trinité'] = true;
  17228. t['Trump Mediaeval'] = true;
  17229. t['Utopia'] = true;
  17230. t['Vale Type'] = true;
  17231. t['Bitstream Vera'] = true;
  17232. t['Vera Serif'] = true;
  17233. t['Versailles'] = true;
  17234. t['Wanted'] = true;
  17235. t['Weiss'] = true;
  17236. t['Wide Latin'] = true;
  17237. t['Windsor'] = true;
  17238. t['XITS'] = true;
  17239. });
  17240. var getSymbolsFonts = getLookupTableFactory(function (t) {
  17241. t['Dingbats'] = true;
  17242. t['Symbol'] = true;
  17243. t['ZapfDingbats'] = true;
  17244. });
  17245. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
  17246. // fonts, but does not embed the CID to GID mapping. The mapping is incomplete
  17247. // for all glyphs, but common for some set of the standard fonts.
  17248. var getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  17249. t[2] = 10; t[3] = 32; t[4] = 33; t[5] = 34; t[6] = 35; t[7] = 36; t[8] = 37;
  17250. t[9] = 38; t[10] = 39; t[11] = 40; t[12] = 41; t[13] = 42; t[14] = 43;
  17251. t[15] = 44; t[16] = 45; t[17] = 46; t[18] = 47; t[19] = 48; t[20] = 49;
  17252. t[21] = 50; t[22] = 51; t[23] = 52; t[24] = 53; t[25] = 54; t[26] = 55;
  17253. t[27] = 56; t[28] = 57; t[29] = 58; t[30] = 894; t[31] = 60; t[32] = 61;
  17254. t[33] = 62; t[34] = 63; t[35] = 64; t[36] = 65; t[37] = 66; t[38] = 67;
  17255. t[39] = 68; t[40] = 69; t[41] = 70; t[42] = 71; t[43] = 72; t[44] = 73;
  17256. t[45] = 74; t[46] = 75; t[47] = 76; t[48] = 77; t[49] = 78; t[50] = 79;
  17257. t[51] = 80; t[52] = 81; t[53] = 82; t[54] = 83; t[55] = 84; t[56] = 85;
  17258. t[57] = 86; t[58] = 87; t[59] = 88; t[60] = 89; t[61] = 90; t[62] = 91;
  17259. t[63] = 92; t[64] = 93; t[65] = 94; t[66] = 95; t[67] = 96; t[68] = 97;
  17260. t[69] = 98; t[70] = 99; t[71] = 100; t[72] = 101; t[73] = 102; t[74] = 103;
  17261. t[75] = 104; t[76] = 105; t[77] = 106; t[78] = 107; t[79] = 108;
  17262. t[80] = 109; t[81] = 110; t[82] = 111; t[83] = 112; t[84] = 113;
  17263. t[85] = 114; t[86] = 115; t[87] = 116; t[88] = 117; t[89] = 118;
  17264. t[90] = 119; t[91] = 120; t[92] = 121; t[93] = 122; t[94] = 123;
  17265. t[95] = 124; t[96] = 125; t[97] = 126; t[98] = 196; t[99] = 197;
  17266. t[100] = 199; t[101] = 201; t[102] = 209; t[103] = 214; t[104] = 220;
  17267. t[105] = 225; t[106] = 224; t[107] = 226; t[108] = 228; t[109] = 227;
  17268. t[110] = 229; t[111] = 231; t[112] = 233; t[113] = 232; t[114] = 234;
  17269. t[115] = 235; t[116] = 237; t[117] = 236; t[118] = 238; t[119] = 239;
  17270. t[120] = 241; t[121] = 243; t[122] = 242; t[123] = 244; t[124] = 246;
  17271. t[125] = 245; t[126] = 250; t[127] = 249; t[128] = 251; t[129] = 252;
  17272. t[130] = 8224; t[131] = 176; t[132] = 162; t[133] = 163; t[134] = 167;
  17273. t[135] = 8226; t[136] = 182; t[137] = 223; t[138] = 174; t[139] = 169;
  17274. t[140] = 8482; t[141] = 180; t[142] = 168; t[143] = 8800; t[144] = 198;
  17275. t[145] = 216; t[146] = 8734; t[147] = 177; t[148] = 8804; t[149] = 8805;
  17276. t[150] = 165; t[151] = 181; t[152] = 8706; t[153] = 8721; t[154] = 8719;
  17277. t[156] = 8747; t[157] = 170; t[158] = 186; t[159] = 8486; t[160] = 230;
  17278. t[161] = 248; t[162] = 191; t[163] = 161; t[164] = 172; t[165] = 8730;
  17279. t[166] = 402; t[167] = 8776; t[168] = 8710; t[169] = 171; t[170] = 187;
  17280. t[171] = 8230; t[210] = 218; t[223] = 711; t[224] = 321; t[225] = 322;
  17281. t[227] = 353; t[229] = 382; t[234] = 253; t[252] = 263; t[253] = 268;
  17282. t[254] = 269; t[258] = 258; t[260] = 260; t[261] = 261; t[265] = 280;
  17283. t[266] = 281; t[268] = 283; t[269] = 313; t[275] = 323; t[276] = 324;
  17284. t[278] = 328; t[284] = 345; t[285] = 346; t[286] = 347; t[292] = 367;
  17285. t[295] = 377; t[296] = 378; t[298] = 380; t[305] = 963; t[306] = 964;
  17286. t[307] = 966; t[308] = 8215; t[309] = 8252; t[310] = 8319; t[311] = 8359;
  17287. t[312] = 8592; t[313] = 8593; t[337] = 9552; t[493] = 1039;
  17288. t[494] = 1040; t[705] = 1524; t[706] = 8362; t[710] = 64288; t[711] = 64298;
  17289. t[759] = 1617; t[761] = 1776; t[763] = 1778; t[775] = 1652; t[777] = 1764;
  17290. t[778] = 1780; t[779] = 1781; t[780] = 1782; t[782] = 771; t[783] = 64726;
  17291. t[786] = 8363; t[788] = 8532; t[790] = 768; t[791] = 769; t[792] = 768;
  17292. t[795] = 803; t[797] = 64336; t[798] = 64337; t[799] = 64342;
  17293. t[800] = 64343; t[801] = 64344; t[802] = 64345; t[803] = 64362;
  17294. t[804] = 64363; t[805] = 64364; t[2424] = 7821; t[2425] = 7822;
  17295. t[2426] = 7823; t[2427] = 7824; t[2428] = 7825; t[2429] = 7826;
  17296. t[2430] = 7827; t[2433] = 7682; t[2678] = 8045; t[2679] = 8046;
  17297. t[2830] = 1552; t[2838] = 686; t[2840] = 751; t[2842] = 753; t[2843] = 754;
  17298. t[2844] = 755; t[2846] = 757; t[2856] = 767; t[2857] = 848; t[2858] = 849;
  17299. t[2862] = 853; t[2863] = 854; t[2864] = 855; t[2865] = 861; t[2866] = 862;
  17300. t[2906] = 7460; t[2908] = 7462; t[2909] = 7463; t[2910] = 7464;
  17301. t[2912] = 7466; t[2913] = 7467; t[2914] = 7468; t[2916] = 7470;
  17302. t[2917] = 7471; t[2918] = 7472; t[2920] = 7474; t[2921] = 7475;
  17303. t[2922] = 7476; t[2924] = 7478; t[2925] = 7479; t[2926] = 7480;
  17304. t[2928] = 7482; t[2929] = 7483; t[2930] = 7484; t[2932] = 7486;
  17305. t[2933] = 7487; t[2934] = 7488; t[2936] = 7490; t[2937] = 7491;
  17306. t[2938] = 7492; t[2940] = 7494; t[2941] = 7495; t[2942] = 7496;
  17307. t[2944] = 7498; t[2946] = 7500; t[2948] = 7502; t[2950] = 7504;
  17308. t[2951] = 7505; t[2952] = 7506; t[2954] = 7508; t[2955] = 7509;
  17309. t[2956] = 7510; t[2958] = 7512; t[2959] = 7513; t[2960] = 7514;
  17310. t[2962] = 7516; t[2963] = 7517; t[2964] = 7518; t[2966] = 7520;
  17311. t[2967] = 7521; t[2968] = 7522; t[2970] = 7524; t[2971] = 7525;
  17312. t[2972] = 7526; t[2974] = 7528; t[2975] = 7529; t[2976] = 7530;
  17313. t[2978] = 1537; t[2979] = 1538; t[2980] = 1539; t[2982] = 1549;
  17314. t[2983] = 1551; t[2984] = 1552; t[2986] = 1554; t[2987] = 1555;
  17315. t[2988] = 1556; t[2990] = 1623; t[2991] = 1624; t[2995] = 1775;
  17316. t[2999] = 1791; t[3002] = 64290; t[3003] = 64291; t[3004] = 64292;
  17317. t[3006] = 64294; t[3007] = 64295; t[3008] = 64296; t[3011] = 1900;
  17318. t[3014] = 8223; t[3015] = 8244; t[3017] = 7532; t[3018] = 7533;
  17319. t[3019] = 7534; t[3075] = 7590; t[3076] = 7591; t[3079] = 7594;
  17320. t[3080] = 7595; t[3083] = 7598; t[3084] = 7599; t[3087] = 7602;
  17321. t[3088] = 7603; t[3091] = 7606; t[3092] = 7607; t[3095] = 7610;
  17322. t[3096] = 7611; t[3099] = 7614; t[3100] = 7615; t[3103] = 7618;
  17323. t[3104] = 7619; t[3107] = 8337; t[3108] = 8338; t[3116] = 1884;
  17324. t[3119] = 1885; t[3120] = 1885; t[3123] = 1886; t[3124] = 1886;
  17325. t[3127] = 1887; t[3128] = 1887; t[3131] = 1888; t[3132] = 1888;
  17326. t[3135] = 1889; t[3136] = 1889; t[3139] = 1890; t[3140] = 1890;
  17327. t[3143] = 1891; t[3144] = 1891; t[3147] = 1892; t[3148] = 1892;
  17328. t[3153] = 580; t[3154] = 581; t[3157] = 584; t[3158] = 585; t[3161] = 588;
  17329. t[3162] = 589; t[3165] = 891; t[3166] = 892; t[3169] = 1274; t[3170] = 1275;
  17330. t[3173] = 1278; t[3174] = 1279; t[3181] = 7622; t[3182] = 7623;
  17331. t[3282] = 11799; t[3316] = 578; t[3379] = 42785; t[3393] = 1159;
  17332. t[3416] = 8377;
  17333. });
  17334. // The glyph map for ArialBlack differs slightly from the glyph map used for
  17335. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  17336. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  17337. var getSupplementalGlyphMapForArialBlack =
  17338. getLookupTableFactory(function (t) {
  17339. t[227] = 322; t[264] = 261; t[291] = 346;
  17340. });
  17341. exports.getStdFontMap = getStdFontMap;
  17342. exports.getNonStdFontMap = getNonStdFontMap;
  17343. exports.getSerifFonts = getSerifFonts;
  17344. exports.getSymbolsFonts = getSymbolsFonts;
  17345. exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts;
  17346. exports.getSupplementalGlyphMapForArialBlack =
  17347. getSupplementalGlyphMapForArialBlack;
  17348. }));
  17349. (function (root, factory) {
  17350. {
  17351. factory((root.pdfjsCoreUnicode = {}), root.pdfjsSharedUtil);
  17352. }
  17353. }(this, function (exports, sharedUtil) {
  17354. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  17355. // Some characters, e.g. copyrightserif, are mapped to the private use area
  17356. // and might not be displayed using standard fonts. Mapping/hacking well-known
  17357. // chars to the similar equivalents in the normal characters range.
  17358. var getSpecialPUASymbols = getLookupTableFactory(function (t) {
  17359. t[63721] = 0x00A9; // copyrightsans (0xF8E9) => copyright
  17360. t[63193] = 0x00A9; // copyrightserif (0xF6D9) => copyright
  17361. t[63720] = 0x00AE; // registersans (0xF8E8) => registered
  17362. t[63194] = 0x00AE; // registerserif (0xF6DA) => registered
  17363. t[63722] = 0x2122; // trademarksans (0xF8EA) => trademark
  17364. t[63195] = 0x2122; // trademarkserif (0xF6DB) => trademark
  17365. t[63729] = 0x23A7; // bracelefttp (0xF8F1)
  17366. t[63730] = 0x23A8; // braceleftmid (0xF8F2)
  17367. t[63731] = 0x23A9; // braceleftbt (0xF8F3)
  17368. t[63740] = 0x23AB; // bracerighttp (0xF8FC)
  17369. t[63741] = 0x23AC; // bracerightmid (0xF8FD)
  17370. t[63742] = 0x23AD; // bracerightbt (0xF8FE)
  17371. t[63726] = 0x23A1; // bracketlefttp (0xF8EE)
  17372. t[63727] = 0x23A2; // bracketleftex (0xF8EF)
  17373. t[63728] = 0x23A3; // bracketleftbt (0xF8F0)
  17374. t[63737] = 0x23A4; // bracketrighttp (0xF8F9)
  17375. t[63738] = 0x23A5; // bracketrightex (0xF8FA)
  17376. t[63739] = 0x23A6; // bracketrightbt (0xF8FB)
  17377. t[63723] = 0x239B; // parenlefttp (0xF8EB)
  17378. t[63724] = 0x239C; // parenleftex (0xF8EC)
  17379. t[63725] = 0x239D; // parenleftbt (0xF8ED)
  17380. t[63734] = 0x239E; // parenrighttp (0xF8F6)
  17381. t[63735] = 0x239F; // parenrightex (0xF8F7)
  17382. t[63736] = 0x23A0; // parenrightbt (0xF8F8)
  17383. });
  17384. function mapSpecialUnicodeValues(code) {
  17385. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  17386. return 0;
  17387. } else if (code >= 0xF600 && code <= 0xF8FF) {
  17388. return (getSpecialPUASymbols()[code] || code);
  17389. }
  17390. return code;
  17391. }
  17392. function getUnicodeForGlyph(name, glyphsUnicodeMap) {
  17393. var unicode = glyphsUnicodeMap[name];
  17394. if (unicode !== undefined) {
  17395. return unicode;
  17396. }
  17397. if (!name) {
  17398. return -1;
  17399. }
  17400. // Try to recover valid Unicode values from 'uniXXXX'/'uXXXX{XX}' glyphs.
  17401. if (name[0] === 'u') {
  17402. var nameLen = name.length, hexStr;
  17403. if (nameLen === 7 && name[1] === 'n' && name[2] === 'i') { // 'uniXXXX'
  17404. hexStr = name.substr(3);
  17405. } else if (nameLen >= 5 && nameLen <= 7) { // 'uXXXX{XX}'
  17406. hexStr = name.substr(1);
  17407. } else {
  17408. return -1;
  17409. }
  17410. // Check for upper-case hexadecimal characters, to avoid false positives.
  17411. if (hexStr === hexStr.toUpperCase()) {
  17412. unicode = parseInt(hexStr, 16);
  17413. if (unicode >= 0) {
  17414. return unicode;
  17415. }
  17416. }
  17417. }
  17418. return -1;
  17419. }
  17420. var UnicodeRanges = [
  17421. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  17422. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  17423. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  17424. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  17425. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  17426. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  17427. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  17428. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  17429. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  17430. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  17431. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  17432. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  17433. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  17434. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  17435. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  17436. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  17437. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  17438. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  17439. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  17440. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  17441. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  17442. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  17443. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  17444. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  17445. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  17446. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  17447. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  17448. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  17449. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  17450. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  17451. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  17452. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  17453. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  17454. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  17455. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks
  17456. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  17457. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  17458. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  17459. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  17460. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  17461. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  17462. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  17463. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  17464. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  17465. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  17466. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  17467. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  17468. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  17469. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  17470. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  17471. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  17472. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  17473. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  17474. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  17475. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  17476. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  17477. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  17478. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  17479. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  17480. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  17481. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  17482. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  17483. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  17484. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  17485. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  17486. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  17487. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  17488. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  17489. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  17490. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  17491. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  17492. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  17493. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  17494. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  17495. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  17496. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  17497. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  17498. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  17499. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  17500. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  17501. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  17502. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  17503. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  17504. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  17505. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  17506. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  17507. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  17508. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  17509. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  17510. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  17511. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  17512. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  17513. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  17514. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  17515. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  17516. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  17517. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  17518. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  17519. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  17520. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  17521. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  17522. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  17523. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  17524. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  17525. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  17526. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  17527. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  17528. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  17529. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  17530. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  17531. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  17532. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  17533. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  17534. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  17535. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  17536. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  17537. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  17538. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  17539. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  17540. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  17541. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  17542. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  17543. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  17544. ];
  17545. function getUnicodeRangeFor(value) {
  17546. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  17547. var range = UnicodeRanges[i];
  17548. if (value >= range.begin && value < range.end) {
  17549. return i;
  17550. }
  17551. }
  17552. return -1;
  17553. }
  17554. function isRTLRangeFor(value) {
  17555. var range = UnicodeRanges[13];
  17556. if (value >= range.begin && value < range.end) {
  17557. return true;
  17558. }
  17559. range = UnicodeRanges[11];
  17560. if (value >= range.begin && value < range.end) {
  17561. return true;
  17562. }
  17563. return false;
  17564. }
  17565. // The normalization table is obtained by filtering the Unicode characters
  17566. // database with <compat> entries.
  17567. var getNormalizedUnicodes = getLookupTableFactory(function (t) {
  17568. t['\u00A8'] = '\u0020\u0308';
  17569. t['\u00AF'] = '\u0020\u0304';
  17570. t['\u00B4'] = '\u0020\u0301';
  17571. t['\u00B5'] = '\u03BC';
  17572. t['\u00B8'] = '\u0020\u0327';
  17573. t['\u0132'] = '\u0049\u004A';
  17574. t['\u0133'] = '\u0069\u006A';
  17575. t['\u013F'] = '\u004C\u00B7';
  17576. t['\u0140'] = '\u006C\u00B7';
  17577. t['\u0149'] = '\u02BC\u006E';
  17578. t['\u017F'] = '\u0073';
  17579. t['\u01C4'] = '\u0044\u017D';
  17580. t['\u01C5'] = '\u0044\u017E';
  17581. t['\u01C6'] = '\u0064\u017E';
  17582. t['\u01C7'] = '\u004C\u004A';
  17583. t['\u01C8'] = '\u004C\u006A';
  17584. t['\u01C9'] = '\u006C\u006A';
  17585. t['\u01CA'] = '\u004E\u004A';
  17586. t['\u01CB'] = '\u004E\u006A';
  17587. t['\u01CC'] = '\u006E\u006A';
  17588. t['\u01F1'] = '\u0044\u005A';
  17589. t['\u01F2'] = '\u0044\u007A';
  17590. t['\u01F3'] = '\u0064\u007A';
  17591. t['\u02D8'] = '\u0020\u0306';
  17592. t['\u02D9'] = '\u0020\u0307';
  17593. t['\u02DA'] = '\u0020\u030A';
  17594. t['\u02DB'] = '\u0020\u0328';
  17595. t['\u02DC'] = '\u0020\u0303';
  17596. t['\u02DD'] = '\u0020\u030B';
  17597. t['\u037A'] = '\u0020\u0345';
  17598. t['\u0384'] = '\u0020\u0301';
  17599. t['\u03D0'] = '\u03B2';
  17600. t['\u03D1'] = '\u03B8';
  17601. t['\u03D2'] = '\u03A5';
  17602. t['\u03D5'] = '\u03C6';
  17603. t['\u03D6'] = '\u03C0';
  17604. t['\u03F0'] = '\u03BA';
  17605. t['\u03F1'] = '\u03C1';
  17606. t['\u03F2'] = '\u03C2';
  17607. t['\u03F4'] = '\u0398';
  17608. t['\u03F5'] = '\u03B5';
  17609. t['\u03F9'] = '\u03A3';
  17610. t['\u0587'] = '\u0565\u0582';
  17611. t['\u0675'] = '\u0627\u0674';
  17612. t['\u0676'] = '\u0648\u0674';
  17613. t['\u0677'] = '\u06C7\u0674';
  17614. t['\u0678'] = '\u064A\u0674';
  17615. t['\u0E33'] = '\u0E4D\u0E32';
  17616. t['\u0EB3'] = '\u0ECD\u0EB2';
  17617. t['\u0EDC'] = '\u0EAB\u0E99';
  17618. t['\u0EDD'] = '\u0EAB\u0EA1';
  17619. t['\u0F77'] = '\u0FB2\u0F81';
  17620. t['\u0F79'] = '\u0FB3\u0F81';
  17621. t['\u1E9A'] = '\u0061\u02BE';
  17622. t['\u1FBD'] = '\u0020\u0313';
  17623. t['\u1FBF'] = '\u0020\u0313';
  17624. t['\u1FC0'] = '\u0020\u0342';
  17625. t['\u1FFE'] = '\u0020\u0314';
  17626. t['\u2002'] = '\u0020';
  17627. t['\u2003'] = '\u0020';
  17628. t['\u2004'] = '\u0020';
  17629. t['\u2005'] = '\u0020';
  17630. t['\u2006'] = '\u0020';
  17631. t['\u2008'] = '\u0020';
  17632. t['\u2009'] = '\u0020';
  17633. t['\u200A'] = '\u0020';
  17634. t['\u2017'] = '\u0020\u0333';
  17635. t['\u2024'] = '\u002E';
  17636. t['\u2025'] = '\u002E\u002E';
  17637. t['\u2026'] = '\u002E\u002E\u002E';
  17638. t['\u2033'] = '\u2032\u2032';
  17639. t['\u2034'] = '\u2032\u2032\u2032';
  17640. t['\u2036'] = '\u2035\u2035';
  17641. t['\u2037'] = '\u2035\u2035\u2035';
  17642. t['\u203C'] = '\u0021\u0021';
  17643. t['\u203E'] = '\u0020\u0305';
  17644. t['\u2047'] = '\u003F\u003F';
  17645. t['\u2048'] = '\u003F\u0021';
  17646. t['\u2049'] = '\u0021\u003F';
  17647. t['\u2057'] = '\u2032\u2032\u2032\u2032';
  17648. t['\u205F'] = '\u0020';
  17649. t['\u20A8'] = '\u0052\u0073';
  17650. t['\u2100'] = '\u0061\u002F\u0063';
  17651. t['\u2101'] = '\u0061\u002F\u0073';
  17652. t['\u2103'] = '\u00B0\u0043';
  17653. t['\u2105'] = '\u0063\u002F\u006F';
  17654. t['\u2106'] = '\u0063\u002F\u0075';
  17655. t['\u2107'] = '\u0190';
  17656. t['\u2109'] = '\u00B0\u0046';
  17657. t['\u2116'] = '\u004E\u006F';
  17658. t['\u2121'] = '\u0054\u0045\u004C';
  17659. t['\u2135'] = '\u05D0';
  17660. t['\u2136'] = '\u05D1';
  17661. t['\u2137'] = '\u05D2';
  17662. t['\u2138'] = '\u05D3';
  17663. t['\u213B'] = '\u0046\u0041\u0058';
  17664. t['\u2160'] = '\u0049';
  17665. t['\u2161'] = '\u0049\u0049';
  17666. t['\u2162'] = '\u0049\u0049\u0049';
  17667. t['\u2163'] = '\u0049\u0056';
  17668. t['\u2164'] = '\u0056';
  17669. t['\u2165'] = '\u0056\u0049';
  17670. t['\u2166'] = '\u0056\u0049\u0049';
  17671. t['\u2167'] = '\u0056\u0049\u0049\u0049';
  17672. t['\u2168'] = '\u0049\u0058';
  17673. t['\u2169'] = '\u0058';
  17674. t['\u216A'] = '\u0058\u0049';
  17675. t['\u216B'] = '\u0058\u0049\u0049';
  17676. t['\u216C'] = '\u004C';
  17677. t['\u216D'] = '\u0043';
  17678. t['\u216E'] = '\u0044';
  17679. t['\u216F'] = '\u004D';
  17680. t['\u2170'] = '\u0069';
  17681. t['\u2171'] = '\u0069\u0069';
  17682. t['\u2172'] = '\u0069\u0069\u0069';
  17683. t['\u2173'] = '\u0069\u0076';
  17684. t['\u2174'] = '\u0076';
  17685. t['\u2175'] = '\u0076\u0069';
  17686. t['\u2176'] = '\u0076\u0069\u0069';
  17687. t['\u2177'] = '\u0076\u0069\u0069\u0069';
  17688. t['\u2178'] = '\u0069\u0078';
  17689. t['\u2179'] = '\u0078';
  17690. t['\u217A'] = '\u0078\u0069';
  17691. t['\u217B'] = '\u0078\u0069\u0069';
  17692. t['\u217C'] = '\u006C';
  17693. t['\u217D'] = '\u0063';
  17694. t['\u217E'] = '\u0064';
  17695. t['\u217F'] = '\u006D';
  17696. t['\u222C'] = '\u222B\u222B';
  17697. t['\u222D'] = '\u222B\u222B\u222B';
  17698. t['\u222F'] = '\u222E\u222E';
  17699. t['\u2230'] = '\u222E\u222E\u222E';
  17700. t['\u2474'] = '\u0028\u0031\u0029';
  17701. t['\u2475'] = '\u0028\u0032\u0029';
  17702. t['\u2476'] = '\u0028\u0033\u0029';
  17703. t['\u2477'] = '\u0028\u0034\u0029';
  17704. t['\u2478'] = '\u0028\u0035\u0029';
  17705. t['\u2479'] = '\u0028\u0036\u0029';
  17706. t['\u247A'] = '\u0028\u0037\u0029';
  17707. t['\u247B'] = '\u0028\u0038\u0029';
  17708. t['\u247C'] = '\u0028\u0039\u0029';
  17709. t['\u247D'] = '\u0028\u0031\u0030\u0029';
  17710. t['\u247E'] = '\u0028\u0031\u0031\u0029';
  17711. t['\u247F'] = '\u0028\u0031\u0032\u0029';
  17712. t['\u2480'] = '\u0028\u0031\u0033\u0029';
  17713. t['\u2481'] = '\u0028\u0031\u0034\u0029';
  17714. t['\u2482'] = '\u0028\u0031\u0035\u0029';
  17715. t['\u2483'] = '\u0028\u0031\u0036\u0029';
  17716. t['\u2484'] = '\u0028\u0031\u0037\u0029';
  17717. t['\u2485'] = '\u0028\u0031\u0038\u0029';
  17718. t['\u2486'] = '\u0028\u0031\u0039\u0029';
  17719. t['\u2487'] = '\u0028\u0032\u0030\u0029';
  17720. t['\u2488'] = '\u0031\u002E';
  17721. t['\u2489'] = '\u0032\u002E';
  17722. t['\u248A'] = '\u0033\u002E';
  17723. t['\u248B'] = '\u0034\u002E';
  17724. t['\u248C'] = '\u0035\u002E';
  17725. t['\u248D'] = '\u0036\u002E';
  17726. t['\u248E'] = '\u0037\u002E';
  17727. t['\u248F'] = '\u0038\u002E';
  17728. t['\u2490'] = '\u0039\u002E';
  17729. t['\u2491'] = '\u0031\u0030\u002E';
  17730. t['\u2492'] = '\u0031\u0031\u002E';
  17731. t['\u2493'] = '\u0031\u0032\u002E';
  17732. t['\u2494'] = '\u0031\u0033\u002E';
  17733. t['\u2495'] = '\u0031\u0034\u002E';
  17734. t['\u2496'] = '\u0031\u0035\u002E';
  17735. t['\u2497'] = '\u0031\u0036\u002E';
  17736. t['\u2498'] = '\u0031\u0037\u002E';
  17737. t['\u2499'] = '\u0031\u0038\u002E';
  17738. t['\u249A'] = '\u0031\u0039\u002E';
  17739. t['\u249B'] = '\u0032\u0030\u002E';
  17740. t['\u249C'] = '\u0028\u0061\u0029';
  17741. t['\u249D'] = '\u0028\u0062\u0029';
  17742. t['\u249E'] = '\u0028\u0063\u0029';
  17743. t['\u249F'] = '\u0028\u0064\u0029';
  17744. t['\u24A0'] = '\u0028\u0065\u0029';
  17745. t['\u24A1'] = '\u0028\u0066\u0029';
  17746. t['\u24A2'] = '\u0028\u0067\u0029';
  17747. t['\u24A3'] = '\u0028\u0068\u0029';
  17748. t['\u24A4'] = '\u0028\u0069\u0029';
  17749. t['\u24A5'] = '\u0028\u006A\u0029';
  17750. t['\u24A6'] = '\u0028\u006B\u0029';
  17751. t['\u24A7'] = '\u0028\u006C\u0029';
  17752. t['\u24A8'] = '\u0028\u006D\u0029';
  17753. t['\u24A9'] = '\u0028\u006E\u0029';
  17754. t['\u24AA'] = '\u0028\u006F\u0029';
  17755. t['\u24AB'] = '\u0028\u0070\u0029';
  17756. t['\u24AC'] = '\u0028\u0071\u0029';
  17757. t['\u24AD'] = '\u0028\u0072\u0029';
  17758. t['\u24AE'] = '\u0028\u0073\u0029';
  17759. t['\u24AF'] = '\u0028\u0074\u0029';
  17760. t['\u24B0'] = '\u0028\u0075\u0029';
  17761. t['\u24B1'] = '\u0028\u0076\u0029';
  17762. t['\u24B2'] = '\u0028\u0077\u0029';
  17763. t['\u24B3'] = '\u0028\u0078\u0029';
  17764. t['\u24B4'] = '\u0028\u0079\u0029';
  17765. t['\u24B5'] = '\u0028\u007A\u0029';
  17766. t['\u2A0C'] = '\u222B\u222B\u222B\u222B';
  17767. t['\u2A74'] = '\u003A\u003A\u003D';
  17768. t['\u2A75'] = '\u003D\u003D';
  17769. t['\u2A76'] = '\u003D\u003D\u003D';
  17770. t['\u2E9F'] = '\u6BCD';
  17771. t['\u2EF3'] = '\u9F9F';
  17772. t['\u2F00'] = '\u4E00';
  17773. t['\u2F01'] = '\u4E28';
  17774. t['\u2F02'] = '\u4E36';
  17775. t['\u2F03'] = '\u4E3F';
  17776. t['\u2F04'] = '\u4E59';
  17777. t['\u2F05'] = '\u4E85';
  17778. t['\u2F06'] = '\u4E8C';
  17779. t['\u2F07'] = '\u4EA0';
  17780. t['\u2F08'] = '\u4EBA';
  17781. t['\u2F09'] = '\u513F';
  17782. t['\u2F0A'] = '\u5165';
  17783. t['\u2F0B'] = '\u516B';
  17784. t['\u2F0C'] = '\u5182';
  17785. t['\u2F0D'] = '\u5196';
  17786. t['\u2F0E'] = '\u51AB';
  17787. t['\u2F0F'] = '\u51E0';
  17788. t['\u2F10'] = '\u51F5';
  17789. t['\u2F11'] = '\u5200';
  17790. t['\u2F12'] = '\u529B';
  17791. t['\u2F13'] = '\u52F9';
  17792. t['\u2F14'] = '\u5315';
  17793. t['\u2F15'] = '\u531A';
  17794. t['\u2F16'] = '\u5338';
  17795. t['\u2F17'] = '\u5341';
  17796. t['\u2F18'] = '\u535C';
  17797. t['\u2F19'] = '\u5369';
  17798. t['\u2F1A'] = '\u5382';
  17799. t['\u2F1B'] = '\u53B6';
  17800. t['\u2F1C'] = '\u53C8';
  17801. t['\u2F1D'] = '\u53E3';
  17802. t['\u2F1E'] = '\u56D7';
  17803. t['\u2F1F'] = '\u571F';
  17804. t['\u2F20'] = '\u58EB';
  17805. t['\u2F21'] = '\u5902';
  17806. t['\u2F22'] = '\u590A';
  17807. t['\u2F23'] = '\u5915';
  17808. t['\u2F24'] = '\u5927';
  17809. t['\u2F25'] = '\u5973';
  17810. t['\u2F26'] = '\u5B50';
  17811. t['\u2F27'] = '\u5B80';
  17812. t['\u2F28'] = '\u5BF8';
  17813. t['\u2F29'] = '\u5C0F';
  17814. t['\u2F2A'] = '\u5C22';
  17815. t['\u2F2B'] = '\u5C38';
  17816. t['\u2F2C'] = '\u5C6E';
  17817. t['\u2F2D'] = '\u5C71';
  17818. t['\u2F2E'] = '\u5DDB';
  17819. t['\u2F2F'] = '\u5DE5';
  17820. t['\u2F30'] = '\u5DF1';
  17821. t['\u2F31'] = '\u5DFE';
  17822. t['\u2F32'] = '\u5E72';
  17823. t['\u2F33'] = '\u5E7A';
  17824. t['\u2F34'] = '\u5E7F';
  17825. t['\u2F35'] = '\u5EF4';
  17826. t['\u2F36'] = '\u5EFE';
  17827. t['\u2F37'] = '\u5F0B';
  17828. t['\u2F38'] = '\u5F13';
  17829. t['\u2F39'] = '\u5F50';
  17830. t['\u2F3A'] = '\u5F61';
  17831. t['\u2F3B'] = '\u5F73';
  17832. t['\u2F3C'] = '\u5FC3';
  17833. t['\u2F3D'] = '\u6208';
  17834. t['\u2F3E'] = '\u6236';
  17835. t['\u2F3F'] = '\u624B';
  17836. t['\u2F40'] = '\u652F';
  17837. t['\u2F41'] = '\u6534';
  17838. t['\u2F42'] = '\u6587';
  17839. t['\u2F43'] = '\u6597';
  17840. t['\u2F44'] = '\u65A4';
  17841. t['\u2F45'] = '\u65B9';
  17842. t['\u2F46'] = '\u65E0';
  17843. t['\u2F47'] = '\u65E5';
  17844. t['\u2F48'] = '\u66F0';
  17845. t['\u2F49'] = '\u6708';
  17846. t['\u2F4A'] = '\u6728';
  17847. t['\u2F4B'] = '\u6B20';
  17848. t['\u2F4C'] = '\u6B62';
  17849. t['\u2F4D'] = '\u6B79';
  17850. t['\u2F4E'] = '\u6BB3';
  17851. t['\u2F4F'] = '\u6BCB';
  17852. t['\u2F50'] = '\u6BD4';
  17853. t['\u2F51'] = '\u6BDB';
  17854. t['\u2F52'] = '\u6C0F';
  17855. t['\u2F53'] = '\u6C14';
  17856. t['\u2F54'] = '\u6C34';
  17857. t['\u2F55'] = '\u706B';
  17858. t['\u2F56'] = '\u722A';
  17859. t['\u2F57'] = '\u7236';
  17860. t['\u2F58'] = '\u723B';
  17861. t['\u2F59'] = '\u723F';
  17862. t['\u2F5A'] = '\u7247';
  17863. t['\u2F5B'] = '\u7259';
  17864. t['\u2F5C'] = '\u725B';
  17865. t['\u2F5D'] = '\u72AC';
  17866. t['\u2F5E'] = '\u7384';
  17867. t['\u2F5F'] = '\u7389';
  17868. t['\u2F60'] = '\u74DC';
  17869. t['\u2F61'] = '\u74E6';
  17870. t['\u2F62'] = '\u7518';
  17871. t['\u2F63'] = '\u751F';
  17872. t['\u2F64'] = '\u7528';
  17873. t['\u2F65'] = '\u7530';
  17874. t['\u2F66'] = '\u758B';
  17875. t['\u2F67'] = '\u7592';
  17876. t['\u2F68'] = '\u7676';
  17877. t['\u2F69'] = '\u767D';
  17878. t['\u2F6A'] = '\u76AE';
  17879. t['\u2F6B'] = '\u76BF';
  17880. t['\u2F6C'] = '\u76EE';
  17881. t['\u2F6D'] = '\u77DB';
  17882. t['\u2F6E'] = '\u77E2';
  17883. t['\u2F6F'] = '\u77F3';
  17884. t['\u2F70'] = '\u793A';
  17885. t['\u2F71'] = '\u79B8';
  17886. t['\u2F72'] = '\u79BE';
  17887. t['\u2F73'] = '\u7A74';
  17888. t['\u2F74'] = '\u7ACB';
  17889. t['\u2F75'] = '\u7AF9';
  17890. t['\u2F76'] = '\u7C73';
  17891. t['\u2F77'] = '\u7CF8';
  17892. t['\u2F78'] = '\u7F36';
  17893. t['\u2F79'] = '\u7F51';
  17894. t['\u2F7A'] = '\u7F8A';
  17895. t['\u2F7B'] = '\u7FBD';
  17896. t['\u2F7C'] = '\u8001';
  17897. t['\u2F7D'] = '\u800C';
  17898. t['\u2F7E'] = '\u8012';
  17899. t['\u2F7F'] = '\u8033';
  17900. t['\u2F80'] = '\u807F';
  17901. t['\u2F81'] = '\u8089';
  17902. t['\u2F82'] = '\u81E3';
  17903. t['\u2F83'] = '\u81EA';
  17904. t['\u2F84'] = '\u81F3';
  17905. t['\u2F85'] = '\u81FC';
  17906. t['\u2F86'] = '\u820C';
  17907. t['\u2F87'] = '\u821B';
  17908. t['\u2F88'] = '\u821F';
  17909. t['\u2F89'] = '\u826E';
  17910. t['\u2F8A'] = '\u8272';
  17911. t['\u2F8B'] = '\u8278';
  17912. t['\u2F8C'] = '\u864D';
  17913. t['\u2F8D'] = '\u866B';
  17914. t['\u2F8E'] = '\u8840';
  17915. t['\u2F8F'] = '\u884C';
  17916. t['\u2F90'] = '\u8863';
  17917. t['\u2F91'] = '\u897E';
  17918. t['\u2F92'] = '\u898B';
  17919. t['\u2F93'] = '\u89D2';
  17920. t['\u2F94'] = '\u8A00';
  17921. t['\u2F95'] = '\u8C37';
  17922. t['\u2F96'] = '\u8C46';
  17923. t['\u2F97'] = '\u8C55';
  17924. t['\u2F98'] = '\u8C78';
  17925. t['\u2F99'] = '\u8C9D';
  17926. t['\u2F9A'] = '\u8D64';
  17927. t['\u2F9B'] = '\u8D70';
  17928. t['\u2F9C'] = '\u8DB3';
  17929. t['\u2F9D'] = '\u8EAB';
  17930. t['\u2F9E'] = '\u8ECA';
  17931. t['\u2F9F'] = '\u8F9B';
  17932. t['\u2FA0'] = '\u8FB0';
  17933. t['\u2FA1'] = '\u8FB5';
  17934. t['\u2FA2'] = '\u9091';
  17935. t['\u2FA3'] = '\u9149';
  17936. t['\u2FA4'] = '\u91C6';
  17937. t['\u2FA5'] = '\u91CC';
  17938. t['\u2FA6'] = '\u91D1';
  17939. t['\u2FA7'] = '\u9577';
  17940. t['\u2FA8'] = '\u9580';
  17941. t['\u2FA9'] = '\u961C';
  17942. t['\u2FAA'] = '\u96B6';
  17943. t['\u2FAB'] = '\u96B9';
  17944. t['\u2FAC'] = '\u96E8';
  17945. t['\u2FAD'] = '\u9751';
  17946. t['\u2FAE'] = '\u975E';
  17947. t['\u2FAF'] = '\u9762';
  17948. t['\u2FB0'] = '\u9769';
  17949. t['\u2FB1'] = '\u97CB';
  17950. t['\u2FB2'] = '\u97ED';
  17951. t['\u2FB3'] = '\u97F3';
  17952. t['\u2FB4'] = '\u9801';
  17953. t['\u2FB5'] = '\u98A8';
  17954. t['\u2FB6'] = '\u98DB';
  17955. t['\u2FB7'] = '\u98DF';
  17956. t['\u2FB8'] = '\u9996';
  17957. t['\u2FB9'] = '\u9999';
  17958. t['\u2FBA'] = '\u99AC';
  17959. t['\u2FBB'] = '\u9AA8';
  17960. t['\u2FBC'] = '\u9AD8';
  17961. t['\u2FBD'] = '\u9ADF';
  17962. t['\u2FBE'] = '\u9B25';
  17963. t['\u2FBF'] = '\u9B2F';
  17964. t['\u2FC0'] = '\u9B32';
  17965. t['\u2FC1'] = '\u9B3C';
  17966. t['\u2FC2'] = '\u9B5A';
  17967. t['\u2FC3'] = '\u9CE5';
  17968. t['\u2FC4'] = '\u9E75';
  17969. t['\u2FC5'] = '\u9E7F';
  17970. t['\u2FC6'] = '\u9EA5';
  17971. t['\u2FC7'] = '\u9EBB';
  17972. t['\u2FC8'] = '\u9EC3';
  17973. t['\u2FC9'] = '\u9ECD';
  17974. t['\u2FCA'] = '\u9ED1';
  17975. t['\u2FCB'] = '\u9EF9';
  17976. t['\u2FCC'] = '\u9EFD';
  17977. t['\u2FCD'] = '\u9F0E';
  17978. t['\u2FCE'] = '\u9F13';
  17979. t['\u2FCF'] = '\u9F20';
  17980. t['\u2FD0'] = '\u9F3B';
  17981. t['\u2FD1'] = '\u9F4A';
  17982. t['\u2FD2'] = '\u9F52';
  17983. t['\u2FD3'] = '\u9F8D';
  17984. t['\u2FD4'] = '\u9F9C';
  17985. t['\u2FD5'] = '\u9FA0';
  17986. t['\u3036'] = '\u3012';
  17987. t['\u3038'] = '\u5341';
  17988. t['\u3039'] = '\u5344';
  17989. t['\u303A'] = '\u5345';
  17990. t['\u309B'] = '\u0020\u3099';
  17991. t['\u309C'] = '\u0020\u309A';
  17992. t['\u3131'] = '\u1100';
  17993. t['\u3132'] = '\u1101';
  17994. t['\u3133'] = '\u11AA';
  17995. t['\u3134'] = '\u1102';
  17996. t['\u3135'] = '\u11AC';
  17997. t['\u3136'] = '\u11AD';
  17998. t['\u3137'] = '\u1103';
  17999. t['\u3138'] = '\u1104';
  18000. t['\u3139'] = '\u1105';
  18001. t['\u313A'] = '\u11B0';
  18002. t['\u313B'] = '\u11B1';
  18003. t['\u313C'] = '\u11B2';
  18004. t['\u313D'] = '\u11B3';
  18005. t['\u313E'] = '\u11B4';
  18006. t['\u313F'] = '\u11B5';
  18007. t['\u3140'] = '\u111A';
  18008. t['\u3141'] = '\u1106';
  18009. t['\u3142'] = '\u1107';
  18010. t['\u3143'] = '\u1108';
  18011. t['\u3144'] = '\u1121';
  18012. t['\u3145'] = '\u1109';
  18013. t['\u3146'] = '\u110A';
  18014. t['\u3147'] = '\u110B';
  18015. t['\u3148'] = '\u110C';
  18016. t['\u3149'] = '\u110D';
  18017. t['\u314A'] = '\u110E';
  18018. t['\u314B'] = '\u110F';
  18019. t['\u314C'] = '\u1110';
  18020. t['\u314D'] = '\u1111';
  18021. t['\u314E'] = '\u1112';
  18022. t['\u314F'] = '\u1161';
  18023. t['\u3150'] = '\u1162';
  18024. t['\u3151'] = '\u1163';
  18025. t['\u3152'] = '\u1164';
  18026. t['\u3153'] = '\u1165';
  18027. t['\u3154'] = '\u1166';
  18028. t['\u3155'] = '\u1167';
  18029. t['\u3156'] = '\u1168';
  18030. t['\u3157'] = '\u1169';
  18031. t['\u3158'] = '\u116A';
  18032. t['\u3159'] = '\u116B';
  18033. t['\u315A'] = '\u116C';
  18034. t['\u315B'] = '\u116D';
  18035. t['\u315C'] = '\u116E';
  18036. t['\u315D'] = '\u116F';
  18037. t['\u315E'] = '\u1170';
  18038. t['\u315F'] = '\u1171';
  18039. t['\u3160'] = '\u1172';
  18040. t['\u3161'] = '\u1173';
  18041. t['\u3162'] = '\u1174';
  18042. t['\u3163'] = '\u1175';
  18043. t['\u3164'] = '\u1160';
  18044. t['\u3165'] = '\u1114';
  18045. t['\u3166'] = '\u1115';
  18046. t['\u3167'] = '\u11C7';
  18047. t['\u3168'] = '\u11C8';
  18048. t['\u3169'] = '\u11CC';
  18049. t['\u316A'] = '\u11CE';
  18050. t['\u316B'] = '\u11D3';
  18051. t['\u316C'] = '\u11D7';
  18052. t['\u316D'] = '\u11D9';
  18053. t['\u316E'] = '\u111C';
  18054. t['\u316F'] = '\u11DD';
  18055. t['\u3170'] = '\u11DF';
  18056. t['\u3171'] = '\u111D';
  18057. t['\u3172'] = '\u111E';
  18058. t['\u3173'] = '\u1120';
  18059. t['\u3174'] = '\u1122';
  18060. t['\u3175'] = '\u1123';
  18061. t['\u3176'] = '\u1127';
  18062. t['\u3177'] = '\u1129';
  18063. t['\u3178'] = '\u112B';
  18064. t['\u3179'] = '\u112C';
  18065. t['\u317A'] = '\u112D';
  18066. t['\u317B'] = '\u112E';
  18067. t['\u317C'] = '\u112F';
  18068. t['\u317D'] = '\u1132';
  18069. t['\u317E'] = '\u1136';
  18070. t['\u317F'] = '\u1140';
  18071. t['\u3180'] = '\u1147';
  18072. t['\u3181'] = '\u114C';
  18073. t['\u3182'] = '\u11F1';
  18074. t['\u3183'] = '\u11F2';
  18075. t['\u3184'] = '\u1157';
  18076. t['\u3185'] = '\u1158';
  18077. t['\u3186'] = '\u1159';
  18078. t['\u3187'] = '\u1184';
  18079. t['\u3188'] = '\u1185';
  18080. t['\u3189'] = '\u1188';
  18081. t['\u318A'] = '\u1191';
  18082. t['\u318B'] = '\u1192';
  18083. t['\u318C'] = '\u1194';
  18084. t['\u318D'] = '\u119E';
  18085. t['\u318E'] = '\u11A1';
  18086. t['\u3200'] = '\u0028\u1100\u0029';
  18087. t['\u3201'] = '\u0028\u1102\u0029';
  18088. t['\u3202'] = '\u0028\u1103\u0029';
  18089. t['\u3203'] = '\u0028\u1105\u0029';
  18090. t['\u3204'] = '\u0028\u1106\u0029';
  18091. t['\u3205'] = '\u0028\u1107\u0029';
  18092. t['\u3206'] = '\u0028\u1109\u0029';
  18093. t['\u3207'] = '\u0028\u110B\u0029';
  18094. t['\u3208'] = '\u0028\u110C\u0029';
  18095. t['\u3209'] = '\u0028\u110E\u0029';
  18096. t['\u320A'] = '\u0028\u110F\u0029';
  18097. t['\u320B'] = '\u0028\u1110\u0029';
  18098. t['\u320C'] = '\u0028\u1111\u0029';
  18099. t['\u320D'] = '\u0028\u1112\u0029';
  18100. t['\u320E'] = '\u0028\u1100\u1161\u0029';
  18101. t['\u320F'] = '\u0028\u1102\u1161\u0029';
  18102. t['\u3210'] = '\u0028\u1103\u1161\u0029';
  18103. t['\u3211'] = '\u0028\u1105\u1161\u0029';
  18104. t['\u3212'] = '\u0028\u1106\u1161\u0029';
  18105. t['\u3213'] = '\u0028\u1107\u1161\u0029';
  18106. t['\u3214'] = '\u0028\u1109\u1161\u0029';
  18107. t['\u3215'] = '\u0028\u110B\u1161\u0029';
  18108. t['\u3216'] = '\u0028\u110C\u1161\u0029';
  18109. t['\u3217'] = '\u0028\u110E\u1161\u0029';
  18110. t['\u3218'] = '\u0028\u110F\u1161\u0029';
  18111. t['\u3219'] = '\u0028\u1110\u1161\u0029';
  18112. t['\u321A'] = '\u0028\u1111\u1161\u0029';
  18113. t['\u321B'] = '\u0028\u1112\u1161\u0029';
  18114. t['\u321C'] = '\u0028\u110C\u116E\u0029';
  18115. t['\u321D'] = '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029';
  18116. t['\u321E'] = '\u0028\u110B\u1169\u1112\u116E\u0029';
  18117. t['\u3220'] = '\u0028\u4E00\u0029';
  18118. t['\u3221'] = '\u0028\u4E8C\u0029';
  18119. t['\u3222'] = '\u0028\u4E09\u0029';
  18120. t['\u3223'] = '\u0028\u56DB\u0029';
  18121. t['\u3224'] = '\u0028\u4E94\u0029';
  18122. t['\u3225'] = '\u0028\u516D\u0029';
  18123. t['\u3226'] = '\u0028\u4E03\u0029';
  18124. t['\u3227'] = '\u0028\u516B\u0029';
  18125. t['\u3228'] = '\u0028\u4E5D\u0029';
  18126. t['\u3229'] = '\u0028\u5341\u0029';
  18127. t['\u322A'] = '\u0028\u6708\u0029';
  18128. t['\u322B'] = '\u0028\u706B\u0029';
  18129. t['\u322C'] = '\u0028\u6C34\u0029';
  18130. t['\u322D'] = '\u0028\u6728\u0029';
  18131. t['\u322E'] = '\u0028\u91D1\u0029';
  18132. t['\u322F'] = '\u0028\u571F\u0029';
  18133. t['\u3230'] = '\u0028\u65E5\u0029';
  18134. t['\u3231'] = '\u0028\u682A\u0029';
  18135. t['\u3232'] = '\u0028\u6709\u0029';
  18136. t['\u3233'] = '\u0028\u793E\u0029';
  18137. t['\u3234'] = '\u0028\u540D\u0029';
  18138. t['\u3235'] = '\u0028\u7279\u0029';
  18139. t['\u3236'] = '\u0028\u8CA1\u0029';
  18140. t['\u3237'] = '\u0028\u795D\u0029';
  18141. t['\u3238'] = '\u0028\u52B4\u0029';
  18142. t['\u3239'] = '\u0028\u4EE3\u0029';
  18143. t['\u323A'] = '\u0028\u547C\u0029';
  18144. t['\u323B'] = '\u0028\u5B66\u0029';
  18145. t['\u323C'] = '\u0028\u76E3\u0029';
  18146. t['\u323D'] = '\u0028\u4F01\u0029';
  18147. t['\u323E'] = '\u0028\u8CC7\u0029';
  18148. t['\u323F'] = '\u0028\u5354\u0029';
  18149. t['\u3240'] = '\u0028\u796D\u0029';
  18150. t['\u3241'] = '\u0028\u4F11\u0029';
  18151. t['\u3242'] = '\u0028\u81EA\u0029';
  18152. t['\u3243'] = '\u0028\u81F3\u0029';
  18153. t['\u32C0'] = '\u0031\u6708';
  18154. t['\u32C1'] = '\u0032\u6708';
  18155. t['\u32C2'] = '\u0033\u6708';
  18156. t['\u32C3'] = '\u0034\u6708';
  18157. t['\u32C4'] = '\u0035\u6708';
  18158. t['\u32C5'] = '\u0036\u6708';
  18159. t['\u32C6'] = '\u0037\u6708';
  18160. t['\u32C7'] = '\u0038\u6708';
  18161. t['\u32C8'] = '\u0039\u6708';
  18162. t['\u32C9'] = '\u0031\u0030\u6708';
  18163. t['\u32CA'] = '\u0031\u0031\u6708';
  18164. t['\u32CB'] = '\u0031\u0032\u6708';
  18165. t['\u3358'] = '\u0030\u70B9';
  18166. t['\u3359'] = '\u0031\u70B9';
  18167. t['\u335A'] = '\u0032\u70B9';
  18168. t['\u335B'] = '\u0033\u70B9';
  18169. t['\u335C'] = '\u0034\u70B9';
  18170. t['\u335D'] = '\u0035\u70B9';
  18171. t['\u335E'] = '\u0036\u70B9';
  18172. t['\u335F'] = '\u0037\u70B9';
  18173. t['\u3360'] = '\u0038\u70B9';
  18174. t['\u3361'] = '\u0039\u70B9';
  18175. t['\u3362'] = '\u0031\u0030\u70B9';
  18176. t['\u3363'] = '\u0031\u0031\u70B9';
  18177. t['\u3364'] = '\u0031\u0032\u70B9';
  18178. t['\u3365'] = '\u0031\u0033\u70B9';
  18179. t['\u3366'] = '\u0031\u0034\u70B9';
  18180. t['\u3367'] = '\u0031\u0035\u70B9';
  18181. t['\u3368'] = '\u0031\u0036\u70B9';
  18182. t['\u3369'] = '\u0031\u0037\u70B9';
  18183. t['\u336A'] = '\u0031\u0038\u70B9';
  18184. t['\u336B'] = '\u0031\u0039\u70B9';
  18185. t['\u336C'] = '\u0032\u0030\u70B9';
  18186. t['\u336D'] = '\u0032\u0031\u70B9';
  18187. t['\u336E'] = '\u0032\u0032\u70B9';
  18188. t['\u336F'] = '\u0032\u0033\u70B9';
  18189. t['\u3370'] = '\u0032\u0034\u70B9';
  18190. t['\u33E0'] = '\u0031\u65E5';
  18191. t['\u33E1'] = '\u0032\u65E5';
  18192. t['\u33E2'] = '\u0033\u65E5';
  18193. t['\u33E3'] = '\u0034\u65E5';
  18194. t['\u33E4'] = '\u0035\u65E5';
  18195. t['\u33E5'] = '\u0036\u65E5';
  18196. t['\u33E6'] = '\u0037\u65E5';
  18197. t['\u33E7'] = '\u0038\u65E5';
  18198. t['\u33E8'] = '\u0039\u65E5';
  18199. t['\u33E9'] = '\u0031\u0030\u65E5';
  18200. t['\u33EA'] = '\u0031\u0031\u65E5';
  18201. t['\u33EB'] = '\u0031\u0032\u65E5';
  18202. t['\u33EC'] = '\u0031\u0033\u65E5';
  18203. t['\u33ED'] = '\u0031\u0034\u65E5';
  18204. t['\u33EE'] = '\u0031\u0035\u65E5';
  18205. t['\u33EF'] = '\u0031\u0036\u65E5';
  18206. t['\u33F0'] = '\u0031\u0037\u65E5';
  18207. t['\u33F1'] = '\u0031\u0038\u65E5';
  18208. t['\u33F2'] = '\u0031\u0039\u65E5';
  18209. t['\u33F3'] = '\u0032\u0030\u65E5';
  18210. t['\u33F4'] = '\u0032\u0031\u65E5';
  18211. t['\u33F5'] = '\u0032\u0032\u65E5';
  18212. t['\u33F6'] = '\u0032\u0033\u65E5';
  18213. t['\u33F7'] = '\u0032\u0034\u65E5';
  18214. t['\u33F8'] = '\u0032\u0035\u65E5';
  18215. t['\u33F9'] = '\u0032\u0036\u65E5';
  18216. t['\u33FA'] = '\u0032\u0037\u65E5';
  18217. t['\u33FB'] = '\u0032\u0038\u65E5';
  18218. t['\u33FC'] = '\u0032\u0039\u65E5';
  18219. t['\u33FD'] = '\u0033\u0030\u65E5';
  18220. t['\u33FE'] = '\u0033\u0031\u65E5';
  18221. t['\uFB00'] = '\u0066\u0066';
  18222. t['\uFB01'] = '\u0066\u0069';
  18223. t['\uFB02'] = '\u0066\u006C';
  18224. t['\uFB03'] = '\u0066\u0066\u0069';
  18225. t['\uFB04'] = '\u0066\u0066\u006C';
  18226. t['\uFB05'] = '\u017F\u0074';
  18227. t['\uFB06'] = '\u0073\u0074';
  18228. t['\uFB13'] = '\u0574\u0576';
  18229. t['\uFB14'] = '\u0574\u0565';
  18230. t['\uFB15'] = '\u0574\u056B';
  18231. t['\uFB16'] = '\u057E\u0576';
  18232. t['\uFB17'] = '\u0574\u056D';
  18233. t['\uFB4F'] = '\u05D0\u05DC';
  18234. t['\uFB50'] = '\u0671';
  18235. t['\uFB51'] = '\u0671';
  18236. t['\uFB52'] = '\u067B';
  18237. t['\uFB53'] = '\u067B';
  18238. t['\uFB54'] = '\u067B';
  18239. t['\uFB55'] = '\u067B';
  18240. t['\uFB56'] = '\u067E';
  18241. t['\uFB57'] = '\u067E';
  18242. t['\uFB58'] = '\u067E';
  18243. t['\uFB59'] = '\u067E';
  18244. t['\uFB5A'] = '\u0680';
  18245. t['\uFB5B'] = '\u0680';
  18246. t['\uFB5C'] = '\u0680';
  18247. t['\uFB5D'] = '\u0680';
  18248. t['\uFB5E'] = '\u067A';
  18249. t['\uFB5F'] = '\u067A';
  18250. t['\uFB60'] = '\u067A';
  18251. t['\uFB61'] = '\u067A';
  18252. t['\uFB62'] = '\u067F';
  18253. t['\uFB63'] = '\u067F';
  18254. t['\uFB64'] = '\u067F';
  18255. t['\uFB65'] = '\u067F';
  18256. t['\uFB66'] = '\u0679';
  18257. t['\uFB67'] = '\u0679';
  18258. t['\uFB68'] = '\u0679';
  18259. t['\uFB69'] = '\u0679';
  18260. t['\uFB6A'] = '\u06A4';
  18261. t['\uFB6B'] = '\u06A4';
  18262. t['\uFB6C'] = '\u06A4';
  18263. t['\uFB6D'] = '\u06A4';
  18264. t['\uFB6E'] = '\u06A6';
  18265. t['\uFB6F'] = '\u06A6';
  18266. t['\uFB70'] = '\u06A6';
  18267. t['\uFB71'] = '\u06A6';
  18268. t['\uFB72'] = '\u0684';
  18269. t['\uFB73'] = '\u0684';
  18270. t['\uFB74'] = '\u0684';
  18271. t['\uFB75'] = '\u0684';
  18272. t['\uFB76'] = '\u0683';
  18273. t['\uFB77'] = '\u0683';
  18274. t['\uFB78'] = '\u0683';
  18275. t['\uFB79'] = '\u0683';
  18276. t['\uFB7A'] = '\u0686';
  18277. t['\uFB7B'] = '\u0686';
  18278. t['\uFB7C'] = '\u0686';
  18279. t['\uFB7D'] = '\u0686';
  18280. t['\uFB7E'] = '\u0687';
  18281. t['\uFB7F'] = '\u0687';
  18282. t['\uFB80'] = '\u0687';
  18283. t['\uFB81'] = '\u0687';
  18284. t['\uFB82'] = '\u068D';
  18285. t['\uFB83'] = '\u068D';
  18286. t['\uFB84'] = '\u068C';
  18287. t['\uFB85'] = '\u068C';
  18288. t['\uFB86'] = '\u068E';
  18289. t['\uFB87'] = '\u068E';
  18290. t['\uFB88'] = '\u0688';
  18291. t['\uFB89'] = '\u0688';
  18292. t['\uFB8A'] = '\u0698';
  18293. t['\uFB8B'] = '\u0698';
  18294. t['\uFB8C'] = '\u0691';
  18295. t['\uFB8D'] = '\u0691';
  18296. t['\uFB8E'] = '\u06A9';
  18297. t['\uFB8F'] = '\u06A9';
  18298. t['\uFB90'] = '\u06A9';
  18299. t['\uFB91'] = '\u06A9';
  18300. t['\uFB92'] = '\u06AF';
  18301. t['\uFB93'] = '\u06AF';
  18302. t['\uFB94'] = '\u06AF';
  18303. t['\uFB95'] = '\u06AF';
  18304. t['\uFB96'] = '\u06B3';
  18305. t['\uFB97'] = '\u06B3';
  18306. t['\uFB98'] = '\u06B3';
  18307. t['\uFB99'] = '\u06B3';
  18308. t['\uFB9A'] = '\u06B1';
  18309. t['\uFB9B'] = '\u06B1';
  18310. t['\uFB9C'] = '\u06B1';
  18311. t['\uFB9D'] = '\u06B1';
  18312. t['\uFB9E'] = '\u06BA';
  18313. t['\uFB9F'] = '\u06BA';
  18314. t['\uFBA0'] = '\u06BB';
  18315. t['\uFBA1'] = '\u06BB';
  18316. t['\uFBA2'] = '\u06BB';
  18317. t['\uFBA3'] = '\u06BB';
  18318. t['\uFBA4'] = '\u06C0';
  18319. t['\uFBA5'] = '\u06C0';
  18320. t['\uFBA6'] = '\u06C1';
  18321. t['\uFBA7'] = '\u06C1';
  18322. t['\uFBA8'] = '\u06C1';
  18323. t['\uFBA9'] = '\u06C1';
  18324. t['\uFBAA'] = '\u06BE';
  18325. t['\uFBAB'] = '\u06BE';
  18326. t['\uFBAC'] = '\u06BE';
  18327. t['\uFBAD'] = '\u06BE';
  18328. t['\uFBAE'] = '\u06D2';
  18329. t['\uFBAF'] = '\u06D2';
  18330. t['\uFBB0'] = '\u06D3';
  18331. t['\uFBB1'] = '\u06D3';
  18332. t['\uFBD3'] = '\u06AD';
  18333. t['\uFBD4'] = '\u06AD';
  18334. t['\uFBD5'] = '\u06AD';
  18335. t['\uFBD6'] = '\u06AD';
  18336. t['\uFBD7'] = '\u06C7';
  18337. t['\uFBD8'] = '\u06C7';
  18338. t['\uFBD9'] = '\u06C6';
  18339. t['\uFBDA'] = '\u06C6';
  18340. t['\uFBDB'] = '\u06C8';
  18341. t['\uFBDC'] = '\u06C8';
  18342. t['\uFBDD'] = '\u0677';
  18343. t['\uFBDE'] = '\u06CB';
  18344. t['\uFBDF'] = '\u06CB';
  18345. t['\uFBE0'] = '\u06C5';
  18346. t['\uFBE1'] = '\u06C5';
  18347. t['\uFBE2'] = '\u06C9';
  18348. t['\uFBE3'] = '\u06C9';
  18349. t['\uFBE4'] = '\u06D0';
  18350. t['\uFBE5'] = '\u06D0';
  18351. t['\uFBE6'] = '\u06D0';
  18352. t['\uFBE7'] = '\u06D0';
  18353. t['\uFBE8'] = '\u0649';
  18354. t['\uFBE9'] = '\u0649';
  18355. t['\uFBEA'] = '\u0626\u0627';
  18356. t['\uFBEB'] = '\u0626\u0627';
  18357. t['\uFBEC'] = '\u0626\u06D5';
  18358. t['\uFBED'] = '\u0626\u06D5';
  18359. t['\uFBEE'] = '\u0626\u0648';
  18360. t['\uFBEF'] = '\u0626\u0648';
  18361. t['\uFBF0'] = '\u0626\u06C7';
  18362. t['\uFBF1'] = '\u0626\u06C7';
  18363. t['\uFBF2'] = '\u0626\u06C6';
  18364. t['\uFBF3'] = '\u0626\u06C6';
  18365. t['\uFBF4'] = '\u0626\u06C8';
  18366. t['\uFBF5'] = '\u0626\u06C8';
  18367. t['\uFBF6'] = '\u0626\u06D0';
  18368. t['\uFBF7'] = '\u0626\u06D0';
  18369. t['\uFBF8'] = '\u0626\u06D0';
  18370. t['\uFBF9'] = '\u0626\u0649';
  18371. t['\uFBFA'] = '\u0626\u0649';
  18372. t['\uFBFB'] = '\u0626\u0649';
  18373. t['\uFBFC'] = '\u06CC';
  18374. t['\uFBFD'] = '\u06CC';
  18375. t['\uFBFE'] = '\u06CC';
  18376. t['\uFBFF'] = '\u06CC';
  18377. t['\uFC00'] = '\u0626\u062C';
  18378. t['\uFC01'] = '\u0626\u062D';
  18379. t['\uFC02'] = '\u0626\u0645';
  18380. t['\uFC03'] = '\u0626\u0649';
  18381. t['\uFC04'] = '\u0626\u064A';
  18382. t['\uFC05'] = '\u0628\u062C';
  18383. t['\uFC06'] = '\u0628\u062D';
  18384. t['\uFC07'] = '\u0628\u062E';
  18385. t['\uFC08'] = '\u0628\u0645';
  18386. t['\uFC09'] = '\u0628\u0649';
  18387. t['\uFC0A'] = '\u0628\u064A';
  18388. t['\uFC0B'] = '\u062A\u062C';
  18389. t['\uFC0C'] = '\u062A\u062D';
  18390. t['\uFC0D'] = '\u062A\u062E';
  18391. t['\uFC0E'] = '\u062A\u0645';
  18392. t['\uFC0F'] = '\u062A\u0649';
  18393. t['\uFC10'] = '\u062A\u064A';
  18394. t['\uFC11'] = '\u062B\u062C';
  18395. t['\uFC12'] = '\u062B\u0645';
  18396. t['\uFC13'] = '\u062B\u0649';
  18397. t['\uFC14'] = '\u062B\u064A';
  18398. t['\uFC15'] = '\u062C\u062D';
  18399. t['\uFC16'] = '\u062C\u0645';
  18400. t['\uFC17'] = '\u062D\u062C';
  18401. t['\uFC18'] = '\u062D\u0645';
  18402. t['\uFC19'] = '\u062E\u062C';
  18403. t['\uFC1A'] = '\u062E\u062D';
  18404. t['\uFC1B'] = '\u062E\u0645';
  18405. t['\uFC1C'] = '\u0633\u062C';
  18406. t['\uFC1D'] = '\u0633\u062D';
  18407. t['\uFC1E'] = '\u0633\u062E';
  18408. t['\uFC1F'] = '\u0633\u0645';
  18409. t['\uFC20'] = '\u0635\u062D';
  18410. t['\uFC21'] = '\u0635\u0645';
  18411. t['\uFC22'] = '\u0636\u062C';
  18412. t['\uFC23'] = '\u0636\u062D';
  18413. t['\uFC24'] = '\u0636\u062E';
  18414. t['\uFC25'] = '\u0636\u0645';
  18415. t['\uFC26'] = '\u0637\u062D';
  18416. t['\uFC27'] = '\u0637\u0645';
  18417. t['\uFC28'] = '\u0638\u0645';
  18418. t['\uFC29'] = '\u0639\u062C';
  18419. t['\uFC2A'] = '\u0639\u0645';
  18420. t['\uFC2B'] = '\u063A\u062C';
  18421. t['\uFC2C'] = '\u063A\u0645';
  18422. t['\uFC2D'] = '\u0641\u062C';
  18423. t['\uFC2E'] = '\u0641\u062D';
  18424. t['\uFC2F'] = '\u0641\u062E';
  18425. t['\uFC30'] = '\u0641\u0645';
  18426. t['\uFC31'] = '\u0641\u0649';
  18427. t['\uFC32'] = '\u0641\u064A';
  18428. t['\uFC33'] = '\u0642\u062D';
  18429. t['\uFC34'] = '\u0642\u0645';
  18430. t['\uFC35'] = '\u0642\u0649';
  18431. t['\uFC36'] = '\u0642\u064A';
  18432. t['\uFC37'] = '\u0643\u0627';
  18433. t['\uFC38'] = '\u0643\u062C';
  18434. t['\uFC39'] = '\u0643\u062D';
  18435. t['\uFC3A'] = '\u0643\u062E';
  18436. t['\uFC3B'] = '\u0643\u0644';
  18437. t['\uFC3C'] = '\u0643\u0645';
  18438. t['\uFC3D'] = '\u0643\u0649';
  18439. t['\uFC3E'] = '\u0643\u064A';
  18440. t['\uFC3F'] = '\u0644\u062C';
  18441. t['\uFC40'] = '\u0644\u062D';
  18442. t['\uFC41'] = '\u0644\u062E';
  18443. t['\uFC42'] = '\u0644\u0645';
  18444. t['\uFC43'] = '\u0644\u0649';
  18445. t['\uFC44'] = '\u0644\u064A';
  18446. t['\uFC45'] = '\u0645\u062C';
  18447. t['\uFC46'] = '\u0645\u062D';
  18448. t['\uFC47'] = '\u0645\u062E';
  18449. t['\uFC48'] = '\u0645\u0645';
  18450. t['\uFC49'] = '\u0645\u0649';
  18451. t['\uFC4A'] = '\u0645\u064A';
  18452. t['\uFC4B'] = '\u0646\u062C';
  18453. t['\uFC4C'] = '\u0646\u062D';
  18454. t['\uFC4D'] = '\u0646\u062E';
  18455. t['\uFC4E'] = '\u0646\u0645';
  18456. t['\uFC4F'] = '\u0646\u0649';
  18457. t['\uFC50'] = '\u0646\u064A';
  18458. t['\uFC51'] = '\u0647\u062C';
  18459. t['\uFC52'] = '\u0647\u0645';
  18460. t['\uFC53'] = '\u0647\u0649';
  18461. t['\uFC54'] = '\u0647\u064A';
  18462. t['\uFC55'] = '\u064A\u062C';
  18463. t['\uFC56'] = '\u064A\u062D';
  18464. t['\uFC57'] = '\u064A\u062E';
  18465. t['\uFC58'] = '\u064A\u0645';
  18466. t['\uFC59'] = '\u064A\u0649';
  18467. t['\uFC5A'] = '\u064A\u064A';
  18468. t['\uFC5B'] = '\u0630\u0670';
  18469. t['\uFC5C'] = '\u0631\u0670';
  18470. t['\uFC5D'] = '\u0649\u0670';
  18471. t['\uFC5E'] = '\u0020\u064C\u0651';
  18472. t['\uFC5F'] = '\u0020\u064D\u0651';
  18473. t['\uFC60'] = '\u0020\u064E\u0651';
  18474. t['\uFC61'] = '\u0020\u064F\u0651';
  18475. t['\uFC62'] = '\u0020\u0650\u0651';
  18476. t['\uFC63'] = '\u0020\u0651\u0670';
  18477. t['\uFC64'] = '\u0626\u0631';
  18478. t['\uFC65'] = '\u0626\u0632';
  18479. t['\uFC66'] = '\u0626\u0645';
  18480. t['\uFC67'] = '\u0626\u0646';
  18481. t['\uFC68'] = '\u0626\u0649';
  18482. t['\uFC69'] = '\u0626\u064A';
  18483. t['\uFC6A'] = '\u0628\u0631';
  18484. t['\uFC6B'] = '\u0628\u0632';
  18485. t['\uFC6C'] = '\u0628\u0645';
  18486. t['\uFC6D'] = '\u0628\u0646';
  18487. t['\uFC6E'] = '\u0628\u0649';
  18488. t['\uFC6F'] = '\u0628\u064A';
  18489. t['\uFC70'] = '\u062A\u0631';
  18490. t['\uFC71'] = '\u062A\u0632';
  18491. t['\uFC72'] = '\u062A\u0645';
  18492. t['\uFC73'] = '\u062A\u0646';
  18493. t['\uFC74'] = '\u062A\u0649';
  18494. t['\uFC75'] = '\u062A\u064A';
  18495. t['\uFC76'] = '\u062B\u0631';
  18496. t['\uFC77'] = '\u062B\u0632';
  18497. t['\uFC78'] = '\u062B\u0645';
  18498. t['\uFC79'] = '\u062B\u0646';
  18499. t['\uFC7A'] = '\u062B\u0649';
  18500. t['\uFC7B'] = '\u062B\u064A';
  18501. t['\uFC7C'] = '\u0641\u0649';
  18502. t['\uFC7D'] = '\u0641\u064A';
  18503. t['\uFC7E'] = '\u0642\u0649';
  18504. t['\uFC7F'] = '\u0642\u064A';
  18505. t['\uFC80'] = '\u0643\u0627';
  18506. t['\uFC81'] = '\u0643\u0644';
  18507. t['\uFC82'] = '\u0643\u0645';
  18508. t['\uFC83'] = '\u0643\u0649';
  18509. t['\uFC84'] = '\u0643\u064A';
  18510. t['\uFC85'] = '\u0644\u0645';
  18511. t['\uFC86'] = '\u0644\u0649';
  18512. t['\uFC87'] = '\u0644\u064A';
  18513. t['\uFC88'] = '\u0645\u0627';
  18514. t['\uFC89'] = '\u0645\u0645';
  18515. t['\uFC8A'] = '\u0646\u0631';
  18516. t['\uFC8B'] = '\u0646\u0632';
  18517. t['\uFC8C'] = '\u0646\u0645';
  18518. t['\uFC8D'] = '\u0646\u0646';
  18519. t['\uFC8E'] = '\u0646\u0649';
  18520. t['\uFC8F'] = '\u0646\u064A';
  18521. t['\uFC90'] = '\u0649\u0670';
  18522. t['\uFC91'] = '\u064A\u0631';
  18523. t['\uFC92'] = '\u064A\u0632';
  18524. t['\uFC93'] = '\u064A\u0645';
  18525. t['\uFC94'] = '\u064A\u0646';
  18526. t['\uFC95'] = '\u064A\u0649';
  18527. t['\uFC96'] = '\u064A\u064A';
  18528. t['\uFC97'] = '\u0626\u062C';
  18529. t['\uFC98'] = '\u0626\u062D';
  18530. t['\uFC99'] = '\u0626\u062E';
  18531. t['\uFC9A'] = '\u0626\u0645';
  18532. t['\uFC9B'] = '\u0626\u0647';
  18533. t['\uFC9C'] = '\u0628\u062C';
  18534. t['\uFC9D'] = '\u0628\u062D';
  18535. t['\uFC9E'] = '\u0628\u062E';
  18536. t['\uFC9F'] = '\u0628\u0645';
  18537. t['\uFCA0'] = '\u0628\u0647';
  18538. t['\uFCA1'] = '\u062A\u062C';
  18539. t['\uFCA2'] = '\u062A\u062D';
  18540. t['\uFCA3'] = '\u062A\u062E';
  18541. t['\uFCA4'] = '\u062A\u0645';
  18542. t['\uFCA5'] = '\u062A\u0647';
  18543. t['\uFCA6'] = '\u062B\u0645';
  18544. t['\uFCA7'] = '\u062C\u062D';
  18545. t['\uFCA8'] = '\u062C\u0645';
  18546. t['\uFCA9'] = '\u062D\u062C';
  18547. t['\uFCAA'] = '\u062D\u0645';
  18548. t['\uFCAB'] = '\u062E\u062C';
  18549. t['\uFCAC'] = '\u062E\u0645';
  18550. t['\uFCAD'] = '\u0633\u062C';
  18551. t['\uFCAE'] = '\u0633\u062D';
  18552. t['\uFCAF'] = '\u0633\u062E';
  18553. t['\uFCB0'] = '\u0633\u0645';
  18554. t['\uFCB1'] = '\u0635\u062D';
  18555. t['\uFCB2'] = '\u0635\u062E';
  18556. t['\uFCB3'] = '\u0635\u0645';
  18557. t['\uFCB4'] = '\u0636\u062C';
  18558. t['\uFCB5'] = '\u0636\u062D';
  18559. t['\uFCB6'] = '\u0636\u062E';
  18560. t['\uFCB7'] = '\u0636\u0645';
  18561. t['\uFCB8'] = '\u0637\u062D';
  18562. t['\uFCB9'] = '\u0638\u0645';
  18563. t['\uFCBA'] = '\u0639\u062C';
  18564. t['\uFCBB'] = '\u0639\u0645';
  18565. t['\uFCBC'] = '\u063A\u062C';
  18566. t['\uFCBD'] = '\u063A\u0645';
  18567. t['\uFCBE'] = '\u0641\u062C';
  18568. t['\uFCBF'] = '\u0641\u062D';
  18569. t['\uFCC0'] = '\u0641\u062E';
  18570. t['\uFCC1'] = '\u0641\u0645';
  18571. t['\uFCC2'] = '\u0642\u062D';
  18572. t['\uFCC3'] = '\u0642\u0645';
  18573. t['\uFCC4'] = '\u0643\u062C';
  18574. t['\uFCC5'] = '\u0643\u062D';
  18575. t['\uFCC6'] = '\u0643\u062E';
  18576. t['\uFCC7'] = '\u0643\u0644';
  18577. t['\uFCC8'] = '\u0643\u0645';
  18578. t['\uFCC9'] = '\u0644\u062C';
  18579. t['\uFCCA'] = '\u0644\u062D';
  18580. t['\uFCCB'] = '\u0644\u062E';
  18581. t['\uFCCC'] = '\u0644\u0645';
  18582. t['\uFCCD'] = '\u0644\u0647';
  18583. t['\uFCCE'] = '\u0645\u062C';
  18584. t['\uFCCF'] = '\u0645\u062D';
  18585. t['\uFCD0'] = '\u0645\u062E';
  18586. t['\uFCD1'] = '\u0645\u0645';
  18587. t['\uFCD2'] = '\u0646\u062C';
  18588. t['\uFCD3'] = '\u0646\u062D';
  18589. t['\uFCD4'] = '\u0646\u062E';
  18590. t['\uFCD5'] = '\u0646\u0645';
  18591. t['\uFCD6'] = '\u0646\u0647';
  18592. t['\uFCD7'] = '\u0647\u062C';
  18593. t['\uFCD8'] = '\u0647\u0645';
  18594. t['\uFCD9'] = '\u0647\u0670';
  18595. t['\uFCDA'] = '\u064A\u062C';
  18596. t['\uFCDB'] = '\u064A\u062D';
  18597. t['\uFCDC'] = '\u064A\u062E';
  18598. t['\uFCDD'] = '\u064A\u0645';
  18599. t['\uFCDE'] = '\u064A\u0647';
  18600. t['\uFCDF'] = '\u0626\u0645';
  18601. t['\uFCE0'] = '\u0626\u0647';
  18602. t['\uFCE1'] = '\u0628\u0645';
  18603. t['\uFCE2'] = '\u0628\u0647';
  18604. t['\uFCE3'] = '\u062A\u0645';
  18605. t['\uFCE4'] = '\u062A\u0647';
  18606. t['\uFCE5'] = '\u062B\u0645';
  18607. t['\uFCE6'] = '\u062B\u0647';
  18608. t['\uFCE7'] = '\u0633\u0645';
  18609. t['\uFCE8'] = '\u0633\u0647';
  18610. t['\uFCE9'] = '\u0634\u0645';
  18611. t['\uFCEA'] = '\u0634\u0647';
  18612. t['\uFCEB'] = '\u0643\u0644';
  18613. t['\uFCEC'] = '\u0643\u0645';
  18614. t['\uFCED'] = '\u0644\u0645';
  18615. t['\uFCEE'] = '\u0646\u0645';
  18616. t['\uFCEF'] = '\u0646\u0647';
  18617. t['\uFCF0'] = '\u064A\u0645';
  18618. t['\uFCF1'] = '\u064A\u0647';
  18619. t['\uFCF2'] = '\u0640\u064E\u0651';
  18620. t['\uFCF3'] = '\u0640\u064F\u0651';
  18621. t['\uFCF4'] = '\u0640\u0650\u0651';
  18622. t['\uFCF5'] = '\u0637\u0649';
  18623. t['\uFCF6'] = '\u0637\u064A';
  18624. t['\uFCF7'] = '\u0639\u0649';
  18625. t['\uFCF8'] = '\u0639\u064A';
  18626. t['\uFCF9'] = '\u063A\u0649';
  18627. t['\uFCFA'] = '\u063A\u064A';
  18628. t['\uFCFB'] = '\u0633\u0649';
  18629. t['\uFCFC'] = '\u0633\u064A';
  18630. t['\uFCFD'] = '\u0634\u0649';
  18631. t['\uFCFE'] = '\u0634\u064A';
  18632. t['\uFCFF'] = '\u062D\u0649';
  18633. t['\uFD00'] = '\u062D\u064A';
  18634. t['\uFD01'] = '\u062C\u0649';
  18635. t['\uFD02'] = '\u062C\u064A';
  18636. t['\uFD03'] = '\u062E\u0649';
  18637. t['\uFD04'] = '\u062E\u064A';
  18638. t['\uFD05'] = '\u0635\u0649';
  18639. t['\uFD06'] = '\u0635\u064A';
  18640. t['\uFD07'] = '\u0636\u0649';
  18641. t['\uFD08'] = '\u0636\u064A';
  18642. t['\uFD09'] = '\u0634\u062C';
  18643. t['\uFD0A'] = '\u0634\u062D';
  18644. t['\uFD0B'] = '\u0634\u062E';
  18645. t['\uFD0C'] = '\u0634\u0645';
  18646. t['\uFD0D'] = '\u0634\u0631';
  18647. t['\uFD0E'] = '\u0633\u0631';
  18648. t['\uFD0F'] = '\u0635\u0631';
  18649. t['\uFD10'] = '\u0636\u0631';
  18650. t['\uFD11'] = '\u0637\u0649';
  18651. t['\uFD12'] = '\u0637\u064A';
  18652. t['\uFD13'] = '\u0639\u0649';
  18653. t['\uFD14'] = '\u0639\u064A';
  18654. t['\uFD15'] = '\u063A\u0649';
  18655. t['\uFD16'] = '\u063A\u064A';
  18656. t['\uFD17'] = '\u0633\u0649';
  18657. t['\uFD18'] = '\u0633\u064A';
  18658. t['\uFD19'] = '\u0634\u0649';
  18659. t['\uFD1A'] = '\u0634\u064A';
  18660. t['\uFD1B'] = '\u062D\u0649';
  18661. t['\uFD1C'] = '\u062D\u064A';
  18662. t['\uFD1D'] = '\u062C\u0649';
  18663. t['\uFD1E'] = '\u062C\u064A';
  18664. t['\uFD1F'] = '\u062E\u0649';
  18665. t['\uFD20'] = '\u062E\u064A';
  18666. t['\uFD21'] = '\u0635\u0649';
  18667. t['\uFD22'] = '\u0635\u064A';
  18668. t['\uFD23'] = '\u0636\u0649';
  18669. t['\uFD24'] = '\u0636\u064A';
  18670. t['\uFD25'] = '\u0634\u062C';
  18671. t['\uFD26'] = '\u0634\u062D';
  18672. t['\uFD27'] = '\u0634\u062E';
  18673. t['\uFD28'] = '\u0634\u0645';
  18674. t['\uFD29'] = '\u0634\u0631';
  18675. t['\uFD2A'] = '\u0633\u0631';
  18676. t['\uFD2B'] = '\u0635\u0631';
  18677. t['\uFD2C'] = '\u0636\u0631';
  18678. t['\uFD2D'] = '\u0634\u062C';
  18679. t['\uFD2E'] = '\u0634\u062D';
  18680. t['\uFD2F'] = '\u0634\u062E';
  18681. t['\uFD30'] = '\u0634\u0645';
  18682. t['\uFD31'] = '\u0633\u0647';
  18683. t['\uFD32'] = '\u0634\u0647';
  18684. t['\uFD33'] = '\u0637\u0645';
  18685. t['\uFD34'] = '\u0633\u062C';
  18686. t['\uFD35'] = '\u0633\u062D';
  18687. t['\uFD36'] = '\u0633\u062E';
  18688. t['\uFD37'] = '\u0634\u062C';
  18689. t['\uFD38'] = '\u0634\u062D';
  18690. t['\uFD39'] = '\u0634\u062E';
  18691. t['\uFD3A'] = '\u0637\u0645';
  18692. t['\uFD3B'] = '\u0638\u0645';
  18693. t['\uFD3C'] = '\u0627\u064B';
  18694. t['\uFD3D'] = '\u0627\u064B';
  18695. t['\uFD50'] = '\u062A\u062C\u0645';
  18696. t['\uFD51'] = '\u062A\u062D\u062C';
  18697. t['\uFD52'] = '\u062A\u062D\u062C';
  18698. t['\uFD53'] = '\u062A\u062D\u0645';
  18699. t['\uFD54'] = '\u062A\u062E\u0645';
  18700. t['\uFD55'] = '\u062A\u0645\u062C';
  18701. t['\uFD56'] = '\u062A\u0645\u062D';
  18702. t['\uFD57'] = '\u062A\u0645\u062E';
  18703. t['\uFD58'] = '\u062C\u0645\u062D';
  18704. t['\uFD59'] = '\u062C\u0645\u062D';
  18705. t['\uFD5A'] = '\u062D\u0645\u064A';
  18706. t['\uFD5B'] = '\u062D\u0645\u0649';
  18707. t['\uFD5C'] = '\u0633\u062D\u062C';
  18708. t['\uFD5D'] = '\u0633\u062C\u062D';
  18709. t['\uFD5E'] = '\u0633\u062C\u0649';
  18710. t['\uFD5F'] = '\u0633\u0645\u062D';
  18711. t['\uFD60'] = '\u0633\u0645\u062D';
  18712. t['\uFD61'] = '\u0633\u0645\u062C';
  18713. t['\uFD62'] = '\u0633\u0645\u0645';
  18714. t['\uFD63'] = '\u0633\u0645\u0645';
  18715. t['\uFD64'] = '\u0635\u062D\u062D';
  18716. t['\uFD65'] = '\u0635\u062D\u062D';
  18717. t['\uFD66'] = '\u0635\u0645\u0645';
  18718. t['\uFD67'] = '\u0634\u062D\u0645';
  18719. t['\uFD68'] = '\u0634\u062D\u0645';
  18720. t['\uFD69'] = '\u0634\u062C\u064A';
  18721. t['\uFD6A'] = '\u0634\u0645\u062E';
  18722. t['\uFD6B'] = '\u0634\u0645\u062E';
  18723. t['\uFD6C'] = '\u0634\u0645\u0645';
  18724. t['\uFD6D'] = '\u0634\u0645\u0645';
  18725. t['\uFD6E'] = '\u0636\u062D\u0649';
  18726. t['\uFD6F'] = '\u0636\u062E\u0645';
  18727. t['\uFD70'] = '\u0636\u062E\u0645';
  18728. t['\uFD71'] = '\u0637\u0645\u062D';
  18729. t['\uFD72'] = '\u0637\u0645\u062D';
  18730. t['\uFD73'] = '\u0637\u0645\u0645';
  18731. t['\uFD74'] = '\u0637\u0645\u064A';
  18732. t['\uFD75'] = '\u0639\u062C\u0645';
  18733. t['\uFD76'] = '\u0639\u0645\u0645';
  18734. t['\uFD77'] = '\u0639\u0645\u0645';
  18735. t['\uFD78'] = '\u0639\u0645\u0649';
  18736. t['\uFD79'] = '\u063A\u0645\u0645';
  18737. t['\uFD7A'] = '\u063A\u0645\u064A';
  18738. t['\uFD7B'] = '\u063A\u0645\u0649';
  18739. t['\uFD7C'] = '\u0641\u062E\u0645';
  18740. t['\uFD7D'] = '\u0641\u062E\u0645';
  18741. t['\uFD7E'] = '\u0642\u0645\u062D';
  18742. t['\uFD7F'] = '\u0642\u0645\u0645';
  18743. t['\uFD80'] = '\u0644\u062D\u0645';
  18744. t['\uFD81'] = '\u0644\u062D\u064A';
  18745. t['\uFD82'] = '\u0644\u062D\u0649';
  18746. t['\uFD83'] = '\u0644\u062C\u062C';
  18747. t['\uFD84'] = '\u0644\u062C\u062C';
  18748. t['\uFD85'] = '\u0644\u062E\u0645';
  18749. t['\uFD86'] = '\u0644\u062E\u0645';
  18750. t['\uFD87'] = '\u0644\u0645\u062D';
  18751. t['\uFD88'] = '\u0644\u0645\u062D';
  18752. t['\uFD89'] = '\u0645\u062D\u062C';
  18753. t['\uFD8A'] = '\u0645\u062D\u0645';
  18754. t['\uFD8B'] = '\u0645\u062D\u064A';
  18755. t['\uFD8C'] = '\u0645\u062C\u062D';
  18756. t['\uFD8D'] = '\u0645\u062C\u0645';
  18757. t['\uFD8E'] = '\u0645\u062E\u062C';
  18758. t['\uFD8F'] = '\u0645\u062E\u0645';
  18759. t['\uFD92'] = '\u0645\u062C\u062E';
  18760. t['\uFD93'] = '\u0647\u0645\u062C';
  18761. t['\uFD94'] = '\u0647\u0645\u0645';
  18762. t['\uFD95'] = '\u0646\u062D\u0645';
  18763. t['\uFD96'] = '\u0646\u062D\u0649';
  18764. t['\uFD97'] = '\u0646\u062C\u0645';
  18765. t['\uFD98'] = '\u0646\u062C\u0645';
  18766. t['\uFD99'] = '\u0646\u062C\u0649';
  18767. t['\uFD9A'] = '\u0646\u0645\u064A';
  18768. t['\uFD9B'] = '\u0646\u0645\u0649';
  18769. t['\uFD9C'] = '\u064A\u0645\u0645';
  18770. t['\uFD9D'] = '\u064A\u0645\u0645';
  18771. t['\uFD9E'] = '\u0628\u062E\u064A';
  18772. t['\uFD9F'] = '\u062A\u062C\u064A';
  18773. t['\uFDA0'] = '\u062A\u062C\u0649';
  18774. t['\uFDA1'] = '\u062A\u062E\u064A';
  18775. t['\uFDA2'] = '\u062A\u062E\u0649';
  18776. t['\uFDA3'] = '\u062A\u0645\u064A';
  18777. t['\uFDA4'] = '\u062A\u0645\u0649';
  18778. t['\uFDA5'] = '\u062C\u0645\u064A';
  18779. t['\uFDA6'] = '\u062C\u062D\u0649';
  18780. t['\uFDA7'] = '\u062C\u0645\u0649';
  18781. t['\uFDA8'] = '\u0633\u062E\u0649';
  18782. t['\uFDA9'] = '\u0635\u062D\u064A';
  18783. t['\uFDAA'] = '\u0634\u062D\u064A';
  18784. t['\uFDAB'] = '\u0636\u062D\u064A';
  18785. t['\uFDAC'] = '\u0644\u062C\u064A';
  18786. t['\uFDAD'] = '\u0644\u0645\u064A';
  18787. t['\uFDAE'] = '\u064A\u062D\u064A';
  18788. t['\uFDAF'] = '\u064A\u062C\u064A';
  18789. t['\uFDB0'] = '\u064A\u0645\u064A';
  18790. t['\uFDB1'] = '\u0645\u0645\u064A';
  18791. t['\uFDB2'] = '\u0642\u0645\u064A';
  18792. t['\uFDB3'] = '\u0646\u062D\u064A';
  18793. t['\uFDB4'] = '\u0642\u0645\u062D';
  18794. t['\uFDB5'] = '\u0644\u062D\u0645';
  18795. t['\uFDB6'] = '\u0639\u0645\u064A';
  18796. t['\uFDB7'] = '\u0643\u0645\u064A';
  18797. t['\uFDB8'] = '\u0646\u062C\u062D';
  18798. t['\uFDB9'] = '\u0645\u062E\u064A';
  18799. t['\uFDBA'] = '\u0644\u062C\u0645';
  18800. t['\uFDBB'] = '\u0643\u0645\u0645';
  18801. t['\uFDBC'] = '\u0644\u062C\u0645';
  18802. t['\uFDBD'] = '\u0646\u062C\u062D';
  18803. t['\uFDBE'] = '\u062C\u062D\u064A';
  18804. t['\uFDBF'] = '\u062D\u062C\u064A';
  18805. t['\uFDC0'] = '\u0645\u062C\u064A';
  18806. t['\uFDC1'] = '\u0641\u0645\u064A';
  18807. t['\uFDC2'] = '\u0628\u062D\u064A';
  18808. t['\uFDC3'] = '\u0643\u0645\u0645';
  18809. t['\uFDC4'] = '\u0639\u062C\u0645';
  18810. t['\uFDC5'] = '\u0635\u0645\u0645';
  18811. t['\uFDC6'] = '\u0633\u062E\u064A';
  18812. t['\uFDC7'] = '\u0646\u062C\u064A';
  18813. t['\uFE49'] = '\u203E';
  18814. t['\uFE4A'] = '\u203E';
  18815. t['\uFE4B'] = '\u203E';
  18816. t['\uFE4C'] = '\u203E';
  18817. t['\uFE4D'] = '\u005F';
  18818. t['\uFE4E'] = '\u005F';
  18819. t['\uFE4F'] = '\u005F';
  18820. t['\uFE80'] = '\u0621';
  18821. t['\uFE81'] = '\u0622';
  18822. t['\uFE82'] = '\u0622';
  18823. t['\uFE83'] = '\u0623';
  18824. t['\uFE84'] = '\u0623';
  18825. t['\uFE85'] = '\u0624';
  18826. t['\uFE86'] = '\u0624';
  18827. t['\uFE87'] = '\u0625';
  18828. t['\uFE88'] = '\u0625';
  18829. t['\uFE89'] = '\u0626';
  18830. t['\uFE8A'] = '\u0626';
  18831. t['\uFE8B'] = '\u0626';
  18832. t['\uFE8C'] = '\u0626';
  18833. t['\uFE8D'] = '\u0627';
  18834. t['\uFE8E'] = '\u0627';
  18835. t['\uFE8F'] = '\u0628';
  18836. t['\uFE90'] = '\u0628';
  18837. t['\uFE91'] = '\u0628';
  18838. t['\uFE92'] = '\u0628';
  18839. t['\uFE93'] = '\u0629';
  18840. t['\uFE94'] = '\u0629';
  18841. t['\uFE95'] = '\u062A';
  18842. t['\uFE96'] = '\u062A';
  18843. t['\uFE97'] = '\u062A';
  18844. t['\uFE98'] = '\u062A';
  18845. t['\uFE99'] = '\u062B';
  18846. t['\uFE9A'] = '\u062B';
  18847. t['\uFE9B'] = '\u062B';
  18848. t['\uFE9C'] = '\u062B';
  18849. t['\uFE9D'] = '\u062C';
  18850. t['\uFE9E'] = '\u062C';
  18851. t['\uFE9F'] = '\u062C';
  18852. t['\uFEA0'] = '\u062C';
  18853. t['\uFEA1'] = '\u062D';
  18854. t['\uFEA2'] = '\u062D';
  18855. t['\uFEA3'] = '\u062D';
  18856. t['\uFEA4'] = '\u062D';
  18857. t['\uFEA5'] = '\u062E';
  18858. t['\uFEA6'] = '\u062E';
  18859. t['\uFEA7'] = '\u062E';
  18860. t['\uFEA8'] = '\u062E';
  18861. t['\uFEA9'] = '\u062F';
  18862. t['\uFEAA'] = '\u062F';
  18863. t['\uFEAB'] = '\u0630';
  18864. t['\uFEAC'] = '\u0630';
  18865. t['\uFEAD'] = '\u0631';
  18866. t['\uFEAE'] = '\u0631';
  18867. t['\uFEAF'] = '\u0632';
  18868. t['\uFEB0'] = '\u0632';
  18869. t['\uFEB1'] = '\u0633';
  18870. t['\uFEB2'] = '\u0633';
  18871. t['\uFEB3'] = '\u0633';
  18872. t['\uFEB4'] = '\u0633';
  18873. t['\uFEB5'] = '\u0634';
  18874. t['\uFEB6'] = '\u0634';
  18875. t['\uFEB7'] = '\u0634';
  18876. t['\uFEB8'] = '\u0634';
  18877. t['\uFEB9'] = '\u0635';
  18878. t['\uFEBA'] = '\u0635';
  18879. t['\uFEBB'] = '\u0635';
  18880. t['\uFEBC'] = '\u0635';
  18881. t['\uFEBD'] = '\u0636';
  18882. t['\uFEBE'] = '\u0636';
  18883. t['\uFEBF'] = '\u0636';
  18884. t['\uFEC0'] = '\u0636';
  18885. t['\uFEC1'] = '\u0637';
  18886. t['\uFEC2'] = '\u0637';
  18887. t['\uFEC3'] = '\u0637';
  18888. t['\uFEC4'] = '\u0637';
  18889. t['\uFEC5'] = '\u0638';
  18890. t['\uFEC6'] = '\u0638';
  18891. t['\uFEC7'] = '\u0638';
  18892. t['\uFEC8'] = '\u0638';
  18893. t['\uFEC9'] = '\u0639';
  18894. t['\uFECA'] = '\u0639';
  18895. t['\uFECB'] = '\u0639';
  18896. t['\uFECC'] = '\u0639';
  18897. t['\uFECD'] = '\u063A';
  18898. t['\uFECE'] = '\u063A';
  18899. t['\uFECF'] = '\u063A';
  18900. t['\uFED0'] = '\u063A';
  18901. t['\uFED1'] = '\u0641';
  18902. t['\uFED2'] = '\u0641';
  18903. t['\uFED3'] = '\u0641';
  18904. t['\uFED4'] = '\u0641';
  18905. t['\uFED5'] = '\u0642';
  18906. t['\uFED6'] = '\u0642';
  18907. t['\uFED7'] = '\u0642';
  18908. t['\uFED8'] = '\u0642';
  18909. t['\uFED9'] = '\u0643';
  18910. t['\uFEDA'] = '\u0643';
  18911. t['\uFEDB'] = '\u0643';
  18912. t['\uFEDC'] = '\u0643';
  18913. t['\uFEDD'] = '\u0644';
  18914. t['\uFEDE'] = '\u0644';
  18915. t['\uFEDF'] = '\u0644';
  18916. t['\uFEE0'] = '\u0644';
  18917. t['\uFEE1'] = '\u0645';
  18918. t['\uFEE2'] = '\u0645';
  18919. t['\uFEE3'] = '\u0645';
  18920. t['\uFEE4'] = '\u0645';
  18921. t['\uFEE5'] = '\u0646';
  18922. t['\uFEE6'] = '\u0646';
  18923. t['\uFEE7'] = '\u0646';
  18924. t['\uFEE8'] = '\u0646';
  18925. t['\uFEE9'] = '\u0647';
  18926. t['\uFEEA'] = '\u0647';
  18927. t['\uFEEB'] = '\u0647';
  18928. t['\uFEEC'] = '\u0647';
  18929. t['\uFEED'] = '\u0648';
  18930. t['\uFEEE'] = '\u0648';
  18931. t['\uFEEF'] = '\u0649';
  18932. t['\uFEF0'] = '\u0649';
  18933. t['\uFEF1'] = '\u064A';
  18934. t['\uFEF2'] = '\u064A';
  18935. t['\uFEF3'] = '\u064A';
  18936. t['\uFEF4'] = '\u064A';
  18937. t['\uFEF5'] = '\u0644\u0622';
  18938. t['\uFEF6'] = '\u0644\u0622';
  18939. t['\uFEF7'] = '\u0644\u0623';
  18940. t['\uFEF8'] = '\u0644\u0623';
  18941. t['\uFEF9'] = '\u0644\u0625';
  18942. t['\uFEFA'] = '\u0644\u0625';
  18943. t['\uFEFB'] = '\u0644\u0627';
  18944. t['\uFEFC'] = '\u0644\u0627';
  18945. });
  18946. function reverseIfRtl(chars) {
  18947. var charsLength = chars.length;
  18948. //reverse an arabic ligature
  18949. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  18950. return chars;
  18951. }
  18952. var s = '';
  18953. for (var ii = charsLength - 1; ii >= 0; ii--) {
  18954. s += chars[ii];
  18955. }
  18956. return s;
  18957. }
  18958. exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues;
  18959. exports.reverseIfRtl = reverseIfRtl;
  18960. exports.getUnicodeRangeFor = getUnicodeRangeFor;
  18961. exports.getNormalizedUnicodes = getNormalizedUnicodes;
  18962. exports.getUnicodeForGlyph = getUnicodeForGlyph;
  18963. }));
  18964. (function (root, factory) {
  18965. {
  18966. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  18967. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  18968. root.pdfjsCoreJpx);
  18969. }
  18970. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  18971. coreJpx) {
  18972. var Util = sharedUtil.Util;
  18973. var error = sharedUtil.error;
  18974. var info = sharedUtil.info;
  18975. var isInt = sharedUtil.isInt;
  18976. var isArray = sharedUtil.isArray;
  18977. var createObjectURL = sharedUtil.createObjectURL;
  18978. var shadow = sharedUtil.shadow;
  18979. var warn = sharedUtil.warn;
  18980. var isSpace = sharedUtil.isSpace;
  18981. var Dict = corePrimitives.Dict;
  18982. var isDict = corePrimitives.isDict;
  18983. var Jbig2Image = coreJbig2.Jbig2Image;
  18984. var JpegImage = coreJpg.JpegImage;
  18985. var JpxImage = coreJpx.JpxImage;
  18986. var Stream = (function StreamClosure() {
  18987. function Stream(arrayBuffer, start, length, dict) {
  18988. this.bytes = (arrayBuffer instanceof Uint8Array ?
  18989. arrayBuffer : new Uint8Array(arrayBuffer));
  18990. this.start = start || 0;
  18991. this.pos = this.start;
  18992. this.end = (start + length) || this.bytes.length;
  18993. this.dict = dict;
  18994. }
  18995. // required methods for a stream. if a particular stream does not
  18996. // implement these, an error should be thrown
  18997. Stream.prototype = {
  18998. get length() {
  18999. return this.end - this.start;
  19000. },
  19001. get isEmpty() {
  19002. return this.length === 0;
  19003. },
  19004. getByte: function Stream_getByte() {
  19005. if (this.pos >= this.end) {
  19006. return -1;
  19007. }
  19008. return this.bytes[this.pos++];
  19009. },
  19010. getUint16: function Stream_getUint16() {
  19011. var b0 = this.getByte();
  19012. var b1 = this.getByte();
  19013. if (b0 === -1 || b1 === -1) {
  19014. return -1;
  19015. }
  19016. return (b0 << 8) + b1;
  19017. },
  19018. getInt32: function Stream_getInt32() {
  19019. var b0 = this.getByte();
  19020. var b1 = this.getByte();
  19021. var b2 = this.getByte();
  19022. var b3 = this.getByte();
  19023. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  19024. },
  19025. // returns subarray of original buffer
  19026. // should only be read
  19027. getBytes: function Stream_getBytes(length) {
  19028. var bytes = this.bytes;
  19029. var pos = this.pos;
  19030. var strEnd = this.end;
  19031. if (!length) {
  19032. return bytes.subarray(pos, strEnd);
  19033. }
  19034. var end = pos + length;
  19035. if (end > strEnd) {
  19036. end = strEnd;
  19037. }
  19038. this.pos = end;
  19039. return bytes.subarray(pos, end);
  19040. },
  19041. peekByte: function Stream_peekByte() {
  19042. var peekedByte = this.getByte();
  19043. this.pos--;
  19044. return peekedByte;
  19045. },
  19046. peekBytes: function Stream_peekBytes(length) {
  19047. var bytes = this.getBytes(length);
  19048. this.pos -= bytes.length;
  19049. return bytes;
  19050. },
  19051. skip: function Stream_skip(n) {
  19052. if (!n) {
  19053. n = 1;
  19054. }
  19055. this.pos += n;
  19056. },
  19057. reset: function Stream_reset() {
  19058. this.pos = this.start;
  19059. },
  19060. moveStart: function Stream_moveStart() {
  19061. this.start = this.pos;
  19062. },
  19063. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  19064. return new Stream(this.bytes.buffer, start, length, dict);
  19065. },
  19066. isStream: true
  19067. };
  19068. return Stream;
  19069. })();
  19070. var StringStream = (function StringStreamClosure() {
  19071. function StringStream(str) {
  19072. var length = str.length;
  19073. var bytes = new Uint8Array(length);
  19074. for (var n = 0; n < length; ++n) {
  19075. bytes[n] = str.charCodeAt(n);
  19076. }
  19077. Stream.call(this, bytes);
  19078. }
  19079. StringStream.prototype = Stream.prototype;
  19080. return StringStream;
  19081. })();
  19082. // super class for the decoding streams
  19083. var DecodeStream = (function DecodeStreamClosure() {
  19084. // Lots of DecodeStreams are created whose buffers are never used. For these
  19085. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  19086. // having special cases that would be required if we used |null| for an empty
  19087. // buffer.
  19088. var emptyBuffer = new Uint8Array(0);
  19089. function DecodeStream(maybeMinBufferLength) {
  19090. this.pos = 0;
  19091. this.bufferLength = 0;
  19092. this.eof = false;
  19093. this.buffer = emptyBuffer;
  19094. this.minBufferLength = 512;
  19095. if (maybeMinBufferLength) {
  19096. // Compute the first power of two that is as big as maybeMinBufferLength.
  19097. while (this.minBufferLength < maybeMinBufferLength) {
  19098. this.minBufferLength *= 2;
  19099. }
  19100. }
  19101. }
  19102. DecodeStream.prototype = {
  19103. get isEmpty() {
  19104. while (!this.eof && this.bufferLength === 0) {
  19105. this.readBlock();
  19106. }
  19107. return this.bufferLength === 0;
  19108. },
  19109. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  19110. var buffer = this.buffer;
  19111. if (requested <= buffer.byteLength) {
  19112. return buffer;
  19113. }
  19114. var size = this.minBufferLength;
  19115. while (size < requested) {
  19116. size *= 2;
  19117. }
  19118. var buffer2 = new Uint8Array(size);
  19119. buffer2.set(buffer);
  19120. return (this.buffer = buffer2);
  19121. },
  19122. getByte: function DecodeStream_getByte() {
  19123. var pos = this.pos;
  19124. while (this.bufferLength <= pos) {
  19125. if (this.eof) {
  19126. return -1;
  19127. }
  19128. this.readBlock();
  19129. }
  19130. return this.buffer[this.pos++];
  19131. },
  19132. getUint16: function DecodeStream_getUint16() {
  19133. var b0 = this.getByte();
  19134. var b1 = this.getByte();
  19135. if (b0 === -1 || b1 === -1) {
  19136. return -1;
  19137. }
  19138. return (b0 << 8) + b1;
  19139. },
  19140. getInt32: function DecodeStream_getInt32() {
  19141. var b0 = this.getByte();
  19142. var b1 = this.getByte();
  19143. var b2 = this.getByte();
  19144. var b3 = this.getByte();
  19145. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  19146. },
  19147. getBytes: function DecodeStream_getBytes(length) {
  19148. var end, pos = this.pos;
  19149. if (length) {
  19150. this.ensureBuffer(pos + length);
  19151. end = pos + length;
  19152. while (!this.eof && this.bufferLength < end) {
  19153. this.readBlock();
  19154. }
  19155. var bufEnd = this.bufferLength;
  19156. if (end > bufEnd) {
  19157. end = bufEnd;
  19158. }
  19159. } else {
  19160. while (!this.eof) {
  19161. this.readBlock();
  19162. }
  19163. end = this.bufferLength;
  19164. }
  19165. this.pos = end;
  19166. return this.buffer.subarray(pos, end);
  19167. },
  19168. peekByte: function DecodeStream_peekByte() {
  19169. var peekedByte = this.getByte();
  19170. this.pos--;
  19171. return peekedByte;
  19172. },
  19173. peekBytes: function DecodeStream_peekBytes(length) {
  19174. var bytes = this.getBytes(length);
  19175. this.pos -= bytes.length;
  19176. return bytes;
  19177. },
  19178. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  19179. var end = start + length;
  19180. while (this.bufferLength <= end && !this.eof) {
  19181. this.readBlock();
  19182. }
  19183. return new Stream(this.buffer, start, length, dict);
  19184. },
  19185. skip: function DecodeStream_skip(n) {
  19186. if (!n) {
  19187. n = 1;
  19188. }
  19189. this.pos += n;
  19190. },
  19191. reset: function DecodeStream_reset() {
  19192. this.pos = 0;
  19193. },
  19194. getBaseStreams: function DecodeStream_getBaseStreams() {
  19195. if (this.str && this.str.getBaseStreams) {
  19196. return this.str.getBaseStreams();
  19197. }
  19198. return [];
  19199. }
  19200. };
  19201. return DecodeStream;
  19202. })();
  19203. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  19204. function StreamsSequenceStream(streams) {
  19205. this.streams = streams;
  19206. DecodeStream.call(this, /* maybeLength = */ null);
  19207. }
  19208. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  19209. StreamsSequenceStream.prototype.readBlock =
  19210. function streamSequenceStreamReadBlock() {
  19211. var streams = this.streams;
  19212. if (streams.length === 0) {
  19213. this.eof = true;
  19214. return;
  19215. }
  19216. var stream = streams.shift();
  19217. var chunk = stream.getBytes();
  19218. var bufferLength = this.bufferLength;
  19219. var newLength = bufferLength + chunk.length;
  19220. var buffer = this.ensureBuffer(newLength);
  19221. buffer.set(chunk, bufferLength);
  19222. this.bufferLength = newLength;
  19223. };
  19224. StreamsSequenceStream.prototype.getBaseStreams =
  19225. function StreamsSequenceStream_getBaseStreams() {
  19226. var baseStreams = [];
  19227. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  19228. var stream = this.streams[i];
  19229. if (stream.getBaseStreams) {
  19230. Util.appendToArray(baseStreams, stream.getBaseStreams());
  19231. }
  19232. }
  19233. return baseStreams;
  19234. };
  19235. return StreamsSequenceStream;
  19236. })();
  19237. var FlateStream = (function FlateStreamClosure() {
  19238. var codeLenCodeMap = new Int32Array([
  19239. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  19240. ]);
  19241. var lengthDecode = new Int32Array([
  19242. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  19243. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  19244. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  19245. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  19246. ]);
  19247. var distDecode = new Int32Array([
  19248. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  19249. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  19250. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  19251. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  19252. ]);
  19253. var fixedLitCodeTab = [new Int32Array([
  19254. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  19255. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  19256. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  19257. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  19258. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  19259. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  19260. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  19261. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  19262. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  19263. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  19264. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  19265. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  19266. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  19267. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  19268. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  19269. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  19270. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  19271. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  19272. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  19273. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  19274. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  19275. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  19276. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  19277. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  19278. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  19279. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  19280. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  19281. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  19282. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  19283. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  19284. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  19285. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  19286. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  19287. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  19288. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  19289. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  19290. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  19291. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  19292. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  19293. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  19294. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  19295. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  19296. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  19297. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  19298. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  19299. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  19300. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  19301. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  19302. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  19303. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  19304. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  19305. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  19306. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  19307. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  19308. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  19309. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  19310. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  19311. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  19312. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  19313. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  19314. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  19315. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  19316. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  19317. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  19318. ]), 9];
  19319. var fixedDistCodeTab = [new Int32Array([
  19320. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  19321. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  19322. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  19323. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  19324. ]), 5];
  19325. function FlateStream(str, maybeLength) {
  19326. this.str = str;
  19327. this.dict = str.dict;
  19328. var cmf = str.getByte();
  19329. var flg = str.getByte();
  19330. if (cmf === -1 || flg === -1) {
  19331. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  19332. }
  19333. if ((cmf & 0x0f) !== 0x08) {
  19334. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  19335. }
  19336. if ((((cmf << 8) + flg) % 31) !== 0) {
  19337. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  19338. }
  19339. if (flg & 0x20) {
  19340. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  19341. }
  19342. this.codeSize = 0;
  19343. this.codeBuf = 0;
  19344. DecodeStream.call(this, maybeLength);
  19345. }
  19346. FlateStream.prototype = Object.create(DecodeStream.prototype);
  19347. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  19348. var str = this.str;
  19349. var codeSize = this.codeSize;
  19350. var codeBuf = this.codeBuf;
  19351. var b;
  19352. while (codeSize < bits) {
  19353. if ((b = str.getByte()) === -1) {
  19354. error('Bad encoding in flate stream');
  19355. }
  19356. codeBuf |= b << codeSize;
  19357. codeSize += 8;
  19358. }
  19359. b = codeBuf & ((1 << bits) - 1);
  19360. this.codeBuf = codeBuf >> bits;
  19361. this.codeSize = codeSize -= bits;
  19362. return b;
  19363. };
  19364. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  19365. var str = this.str;
  19366. var codes = table[0];
  19367. var maxLen = table[1];
  19368. var codeSize = this.codeSize;
  19369. var codeBuf = this.codeBuf;
  19370. var b;
  19371. while (codeSize < maxLen) {
  19372. if ((b = str.getByte()) === -1) {
  19373. // premature end of stream. code might however still be valid.
  19374. // codeSize < codeLen check below guards against incomplete codeVal.
  19375. break;
  19376. }
  19377. codeBuf |= (b << codeSize);
  19378. codeSize += 8;
  19379. }
  19380. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  19381. var codeLen = code >> 16;
  19382. var codeVal = code & 0xffff;
  19383. if (codeLen < 1 || codeSize < codeLen) {
  19384. error('Bad encoding in flate stream');
  19385. }
  19386. this.codeBuf = (codeBuf >> codeLen);
  19387. this.codeSize = (codeSize - codeLen);
  19388. return codeVal;
  19389. };
  19390. FlateStream.prototype.generateHuffmanTable =
  19391. function flateStreamGenerateHuffmanTable(lengths) {
  19392. var n = lengths.length;
  19393. // find max code length
  19394. var maxLen = 0;
  19395. var i;
  19396. for (i = 0; i < n; ++i) {
  19397. if (lengths[i] > maxLen) {
  19398. maxLen = lengths[i];
  19399. }
  19400. }
  19401. // build the table
  19402. var size = 1 << maxLen;
  19403. var codes = new Int32Array(size);
  19404. for (var len = 1, code = 0, skip = 2;
  19405. len <= maxLen;
  19406. ++len, code <<= 1, skip <<= 1) {
  19407. for (var val = 0; val < n; ++val) {
  19408. if (lengths[val] === len) {
  19409. // bit-reverse the code
  19410. var code2 = 0;
  19411. var t = code;
  19412. for (i = 0; i < len; ++i) {
  19413. code2 = (code2 << 1) | (t & 1);
  19414. t >>= 1;
  19415. }
  19416. // fill the table entries
  19417. for (i = code2; i < size; i += skip) {
  19418. codes[i] = (len << 16) | val;
  19419. }
  19420. ++code;
  19421. }
  19422. }
  19423. }
  19424. return [codes, maxLen];
  19425. };
  19426. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  19427. var buffer, len;
  19428. var str = this.str;
  19429. // read block header
  19430. var hdr = this.getBits(3);
  19431. if (hdr & 1) {
  19432. this.eof = true;
  19433. }
  19434. hdr >>= 1;
  19435. if (hdr === 0) { // uncompressed block
  19436. var b;
  19437. if ((b = str.getByte()) === -1) {
  19438. error('Bad block header in flate stream');
  19439. }
  19440. var blockLen = b;
  19441. if ((b = str.getByte()) === -1) {
  19442. error('Bad block header in flate stream');
  19443. }
  19444. blockLen |= (b << 8);
  19445. if ((b = str.getByte()) === -1) {
  19446. error('Bad block header in flate stream');
  19447. }
  19448. var check = b;
  19449. if ((b = str.getByte()) === -1) {
  19450. error('Bad block header in flate stream');
  19451. }
  19452. check |= (b << 8);
  19453. if (check !== (~blockLen & 0xffff) &&
  19454. (blockLen !== 0 || check !== 0)) {
  19455. // Ignoring error for bad "empty" block (see issue 1277)
  19456. error('Bad uncompressed block length in flate stream');
  19457. }
  19458. this.codeBuf = 0;
  19459. this.codeSize = 0;
  19460. var bufferLength = this.bufferLength;
  19461. buffer = this.ensureBuffer(bufferLength + blockLen);
  19462. var end = bufferLength + blockLen;
  19463. this.bufferLength = end;
  19464. if (blockLen === 0) {
  19465. if (str.peekByte() === -1) {
  19466. this.eof = true;
  19467. }
  19468. } else {
  19469. for (var n = bufferLength; n < end; ++n) {
  19470. if ((b = str.getByte()) === -1) {
  19471. this.eof = true;
  19472. break;
  19473. }
  19474. buffer[n] = b;
  19475. }
  19476. }
  19477. return;
  19478. }
  19479. var litCodeTable;
  19480. var distCodeTable;
  19481. if (hdr === 1) { // compressed block, fixed codes
  19482. litCodeTable = fixedLitCodeTab;
  19483. distCodeTable = fixedDistCodeTab;
  19484. } else if (hdr === 2) { // compressed block, dynamic codes
  19485. var numLitCodes = this.getBits(5) + 257;
  19486. var numDistCodes = this.getBits(5) + 1;
  19487. var numCodeLenCodes = this.getBits(4) + 4;
  19488. // build the code lengths code table
  19489. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  19490. var i;
  19491. for (i = 0; i < numCodeLenCodes; ++i) {
  19492. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  19493. }
  19494. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  19495. // build the literal and distance code tables
  19496. len = 0;
  19497. i = 0;
  19498. var codes = numLitCodes + numDistCodes;
  19499. var codeLengths = new Uint8Array(codes);
  19500. var bitsLength, bitsOffset, what;
  19501. while (i < codes) {
  19502. var code = this.getCode(codeLenCodeTab);
  19503. if (code === 16) {
  19504. bitsLength = 2; bitsOffset = 3; what = len;
  19505. } else if (code === 17) {
  19506. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  19507. } else if (code === 18) {
  19508. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  19509. } else {
  19510. codeLengths[i++] = len = code;
  19511. continue;
  19512. }
  19513. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  19514. while (repeatLength-- > 0) {
  19515. codeLengths[i++] = what;
  19516. }
  19517. }
  19518. litCodeTable =
  19519. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  19520. distCodeTable =
  19521. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  19522. } else {
  19523. error('Unknown block type in flate stream');
  19524. }
  19525. buffer = this.buffer;
  19526. var limit = buffer ? buffer.length : 0;
  19527. var pos = this.bufferLength;
  19528. while (true) {
  19529. var code1 = this.getCode(litCodeTable);
  19530. if (code1 < 256) {
  19531. if (pos + 1 >= limit) {
  19532. buffer = this.ensureBuffer(pos + 1);
  19533. limit = buffer.length;
  19534. }
  19535. buffer[pos++] = code1;
  19536. continue;
  19537. }
  19538. if (code1 === 256) {
  19539. this.bufferLength = pos;
  19540. return;
  19541. }
  19542. code1 -= 257;
  19543. code1 = lengthDecode[code1];
  19544. var code2 = code1 >> 16;
  19545. if (code2 > 0) {
  19546. code2 = this.getBits(code2);
  19547. }
  19548. len = (code1 & 0xffff) + code2;
  19549. code1 = this.getCode(distCodeTable);
  19550. code1 = distDecode[code1];
  19551. code2 = code1 >> 16;
  19552. if (code2 > 0) {
  19553. code2 = this.getBits(code2);
  19554. }
  19555. var dist = (code1 & 0xffff) + code2;
  19556. if (pos + len >= limit) {
  19557. buffer = this.ensureBuffer(pos + len);
  19558. limit = buffer.length;
  19559. }
  19560. for (var k = 0; k < len; ++k, ++pos) {
  19561. buffer[pos] = buffer[pos - dist];
  19562. }
  19563. }
  19564. };
  19565. return FlateStream;
  19566. })();
  19567. var PredictorStream = (function PredictorStreamClosure() {
  19568. function PredictorStream(str, maybeLength, params) {
  19569. if (!isDict(params)) {
  19570. return str; // no prediction
  19571. }
  19572. var predictor = this.predictor = params.get('Predictor') || 1;
  19573. if (predictor <= 1) {
  19574. return str; // no prediction
  19575. }
  19576. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  19577. error('Unsupported predictor: ' + predictor);
  19578. }
  19579. if (predictor === 2) {
  19580. this.readBlock = this.readBlockTiff;
  19581. } else {
  19582. this.readBlock = this.readBlockPng;
  19583. }
  19584. this.str = str;
  19585. this.dict = str.dict;
  19586. var colors = this.colors = params.get('Colors') || 1;
  19587. var bits = this.bits = params.get('BitsPerComponent') || 8;
  19588. var columns = this.columns = params.get('Columns') || 1;
  19589. this.pixBytes = (colors * bits + 7) >> 3;
  19590. this.rowBytes = (columns * colors * bits + 7) >> 3;
  19591. DecodeStream.call(this, maybeLength);
  19592. return this;
  19593. }
  19594. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  19595. PredictorStream.prototype.readBlockTiff =
  19596. function predictorStreamReadBlockTiff() {
  19597. var rowBytes = this.rowBytes;
  19598. var bufferLength = this.bufferLength;
  19599. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  19600. var bits = this.bits;
  19601. var colors = this.colors;
  19602. var rawBytes = this.str.getBytes(rowBytes);
  19603. this.eof = !rawBytes.length;
  19604. if (this.eof) {
  19605. return;
  19606. }
  19607. var inbuf = 0, outbuf = 0;
  19608. var inbits = 0, outbits = 0;
  19609. var pos = bufferLength;
  19610. var i;
  19611. if (bits === 1) {
  19612. for (i = 0; i < rowBytes; ++i) {
  19613. var c = rawBytes[i];
  19614. inbuf = (inbuf << 8) | c;
  19615. // bitwise addition is exclusive or
  19616. // first shift inbuf and then add
  19617. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  19618. // truncate inbuf (assumes colors < 16)
  19619. inbuf &= 0xFFFF;
  19620. }
  19621. } else if (bits === 8) {
  19622. for (i = 0; i < colors; ++i) {
  19623. buffer[pos++] = rawBytes[i];
  19624. }
  19625. for (; i < rowBytes; ++i) {
  19626. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  19627. pos++;
  19628. }
  19629. } else {
  19630. var compArray = new Uint8Array(colors + 1);
  19631. var bitMask = (1 << bits) - 1;
  19632. var j = 0, k = bufferLength;
  19633. var columns = this.columns;
  19634. for (i = 0; i < columns; ++i) {
  19635. for (var kk = 0; kk < colors; ++kk) {
  19636. if (inbits < bits) {
  19637. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  19638. inbits += 8;
  19639. }
  19640. compArray[kk] = (compArray[kk] +
  19641. (inbuf >> (inbits - bits))) & bitMask;
  19642. inbits -= bits;
  19643. outbuf = (outbuf << bits) | compArray[kk];
  19644. outbits += bits;
  19645. if (outbits >= 8) {
  19646. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  19647. outbits -= 8;
  19648. }
  19649. }
  19650. }
  19651. if (outbits > 0) {
  19652. buffer[k++] = (outbuf << (8 - outbits)) +
  19653. (inbuf & ((1 << (8 - outbits)) - 1));
  19654. }
  19655. }
  19656. this.bufferLength += rowBytes;
  19657. };
  19658. PredictorStream.prototype.readBlockPng =
  19659. function predictorStreamReadBlockPng() {
  19660. var rowBytes = this.rowBytes;
  19661. var pixBytes = this.pixBytes;
  19662. var predictor = this.str.getByte();
  19663. var rawBytes = this.str.getBytes(rowBytes);
  19664. this.eof = !rawBytes.length;
  19665. if (this.eof) {
  19666. return;
  19667. }
  19668. var bufferLength = this.bufferLength;
  19669. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  19670. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  19671. if (prevRow.length === 0) {
  19672. prevRow = new Uint8Array(rowBytes);
  19673. }
  19674. var i, j = bufferLength, up, c;
  19675. switch (predictor) {
  19676. case 0:
  19677. for (i = 0; i < rowBytes; ++i) {
  19678. buffer[j++] = rawBytes[i];
  19679. }
  19680. break;
  19681. case 1:
  19682. for (i = 0; i < pixBytes; ++i) {
  19683. buffer[j++] = rawBytes[i];
  19684. }
  19685. for (; i < rowBytes; ++i) {
  19686. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  19687. j++;
  19688. }
  19689. break;
  19690. case 2:
  19691. for (i = 0; i < rowBytes; ++i) {
  19692. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  19693. }
  19694. break;
  19695. case 3:
  19696. for (i = 0; i < pixBytes; ++i) {
  19697. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  19698. }
  19699. for (; i < rowBytes; ++i) {
  19700. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  19701. rawBytes[i]) & 0xFF;
  19702. j++;
  19703. }
  19704. break;
  19705. case 4:
  19706. // we need to save the up left pixels values. the simplest way
  19707. // is to create a new buffer
  19708. for (i = 0; i < pixBytes; ++i) {
  19709. up = prevRow[i];
  19710. c = rawBytes[i];
  19711. buffer[j++] = up + c;
  19712. }
  19713. for (; i < rowBytes; ++i) {
  19714. up = prevRow[i];
  19715. var upLeft = prevRow[i - pixBytes];
  19716. var left = buffer[j - pixBytes];
  19717. var p = left + up - upLeft;
  19718. var pa = p - left;
  19719. if (pa < 0) {
  19720. pa = -pa;
  19721. }
  19722. var pb = p - up;
  19723. if (pb < 0) {
  19724. pb = -pb;
  19725. }
  19726. var pc = p - upLeft;
  19727. if (pc < 0) {
  19728. pc = -pc;
  19729. }
  19730. c = rawBytes[i];
  19731. if (pa <= pb && pa <= pc) {
  19732. buffer[j++] = left + c;
  19733. } else if (pb <= pc) {
  19734. buffer[j++] = up + c;
  19735. } else {
  19736. buffer[j++] = upLeft + c;
  19737. }
  19738. }
  19739. break;
  19740. default:
  19741. error('Unsupported predictor: ' + predictor);
  19742. }
  19743. this.bufferLength += rowBytes;
  19744. };
  19745. return PredictorStream;
  19746. })();
  19747. /**
  19748. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  19749. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  19750. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  19751. * a library to decode these images and the stream behaves like all the other
  19752. * DecodeStreams.
  19753. */
  19754. var JpegStream = (function JpegStreamClosure() {
  19755. function JpegStream(stream, maybeLength, dict) {
  19756. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  19757. // Note: this seems to mainly affect inline images.
  19758. var ch;
  19759. while ((ch = stream.getByte()) !== -1) {
  19760. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  19761. stream.skip(-1); // Reset the stream position to the SOI.
  19762. break;
  19763. }
  19764. }
  19765. this.stream = stream;
  19766. this.maybeLength = maybeLength;
  19767. this.dict = dict;
  19768. DecodeStream.call(this, maybeLength);
  19769. }
  19770. JpegStream.prototype = Object.create(DecodeStream.prototype);
  19771. Object.defineProperty(JpegStream.prototype, 'bytes', {
  19772. get: function JpegStream_bytes() {
  19773. // If this.maybeLength is null, we'll get the entire stream.
  19774. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  19775. },
  19776. configurable: true
  19777. });
  19778. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  19779. if (this.bufferLength) {
  19780. return;
  19781. }
  19782. var jpegImage = new JpegImage();
  19783. // Checking if values need to be transformed before conversion.
  19784. var decodeArr = this.dict.getArray('Decode', 'D');
  19785. if (this.forceRGB && isArray(decodeArr)) {
  19786. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  19787. var decodeArrLength = decodeArr.length;
  19788. var transform = new Int32Array(decodeArrLength);
  19789. var transformNeeded = false;
  19790. var maxValue = (1 << bitsPerComponent) - 1;
  19791. for (var i = 0; i < decodeArrLength; i += 2) {
  19792. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  19793. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  19794. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  19795. transformNeeded = true;
  19796. }
  19797. }
  19798. if (transformNeeded) {
  19799. jpegImage.decodeTransform = transform;
  19800. }
  19801. }
  19802. // Fetching the 'ColorTransform' entry, if it exists.
  19803. var decodeParams = this.dict.get('DecodeParms', 'DP');
  19804. if (isDict(decodeParams)) {
  19805. var colorTransform = decodeParams.get('ColorTransform');
  19806. if (isInt(colorTransform)) {
  19807. jpegImage.colorTransform = colorTransform;
  19808. }
  19809. }
  19810. jpegImage.parse(this.bytes);
  19811. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  19812. this.forceRGB);
  19813. this.buffer = data;
  19814. this.bufferLength = data.length;
  19815. this.eof = true;
  19816. };
  19817. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  19818. this.ensureBuffer();
  19819. return this.buffer;
  19820. };
  19821. JpegStream.prototype.getIR = function JpegStream_getIR(forceDataSchema) {
  19822. return createObjectURL(this.bytes, 'image/jpeg', forceDataSchema);
  19823. };
  19824. return JpegStream;
  19825. })();
  19826. /**
  19827. * For JPEG 2000's we use a library to decode these images and
  19828. * the stream behaves like all the other DecodeStreams.
  19829. */
  19830. var JpxStream = (function JpxStreamClosure() {
  19831. function JpxStream(stream, maybeLength, dict) {
  19832. this.stream = stream;
  19833. this.maybeLength = maybeLength;
  19834. this.dict = dict;
  19835. DecodeStream.call(this, maybeLength);
  19836. }
  19837. JpxStream.prototype = Object.create(DecodeStream.prototype);
  19838. Object.defineProperty(JpxStream.prototype, 'bytes', {
  19839. get: function JpxStream_bytes() {
  19840. // If this.maybeLength is null, we'll get the entire stream.
  19841. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  19842. },
  19843. configurable: true
  19844. });
  19845. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  19846. if (this.bufferLength) {
  19847. return;
  19848. }
  19849. var jpxImage = new JpxImage();
  19850. jpxImage.parse(this.bytes);
  19851. var width = jpxImage.width;
  19852. var height = jpxImage.height;
  19853. var componentsCount = jpxImage.componentsCount;
  19854. var tileCount = jpxImage.tiles.length;
  19855. if (tileCount === 1) {
  19856. this.buffer = jpxImage.tiles[0].items;
  19857. } else {
  19858. var data = new Uint8Array(width * height * componentsCount);
  19859. for (var k = 0; k < tileCount; k++) {
  19860. var tileComponents = jpxImage.tiles[k];
  19861. var tileWidth = tileComponents.width;
  19862. var tileHeight = tileComponents.height;
  19863. var tileLeft = tileComponents.left;
  19864. var tileTop = tileComponents.top;
  19865. var src = tileComponents.items;
  19866. var srcPosition = 0;
  19867. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  19868. var imgRowSize = width * componentsCount;
  19869. var tileRowSize = tileWidth * componentsCount;
  19870. for (var j = 0; j < tileHeight; j++) {
  19871. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  19872. data.set(rowBytes, dataPosition);
  19873. srcPosition += tileRowSize;
  19874. dataPosition += imgRowSize;
  19875. }
  19876. }
  19877. this.buffer = data;
  19878. }
  19879. this.bufferLength = this.buffer.length;
  19880. this.eof = true;
  19881. };
  19882. return JpxStream;
  19883. })();
  19884. /**
  19885. * For JBIG2's we use a library to decode these images and
  19886. * the stream behaves like all the other DecodeStreams.
  19887. */
  19888. var Jbig2Stream = (function Jbig2StreamClosure() {
  19889. function Jbig2Stream(stream, maybeLength, dict) {
  19890. this.stream = stream;
  19891. this.maybeLength = maybeLength;
  19892. this.dict = dict;
  19893. DecodeStream.call(this, maybeLength);
  19894. }
  19895. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  19896. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  19897. get: function Jbig2Stream_bytes() {
  19898. // If this.maybeLength is null, we'll get the entire stream.
  19899. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  19900. },
  19901. configurable: true
  19902. });
  19903. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  19904. if (this.bufferLength) {
  19905. return;
  19906. }
  19907. var jbig2Image = new Jbig2Image();
  19908. var chunks = [];
  19909. var decodeParams = this.dict.getArray('DecodeParms', 'DP');
  19910. // According to the PDF specification, DecodeParms can be either
  19911. // a dictionary, or an array whose elements are dictionaries.
  19912. if (isArray(decodeParams)) {
  19913. if (decodeParams.length > 1) {
  19914. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  19915. 'not supported.');
  19916. }
  19917. decodeParams = decodeParams[0];
  19918. }
  19919. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  19920. var globalsStream = decodeParams.get('JBIG2Globals');
  19921. var globals = globalsStream.getBytes();
  19922. chunks.push({data: globals, start: 0, end: globals.length});
  19923. }
  19924. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  19925. var data = jbig2Image.parseChunks(chunks);
  19926. var dataLength = data.length;
  19927. // JBIG2 had black as 1 and white as 0, inverting the colors
  19928. for (var i = 0; i < dataLength; i++) {
  19929. data[i] ^= 0xFF;
  19930. }
  19931. this.buffer = data;
  19932. this.bufferLength = dataLength;
  19933. this.eof = true;
  19934. };
  19935. return Jbig2Stream;
  19936. })();
  19937. var DecryptStream = (function DecryptStreamClosure() {
  19938. function DecryptStream(str, maybeLength, decrypt) {
  19939. this.str = str;
  19940. this.dict = str.dict;
  19941. this.decrypt = decrypt;
  19942. this.nextChunk = null;
  19943. this.initialized = false;
  19944. DecodeStream.call(this, maybeLength);
  19945. }
  19946. var chunkSize = 512;
  19947. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  19948. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  19949. var chunk;
  19950. if (this.initialized) {
  19951. chunk = this.nextChunk;
  19952. } else {
  19953. chunk = this.str.getBytes(chunkSize);
  19954. this.initialized = true;
  19955. }
  19956. if (!chunk || chunk.length === 0) {
  19957. this.eof = true;
  19958. return;
  19959. }
  19960. this.nextChunk = this.str.getBytes(chunkSize);
  19961. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  19962. var decrypt = this.decrypt;
  19963. chunk = decrypt(chunk, !hasMoreData);
  19964. var bufferLength = this.bufferLength;
  19965. var i, n = chunk.length;
  19966. var buffer = this.ensureBuffer(bufferLength + n);
  19967. for (i = 0; i < n; i++) {
  19968. buffer[bufferLength++] = chunk[i];
  19969. }
  19970. this.bufferLength = bufferLength;
  19971. };
  19972. return DecryptStream;
  19973. })();
  19974. var Ascii85Stream = (function Ascii85StreamClosure() {
  19975. function Ascii85Stream(str, maybeLength) {
  19976. this.str = str;
  19977. this.dict = str.dict;
  19978. this.input = new Uint8Array(5);
  19979. // Most streams increase in size when decoded, but Ascii85 streams
  19980. // typically shrink by ~20%.
  19981. if (maybeLength) {
  19982. maybeLength = 0.8 * maybeLength;
  19983. }
  19984. DecodeStream.call(this, maybeLength);
  19985. }
  19986. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  19987. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  19988. var TILDA_CHAR = 0x7E; // '~'
  19989. var Z_LOWER_CHAR = 0x7A; // 'z'
  19990. var EOF = -1;
  19991. var str = this.str;
  19992. var c = str.getByte();
  19993. while (isSpace(c)) {
  19994. c = str.getByte();
  19995. }
  19996. if (c === EOF || c === TILDA_CHAR) {
  19997. this.eof = true;
  19998. return;
  19999. }
  20000. var bufferLength = this.bufferLength, buffer;
  20001. var i;
  20002. // special code for z
  20003. if (c === Z_LOWER_CHAR) {
  20004. buffer = this.ensureBuffer(bufferLength + 4);
  20005. for (i = 0; i < 4; ++i) {
  20006. buffer[bufferLength + i] = 0;
  20007. }
  20008. this.bufferLength += 4;
  20009. } else {
  20010. var input = this.input;
  20011. input[0] = c;
  20012. for (i = 1; i < 5; ++i) {
  20013. c = str.getByte();
  20014. while (isSpace(c)) {
  20015. c = str.getByte();
  20016. }
  20017. input[i] = c;
  20018. if (c === EOF || c === TILDA_CHAR) {
  20019. break;
  20020. }
  20021. }
  20022. buffer = this.ensureBuffer(bufferLength + i - 1);
  20023. this.bufferLength += i - 1;
  20024. // partial ending;
  20025. if (i < 5) {
  20026. for (; i < 5; ++i) {
  20027. input[i] = 0x21 + 84;
  20028. }
  20029. this.eof = true;
  20030. }
  20031. var t = 0;
  20032. for (i = 0; i < 5; ++i) {
  20033. t = t * 85 + (input[i] - 0x21);
  20034. }
  20035. for (i = 3; i >= 0; --i) {
  20036. buffer[bufferLength + i] = t & 0xFF;
  20037. t >>= 8;
  20038. }
  20039. }
  20040. };
  20041. return Ascii85Stream;
  20042. })();
  20043. var AsciiHexStream = (function AsciiHexStreamClosure() {
  20044. function AsciiHexStream(str, maybeLength) {
  20045. this.str = str;
  20046. this.dict = str.dict;
  20047. this.firstDigit = -1;
  20048. // Most streams increase in size when decoded, but AsciiHex streams shrink
  20049. // by 50%.
  20050. if (maybeLength) {
  20051. maybeLength = 0.5 * maybeLength;
  20052. }
  20053. DecodeStream.call(this, maybeLength);
  20054. }
  20055. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  20056. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  20057. var UPSTREAM_BLOCK_SIZE = 8000;
  20058. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  20059. if (!bytes.length) {
  20060. this.eof = true;
  20061. return;
  20062. }
  20063. var maxDecodeLength = (bytes.length + 1) >> 1;
  20064. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  20065. var bufferLength = this.bufferLength;
  20066. var firstDigit = this.firstDigit;
  20067. for (var i = 0, ii = bytes.length; i < ii; i++) {
  20068. var ch = bytes[i], digit;
  20069. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  20070. digit = ch & 0x0F;
  20071. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  20072. // 'A'-'Z', 'a'-'z'
  20073. digit = (ch & 0x0F) + 9;
  20074. } else if (ch === 0x3E) { // '>'
  20075. this.eof = true;
  20076. break;
  20077. } else { // probably whitespace
  20078. continue; // ignoring
  20079. }
  20080. if (firstDigit < 0) {
  20081. firstDigit = digit;
  20082. } else {
  20083. buffer[bufferLength++] = (firstDigit << 4) | digit;
  20084. firstDigit = -1;
  20085. }
  20086. }
  20087. if (firstDigit >= 0 && this.eof) {
  20088. // incomplete byte
  20089. buffer[bufferLength++] = (firstDigit << 4);
  20090. firstDigit = -1;
  20091. }
  20092. this.firstDigit = firstDigit;
  20093. this.bufferLength = bufferLength;
  20094. };
  20095. return AsciiHexStream;
  20096. })();
  20097. var RunLengthStream = (function RunLengthStreamClosure() {
  20098. function RunLengthStream(str, maybeLength) {
  20099. this.str = str;
  20100. this.dict = str.dict;
  20101. DecodeStream.call(this, maybeLength);
  20102. }
  20103. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  20104. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  20105. // The repeatHeader has following format. The first byte defines type of run
  20106. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  20107. // (in addition to the second byte from the header), n = 129 through 255 -
  20108. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  20109. var repeatHeader = this.str.getBytes(2);
  20110. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  20111. this.eof = true;
  20112. return;
  20113. }
  20114. var buffer;
  20115. var bufferLength = this.bufferLength;
  20116. var n = repeatHeader[0];
  20117. if (n < 128) {
  20118. // copy n bytes
  20119. buffer = this.ensureBuffer(bufferLength + n + 1);
  20120. buffer[bufferLength++] = repeatHeader[1];
  20121. if (n > 0) {
  20122. var source = this.str.getBytes(n);
  20123. buffer.set(source, bufferLength);
  20124. bufferLength += n;
  20125. }
  20126. } else {
  20127. n = 257 - n;
  20128. var b = repeatHeader[1];
  20129. buffer = this.ensureBuffer(bufferLength + n + 1);
  20130. for (var i = 0; i < n; i++) {
  20131. buffer[bufferLength++] = b;
  20132. }
  20133. }
  20134. this.bufferLength = bufferLength;
  20135. };
  20136. return RunLengthStream;
  20137. })();
  20138. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  20139. var ccittEOL = -2;
  20140. var ccittEOF = -1;
  20141. var twoDimPass = 0;
  20142. var twoDimHoriz = 1;
  20143. var twoDimVert0 = 2;
  20144. var twoDimVertR1 = 3;
  20145. var twoDimVertL1 = 4;
  20146. var twoDimVertR2 = 5;
  20147. var twoDimVertL2 = 6;
  20148. var twoDimVertR3 = 7;
  20149. var twoDimVertL3 = 8;
  20150. var twoDimTable = [
  20151. [-1, -1], [-1, -1], // 000000x
  20152. [7, twoDimVertL3], // 0000010
  20153. [7, twoDimVertR3], // 0000011
  20154. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  20155. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  20156. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  20157. [4, twoDimPass], [4, twoDimPass],
  20158. [4, twoDimPass], [4, twoDimPass],
  20159. [4, twoDimPass], [4, twoDimPass],
  20160. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  20161. [3, twoDimHoriz], [3, twoDimHoriz],
  20162. [3, twoDimHoriz], [3, twoDimHoriz],
  20163. [3, twoDimHoriz], [3, twoDimHoriz],
  20164. [3, twoDimHoriz], [3, twoDimHoriz],
  20165. [3, twoDimHoriz], [3, twoDimHoriz],
  20166. [3, twoDimHoriz], [3, twoDimHoriz],
  20167. [3, twoDimHoriz], [3, twoDimHoriz],
  20168. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  20169. [3, twoDimVertL1], [3, twoDimVertL1],
  20170. [3, twoDimVertL1], [3, twoDimVertL1],
  20171. [3, twoDimVertL1], [3, twoDimVertL1],
  20172. [3, twoDimVertL1], [3, twoDimVertL1],
  20173. [3, twoDimVertL1], [3, twoDimVertL1],
  20174. [3, twoDimVertL1], [3, twoDimVertL1],
  20175. [3, twoDimVertL1], [3, twoDimVertL1],
  20176. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  20177. [3, twoDimVertR1], [3, twoDimVertR1],
  20178. [3, twoDimVertR1], [3, twoDimVertR1],
  20179. [3, twoDimVertR1], [3, twoDimVertR1],
  20180. [3, twoDimVertR1], [3, twoDimVertR1],
  20181. [3, twoDimVertR1], [3, twoDimVertR1],
  20182. [3, twoDimVertR1], [3, twoDimVertR1],
  20183. [3, twoDimVertR1], [3, twoDimVertR1],
  20184. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  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. [1, twoDimVert0], [1, twoDimVert0],
  20194. [1, twoDimVert0], [1, twoDimVert0],
  20195. [1, twoDimVert0], [1, twoDimVert0],
  20196. [1, twoDimVert0], [1, twoDimVert0],
  20197. [1, twoDimVert0], [1, twoDimVert0],
  20198. [1, twoDimVert0], [1, twoDimVert0],
  20199. [1, twoDimVert0], [1, twoDimVert0],
  20200. [1, twoDimVert0], [1, twoDimVert0],
  20201. [1, twoDimVert0], [1, twoDimVert0],
  20202. [1, twoDimVert0], [1, twoDimVert0],
  20203. [1, twoDimVert0], [1, twoDimVert0],
  20204. [1, twoDimVert0], [1, twoDimVert0],
  20205. [1, twoDimVert0], [1, twoDimVert0],
  20206. [1, twoDimVert0], [1, twoDimVert0],
  20207. [1, twoDimVert0], [1, twoDimVert0],
  20208. [1, twoDimVert0], [1, twoDimVert0],
  20209. [1, twoDimVert0], [1, twoDimVert0],
  20210. [1, twoDimVert0], [1, twoDimVert0],
  20211. [1, twoDimVert0], [1, twoDimVert0],
  20212. [1, twoDimVert0], [1, twoDimVert0],
  20213. [1, twoDimVert0], [1, twoDimVert0],
  20214. [1, twoDimVert0], [1, twoDimVert0],
  20215. [1, twoDimVert0], [1, twoDimVert0]
  20216. ];
  20217. var whiteTable1 = [
  20218. [-1, -1], // 00000
  20219. [12, ccittEOL], // 00001
  20220. [-1, -1], [-1, -1], // 0001x
  20221. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  20222. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  20223. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  20224. [11, 1792], [11, 1792], // 1000x
  20225. [12, 1984], // 10010
  20226. [12, 2048], // 10011
  20227. [12, 2112], // 10100
  20228. [12, 2176], // 10101
  20229. [12, 2240], // 10110
  20230. [12, 2304], // 10111
  20231. [11, 1856], [11, 1856], // 1100x
  20232. [11, 1920], [11, 1920], // 1101x
  20233. [12, 2368], // 11100
  20234. [12, 2432], // 11101
  20235. [12, 2496], // 11110
  20236. [12, 2560] // 11111
  20237. ];
  20238. var whiteTable2 = [
  20239. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  20240. [8, 29], [8, 29], // 00000010x
  20241. [8, 30], [8, 30], // 00000011x
  20242. [8, 45], [8, 45], // 00000100x
  20243. [8, 46], [8, 46], // 00000101x
  20244. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  20245. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  20246. [8, 47], [8, 47], // 00001010x
  20247. [8, 48], [8, 48], // 00001011x
  20248. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  20249. [6, 13], [6, 13], [6, 13], [6, 13],
  20250. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  20251. [8, 33], [8, 33], // 00010010x
  20252. [8, 34], [8, 34], // 00010011x
  20253. [8, 35], [8, 35], // 00010100x
  20254. [8, 36], [8, 36], // 00010101x
  20255. [8, 37], [8, 37], // 00010110x
  20256. [8, 38], [8, 38], // 00010111x
  20257. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  20258. [8, 31], [8, 31], // 00011010x
  20259. [8, 32], [8, 32], // 00011011x
  20260. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  20261. [6, 1], [6, 1], [6, 1], [6, 1],
  20262. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  20263. [6, 12], [6, 12], [6, 12], [6, 12],
  20264. [8, 53], [8, 53], // 00100100x
  20265. [8, 54], [8, 54], // 00100101x
  20266. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  20267. [8, 39], [8, 39], // 00101000x
  20268. [8, 40], [8, 40], // 00101001x
  20269. [8, 41], [8, 41], // 00101010x
  20270. [8, 42], [8, 42], // 00101011x
  20271. [8, 43], [8, 43], // 00101100x
  20272. [8, 44], [8, 44], // 00101101x
  20273. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  20274. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  20275. [8, 61], [8, 61], // 00110010x
  20276. [8, 62], [8, 62], // 00110011x
  20277. [8, 63], [8, 63], // 00110100x
  20278. [8, 0], [8, 0], // 00110101x
  20279. [8, 320], [8, 320], // 00110110x
  20280. [8, 384], [8, 384], // 00110111x
  20281. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  20282. [5, 10], [5, 10], [5, 10], [5, 10],
  20283. [5, 10], [5, 10], [5, 10], [5, 10],
  20284. [5, 10], [5, 10], [5, 10], [5, 10],
  20285. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  20286. [5, 11], [5, 11], [5, 11], [5, 11],
  20287. [5, 11], [5, 11], [5, 11], [5, 11],
  20288. [5, 11], [5, 11], [5, 11], [5, 11],
  20289. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  20290. [8, 59], [8, 59], // 01001010x
  20291. [8, 60], [8, 60], // 01001011x
  20292. [9, 1472], // 010011000
  20293. [9, 1536], // 010011001
  20294. [9, 1600], // 010011010
  20295. [9, 1728], // 010011011
  20296. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  20297. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  20298. [8, 49], [8, 49], // 01010010x
  20299. [8, 50], [8, 50], // 01010011x
  20300. [8, 51], [8, 51], // 01010100x
  20301. [8, 52], [8, 52], // 01010101x
  20302. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  20303. [8, 55], [8, 55], // 01011000x
  20304. [8, 56], [8, 56], // 01011001x
  20305. [8, 57], [8, 57], // 01011010x
  20306. [8, 58], [8, 58], // 01011011x
  20307. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  20308. [6, 192], [6, 192], [6, 192], [6, 192],
  20309. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  20310. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  20311. [8, 448], [8, 448], // 01100100x
  20312. [8, 512], [8, 512], // 01100101x
  20313. [9, 704], // 011001100
  20314. [9, 768], // 011001101
  20315. [8, 640], [8, 640], // 01100111x
  20316. [8, 576], [8, 576], // 01101000x
  20317. [9, 832], // 011010010
  20318. [9, 896], // 011010011
  20319. [9, 960], // 011010100
  20320. [9, 1024], // 011010101
  20321. [9, 1088], // 011010110
  20322. [9, 1152], // 011010111
  20323. [9, 1216], // 011011000
  20324. [9, 1280], // 011011001
  20325. [9, 1344], // 011011010
  20326. [9, 1408], // 011011011
  20327. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  20328. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  20329. [4, 2], [4, 2], [4, 2], [4, 2],
  20330. [4, 2], [4, 2], [4, 2], [4, 2],
  20331. [4, 2], [4, 2], [4, 2], [4, 2],
  20332. [4, 2], [4, 2], [4, 2], [4, 2],
  20333. [4, 2], [4, 2], [4, 2], [4, 2],
  20334. [4, 2], [4, 2], [4, 2], [4, 2],
  20335. [4, 2], [4, 2], [4, 2], [4, 2],
  20336. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  20337. [4, 3], [4, 3], [4, 3], [4, 3],
  20338. [4, 3], [4, 3], [4, 3], [4, 3],
  20339. [4, 3], [4, 3], [4, 3], [4, 3],
  20340. [4, 3], [4, 3], [4, 3], [4, 3],
  20341. [4, 3], [4, 3], [4, 3], [4, 3],
  20342. [4, 3], [4, 3], [4, 3], [4, 3],
  20343. [4, 3], [4, 3], [4, 3], [4, 3],
  20344. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  20345. [5, 128], [5, 128], [5, 128], [5, 128],
  20346. [5, 128], [5, 128], [5, 128], [5, 128],
  20347. [5, 128], [5, 128], [5, 128], [5, 128],
  20348. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  20349. [5, 8], [5, 8], [5, 8], [5, 8],
  20350. [5, 8], [5, 8], [5, 8], [5, 8],
  20351. [5, 8], [5, 8], [5, 8], [5, 8],
  20352. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  20353. [5, 9], [5, 9], [5, 9], [5, 9],
  20354. [5, 9], [5, 9], [5, 9], [5, 9],
  20355. [5, 9], [5, 9], [5, 9], [5, 9],
  20356. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  20357. [6, 16], [6, 16], [6, 16], [6, 16],
  20358. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  20359. [6, 17], [6, 17], [6, 17], [6, 17],
  20360. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  20361. [4, 4], [4, 4], [4, 4], [4, 4],
  20362. [4, 4], [4, 4], [4, 4], [4, 4],
  20363. [4, 4], [4, 4], [4, 4], [4, 4],
  20364. [4, 4], [4, 4], [4, 4], [4, 4],
  20365. [4, 4], [4, 4], [4, 4], [4, 4],
  20366. [4, 4], [4, 4], [4, 4], [4, 4],
  20367. [4, 4], [4, 4], [4, 4], [4, 4],
  20368. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  20369. [4, 5], [4, 5], [4, 5], [4, 5],
  20370. [4, 5], [4, 5], [4, 5], [4, 5],
  20371. [4, 5], [4, 5], [4, 5], [4, 5],
  20372. [4, 5], [4, 5], [4, 5], [4, 5],
  20373. [4, 5], [4, 5], [4, 5], [4, 5],
  20374. [4, 5], [4, 5], [4, 5], [4, 5],
  20375. [4, 5], [4, 5], [4, 5], [4, 5],
  20376. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  20377. [6, 14], [6, 14], [6, 14], [6, 14],
  20378. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  20379. [6, 15], [6, 15], [6, 15], [6, 15],
  20380. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  20381. [5, 64], [5, 64], [5, 64], [5, 64],
  20382. [5, 64], [5, 64], [5, 64], [5, 64],
  20383. [5, 64], [5, 64], [5, 64], [5, 64],
  20384. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  20385. [4, 6], [4, 6], [4, 6], [4, 6],
  20386. [4, 6], [4, 6], [4, 6], [4, 6],
  20387. [4, 6], [4, 6], [4, 6], [4, 6],
  20388. [4, 6], [4, 6], [4, 6], [4, 6],
  20389. [4, 6], [4, 6], [4, 6], [4, 6],
  20390. [4, 6], [4, 6], [4, 6], [4, 6],
  20391. [4, 6], [4, 6], [4, 6], [4, 6],
  20392. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  20393. [4, 7], [4, 7], [4, 7], [4, 7],
  20394. [4, 7], [4, 7], [4, 7], [4, 7],
  20395. [4, 7], [4, 7], [4, 7], [4, 7],
  20396. [4, 7], [4, 7], [4, 7], [4, 7],
  20397. [4, 7], [4, 7], [4, 7], [4, 7],
  20398. [4, 7], [4, 7], [4, 7], [4, 7],
  20399. [4, 7], [4, 7], [4, 7], [4, 7]
  20400. ];
  20401. var blackTable1 = [
  20402. [-1, -1], [-1, -1], // 000000000000x
  20403. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  20404. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  20405. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  20406. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  20407. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  20408. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  20409. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  20410. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  20411. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  20412. [12, 1984], [12, 1984], // 000000010010x
  20413. [12, 2048], [12, 2048], // 000000010011x
  20414. [12, 2112], [12, 2112], // 000000010100x
  20415. [12, 2176], [12, 2176], // 000000010101x
  20416. [12, 2240], [12, 2240], // 000000010110x
  20417. [12, 2304], [12, 2304], // 000000010111x
  20418. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  20419. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  20420. [12, 2368], [12, 2368], // 000000011100x
  20421. [12, 2432], [12, 2432], // 000000011101x
  20422. [12, 2496], [12, 2496], // 000000011110x
  20423. [12, 2560], [12, 2560], // 000000011111x
  20424. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  20425. [10, 18], [10, 18], [10, 18], [10, 18],
  20426. [12, 52], [12, 52], // 000000100100x
  20427. [13, 640], // 0000001001010
  20428. [13, 704], // 0000001001011
  20429. [13, 768], // 0000001001100
  20430. [13, 832], // 0000001001101
  20431. [12, 55], [12, 55], // 000000100111x
  20432. [12, 56], [12, 56], // 000000101000x
  20433. [13, 1280], // 0000001010010
  20434. [13, 1344], // 0000001010011
  20435. [13, 1408], // 0000001010100
  20436. [13, 1472], // 0000001010101
  20437. [12, 59], [12, 59], // 000000101011x
  20438. [12, 60], [12, 60], // 000000101100x
  20439. [13, 1536], // 0000001011010
  20440. [13, 1600], // 0000001011011
  20441. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  20442. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  20443. [13, 1664], // 0000001100100
  20444. [13, 1728], // 0000001100101
  20445. [12, 320], [12, 320], // 000000110011x
  20446. [12, 384], [12, 384], // 000000110100x
  20447. [12, 448], [12, 448], // 000000110101x
  20448. [13, 512], // 0000001101100
  20449. [13, 576], // 0000001101101
  20450. [12, 53], [12, 53], // 000000110111x
  20451. [12, 54], [12, 54], // 000000111000x
  20452. [13, 896], // 0000001110010
  20453. [13, 960], // 0000001110011
  20454. [13, 1024], // 0000001110100
  20455. [13, 1088], // 0000001110101
  20456. [13, 1152], // 0000001110110
  20457. [13, 1216], // 0000001110111
  20458. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  20459. [10, 64], [10, 64], [10, 64], [10, 64]
  20460. ];
  20461. var blackTable2 = [
  20462. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  20463. [8, 13], [8, 13], [8, 13], [8, 13],
  20464. [8, 13], [8, 13], [8, 13], [8, 13],
  20465. [8, 13], [8, 13], [8, 13], [8, 13],
  20466. [11, 23], [11, 23], // 00000101000x
  20467. [12, 50], // 000001010010
  20468. [12, 51], // 000001010011
  20469. [12, 44], // 000001010100
  20470. [12, 45], // 000001010101
  20471. [12, 46], // 000001010110
  20472. [12, 47], // 000001010111
  20473. [12, 57], // 000001011000
  20474. [12, 58], // 000001011001
  20475. [12, 61], // 000001011010
  20476. [12, 256], // 000001011011
  20477. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  20478. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  20479. [12, 48], // 000001100100
  20480. [12, 49], // 000001100101
  20481. [12, 62], // 000001100110
  20482. [12, 63], // 000001100111
  20483. [12, 30], // 000001101000
  20484. [12, 31], // 000001101001
  20485. [12, 32], // 000001101010
  20486. [12, 33], // 000001101011
  20487. [12, 40], // 000001101100
  20488. [12, 41], // 000001101101
  20489. [11, 22], [11, 22], // 00000110111x
  20490. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  20491. [8, 14], [8, 14], [8, 14], [8, 14],
  20492. [8, 14], [8, 14], [8, 14], [8, 14],
  20493. [8, 14], [8, 14], [8, 14], [8, 14],
  20494. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  20495. [7, 10], [7, 10], [7, 10], [7, 10],
  20496. [7, 10], [7, 10], [7, 10], [7, 10],
  20497. [7, 10], [7, 10], [7, 10], [7, 10],
  20498. [7, 10], [7, 10], [7, 10], [7, 10],
  20499. [7, 10], [7, 10], [7, 10], [7, 10],
  20500. [7, 10], [7, 10], [7, 10], [7, 10],
  20501. [7, 10], [7, 10], [7, 10], [7, 10],
  20502. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  20503. [7, 11], [7, 11], [7, 11], [7, 11],
  20504. [7, 11], [7, 11], [7, 11], [7, 11],
  20505. [7, 11], [7, 11], [7, 11], [7, 11],
  20506. [7, 11], [7, 11], [7, 11], [7, 11],
  20507. [7, 11], [7, 11], [7, 11], [7, 11],
  20508. [7, 11], [7, 11], [7, 11], [7, 11],
  20509. [7, 11], [7, 11], [7, 11], [7, 11],
  20510. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  20511. [9, 15], [9, 15], [9, 15], [9, 15],
  20512. [12, 128], // 000011001000
  20513. [12, 192], // 000011001001
  20514. [12, 26], // 000011001010
  20515. [12, 27], // 000011001011
  20516. [12, 28], // 000011001100
  20517. [12, 29], // 000011001101
  20518. [11, 19], [11, 19], // 00001100111x
  20519. [11, 20], [11, 20], // 00001101000x
  20520. [12, 34], // 000011010010
  20521. [12, 35], // 000011010011
  20522. [12, 36], // 000011010100
  20523. [12, 37], // 000011010101
  20524. [12, 38], // 000011010110
  20525. [12, 39], // 000011010111
  20526. [11, 21], [11, 21], // 00001101100x
  20527. [12, 42], // 000011011010
  20528. [12, 43], // 000011011011
  20529. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  20530. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  20531. [7, 12], [7, 12], [7, 12], [7, 12],
  20532. [7, 12], [7, 12], [7, 12], [7, 12],
  20533. [7, 12], [7, 12], [7, 12], [7, 12],
  20534. [7, 12], [7, 12], [7, 12], [7, 12],
  20535. [7, 12], [7, 12], [7, 12], [7, 12],
  20536. [7, 12], [7, 12], [7, 12], [7, 12],
  20537. [7, 12], [7, 12], [7, 12], [7, 12]
  20538. ];
  20539. var blackTable3 = [
  20540. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  20541. [6, 9], // 000100
  20542. [6, 8], // 000101
  20543. [5, 7], [5, 7], // 00011x
  20544. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  20545. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  20546. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  20547. [3, 1], [3, 1], [3, 1], [3, 1],
  20548. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  20549. [3, 4], [3, 4], [3, 4], [3, 4],
  20550. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  20551. [2, 3], [2, 3], [2, 3], [2, 3],
  20552. [2, 3], [2, 3], [2, 3], [2, 3],
  20553. [2, 3], [2, 3], [2, 3], [2, 3],
  20554. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  20555. [2, 2], [2, 2], [2, 2], [2, 2],
  20556. [2, 2], [2, 2], [2, 2], [2, 2],
  20557. [2, 2], [2, 2], [2, 2], [2, 2]
  20558. ];
  20559. function CCITTFaxStream(str, maybeLength, params) {
  20560. this.str = str;
  20561. this.dict = str.dict;
  20562. params = params || Dict.empty;
  20563. this.encoding = params.get('K') || 0;
  20564. this.eoline = params.get('EndOfLine') || false;
  20565. this.byteAlign = params.get('EncodedByteAlign') || false;
  20566. this.columns = params.get('Columns') || 1728;
  20567. this.rows = params.get('Rows') || 0;
  20568. var eoblock = params.get('EndOfBlock');
  20569. if (eoblock === null || eoblock === undefined) {
  20570. eoblock = true;
  20571. }
  20572. this.eoblock = eoblock;
  20573. this.black = params.get('BlackIs1') || false;
  20574. this.codingLine = new Uint32Array(this.columns + 1);
  20575. this.refLine = new Uint32Array(this.columns + 2);
  20576. this.codingLine[0] = this.columns;
  20577. this.codingPos = 0;
  20578. this.row = 0;
  20579. this.nextLine2D = this.encoding < 0;
  20580. this.inputBits = 0;
  20581. this.inputBuf = 0;
  20582. this.outputBits = 0;
  20583. var code1;
  20584. while ((code1 = this.lookBits(12)) === 0) {
  20585. this.eatBits(1);
  20586. }
  20587. if (code1 === 1) {
  20588. this.eatBits(12);
  20589. }
  20590. if (this.encoding > 0) {
  20591. this.nextLine2D = !this.lookBits(1);
  20592. this.eatBits(1);
  20593. }
  20594. DecodeStream.call(this, maybeLength);
  20595. }
  20596. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  20597. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  20598. while (!this.eof) {
  20599. var c = this.lookChar();
  20600. this.ensureBuffer(this.bufferLength + 1);
  20601. this.buffer[this.bufferLength++] = c;
  20602. }
  20603. };
  20604. CCITTFaxStream.prototype.addPixels =
  20605. function ccittFaxStreamAddPixels(a1, blackPixels) {
  20606. var codingLine = this.codingLine;
  20607. var codingPos = this.codingPos;
  20608. if (a1 > codingLine[codingPos]) {
  20609. if (a1 > this.columns) {
  20610. info('row is wrong length');
  20611. this.err = true;
  20612. a1 = this.columns;
  20613. }
  20614. if ((codingPos & 1) ^ blackPixels) {
  20615. ++codingPos;
  20616. }
  20617. codingLine[codingPos] = a1;
  20618. }
  20619. this.codingPos = codingPos;
  20620. };
  20621. CCITTFaxStream.prototype.addPixelsNeg =
  20622. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  20623. var codingLine = this.codingLine;
  20624. var codingPos = this.codingPos;
  20625. if (a1 > codingLine[codingPos]) {
  20626. if (a1 > this.columns) {
  20627. info('row is wrong length');
  20628. this.err = true;
  20629. a1 = this.columns;
  20630. }
  20631. if ((codingPos & 1) ^ blackPixels) {
  20632. ++codingPos;
  20633. }
  20634. codingLine[codingPos] = a1;
  20635. } else if (a1 < codingLine[codingPos]) {
  20636. if (a1 < 0) {
  20637. info('invalid code');
  20638. this.err = true;
  20639. a1 = 0;
  20640. }
  20641. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  20642. --codingPos;
  20643. }
  20644. codingLine[codingPos] = a1;
  20645. }
  20646. this.codingPos = codingPos;
  20647. };
  20648. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  20649. var refLine = this.refLine;
  20650. var codingLine = this.codingLine;
  20651. var columns = this.columns;
  20652. var refPos, blackPixels, bits, i;
  20653. if (this.outputBits === 0) {
  20654. if (this.eof) {
  20655. return null;
  20656. }
  20657. this.err = false;
  20658. var code1, code2, code3;
  20659. if (this.nextLine2D) {
  20660. for (i = 0; codingLine[i] < columns; ++i) {
  20661. refLine[i] = codingLine[i];
  20662. }
  20663. refLine[i++] = columns;
  20664. refLine[i] = columns;
  20665. codingLine[0] = 0;
  20666. this.codingPos = 0;
  20667. refPos = 0;
  20668. blackPixels = 0;
  20669. while (codingLine[this.codingPos] < columns) {
  20670. code1 = this.getTwoDimCode();
  20671. switch (code1) {
  20672. case twoDimPass:
  20673. this.addPixels(refLine[refPos + 1], blackPixels);
  20674. if (refLine[refPos + 1] < columns) {
  20675. refPos += 2;
  20676. }
  20677. break;
  20678. case twoDimHoriz:
  20679. code1 = code2 = 0;
  20680. if (blackPixels) {
  20681. do {
  20682. code1 += (code3 = this.getBlackCode());
  20683. } while (code3 >= 64);
  20684. do {
  20685. code2 += (code3 = this.getWhiteCode());
  20686. } while (code3 >= 64);
  20687. } else {
  20688. do {
  20689. code1 += (code3 = this.getWhiteCode());
  20690. } while (code3 >= 64);
  20691. do {
  20692. code2 += (code3 = this.getBlackCode());
  20693. } while (code3 >= 64);
  20694. }
  20695. this.addPixels(codingLine[this.codingPos] +
  20696. code1, blackPixels);
  20697. if (codingLine[this.codingPos] < columns) {
  20698. this.addPixels(codingLine[this.codingPos] + code2,
  20699. blackPixels ^ 1);
  20700. }
  20701. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20702. refLine[refPos] < columns) {
  20703. refPos += 2;
  20704. }
  20705. break;
  20706. case twoDimVertR3:
  20707. this.addPixels(refLine[refPos] + 3, blackPixels);
  20708. blackPixels ^= 1;
  20709. if (codingLine[this.codingPos] < columns) {
  20710. ++refPos;
  20711. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20712. refLine[refPos] < columns) {
  20713. refPos += 2;
  20714. }
  20715. }
  20716. break;
  20717. case twoDimVertR2:
  20718. this.addPixels(refLine[refPos] + 2, blackPixels);
  20719. blackPixels ^= 1;
  20720. if (codingLine[this.codingPos] < columns) {
  20721. ++refPos;
  20722. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20723. refLine[refPos] < columns) {
  20724. refPos += 2;
  20725. }
  20726. }
  20727. break;
  20728. case twoDimVertR1:
  20729. this.addPixels(refLine[refPos] + 1, blackPixels);
  20730. blackPixels ^= 1;
  20731. if (codingLine[this.codingPos] < columns) {
  20732. ++refPos;
  20733. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20734. refLine[refPos] < columns) {
  20735. refPos += 2;
  20736. }
  20737. }
  20738. break;
  20739. case twoDimVert0:
  20740. this.addPixels(refLine[refPos], blackPixels);
  20741. blackPixels ^= 1;
  20742. if (codingLine[this.codingPos] < columns) {
  20743. ++refPos;
  20744. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20745. refLine[refPos] < columns) {
  20746. refPos += 2;
  20747. }
  20748. }
  20749. break;
  20750. case twoDimVertL3:
  20751. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  20752. blackPixels ^= 1;
  20753. if (codingLine[this.codingPos] < columns) {
  20754. if (refPos > 0) {
  20755. --refPos;
  20756. } else {
  20757. ++refPos;
  20758. }
  20759. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20760. refLine[refPos] < columns) {
  20761. refPos += 2;
  20762. }
  20763. }
  20764. break;
  20765. case twoDimVertL2:
  20766. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  20767. blackPixels ^= 1;
  20768. if (codingLine[this.codingPos] < columns) {
  20769. if (refPos > 0) {
  20770. --refPos;
  20771. } else {
  20772. ++refPos;
  20773. }
  20774. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20775. refLine[refPos] < columns) {
  20776. refPos += 2;
  20777. }
  20778. }
  20779. break;
  20780. case twoDimVertL1:
  20781. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  20782. blackPixels ^= 1;
  20783. if (codingLine[this.codingPos] < columns) {
  20784. if (refPos > 0) {
  20785. --refPos;
  20786. } else {
  20787. ++refPos;
  20788. }
  20789. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20790. refLine[refPos] < columns) {
  20791. refPos += 2;
  20792. }
  20793. }
  20794. break;
  20795. case ccittEOF:
  20796. this.addPixels(columns, 0);
  20797. this.eof = true;
  20798. break;
  20799. default:
  20800. info('bad 2d code');
  20801. this.addPixels(columns, 0);
  20802. this.err = true;
  20803. }
  20804. }
  20805. } else {
  20806. codingLine[0] = 0;
  20807. this.codingPos = 0;
  20808. blackPixels = 0;
  20809. while (codingLine[this.codingPos] < columns) {
  20810. code1 = 0;
  20811. if (blackPixels) {
  20812. do {
  20813. code1 += (code3 = this.getBlackCode());
  20814. } while (code3 >= 64);
  20815. } else {
  20816. do {
  20817. code1 += (code3 = this.getWhiteCode());
  20818. } while (code3 >= 64);
  20819. }
  20820. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  20821. blackPixels ^= 1;
  20822. }
  20823. }
  20824. var gotEOL = false;
  20825. if (this.byteAlign) {
  20826. this.inputBits &= ~7;
  20827. }
  20828. if (!this.eoblock && this.row === this.rows - 1) {
  20829. this.eof = true;
  20830. } else {
  20831. code1 = this.lookBits(12);
  20832. if (this.eoline) {
  20833. while (code1 !== ccittEOF && code1 !== 1) {
  20834. this.eatBits(1);
  20835. code1 = this.lookBits(12);
  20836. }
  20837. } else {
  20838. while (code1 === 0) {
  20839. this.eatBits(1);
  20840. code1 = this.lookBits(12);
  20841. }
  20842. }
  20843. if (code1 === 1) {
  20844. this.eatBits(12);
  20845. gotEOL = true;
  20846. } else if (code1 === ccittEOF) {
  20847. this.eof = true;
  20848. }
  20849. }
  20850. if (!this.eof && this.encoding > 0) {
  20851. this.nextLine2D = !this.lookBits(1);
  20852. this.eatBits(1);
  20853. }
  20854. if (this.eoblock && gotEOL && this.byteAlign) {
  20855. code1 = this.lookBits(12);
  20856. if (code1 === 1) {
  20857. this.eatBits(12);
  20858. if (this.encoding > 0) {
  20859. this.lookBits(1);
  20860. this.eatBits(1);
  20861. }
  20862. if (this.encoding >= 0) {
  20863. for (i = 0; i < 4; ++i) {
  20864. code1 = this.lookBits(12);
  20865. if (code1 !== 1) {
  20866. info('bad rtc code: ' + code1);
  20867. }
  20868. this.eatBits(12);
  20869. if (this.encoding > 0) {
  20870. this.lookBits(1);
  20871. this.eatBits(1);
  20872. }
  20873. }
  20874. }
  20875. this.eof = true;
  20876. }
  20877. } else if (this.err && this.eoline) {
  20878. while (true) {
  20879. code1 = this.lookBits(13);
  20880. if (code1 === ccittEOF) {
  20881. this.eof = true;
  20882. return null;
  20883. }
  20884. if ((code1 >> 1) === 1) {
  20885. break;
  20886. }
  20887. this.eatBits(1);
  20888. }
  20889. this.eatBits(12);
  20890. if (this.encoding > 0) {
  20891. this.eatBits(1);
  20892. this.nextLine2D = !(code1 & 1);
  20893. }
  20894. }
  20895. if (codingLine[0] > 0) {
  20896. this.outputBits = codingLine[this.codingPos = 0];
  20897. } else {
  20898. this.outputBits = codingLine[this.codingPos = 1];
  20899. }
  20900. this.row++;
  20901. }
  20902. var c;
  20903. if (this.outputBits >= 8) {
  20904. c = (this.codingPos & 1) ? 0 : 0xFF;
  20905. this.outputBits -= 8;
  20906. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  20907. this.codingPos++;
  20908. this.outputBits = (codingLine[this.codingPos] -
  20909. codingLine[this.codingPos - 1]);
  20910. }
  20911. } else {
  20912. bits = 8;
  20913. c = 0;
  20914. do {
  20915. if (this.outputBits > bits) {
  20916. c <<= bits;
  20917. if (!(this.codingPos & 1)) {
  20918. c |= 0xFF >> (8 - bits);
  20919. }
  20920. this.outputBits -= bits;
  20921. bits = 0;
  20922. } else {
  20923. c <<= this.outputBits;
  20924. if (!(this.codingPos & 1)) {
  20925. c |= 0xFF >> (8 - this.outputBits);
  20926. }
  20927. bits -= this.outputBits;
  20928. this.outputBits = 0;
  20929. if (codingLine[this.codingPos] < columns) {
  20930. this.codingPos++;
  20931. this.outputBits = (codingLine[this.codingPos] -
  20932. codingLine[this.codingPos - 1]);
  20933. } else if (bits > 0) {
  20934. c <<= bits;
  20935. bits = 0;
  20936. }
  20937. }
  20938. } while (bits);
  20939. }
  20940. if (this.black) {
  20941. c ^= 0xFF;
  20942. }
  20943. return c;
  20944. };
  20945. // This functions returns the code found from the table.
  20946. // The start and end parameters set the boundaries for searching the table.
  20947. // The limit parameter is optional. Function returns an array with three
  20948. // values. The first array element indicates whether a valid code is being
  20949. // returned. The second array element is the actual code. The third array
  20950. // element indicates whether EOF was reached.
  20951. CCITTFaxStream.prototype.findTableCode =
  20952. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  20953. var limitValue = limit || 0;
  20954. for (var i = start; i <= end; ++i) {
  20955. var code = this.lookBits(i);
  20956. if (code === ccittEOF) {
  20957. return [true, 1, false];
  20958. }
  20959. if (i < end) {
  20960. code <<= end - i;
  20961. }
  20962. if (!limitValue || code >= limitValue) {
  20963. var p = table[code - limitValue];
  20964. if (p[0] === i) {
  20965. this.eatBits(i);
  20966. return [true, p[1], true];
  20967. }
  20968. }
  20969. }
  20970. return [false, 0, false];
  20971. };
  20972. CCITTFaxStream.prototype.getTwoDimCode =
  20973. function ccittFaxStreamGetTwoDimCode() {
  20974. var code = 0;
  20975. var p;
  20976. if (this.eoblock) {
  20977. code = this.lookBits(7);
  20978. p = twoDimTable[code];
  20979. if (p && p[0] > 0) {
  20980. this.eatBits(p[0]);
  20981. return p[1];
  20982. }
  20983. } else {
  20984. var result = this.findTableCode(1, 7, twoDimTable);
  20985. if (result[0] && result[2]) {
  20986. return result[1];
  20987. }
  20988. }
  20989. info('Bad two dim code');
  20990. return ccittEOF;
  20991. };
  20992. CCITTFaxStream.prototype.getWhiteCode =
  20993. function ccittFaxStreamGetWhiteCode() {
  20994. var code = 0;
  20995. var p;
  20996. if (this.eoblock) {
  20997. code = this.lookBits(12);
  20998. if (code === ccittEOF) {
  20999. return 1;
  21000. }
  21001. if ((code >> 5) === 0) {
  21002. p = whiteTable1[code];
  21003. } else {
  21004. p = whiteTable2[code >> 3];
  21005. }
  21006. if (p[0] > 0) {
  21007. this.eatBits(p[0]);
  21008. return p[1];
  21009. }
  21010. } else {
  21011. var result = this.findTableCode(1, 9, whiteTable2);
  21012. if (result[0]) {
  21013. return result[1];
  21014. }
  21015. result = this.findTableCode(11, 12, whiteTable1);
  21016. if (result[0]) {
  21017. return result[1];
  21018. }
  21019. }
  21020. info('bad white code');
  21021. this.eatBits(1);
  21022. return 1;
  21023. };
  21024. CCITTFaxStream.prototype.getBlackCode =
  21025. function ccittFaxStreamGetBlackCode() {
  21026. var code, p;
  21027. if (this.eoblock) {
  21028. code = this.lookBits(13);
  21029. if (code === ccittEOF) {
  21030. return 1;
  21031. }
  21032. if ((code >> 7) === 0) {
  21033. p = blackTable1[code];
  21034. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  21035. p = blackTable2[(code >> 1) - 64];
  21036. } else {
  21037. p = blackTable3[code >> 7];
  21038. }
  21039. if (p[0] > 0) {
  21040. this.eatBits(p[0]);
  21041. return p[1];
  21042. }
  21043. } else {
  21044. var result = this.findTableCode(2, 6, blackTable3);
  21045. if (result[0]) {
  21046. return result[1];
  21047. }
  21048. result = this.findTableCode(7, 12, blackTable2, 64);
  21049. if (result[0]) {
  21050. return result[1];
  21051. }
  21052. result = this.findTableCode(10, 13, blackTable1);
  21053. if (result[0]) {
  21054. return result[1];
  21055. }
  21056. }
  21057. info('bad black code');
  21058. this.eatBits(1);
  21059. return 1;
  21060. };
  21061. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  21062. var c;
  21063. while (this.inputBits < n) {
  21064. if ((c = this.str.getByte()) === -1) {
  21065. if (this.inputBits === 0) {
  21066. return ccittEOF;
  21067. }
  21068. return ((this.inputBuf << (n - this.inputBits)) &
  21069. (0xFFFF >> (16 - n)));
  21070. }
  21071. this.inputBuf = (this.inputBuf << 8) | c;
  21072. this.inputBits += 8;
  21073. }
  21074. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  21075. };
  21076. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  21077. if ((this.inputBits -= n) < 0) {
  21078. this.inputBits = 0;
  21079. }
  21080. };
  21081. return CCITTFaxStream;
  21082. })();
  21083. var LZWStream = (function LZWStreamClosure() {
  21084. function LZWStream(str, maybeLength, earlyChange) {
  21085. this.str = str;
  21086. this.dict = str.dict;
  21087. this.cachedData = 0;
  21088. this.bitsCached = 0;
  21089. var maxLzwDictionarySize = 4096;
  21090. var lzwState = {
  21091. earlyChange: earlyChange,
  21092. codeLength: 9,
  21093. nextCode: 258,
  21094. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  21095. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  21096. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  21097. currentSequence: new Uint8Array(maxLzwDictionarySize),
  21098. currentSequenceLength: 0
  21099. };
  21100. for (var i = 0; i < 256; ++i) {
  21101. lzwState.dictionaryValues[i] = i;
  21102. lzwState.dictionaryLengths[i] = 1;
  21103. }
  21104. this.lzwState = lzwState;
  21105. DecodeStream.call(this, maybeLength);
  21106. }
  21107. LZWStream.prototype = Object.create(DecodeStream.prototype);
  21108. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  21109. var bitsCached = this.bitsCached;
  21110. var cachedData = this.cachedData;
  21111. while (bitsCached < n) {
  21112. var c = this.str.getByte();
  21113. if (c === -1) {
  21114. this.eof = true;
  21115. return null;
  21116. }
  21117. cachedData = (cachedData << 8) | c;
  21118. bitsCached += 8;
  21119. }
  21120. this.bitsCached = (bitsCached -= n);
  21121. this.cachedData = cachedData;
  21122. this.lastCode = null;
  21123. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  21124. };
  21125. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  21126. var blockSize = 512;
  21127. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  21128. var i, j, q;
  21129. var lzwState = this.lzwState;
  21130. if (!lzwState) {
  21131. return; // eof was found
  21132. }
  21133. var earlyChange = lzwState.earlyChange;
  21134. var nextCode = lzwState.nextCode;
  21135. var dictionaryValues = lzwState.dictionaryValues;
  21136. var dictionaryLengths = lzwState.dictionaryLengths;
  21137. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  21138. var codeLength = lzwState.codeLength;
  21139. var prevCode = lzwState.prevCode;
  21140. var currentSequence = lzwState.currentSequence;
  21141. var currentSequenceLength = lzwState.currentSequenceLength;
  21142. var decodedLength = 0;
  21143. var currentBufferLength = this.bufferLength;
  21144. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  21145. for (i = 0; i < blockSize; i++) {
  21146. var code = this.readBits(codeLength);
  21147. var hasPrev = currentSequenceLength > 0;
  21148. if (code < 256) {
  21149. currentSequence[0] = code;
  21150. currentSequenceLength = 1;
  21151. } else if (code >= 258) {
  21152. if (code < nextCode) {
  21153. currentSequenceLength = dictionaryLengths[code];
  21154. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  21155. currentSequence[j] = dictionaryValues[q];
  21156. q = dictionaryPrevCodes[q];
  21157. }
  21158. } else {
  21159. currentSequence[currentSequenceLength++] = currentSequence[0];
  21160. }
  21161. } else if (code === 256) {
  21162. codeLength = 9;
  21163. nextCode = 258;
  21164. currentSequenceLength = 0;
  21165. continue;
  21166. } else {
  21167. this.eof = true;
  21168. delete this.lzwState;
  21169. break;
  21170. }
  21171. if (hasPrev) {
  21172. dictionaryPrevCodes[nextCode] = prevCode;
  21173. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  21174. dictionaryValues[nextCode] = currentSequence[0];
  21175. nextCode++;
  21176. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  21177. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  21178. 0.6931471805599453 + 1, 12) | 0;
  21179. }
  21180. prevCode = code;
  21181. decodedLength += currentSequenceLength;
  21182. if (estimatedDecodedSize < decodedLength) {
  21183. do {
  21184. estimatedDecodedSize += decodedSizeDelta;
  21185. } while (estimatedDecodedSize < decodedLength);
  21186. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  21187. }
  21188. for (j = 0; j < currentSequenceLength; j++) {
  21189. buffer[currentBufferLength++] = currentSequence[j];
  21190. }
  21191. }
  21192. lzwState.nextCode = nextCode;
  21193. lzwState.codeLength = codeLength;
  21194. lzwState.prevCode = prevCode;
  21195. lzwState.currentSequenceLength = currentSequenceLength;
  21196. this.bufferLength = currentBufferLength;
  21197. };
  21198. return LZWStream;
  21199. })();
  21200. var NullStream = (function NullStreamClosure() {
  21201. function NullStream() {
  21202. Stream.call(this, new Uint8Array(0));
  21203. }
  21204. NullStream.prototype = Stream.prototype;
  21205. return NullStream;
  21206. })();
  21207. exports.Ascii85Stream = Ascii85Stream;
  21208. exports.AsciiHexStream = AsciiHexStream;
  21209. exports.CCITTFaxStream = CCITTFaxStream;
  21210. exports.DecryptStream = DecryptStream;
  21211. exports.DecodeStream = DecodeStream;
  21212. exports.FlateStream = FlateStream;
  21213. exports.Jbig2Stream = Jbig2Stream;
  21214. exports.JpegStream = JpegStream;
  21215. exports.JpxStream = JpxStream;
  21216. exports.NullStream = NullStream;
  21217. exports.PredictorStream = PredictorStream;
  21218. exports.RunLengthStream = RunLengthStream;
  21219. exports.Stream = Stream;
  21220. exports.StreamsSequenceStream = StreamsSequenceStream;
  21221. exports.StringStream = StringStream;
  21222. exports.LZWStream = LZWStream;
  21223. }));
  21224. (function (root, factory) {
  21225. {
  21226. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  21227. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  21228. }
  21229. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  21230. var PasswordException = sharedUtil.PasswordException;
  21231. var PasswordResponses = sharedUtil.PasswordResponses;
  21232. var bytesToString = sharedUtil.bytesToString;
  21233. var error = sharedUtil.error;
  21234. var isInt = sharedUtil.isInt;
  21235. var stringToBytes = sharedUtil.stringToBytes;
  21236. var utf8StringToString = sharedUtil.utf8StringToString;
  21237. var warn = sharedUtil.warn;
  21238. var Name = corePrimitives.Name;
  21239. var isName = corePrimitives.isName;
  21240. var isDict = corePrimitives.isDict;
  21241. var DecryptStream = coreStream.DecryptStream;
  21242. var ARCFourCipher = (function ARCFourCipherClosure() {
  21243. function ARCFourCipher(key) {
  21244. this.a = 0;
  21245. this.b = 0;
  21246. var s = new Uint8Array(256);
  21247. var i, j = 0, tmp, keyLength = key.length;
  21248. for (i = 0; i < 256; ++i) {
  21249. s[i] = i;
  21250. }
  21251. for (i = 0; i < 256; ++i) {
  21252. tmp = s[i];
  21253. j = (j + tmp + key[i % keyLength]) & 0xFF;
  21254. s[i] = s[j];
  21255. s[j] = tmp;
  21256. }
  21257. this.s = s;
  21258. }
  21259. ARCFourCipher.prototype = {
  21260. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  21261. var i, n = data.length, tmp, tmp2;
  21262. var a = this.a, b = this.b, s = this.s;
  21263. var output = new Uint8Array(n);
  21264. for (i = 0; i < n; ++i) {
  21265. a = (a + 1) & 0xFF;
  21266. tmp = s[a];
  21267. b = (b + tmp) & 0xFF;
  21268. tmp2 = s[b];
  21269. s[a] = tmp2;
  21270. s[b] = tmp;
  21271. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  21272. }
  21273. this.a = a;
  21274. this.b = b;
  21275. return output;
  21276. }
  21277. };
  21278. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  21279. return ARCFourCipher;
  21280. })();
  21281. var calculateMD5 = (function calculateMD5Closure() {
  21282. var r = new Uint8Array([
  21283. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  21284. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  21285. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  21286. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  21287. var k = new Int32Array([
  21288. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  21289. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  21290. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  21291. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  21292. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  21293. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  21294. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  21295. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  21296. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  21297. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  21298. -145523070, -1120210379, 718787259, -343485551]);
  21299. function hash(data, offset, length) {
  21300. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  21301. // pre-processing
  21302. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  21303. var padded = new Uint8Array(paddedLength);
  21304. var i, j, n;
  21305. for (i = 0; i < length; ++i) {
  21306. padded[i] = data[offset++];
  21307. }
  21308. padded[i++] = 0x80;
  21309. n = paddedLength - 8;
  21310. while (i < n) {
  21311. padded[i++] = 0;
  21312. }
  21313. padded[i++] = (length << 3) & 0xFF;
  21314. padded[i++] = (length >> 5) & 0xFF;
  21315. padded[i++] = (length >> 13) & 0xFF;
  21316. padded[i++] = (length >> 21) & 0xFF;
  21317. padded[i++] = (length >>> 29) & 0xFF;
  21318. padded[i++] = 0;
  21319. padded[i++] = 0;
  21320. padded[i++] = 0;
  21321. var w = new Int32Array(16);
  21322. for (i = 0; i < paddedLength;) {
  21323. for (j = 0; j < 16; ++j, i += 4) {
  21324. w[j] = (padded[i] | (padded[i + 1] << 8) |
  21325. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  21326. }
  21327. var a = h0, b = h1, c = h2, d = h3, f, g;
  21328. for (j = 0; j < 64; ++j) {
  21329. if (j < 16) {
  21330. f = (b & c) | ((~b) & d);
  21331. g = j;
  21332. } else if (j < 32) {
  21333. f = (d & b) | ((~d) & c);
  21334. g = (5 * j + 1) & 15;
  21335. } else if (j < 48) {
  21336. f = b ^ c ^ d;
  21337. g = (3 * j + 5) & 15;
  21338. } else {
  21339. f = c ^ (b | (~d));
  21340. g = (7 * j) & 15;
  21341. }
  21342. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  21343. d = c;
  21344. c = b;
  21345. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  21346. a = tmp;
  21347. }
  21348. h0 = (h0 + a) | 0;
  21349. h1 = (h1 + b) | 0;
  21350. h2 = (h2 + c) | 0;
  21351. h3 = (h3 + d) | 0;
  21352. }
  21353. return new Uint8Array([
  21354. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  21355. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  21356. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  21357. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  21358. ]);
  21359. }
  21360. return hash;
  21361. })();
  21362. var Word64 = (function Word64Closure() {
  21363. function Word64(highInteger, lowInteger) {
  21364. this.high = highInteger | 0;
  21365. this.low = lowInteger | 0;
  21366. }
  21367. Word64.prototype = {
  21368. and: function Word64_and(word) {
  21369. this.high &= word.high;
  21370. this.low &= word.low;
  21371. },
  21372. xor: function Word64_xor(word) {
  21373. this.high ^= word.high;
  21374. this.low ^= word.low;
  21375. },
  21376. or: function Word64_or(word) {
  21377. this.high |= word.high;
  21378. this.low |= word.low;
  21379. },
  21380. shiftRight: function Word64_shiftRight(places) {
  21381. if (places >= 32) {
  21382. this.low = (this.high >>> (places - 32)) | 0;
  21383. this.high = 0;
  21384. } else {
  21385. this.low = (this.low >>> places) | (this.high << (32 - places));
  21386. this.high = (this.high >>> places) | 0;
  21387. }
  21388. },
  21389. shiftLeft: function Word64_shiftLeft(places) {
  21390. if (places >= 32) {
  21391. this.high = this.low << (places - 32);
  21392. this.low = 0;
  21393. } else {
  21394. this.high = (this.high << places) | (this.low >>> (32 - places));
  21395. this.low = this.low << places;
  21396. }
  21397. },
  21398. rotateRight: function Word64_rotateRight(places) {
  21399. var low, high;
  21400. if (places & 32) {
  21401. high = this.low;
  21402. low = this.high;
  21403. } else {
  21404. low = this.low;
  21405. high = this.high;
  21406. }
  21407. places &= 31;
  21408. this.low = (low >>> places) | (high << (32 - places));
  21409. this.high = (high >>> places) | (low << (32 - places));
  21410. },
  21411. not: function Word64_not() {
  21412. this.high = ~this.high;
  21413. this.low = ~this.low;
  21414. },
  21415. add: function Word64_add(word) {
  21416. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  21417. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  21418. if (lowAdd > 0xFFFFFFFF) {
  21419. highAdd += 1;
  21420. }
  21421. this.low = lowAdd | 0;
  21422. this.high = highAdd | 0;
  21423. },
  21424. copyTo: function Word64_copyTo(bytes, offset) {
  21425. bytes[offset] = (this.high >>> 24) & 0xFF;
  21426. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  21427. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  21428. bytes[offset + 3] = this.high & 0xFF;
  21429. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  21430. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  21431. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  21432. bytes[offset + 7] = this.low & 0xFF;
  21433. },
  21434. assign: function Word64_assign(word) {
  21435. this.high = word.high;
  21436. this.low = word.low;
  21437. }
  21438. };
  21439. return Word64;
  21440. })();
  21441. var calculateSHA256 = (function calculateSHA256Closure() {
  21442. function rotr(x, n) {
  21443. return (x >>> n) | (x << 32 - n);
  21444. }
  21445. function ch(x, y, z) {
  21446. return (x & y) ^ (~x & z);
  21447. }
  21448. function maj(x, y, z) {
  21449. return (x & y) ^ (x & z) ^ (y & z);
  21450. }
  21451. function sigma(x) {
  21452. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  21453. }
  21454. function sigmaPrime(x) {
  21455. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  21456. }
  21457. function littleSigma(x) {
  21458. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  21459. }
  21460. function littleSigmaPrime(x) {
  21461. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  21462. }
  21463. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  21464. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  21465. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  21466. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  21467. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  21468. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  21469. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  21470. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  21471. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  21472. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  21473. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  21474. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  21475. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  21476. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  21477. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  21478. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  21479. function hash(data, offset, length) {
  21480. // initial hash values
  21481. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  21482. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  21483. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  21484. // pre-processing
  21485. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  21486. var padded = new Uint8Array(paddedLength);
  21487. var i, j, n;
  21488. for (i = 0; i < length; ++i) {
  21489. padded[i] = data[offset++];
  21490. }
  21491. padded[i++] = 0x80;
  21492. n = paddedLength - 8;
  21493. while (i < n) {
  21494. padded[i++] = 0;
  21495. }
  21496. padded[i++] = 0;
  21497. padded[i++] = 0;
  21498. padded[i++] = 0;
  21499. padded[i++] = (length >>> 29) & 0xFF;
  21500. padded[i++] = (length >> 21) & 0xFF;
  21501. padded[i++] = (length >> 13) & 0xFF;
  21502. padded[i++] = (length >> 5) & 0xFF;
  21503. padded[i++] = (length << 3) & 0xFF;
  21504. var w = new Uint32Array(64);
  21505. // for each 512 bit block
  21506. for (i = 0; i < paddedLength;) {
  21507. for (j = 0; j < 16; ++j) {
  21508. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  21509. (padded[i + 2] << 8) | (padded[i + 3]));
  21510. i += 4;
  21511. }
  21512. for (j = 16; j < 64; ++j) {
  21513. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  21514. littleSigma(w[j - 15]) + w[j - 16] | 0;
  21515. }
  21516. var a = h0, b = h1, c = h2, d = h3, e = h4,
  21517. f = h5, g = h6, h = h7, t1, t2;
  21518. for (j = 0; j < 64; ++j) {
  21519. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  21520. t2 = sigma(a) + maj(a, b, c);
  21521. h = g;
  21522. g = f;
  21523. f = e;
  21524. e = (d + t1) | 0;
  21525. d = c;
  21526. c = b;
  21527. b = a;
  21528. a = (t1 + t2) | 0;
  21529. }
  21530. h0 = (h0 + a) | 0;
  21531. h1 = (h1 + b) | 0;
  21532. h2 = (h2 + c) | 0;
  21533. h3 = (h3 + d) | 0;
  21534. h4 = (h4 + e) | 0;
  21535. h5 = (h5 + f) | 0;
  21536. h6 = (h6 + g) | 0;
  21537. h7 = (h7 + h) | 0;
  21538. }
  21539. return new Uint8Array([
  21540. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  21541. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  21542. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  21543. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  21544. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  21545. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  21546. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  21547. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  21548. ]);
  21549. }
  21550. return hash;
  21551. })();
  21552. var calculateSHA512 = (function calculateSHA512Closure() {
  21553. function ch(result, x, y, z, tmp) {
  21554. result.assign(x);
  21555. result.and(y);
  21556. tmp.assign(x);
  21557. tmp.not();
  21558. tmp.and(z);
  21559. result.xor(tmp);
  21560. }
  21561. function maj(result, x, y, z, tmp) {
  21562. result.assign(x);
  21563. result.and(y);
  21564. tmp.assign(x);
  21565. tmp.and(z);
  21566. result.xor(tmp);
  21567. tmp.assign(y);
  21568. tmp.and(z);
  21569. result.xor(tmp);
  21570. }
  21571. function sigma(result, x, tmp) {
  21572. result.assign(x);
  21573. result.rotateRight(28);
  21574. tmp.assign(x);
  21575. tmp.rotateRight(34);
  21576. result.xor(tmp);
  21577. tmp.assign(x);
  21578. tmp.rotateRight(39);
  21579. result.xor(tmp);
  21580. }
  21581. function sigmaPrime(result, x, tmp) {
  21582. result.assign(x);
  21583. result.rotateRight(14);
  21584. tmp.assign(x);
  21585. tmp.rotateRight(18);
  21586. result.xor(tmp);
  21587. tmp.assign(x);
  21588. tmp.rotateRight(41);
  21589. result.xor(tmp);
  21590. }
  21591. function littleSigma(result, x, tmp) {
  21592. result.assign(x);
  21593. result.rotateRight(1);
  21594. tmp.assign(x);
  21595. tmp.rotateRight(8);
  21596. result.xor(tmp);
  21597. tmp.assign(x);
  21598. tmp.shiftRight(7);
  21599. result.xor(tmp);
  21600. }
  21601. function littleSigmaPrime(result, x, tmp) {
  21602. result.assign(x);
  21603. result.rotateRight(19);
  21604. tmp.assign(x);
  21605. tmp.rotateRight(61);
  21606. result.xor(tmp);
  21607. tmp.assign(x);
  21608. tmp.shiftRight(6);
  21609. result.xor(tmp);
  21610. }
  21611. var k = [
  21612. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  21613. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  21614. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  21615. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  21616. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  21617. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  21618. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  21619. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  21620. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  21621. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  21622. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  21623. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  21624. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  21625. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  21626. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  21627. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  21628. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  21629. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  21630. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  21631. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  21632. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  21633. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  21634. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  21635. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  21636. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  21637. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  21638. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  21639. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  21640. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  21641. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  21642. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  21643. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  21644. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  21645. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  21646. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  21647. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  21648. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  21649. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  21650. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  21651. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  21652. function hash(data, offset, length, mode384) {
  21653. mode384 = !!mode384;
  21654. // initial hash values
  21655. var h0, h1, h2, h3, h4, h5, h6, h7;
  21656. if (!mode384) {
  21657. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  21658. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  21659. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  21660. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  21661. h4 = new Word64(0x510e527f, 0xade682d1);
  21662. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  21663. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  21664. h7 = new Word64(0x5be0cd19, 0x137e2179);
  21665. }
  21666. else {
  21667. // SHA384 is exactly the same
  21668. // except with different starting values and a trimmed result
  21669. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  21670. h1 = new Word64(0x629a292a, 0x367cd507);
  21671. h2 = new Word64(0x9159015a, 0x3070dd17);
  21672. h3 = new Word64(0x152fecd8, 0xf70e5939);
  21673. h4 = new Word64(0x67332667, 0xffc00b31);
  21674. h5 = new Word64(0x8eb44a87, 0x68581511);
  21675. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  21676. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  21677. }
  21678. // pre-processing
  21679. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  21680. var padded = new Uint8Array(paddedLength);
  21681. var i, j, n;
  21682. for (i = 0; i < length; ++i) {
  21683. padded[i] = data[offset++];
  21684. }
  21685. padded[i++] = 0x80;
  21686. n = paddedLength - 16;
  21687. while (i < n) {
  21688. padded[i++] = 0;
  21689. }
  21690. padded[i++] = 0;
  21691. padded[i++] = 0;
  21692. padded[i++] = 0;
  21693. padded[i++] = 0;
  21694. padded[i++] = 0;
  21695. padded[i++] = 0;
  21696. padded[i++] = 0;
  21697. padded[i++] = 0;
  21698. padded[i++] = 0;
  21699. padded[i++] = 0;
  21700. padded[i++] = 0;
  21701. padded[i++] = (length >>> 29) & 0xFF;
  21702. padded[i++] = (length >> 21) & 0xFF;
  21703. padded[i++] = (length >> 13) & 0xFF;
  21704. padded[i++] = (length >> 5) & 0xFF;
  21705. padded[i++] = (length << 3) & 0xFF;
  21706. var w = new Array(80);
  21707. for (i = 0; i < 80; i++) {
  21708. w[i] = new Word64(0, 0);
  21709. }
  21710. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  21711. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  21712. var g = new Word64(0, 0), h = new Word64(0, 0);
  21713. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  21714. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  21715. // for each 1024 bit block
  21716. for (i = 0; i < paddedLength;) {
  21717. for (j = 0; j < 16; ++j) {
  21718. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  21719. (padded[i + 2] << 8) | (padded[i + 3]);
  21720. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  21721. (padded[i + 6]) << 8 | (padded[i + 7]);
  21722. i += 8;
  21723. }
  21724. for (j = 16; j < 80; ++j) {
  21725. tmp3 = w[j];
  21726. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  21727. tmp3.add(w[j - 7]);
  21728. littleSigma(tmp1, w[j - 15], tmp2);
  21729. tmp3.add(tmp1);
  21730. tmp3.add(w[j - 16]);
  21731. }
  21732. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  21733. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  21734. for (j = 0; j < 80; ++j) {
  21735. t1.assign(h);
  21736. sigmaPrime(tmp1, e, tmp2);
  21737. t1.add(tmp1);
  21738. ch(tmp1, e, f, g, tmp2);
  21739. t1.add(tmp1);
  21740. t1.add(k[j]);
  21741. t1.add(w[j]);
  21742. sigma(t2, a, tmp2);
  21743. maj(tmp1, a, b, c, tmp2);
  21744. t2.add(tmp1);
  21745. tmp3 = h;
  21746. h = g;
  21747. g = f;
  21748. f = e;
  21749. d.add(t1);
  21750. e = d;
  21751. d = c;
  21752. c = b;
  21753. b = a;
  21754. tmp3.assign(t1);
  21755. tmp3.add(t2);
  21756. a = tmp3;
  21757. }
  21758. h0.add(a);
  21759. h1.add(b);
  21760. h2.add(c);
  21761. h3.add(d);
  21762. h4.add(e);
  21763. h5.add(f);
  21764. h6.add(g);
  21765. h7.add(h);
  21766. }
  21767. var result;
  21768. if (!mode384) {
  21769. result = new Uint8Array(64);
  21770. h0.copyTo(result,0);
  21771. h1.copyTo(result,8);
  21772. h2.copyTo(result,16);
  21773. h3.copyTo(result,24);
  21774. h4.copyTo(result,32);
  21775. h5.copyTo(result,40);
  21776. h6.copyTo(result,48);
  21777. h7.copyTo(result,56);
  21778. }
  21779. else {
  21780. result = new Uint8Array(48);
  21781. h0.copyTo(result,0);
  21782. h1.copyTo(result,8);
  21783. h2.copyTo(result,16);
  21784. h3.copyTo(result,24);
  21785. h4.copyTo(result,32);
  21786. h5.copyTo(result,40);
  21787. }
  21788. return result;
  21789. }
  21790. return hash;
  21791. })();
  21792. var calculateSHA384 = (function calculateSHA384Closure() {
  21793. function hash(data, offset, length) {
  21794. return calculateSHA512(data, offset, length, true);
  21795. }
  21796. return hash;
  21797. })();
  21798. var NullCipher = (function NullCipherClosure() {
  21799. function NullCipher() {
  21800. }
  21801. NullCipher.prototype = {
  21802. decryptBlock: function NullCipher_decryptBlock(data) {
  21803. return data;
  21804. }
  21805. };
  21806. return NullCipher;
  21807. })();
  21808. var AES128Cipher = (function AES128CipherClosure() {
  21809. var rcon = new Uint8Array([
  21810. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  21811. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  21812. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  21813. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  21814. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  21815. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  21816. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  21817. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  21818. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  21819. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  21820. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  21821. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  21822. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  21823. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  21824. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  21825. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  21826. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  21827. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  21828. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  21829. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  21830. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  21831. 0x74, 0xe8, 0xcb, 0x8d]);
  21832. var s = new Uint8Array([
  21833. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  21834. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  21835. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  21836. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  21837. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  21838. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  21839. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  21840. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  21841. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  21842. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  21843. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  21844. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  21845. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  21846. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  21847. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  21848. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  21849. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  21850. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  21851. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  21852. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  21853. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  21854. 0xb0, 0x54, 0xbb, 0x16]);
  21855. var inv_s = new Uint8Array([
  21856. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  21857. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  21858. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  21859. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  21860. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  21861. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  21862. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  21863. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  21864. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  21865. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  21866. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  21867. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  21868. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  21869. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  21870. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  21871. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  21872. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  21873. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  21874. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  21875. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  21876. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  21877. 0x55, 0x21, 0x0c, 0x7d]);
  21878. var mixCol = new Uint8Array(256);
  21879. for (var i = 0; i < 256; i++) {
  21880. if (i < 128) {
  21881. mixCol[i] = i << 1;
  21882. } else {
  21883. mixCol[i] = (i << 1) ^ 0x1b;
  21884. }
  21885. }
  21886. var mix = new Uint32Array([
  21887. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  21888. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  21889. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  21890. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  21891. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  21892. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  21893. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  21894. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  21895. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  21896. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  21897. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  21898. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  21899. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  21900. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  21901. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  21902. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  21903. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  21904. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  21905. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  21906. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  21907. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  21908. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  21909. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  21910. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  21911. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  21912. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  21913. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  21914. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  21915. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  21916. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  21917. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  21918. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  21919. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  21920. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  21921. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  21922. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  21923. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  21924. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  21925. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  21926. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  21927. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  21928. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  21929. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  21930. function expandKey128(cipherKey) {
  21931. var b = 176, result = new Uint8Array(b);
  21932. result.set(cipherKey);
  21933. for (var j = 16, i = 1; j < b; ++i) {
  21934. // RotWord
  21935. var t1 = result[j - 3], t2 = result[j - 2],
  21936. t3 = result[j - 1], t4 = result[j - 4];
  21937. // SubWord
  21938. t1 = s[t1];
  21939. t2 = s[t2];
  21940. t3 = s[t3];
  21941. t4 = s[t4];
  21942. // Rcon
  21943. t1 = t1 ^ rcon[i];
  21944. for (var n = 0; n < 4; ++n) {
  21945. result[j] = (t1 ^= result[j - 16]);
  21946. j++;
  21947. result[j] = (t2 ^= result[j - 16]);
  21948. j++;
  21949. result[j] = (t3 ^= result[j - 16]);
  21950. j++;
  21951. result[j] = (t4 ^= result[j - 16]);
  21952. j++;
  21953. }
  21954. }
  21955. return result;
  21956. }
  21957. function decrypt128(input, key) {
  21958. var state = new Uint8Array(16);
  21959. state.set(input);
  21960. var i, j, k;
  21961. var t, u, v;
  21962. // AddRoundKey
  21963. for (j = 0, k = 160; j < 16; ++j, ++k) {
  21964. state[j] ^= key[k];
  21965. }
  21966. for (i = 9; i >= 1; --i) {
  21967. // InvShiftRows
  21968. t = state[13];
  21969. state[13] = state[9];
  21970. state[9] = state[5];
  21971. state[5] = state[1];
  21972. state[1] = t;
  21973. t = state[14];
  21974. u = state[10];
  21975. state[14] = state[6];
  21976. state[10] = state[2];
  21977. state[6] = t;
  21978. state[2] = u;
  21979. t = state[15];
  21980. u = state[11];
  21981. v = state[7];
  21982. state[15] = state[3];
  21983. state[11] = t;
  21984. state[7] = u;
  21985. state[3] = v;
  21986. // InvSubBytes
  21987. for (j = 0; j < 16; ++j) {
  21988. state[j] = inv_s[state[j]];
  21989. }
  21990. // AddRoundKey
  21991. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  21992. state[j] ^= key[k];
  21993. }
  21994. // InvMixColumns
  21995. for (j = 0; j < 16; j += 4) {
  21996. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  21997. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  21998. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  21999. (s3 >>> 24) ^ (s3 << 8));
  22000. state[j] = (t >>> 24) & 0xFF;
  22001. state[j + 1] = (t >> 16) & 0xFF;
  22002. state[j + 2] = (t >> 8) & 0xFF;
  22003. state[j + 3] = t & 0xFF;
  22004. }
  22005. }
  22006. // InvShiftRows
  22007. t = state[13];
  22008. state[13] = state[9];
  22009. state[9] = state[5];
  22010. state[5] = state[1];
  22011. state[1] = t;
  22012. t = state[14];
  22013. u = state[10];
  22014. state[14] = state[6];
  22015. state[10] = state[2];
  22016. state[6] = t;
  22017. state[2] = u;
  22018. t = state[15];
  22019. u = state[11];
  22020. v = state[7];
  22021. state[15] = state[3];
  22022. state[11] = t;
  22023. state[7] = u;
  22024. state[3] = v;
  22025. for (j = 0; j < 16; ++j) {
  22026. // InvSubBytes
  22027. state[j] = inv_s[state[j]];
  22028. // AddRoundKey
  22029. state[j] ^= key[j];
  22030. }
  22031. return state;
  22032. }
  22033. function encrypt128(input, key) {
  22034. var t, u, v, k;
  22035. var state = new Uint8Array(16);
  22036. state.set(input);
  22037. for (j = 0; j < 16; ++j) {
  22038. // AddRoundKey
  22039. state[j] ^= key[j];
  22040. }
  22041. for (i = 1; i < 10; i++) {
  22042. //SubBytes
  22043. for (j = 0; j < 16; ++j) {
  22044. state[j] = s[state[j]];
  22045. }
  22046. //ShiftRows
  22047. v = state[1];
  22048. state[1] = state[5];
  22049. state[5] = state[9];
  22050. state[9] = state[13];
  22051. state[13] = v;
  22052. v = state[2];
  22053. u = state[6];
  22054. state[2] = state[10];
  22055. state[6] = state[14];
  22056. state[10] = v;
  22057. state[14] = u;
  22058. v = state[3];
  22059. u = state[7];
  22060. t = state[11];
  22061. state[3] = state[15];
  22062. state[7] = v;
  22063. state[11] = u;
  22064. state[15] = t;
  22065. //MixColumns
  22066. for (var j = 0; j < 16; j += 4) {
  22067. var s0 = state[j + 0], s1 = state[j + 1];
  22068. var s2 = state[j + 2], s3 = state[j + 3];
  22069. t = s0 ^ s1 ^ s2 ^ s3;
  22070. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  22071. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  22072. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  22073. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  22074. }
  22075. //AddRoundKey
  22076. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  22077. state[j] ^= key[k];
  22078. }
  22079. }
  22080. //SubBytes
  22081. for (j = 0; j < 16; ++j) {
  22082. state[j] = s[state[j]];
  22083. }
  22084. //ShiftRows
  22085. v = state[1];
  22086. state[1] = state[5];
  22087. state[5] = state[9];
  22088. state[9] = state[13];
  22089. state[13] = v;
  22090. v = state[2];
  22091. u = state[6];
  22092. state[2] = state[10];
  22093. state[6] = state[14];
  22094. state[10] = v;
  22095. state[14] = u;
  22096. v = state[3];
  22097. u = state[7];
  22098. t = state[11];
  22099. state[3] = state[15];
  22100. state[7] = v;
  22101. state[11] = u;
  22102. state[15] = t;
  22103. //AddRoundKey
  22104. for (j = 0, k = 160; j < 16; ++j, ++k) {
  22105. state[j] ^= key[k];
  22106. }
  22107. return state;
  22108. }
  22109. function AES128Cipher(key) {
  22110. this.key = expandKey128(key);
  22111. this.buffer = new Uint8Array(16);
  22112. this.bufferPosition = 0;
  22113. }
  22114. function decryptBlock2(data, finalize) {
  22115. var i, j, ii, sourceLength = data.length,
  22116. buffer = this.buffer, bufferLength = this.bufferPosition,
  22117. result = [], iv = this.iv;
  22118. for (i = 0; i < sourceLength; ++i) {
  22119. buffer[bufferLength] = data[i];
  22120. ++bufferLength;
  22121. if (bufferLength < 16) {
  22122. continue;
  22123. }
  22124. // buffer is full, decrypting
  22125. var plain = decrypt128(buffer, this.key);
  22126. // xor-ing the IV vector to get plain text
  22127. for (j = 0; j < 16; ++j) {
  22128. plain[j] ^= iv[j];
  22129. }
  22130. iv = buffer;
  22131. result.push(plain);
  22132. buffer = new Uint8Array(16);
  22133. bufferLength = 0;
  22134. }
  22135. // saving incomplete buffer
  22136. this.buffer = buffer;
  22137. this.bufferLength = bufferLength;
  22138. this.iv = iv;
  22139. if (result.length === 0) {
  22140. return new Uint8Array([]);
  22141. }
  22142. // combining plain text blocks into one
  22143. var outputLength = 16 * result.length;
  22144. if (finalize) {
  22145. // undo a padding that is described in RFC 2898
  22146. var lastBlock = result[result.length - 1];
  22147. var psLen = lastBlock[15];
  22148. if (psLen <= 16) {
  22149. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  22150. if (lastBlock[i] !== psLen) {
  22151. // Invalid padding, assume that the block has no padding.
  22152. psLen = 0;
  22153. break;
  22154. }
  22155. }
  22156. outputLength -= psLen;
  22157. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  22158. }
  22159. }
  22160. var output = new Uint8Array(outputLength);
  22161. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  22162. output.set(result[i], j);
  22163. }
  22164. return output;
  22165. }
  22166. AES128Cipher.prototype = {
  22167. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  22168. var i, sourceLength = data.length;
  22169. var buffer = this.buffer, bufferLength = this.bufferPosition;
  22170. // waiting for IV values -- they are at the start of the stream
  22171. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  22172. buffer[bufferLength] = data[i];
  22173. }
  22174. if (bufferLength < 16) {
  22175. // need more data
  22176. this.bufferLength = bufferLength;
  22177. return new Uint8Array([]);
  22178. }
  22179. this.iv = buffer;
  22180. this.buffer = new Uint8Array(16);
  22181. this.bufferLength = 0;
  22182. // starting decryption
  22183. this.decryptBlock = decryptBlock2;
  22184. return this.decryptBlock(data.subarray(16), finalize);
  22185. },
  22186. encrypt: function AES128Cipher_encrypt(data, iv) {
  22187. var i, j, ii, sourceLength = data.length,
  22188. buffer = this.buffer, bufferLength = this.bufferPosition,
  22189. result = [];
  22190. if (!iv) {
  22191. iv = new Uint8Array(16);
  22192. }
  22193. for (i = 0; i < sourceLength; ++i) {
  22194. buffer[bufferLength] = data[i];
  22195. ++bufferLength;
  22196. if (bufferLength < 16) {
  22197. continue;
  22198. }
  22199. for (j = 0; j < 16; ++j) {
  22200. buffer[j] ^= iv[j];
  22201. }
  22202. // buffer is full, encrypting
  22203. var cipher = encrypt128(buffer, this.key);
  22204. iv = cipher;
  22205. result.push(cipher);
  22206. buffer = new Uint8Array(16);
  22207. bufferLength = 0;
  22208. }
  22209. // saving incomplete buffer
  22210. this.buffer = buffer;
  22211. this.bufferLength = bufferLength;
  22212. this.iv = iv;
  22213. if (result.length === 0) {
  22214. return new Uint8Array([]);
  22215. }
  22216. // combining plain text blocks into one
  22217. var outputLength = 16 * result.length;
  22218. var output = new Uint8Array(outputLength);
  22219. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  22220. output.set(result[i], j);
  22221. }
  22222. return output;
  22223. }
  22224. };
  22225. return AES128Cipher;
  22226. })();
  22227. var AES256Cipher = (function AES256CipherClosure() {
  22228. var rcon = new Uint8Array([
  22229. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  22230. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  22231. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  22232. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  22233. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  22234. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  22235. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  22236. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  22237. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  22238. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  22239. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  22240. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  22241. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  22242. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  22243. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  22244. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  22245. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  22246. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  22247. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  22248. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  22249. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  22250. 0x74, 0xe8, 0xcb, 0x8d]);
  22251. var s = new Uint8Array([
  22252. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  22253. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  22254. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  22255. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  22256. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  22257. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  22258. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  22259. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  22260. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  22261. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  22262. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  22263. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  22264. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  22265. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  22266. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  22267. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  22268. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  22269. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  22270. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  22271. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  22272. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  22273. 0xb0, 0x54, 0xbb, 0x16]);
  22274. var inv_s = new Uint8Array([
  22275. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  22276. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  22277. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  22278. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  22279. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  22280. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  22281. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  22282. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  22283. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  22284. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  22285. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  22286. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  22287. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  22288. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  22289. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  22290. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  22291. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  22292. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  22293. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  22294. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  22295. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  22296. 0x55, 0x21, 0x0c, 0x7d]);
  22297. var mixCol = new Uint8Array(256);
  22298. for (var i = 0; i < 256; i++) {
  22299. if (i < 128) {
  22300. mixCol[i] = i << 1;
  22301. } else {
  22302. mixCol[i] = (i << 1) ^ 0x1b;
  22303. }
  22304. }
  22305. var mix = new Uint32Array([
  22306. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  22307. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  22308. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  22309. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  22310. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  22311. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  22312. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  22313. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  22314. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  22315. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  22316. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  22317. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  22318. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  22319. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  22320. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  22321. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  22322. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  22323. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  22324. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  22325. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  22326. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  22327. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  22328. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  22329. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  22330. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  22331. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  22332. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  22333. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  22334. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  22335. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  22336. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  22337. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  22338. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  22339. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  22340. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  22341. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  22342. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  22343. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  22344. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  22345. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  22346. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  22347. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  22348. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  22349. function expandKey256(cipherKey) {
  22350. var b = 240, result = new Uint8Array(b);
  22351. var r = 1;
  22352. result.set(cipherKey);
  22353. for (var j = 32, i = 1; j < b; ++i) {
  22354. if (j % 32 === 16) {
  22355. t1 = s[t1];
  22356. t2 = s[t2];
  22357. t3 = s[t3];
  22358. t4 = s[t4];
  22359. } else if (j % 32 === 0) {
  22360. // RotWord
  22361. var t1 = result[j - 3], t2 = result[j - 2],
  22362. t3 = result[j - 1], t4 = result[j - 4];
  22363. // SubWord
  22364. t1 = s[t1];
  22365. t2 = s[t2];
  22366. t3 = s[t3];
  22367. t4 = s[t4];
  22368. // Rcon
  22369. t1 = t1 ^ r;
  22370. if ((r <<= 1) >= 256) {
  22371. r = (r ^ 0x1b) & 0xFF;
  22372. }
  22373. }
  22374. for (var n = 0; n < 4; ++n) {
  22375. result[j] = (t1 ^= result[j - 32]);
  22376. j++;
  22377. result[j] = (t2 ^= result[j - 32]);
  22378. j++;
  22379. result[j] = (t3 ^= result[j - 32]);
  22380. j++;
  22381. result[j] = (t4 ^= result[j - 32]);
  22382. j++;
  22383. }
  22384. }
  22385. return result;
  22386. }
  22387. function decrypt256(input, key) {
  22388. var state = new Uint8Array(16);
  22389. state.set(input);
  22390. var i, j, k;
  22391. var t, u, v;
  22392. // AddRoundKey
  22393. for (j = 0, k = 224; j < 16; ++j, ++k) {
  22394. state[j] ^= key[k];
  22395. }
  22396. for (i = 13; i >= 1; --i) {
  22397. // InvShiftRows
  22398. t = state[13];
  22399. state[13] = state[9];
  22400. state[9] = state[5];
  22401. state[5] = state[1];
  22402. state[1] = t;
  22403. t = state[14];
  22404. u = state[10];
  22405. state[14] = state[6];
  22406. state[10] = state[2];
  22407. state[6] = t;
  22408. state[2] = u;
  22409. t = state[15];
  22410. u = state[11];
  22411. v = state[7];
  22412. state[15] = state[3];
  22413. state[11] = t;
  22414. state[7] = u;
  22415. state[3] = v;
  22416. // InvSubBytes
  22417. for (j = 0; j < 16; ++j) {
  22418. state[j] = inv_s[state[j]];
  22419. }
  22420. // AddRoundKey
  22421. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  22422. state[j] ^= key[k];
  22423. }
  22424. // InvMixColumns
  22425. for (j = 0; j < 16; j += 4) {
  22426. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  22427. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  22428. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  22429. (s3 >>> 24) ^ (s3 << 8));
  22430. state[j] = (t >>> 24) & 0xFF;
  22431. state[j + 1] = (t >> 16) & 0xFF;
  22432. state[j + 2] = (t >> 8) & 0xFF;
  22433. state[j + 3] = t & 0xFF;
  22434. }
  22435. }
  22436. // InvShiftRows
  22437. t = state[13];
  22438. state[13] = state[9];
  22439. state[9] = state[5];
  22440. state[5] = state[1];
  22441. state[1] = t;
  22442. t = state[14];
  22443. u = state[10];
  22444. state[14] = state[6];
  22445. state[10] = state[2];
  22446. state[6] = t;
  22447. state[2] = u;
  22448. t = state[15];
  22449. u = state[11];
  22450. v = state[7];
  22451. state[15] = state[3];
  22452. state[11] = t;
  22453. state[7] = u;
  22454. state[3] = v;
  22455. for (j = 0; j < 16; ++j) {
  22456. // InvSubBytes
  22457. state[j] = inv_s[state[j]];
  22458. // AddRoundKey
  22459. state[j] ^= key[j];
  22460. }
  22461. return state;
  22462. }
  22463. function encrypt256(input, key) {
  22464. var t, u, v, k;
  22465. var state = new Uint8Array(16);
  22466. state.set(input);
  22467. for (j = 0; j < 16; ++j) {
  22468. // AddRoundKey
  22469. state[j] ^= key[j];
  22470. }
  22471. for (i = 1; i < 14; i++) {
  22472. //SubBytes
  22473. for (j = 0; j < 16; ++j) {
  22474. state[j] = s[state[j]];
  22475. }
  22476. //ShiftRows
  22477. v = state[1];
  22478. state[1] = state[5];
  22479. state[5] = state[9];
  22480. state[9] = state[13];
  22481. state[13] = v;
  22482. v = state[2];
  22483. u = state[6];
  22484. state[2] = state[10];
  22485. state[6] = state[14];
  22486. state[10] = v;
  22487. state[14] = u;
  22488. v = state[3];
  22489. u = state[7];
  22490. t = state[11];
  22491. state[3] = state[15];
  22492. state[7] = v;
  22493. state[11] = u;
  22494. state[15] = t;
  22495. //MixColumns
  22496. for (var j = 0; j < 16; j += 4) {
  22497. var s0 = state[j + 0], s1 = state[j + 1];
  22498. var s2 = state[j + 2], s3 = state[j + 3];
  22499. t = s0 ^ s1 ^ s2 ^ s3;
  22500. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  22501. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  22502. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  22503. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  22504. }
  22505. //AddRoundKey
  22506. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  22507. state[j] ^= key[k];
  22508. }
  22509. }
  22510. //SubBytes
  22511. for (j = 0; j < 16; ++j) {
  22512. state[j] = s[state[j]];
  22513. }
  22514. //ShiftRows
  22515. v = state[1];
  22516. state[1] = state[5];
  22517. state[5] = state[9];
  22518. state[9] = state[13];
  22519. state[13] = v;
  22520. v = state[2];
  22521. u = state[6];
  22522. state[2] = state[10];
  22523. state[6] = state[14];
  22524. state[10] = v;
  22525. state[14] = u;
  22526. v = state[3];
  22527. u = state[7];
  22528. t = state[11];
  22529. state[3] = state[15];
  22530. state[7] = v;
  22531. state[11] = u;
  22532. state[15] = t;
  22533. //AddRoundKey
  22534. for (j = 0, k = 224; j < 16; ++j, ++k) {
  22535. state[j] ^= key[k];
  22536. }
  22537. return state;
  22538. }
  22539. function AES256Cipher(key) {
  22540. this.key = expandKey256(key);
  22541. this.buffer = new Uint8Array(16);
  22542. this.bufferPosition = 0;
  22543. }
  22544. function decryptBlock2(data, finalize) {
  22545. var i, j, ii, sourceLength = data.length,
  22546. buffer = this.buffer, bufferLength = this.bufferPosition,
  22547. result = [], iv = this.iv;
  22548. for (i = 0; i < sourceLength; ++i) {
  22549. buffer[bufferLength] = data[i];
  22550. ++bufferLength;
  22551. if (bufferLength < 16) {
  22552. continue;
  22553. }
  22554. // buffer is full, decrypting
  22555. var plain = decrypt256(buffer, this.key);
  22556. // xor-ing the IV vector to get plain text
  22557. for (j = 0; j < 16; ++j) {
  22558. plain[j] ^= iv[j];
  22559. }
  22560. iv = buffer;
  22561. result.push(plain);
  22562. buffer = new Uint8Array(16);
  22563. bufferLength = 0;
  22564. }
  22565. // saving incomplete buffer
  22566. this.buffer = buffer;
  22567. this.bufferLength = bufferLength;
  22568. this.iv = iv;
  22569. if (result.length === 0) {
  22570. return new Uint8Array([]);
  22571. }
  22572. // combining plain text blocks into one
  22573. var outputLength = 16 * result.length;
  22574. if (finalize) {
  22575. // undo a padding that is described in RFC 2898
  22576. var lastBlock = result[result.length - 1];
  22577. var psLen = lastBlock[15];
  22578. if (psLen <= 16) {
  22579. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  22580. if (lastBlock[i] !== psLen) {
  22581. // Invalid padding, assume that the block has no padding.
  22582. psLen = 0;
  22583. break;
  22584. }
  22585. }
  22586. outputLength -= psLen;
  22587. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  22588. }
  22589. }
  22590. var output = new Uint8Array(outputLength);
  22591. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  22592. output.set(result[i], j);
  22593. }
  22594. return output;
  22595. }
  22596. AES256Cipher.prototype = {
  22597. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  22598. var i, sourceLength = data.length;
  22599. var buffer = this.buffer, bufferLength = this.bufferPosition;
  22600. // if not supplied an IV wait for IV values
  22601. // they are at the start of the stream
  22602. if (iv) {
  22603. this.iv = iv;
  22604. } else {
  22605. for (i = 0; bufferLength < 16 &&
  22606. i < sourceLength; ++i, ++bufferLength) {
  22607. buffer[bufferLength] = data[i];
  22608. }
  22609. if (bufferLength < 16) {
  22610. //need more data
  22611. this.bufferLength = bufferLength;
  22612. return new Uint8Array([]);
  22613. }
  22614. this.iv = buffer;
  22615. data = data.subarray(16);
  22616. }
  22617. this.buffer = new Uint8Array(16);
  22618. this.bufferLength = 0;
  22619. // starting decryption
  22620. this.decryptBlock = decryptBlock2;
  22621. return this.decryptBlock(data, finalize);
  22622. },
  22623. encrypt: function AES256Cipher_encrypt(data, iv) {
  22624. var i, j, ii, sourceLength = data.length,
  22625. buffer = this.buffer, bufferLength = this.bufferPosition,
  22626. result = [];
  22627. if (!iv) {
  22628. iv = new Uint8Array(16);
  22629. }
  22630. for (i = 0; i < sourceLength; ++i) {
  22631. buffer[bufferLength] = data[i];
  22632. ++bufferLength;
  22633. if (bufferLength < 16) {
  22634. continue;
  22635. }
  22636. for (j = 0; j < 16; ++j) {
  22637. buffer[j] ^= iv[j];
  22638. }
  22639. // buffer is full, encrypting
  22640. var cipher = encrypt256(buffer, this.key);
  22641. this.iv = cipher;
  22642. result.push(cipher);
  22643. buffer = new Uint8Array(16);
  22644. bufferLength = 0;
  22645. }
  22646. // saving incomplete buffer
  22647. this.buffer = buffer;
  22648. this.bufferLength = bufferLength;
  22649. this.iv = iv;
  22650. if (result.length === 0) {
  22651. return new Uint8Array([]);
  22652. }
  22653. // combining plain text blocks into one
  22654. var outputLength = 16 * result.length;
  22655. var output = new Uint8Array(outputLength);
  22656. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  22657. output.set(result[i], j);
  22658. }
  22659. return output;
  22660. }
  22661. };
  22662. return AES256Cipher;
  22663. })();
  22664. var PDF17 = (function PDF17Closure() {
  22665. function compareByteArrays(array1, array2) {
  22666. if (array1.length !== array2.length) {
  22667. return false;
  22668. }
  22669. for (var i = 0; i < array1.length; i++) {
  22670. if (array1[i] !== array2[i]) {
  22671. return false;
  22672. }
  22673. }
  22674. return true;
  22675. }
  22676. function PDF17() {
  22677. }
  22678. PDF17.prototype = {
  22679. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  22680. ownerValidationSalt,
  22681. userBytes,
  22682. ownerPassword) {
  22683. var hashData = new Uint8Array(password.length + 56);
  22684. hashData.set(password, 0);
  22685. hashData.set(ownerValidationSalt, password.length);
  22686. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  22687. var result = calculateSHA256(hashData, 0, hashData.length);
  22688. return compareByteArrays(result, ownerPassword);
  22689. },
  22690. checkUserPassword: function PDF17_checkUserPassword(password,
  22691. userValidationSalt,
  22692. userPassword) {
  22693. var hashData = new Uint8Array(password.length + 8);
  22694. hashData.set(password, 0);
  22695. hashData.set(userValidationSalt, password.length);
  22696. var result = calculateSHA256(hashData, 0, hashData.length);
  22697. return compareByteArrays(result, userPassword);
  22698. },
  22699. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  22700. ownerEncryption) {
  22701. var hashData = new Uint8Array(password.length + 56);
  22702. hashData.set(password, 0);
  22703. hashData.set(ownerKeySalt, password.length);
  22704. hashData.set(userBytes, password.length + ownerKeySalt.length);
  22705. var key = calculateSHA256(hashData, 0, hashData.length);
  22706. var cipher = new AES256Cipher(key);
  22707. return cipher.decryptBlock(ownerEncryption,
  22708. false,
  22709. new Uint8Array(16));
  22710. },
  22711. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  22712. userEncryption) {
  22713. var hashData = new Uint8Array(password.length + 8);
  22714. hashData.set(password, 0);
  22715. hashData.set(userKeySalt, password.length);
  22716. //key is the decryption key for the UE string
  22717. var key = calculateSHA256(hashData, 0, hashData.length);
  22718. var cipher = new AES256Cipher(key);
  22719. return cipher.decryptBlock(userEncryption,
  22720. false,
  22721. new Uint8Array(16));
  22722. }
  22723. };
  22724. return PDF17;
  22725. })();
  22726. var PDF20 = (function PDF20Closure() {
  22727. function concatArrays(array1, array2) {
  22728. var t = new Uint8Array(array1.length + array2.length);
  22729. t.set(array1, 0);
  22730. t.set(array2, array1.length);
  22731. return t;
  22732. }
  22733. function calculatePDF20Hash(password, input, userBytes) {
  22734. //This refers to Algorithm 2.B as defined in ISO 32000-2
  22735. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  22736. var e = [0];
  22737. var i = 0;
  22738. while (i < 64 || e[e.length - 1] > i - 32) {
  22739. var arrayLength = password.length + k.length + userBytes.length;
  22740. var k1 = new Uint8Array(arrayLength * 64);
  22741. var array = concatArrays(password, k);
  22742. array = concatArrays(array, userBytes);
  22743. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  22744. k1.set(array, pos);
  22745. }
  22746. //AES128 CBC NO PADDING with
  22747. //first 16 bytes of k as the key and the second 16 as the iv.
  22748. var cipher = new AES128Cipher(k.subarray(0, 16));
  22749. e = cipher.encrypt(k1, k.subarray(16, 32));
  22750. //Now we have to take the first 16 bytes of an unsigned
  22751. //big endian integer... and compute the remainder
  22752. //modulo 3.... That is a fairly large number and
  22753. //JavaScript isn't going to handle that well...
  22754. //So we're using a trick that allows us to perform
  22755. //modulo math byte by byte
  22756. var remainder = 0;
  22757. for (var z = 0; z < 16; z++) {
  22758. remainder *= (256 % 3);
  22759. remainder %= 3;
  22760. remainder += ((e[z] >>> 0) % 3);
  22761. remainder %= 3;
  22762. }
  22763. if (remainder === 0) {
  22764. k = calculateSHA256(e, 0, e.length);
  22765. }
  22766. else if (remainder === 1) {
  22767. k = calculateSHA384(e, 0, e.length);
  22768. }
  22769. else if (remainder === 2) {
  22770. k = calculateSHA512(e, 0, e.length);
  22771. }
  22772. i++;
  22773. }
  22774. return k.subarray(0, 32);
  22775. }
  22776. function PDF20() {
  22777. }
  22778. function compareByteArrays(array1, array2) {
  22779. if (array1.length !== array2.length) {
  22780. return false;
  22781. }
  22782. for (var i = 0; i < array1.length; i++) {
  22783. if (array1[i] !== array2[i]) {
  22784. return false;
  22785. }
  22786. }
  22787. return true;
  22788. }
  22789. PDF20.prototype = {
  22790. hash: function PDF20_hash(password, concatBytes, userBytes) {
  22791. return calculatePDF20Hash(password, concatBytes, userBytes);
  22792. },
  22793. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  22794. ownerValidationSalt,
  22795. userBytes,
  22796. ownerPassword) {
  22797. var hashData = new Uint8Array(password.length + 56);
  22798. hashData.set(password, 0);
  22799. hashData.set(ownerValidationSalt, password.length);
  22800. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  22801. var result = calculatePDF20Hash(password, hashData, userBytes);
  22802. return compareByteArrays(result, ownerPassword);
  22803. },
  22804. checkUserPassword: function PDF20_checkUserPassword(password,
  22805. userValidationSalt,
  22806. userPassword) {
  22807. var hashData = new Uint8Array(password.length + 8);
  22808. hashData.set(password, 0);
  22809. hashData.set(userValidationSalt, password.length);
  22810. var result = calculatePDF20Hash(password, hashData, []);
  22811. return compareByteArrays(result, userPassword);
  22812. },
  22813. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  22814. ownerEncryption) {
  22815. var hashData = new Uint8Array(password.length + 56);
  22816. hashData.set(password, 0);
  22817. hashData.set(ownerKeySalt, password.length);
  22818. hashData.set(userBytes, password.length + ownerKeySalt.length);
  22819. var key = calculatePDF20Hash(password, hashData, userBytes);
  22820. var cipher = new AES256Cipher(key);
  22821. return cipher.decryptBlock(ownerEncryption,
  22822. false,
  22823. new Uint8Array(16));
  22824. },
  22825. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  22826. userEncryption) {
  22827. var hashData = new Uint8Array(password.length + 8);
  22828. hashData.set(password, 0);
  22829. hashData.set(userKeySalt, password.length);
  22830. //key is the decryption key for the UE string
  22831. var key = calculatePDF20Hash(password, hashData, []);
  22832. var cipher = new AES256Cipher(key);
  22833. return cipher.decryptBlock(userEncryption,
  22834. false,
  22835. new Uint8Array(16));
  22836. }
  22837. };
  22838. return PDF20;
  22839. })();
  22840. var CipherTransform = (function CipherTransformClosure() {
  22841. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  22842. this.stringCipherConstructor = stringCipherConstructor;
  22843. this.streamCipherConstructor = streamCipherConstructor;
  22844. }
  22845. CipherTransform.prototype = {
  22846. createStream: function CipherTransform_createStream(stream, length) {
  22847. var cipher = new this.streamCipherConstructor();
  22848. return new DecryptStream(stream, length,
  22849. function cipherTransformDecryptStream(data, finalize) {
  22850. return cipher.decryptBlock(data, finalize);
  22851. }
  22852. );
  22853. },
  22854. decryptString: function CipherTransform_decryptString(s) {
  22855. var cipher = new this.stringCipherConstructor();
  22856. var data = stringToBytes(s);
  22857. data = cipher.decryptBlock(data, true);
  22858. return bytesToString(data);
  22859. }
  22860. };
  22861. return CipherTransform;
  22862. })();
  22863. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  22864. var defaultPasswordBytes = new Uint8Array([
  22865. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  22866. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  22867. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  22868. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  22869. function createEncryptionKey20(revision, password, ownerPassword,
  22870. ownerValidationSalt, ownerKeySalt, uBytes,
  22871. userPassword, userValidationSalt, userKeySalt,
  22872. ownerEncryption, userEncryption, perms) {
  22873. if (password) {
  22874. var passwordLength = Math.min(127, password.length);
  22875. password = password.subarray(0, passwordLength);
  22876. } else {
  22877. password = [];
  22878. }
  22879. var pdfAlgorithm;
  22880. if (revision === 6) {
  22881. pdfAlgorithm = new PDF20();
  22882. } else {
  22883. pdfAlgorithm = new PDF17();
  22884. }
  22885. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  22886. userPassword)) {
  22887. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  22888. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  22889. ownerValidationSalt,
  22890. uBytes,
  22891. ownerPassword)) {
  22892. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  22893. ownerEncryption);
  22894. }
  22895. return null;
  22896. }
  22897. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  22898. flags, revision, keyLength, encryptMetadata) {
  22899. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  22900. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  22901. if (password) {
  22902. n = Math.min(32, password.length);
  22903. for (; i < n; ++i) {
  22904. hashData[i] = password[i];
  22905. }
  22906. }
  22907. j = 0;
  22908. while (i < 32) {
  22909. hashData[i++] = defaultPasswordBytes[j++];
  22910. }
  22911. // as now the padded password in the hashData[0..i]
  22912. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  22913. hashData[i++] = ownerPassword[j];
  22914. }
  22915. hashData[i++] = flags & 0xFF;
  22916. hashData[i++] = (flags >> 8) & 0xFF;
  22917. hashData[i++] = (flags >> 16) & 0xFF;
  22918. hashData[i++] = (flags >>> 24) & 0xFF;
  22919. for (j = 0, n = fileId.length; j < n; ++j) {
  22920. hashData[i++] = fileId[j];
  22921. }
  22922. if (revision >= 4 && !encryptMetadata) {
  22923. hashData[i++] = 0xFF;
  22924. hashData[i++] = 0xFF;
  22925. hashData[i++] = 0xFF;
  22926. hashData[i++] = 0xFF;
  22927. }
  22928. var hash = calculateMD5(hashData, 0, i);
  22929. var keyLengthInBytes = keyLength >> 3;
  22930. if (revision >= 3) {
  22931. for (j = 0; j < 50; ++j) {
  22932. hash = calculateMD5(hash, 0, keyLengthInBytes);
  22933. }
  22934. }
  22935. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  22936. var cipher, checkData;
  22937. if (revision >= 3) {
  22938. for (i = 0; i < 32; ++i) {
  22939. hashData[i] = defaultPasswordBytes[i];
  22940. }
  22941. for (j = 0, n = fileId.length; j < n; ++j) {
  22942. hashData[i++] = fileId[j];
  22943. }
  22944. cipher = new ARCFourCipher(encryptionKey);
  22945. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  22946. n = encryptionKey.length;
  22947. var derivedKey = new Uint8Array(n), k;
  22948. for (j = 1; j <= 19; ++j) {
  22949. for (k = 0; k < n; ++k) {
  22950. derivedKey[k] = encryptionKey[k] ^ j;
  22951. }
  22952. cipher = new ARCFourCipher(derivedKey);
  22953. checkData = cipher.encryptBlock(checkData);
  22954. }
  22955. for (j = 0, n = checkData.length; j < n; ++j) {
  22956. if (userPassword[j] !== checkData[j]) {
  22957. return null;
  22958. }
  22959. }
  22960. } else {
  22961. cipher = new ARCFourCipher(encryptionKey);
  22962. checkData = cipher.encryptBlock(defaultPasswordBytes);
  22963. for (j = 0, n = checkData.length; j < n; ++j) {
  22964. if (userPassword[j] !== checkData[j]) {
  22965. return null;
  22966. }
  22967. }
  22968. }
  22969. return encryptionKey;
  22970. }
  22971. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  22972. var hashData = new Uint8Array(32), i = 0, j, n;
  22973. n = Math.min(32, password.length);
  22974. for (; i < n; ++i) {
  22975. hashData[i] = password[i];
  22976. }
  22977. j = 0;
  22978. while (i < 32) {
  22979. hashData[i++] = defaultPasswordBytes[j++];
  22980. }
  22981. var hash = calculateMD5(hashData, 0, i);
  22982. var keyLengthInBytes = keyLength >> 3;
  22983. if (revision >= 3) {
  22984. for (j = 0; j < 50; ++j) {
  22985. hash = calculateMD5(hash, 0, hash.length);
  22986. }
  22987. }
  22988. var cipher, userPassword;
  22989. if (revision >= 3) {
  22990. userPassword = ownerPassword;
  22991. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  22992. for (j = 19; j >= 0; j--) {
  22993. for (k = 0; k < keyLengthInBytes; ++k) {
  22994. derivedKey[k] = hash[k] ^ j;
  22995. }
  22996. cipher = new ARCFourCipher(derivedKey);
  22997. userPassword = cipher.encryptBlock(userPassword);
  22998. }
  22999. } else {
  23000. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  23001. userPassword = cipher.encryptBlock(ownerPassword);
  23002. }
  23003. return userPassword;
  23004. }
  23005. var identityName = Name.get('Identity');
  23006. function CipherTransformFactory(dict, fileId, password) {
  23007. var filter = dict.get('Filter');
  23008. if (!isName(filter, 'Standard')) {
  23009. error('unknown encryption method');
  23010. }
  23011. this.dict = dict;
  23012. var algorithm = dict.get('V');
  23013. if (!isInt(algorithm) ||
  23014. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  23015. algorithm !== 5)) {
  23016. error('unsupported encryption algorithm');
  23017. }
  23018. this.algorithm = algorithm;
  23019. var keyLength = dict.get('Length');
  23020. if (!keyLength) {
  23021. // Spec asks to rely on encryption dictionary's Length entry, however
  23022. // some PDFs don't have it. Trying to recover.
  23023. if (algorithm <= 3) {
  23024. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  23025. keyLength = 40;
  23026. } else {
  23027. // Trying to find default handler -- it usually has Length.
  23028. var cfDict = dict.get('CF');
  23029. var streamCryptoName = dict.get('StmF');
  23030. if (isDict(cfDict) && isName(streamCryptoName)) {
  23031. var handlerDict = cfDict.get(streamCryptoName.name);
  23032. keyLength = (handlerDict && handlerDict.get('Length')) || 128;
  23033. if (keyLength < 40) {
  23034. // Sometimes it's incorrect value of bits, generators specify bytes.
  23035. keyLength <<= 3;
  23036. }
  23037. }
  23038. }
  23039. }
  23040. if (!isInt(keyLength) ||
  23041. keyLength < 40 || (keyLength % 8) !== 0) {
  23042. error('invalid key length');
  23043. }
  23044. // prepare keys
  23045. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  23046. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  23047. var flags = dict.get('P');
  23048. var revision = dict.get('R');
  23049. // meaningful when V is 4 or 5
  23050. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  23051. dict.get('EncryptMetadata') !== false);
  23052. this.encryptMetadata = encryptMetadata;
  23053. var fileIdBytes = stringToBytes(fileId);
  23054. var passwordBytes;
  23055. if (password) {
  23056. if (revision === 6) {
  23057. try {
  23058. password = utf8StringToString(password);
  23059. } catch (ex) {
  23060. warn('CipherTransformFactory: ' +
  23061. 'Unable to convert UTF8 encoded password.');
  23062. }
  23063. }
  23064. passwordBytes = stringToBytes(password);
  23065. }
  23066. var encryptionKey;
  23067. if (algorithm !== 5) {
  23068. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  23069. ownerPassword, userPassword, flags,
  23070. revision, keyLength, encryptMetadata);
  23071. }
  23072. else {
  23073. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  23074. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  23075. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  23076. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  23077. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  23078. var ownerEncryption = stringToBytes(dict.get('OE'));
  23079. var userEncryption = stringToBytes(dict.get('UE'));
  23080. var perms = stringToBytes(dict.get('Perms'));
  23081. encryptionKey =
  23082. createEncryptionKey20(revision, passwordBytes,
  23083. ownerPassword, ownerValidationSalt,
  23084. ownerKeySalt, uBytes,
  23085. userPassword, userValidationSalt,
  23086. userKeySalt, ownerEncryption,
  23087. userEncryption, perms);
  23088. }
  23089. if (!encryptionKey && !password) {
  23090. throw new PasswordException('No password given',
  23091. PasswordResponses.NEED_PASSWORD);
  23092. } else if (!encryptionKey && password) {
  23093. // Attempting use the password as an owner password
  23094. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  23095. revision, keyLength);
  23096. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  23097. ownerPassword, userPassword, flags,
  23098. revision, keyLength, encryptMetadata);
  23099. }
  23100. if (!encryptionKey) {
  23101. throw new PasswordException('Incorrect Password',
  23102. PasswordResponses.INCORRECT_PASSWORD);
  23103. }
  23104. this.encryptionKey = encryptionKey;
  23105. if (algorithm >= 4) {
  23106. this.cf = dict.get('CF');
  23107. this.stmf = dict.get('StmF') || identityName;
  23108. this.strf = dict.get('StrF') || identityName;
  23109. this.eff = dict.get('EFF') || this.stmf;
  23110. }
  23111. }
  23112. function buildObjectKey(num, gen, encryptionKey, isAes) {
  23113. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  23114. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  23115. key[i] = encryptionKey[i];
  23116. }
  23117. key[i++] = num & 0xFF;
  23118. key[i++] = (num >> 8) & 0xFF;
  23119. key[i++] = (num >> 16) & 0xFF;
  23120. key[i++] = gen & 0xFF;
  23121. key[i++] = (gen >> 8) & 0xFF;
  23122. if (isAes) {
  23123. key[i++] = 0x73;
  23124. key[i++] = 0x41;
  23125. key[i++] = 0x6C;
  23126. key[i++] = 0x54;
  23127. }
  23128. var hash = calculateMD5(key, 0, i);
  23129. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  23130. }
  23131. function buildCipherConstructor(cf, name, num, gen, key) {
  23132. var cryptFilter = cf.get(name.name);
  23133. var cfm;
  23134. if (cryptFilter !== null && cryptFilter !== undefined) {
  23135. cfm = cryptFilter.get('CFM');
  23136. }
  23137. if (!cfm || cfm.name === 'None') {
  23138. return function cipherTransformFactoryBuildCipherConstructorNone() {
  23139. return new NullCipher();
  23140. };
  23141. }
  23142. if ('V2' === cfm.name) {
  23143. return function cipherTransformFactoryBuildCipherConstructorV2() {
  23144. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  23145. };
  23146. }
  23147. if ('AESV2' === cfm.name) {
  23148. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  23149. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  23150. };
  23151. }
  23152. if ('AESV3' === cfm.name) {
  23153. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  23154. return new AES256Cipher(key);
  23155. };
  23156. }
  23157. error('Unknown crypto method');
  23158. }
  23159. CipherTransformFactory.prototype = {
  23160. createCipherTransform:
  23161. function CipherTransformFactory_createCipherTransform(num, gen) {
  23162. if (this.algorithm === 4 || this.algorithm === 5) {
  23163. return new CipherTransform(
  23164. buildCipherConstructor(this.cf, this.stmf,
  23165. num, gen, this.encryptionKey),
  23166. buildCipherConstructor(this.cf, this.strf,
  23167. num, gen, this.encryptionKey));
  23168. }
  23169. // algorithms 1 and 2
  23170. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  23171. var cipherConstructor = function buildCipherCipherConstructor() {
  23172. return new ARCFourCipher(key);
  23173. };
  23174. return new CipherTransform(cipherConstructor, cipherConstructor);
  23175. }
  23176. };
  23177. return CipherTransformFactory;
  23178. })();
  23179. exports.AES128Cipher = AES128Cipher;
  23180. exports.AES256Cipher = AES256Cipher;
  23181. exports.ARCFourCipher = ARCFourCipher;
  23182. exports.CipherTransformFactory = CipherTransformFactory;
  23183. exports.PDF17 = PDF17;
  23184. exports.PDF20 = PDF20;
  23185. exports.calculateMD5 = calculateMD5;
  23186. exports.calculateSHA256 = calculateSHA256;
  23187. exports.calculateSHA384 = calculateSHA384;
  23188. exports.calculateSHA512 = calculateSHA512;
  23189. }));
  23190. (function (root, factory) {
  23191. {
  23192. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  23193. root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings,
  23194. root.pdfjsCoreCFFParser);
  23195. }
  23196. }(this, function (exports, sharedUtil, coreStream, coreGlyphList,
  23197. coreEncodings, coreCFFParser) {
  23198. var Util = sharedUtil.Util;
  23199. var bytesToString = sharedUtil.bytesToString;
  23200. var error = sharedUtil.error;
  23201. var Stream = coreStream.Stream;
  23202. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  23203. var StandardEncoding = coreEncodings.StandardEncoding;
  23204. var CFFParser = coreCFFParser.CFFParser;
  23205. var FontRendererFactory = (function FontRendererFactoryClosure() {
  23206. function getLong(data, offset) {
  23207. return (data[offset] << 24) | (data[offset + 1] << 16) |
  23208. (data[offset + 2] << 8) | data[offset + 3];
  23209. }
  23210. function getUshort(data, offset) {
  23211. return (data[offset] << 8) | data[offset + 1];
  23212. }
  23213. function parseCmap(data, start, end) {
  23214. var offset = (getUshort(data, start + 2) === 1 ?
  23215. getLong(data, start + 8) : getLong(data, start + 16));
  23216. var format = getUshort(data, start + offset);
  23217. var length, ranges, p, i;
  23218. if (format === 4) {
  23219. length = getUshort(data, start + offset + 2);
  23220. var segCount = getUshort(data, start + offset + 6) >> 1;
  23221. p = start + offset + 14;
  23222. ranges = [];
  23223. for (i = 0; i < segCount; i++, p += 2) {
  23224. ranges[i] = {end: getUshort(data, p)};
  23225. }
  23226. p += 2;
  23227. for (i = 0; i < segCount; i++, p += 2) {
  23228. ranges[i].start = getUshort(data, p);
  23229. }
  23230. for (i = 0; i < segCount; i++, p += 2) {
  23231. ranges[i].idDelta = getUshort(data, p);
  23232. }
  23233. for (i = 0; i < segCount; i++, p += 2) {
  23234. var idOffset = getUshort(data, p);
  23235. if (idOffset === 0) {
  23236. continue;
  23237. }
  23238. ranges[i].ids = [];
  23239. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  23240. ranges[i].ids[j] = getUshort(data, p + idOffset);
  23241. idOffset += 2;
  23242. }
  23243. }
  23244. return ranges;
  23245. } else if (format === 12) {
  23246. length = getLong(data, start + offset + 4);
  23247. var groups = getLong(data, start + offset + 12);
  23248. p = start + offset + 16;
  23249. ranges = [];
  23250. for (i = 0; i < groups; i++) {
  23251. ranges.push({
  23252. start: getLong(data, p),
  23253. end: getLong(data, p + 4),
  23254. idDelta: getLong(data, p + 8) - getLong(data, p)
  23255. });
  23256. p += 12;
  23257. }
  23258. return ranges;
  23259. }
  23260. error('not supported cmap: ' + format);
  23261. }
  23262. function parseCff(data, start, end, seacAnalysisEnabled) {
  23263. var properties = {};
  23264. var parser = new CFFParser(new Stream(data, start, end - start),
  23265. properties, seacAnalysisEnabled);
  23266. var cff = parser.parse();
  23267. return {
  23268. glyphs: cff.charStrings.objects,
  23269. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  23270. cff.topDict.privateDict.subrsIndex.objects),
  23271. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  23272. };
  23273. }
  23274. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  23275. var itemSize, itemDecode;
  23276. if (isGlyphLocationsLong) {
  23277. itemSize = 4;
  23278. itemDecode = function fontItemDecodeLong(data, offset) {
  23279. return (data[offset] << 24) | (data[offset + 1] << 16) |
  23280. (data[offset + 2] << 8) | data[offset + 3];
  23281. };
  23282. } else {
  23283. itemSize = 2;
  23284. itemDecode = function fontItemDecode(data, offset) {
  23285. return (data[offset] << 9) | (data[offset + 1] << 1);
  23286. };
  23287. }
  23288. var glyphs = [];
  23289. var startOffset = itemDecode(loca, 0);
  23290. for (var j = itemSize; j < loca.length; j += itemSize) {
  23291. var endOffset = itemDecode(loca, j);
  23292. glyphs.push(glyf.subarray(startOffset, endOffset));
  23293. startOffset = endOffset;
  23294. }
  23295. return glyphs;
  23296. }
  23297. function lookupCmap(ranges, unicode) {
  23298. var code = unicode.charCodeAt(0), gid = 0;
  23299. var l = 0, r = ranges.length - 1;
  23300. while (l < r) {
  23301. var c = (l + r + 1) >> 1;
  23302. if (code < ranges[c].start) {
  23303. r = c - 1;
  23304. } else {
  23305. l = c;
  23306. }
  23307. }
  23308. if (ranges[l].start <= code && code <= ranges[l].end) {
  23309. gid = (ranges[l].idDelta + (ranges[l].ids ?
  23310. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  23311. }
  23312. return {
  23313. charCode: code,
  23314. glyphId: gid,
  23315. };
  23316. }
  23317. function compileGlyf(code, cmds, font) {
  23318. function moveTo(x, y) {
  23319. cmds.push({cmd: 'moveTo', args: [x, y]});
  23320. }
  23321. function lineTo(x, y) {
  23322. cmds.push({cmd: 'lineTo', args: [x, y]});
  23323. }
  23324. function quadraticCurveTo(xa, ya, x, y) {
  23325. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  23326. }
  23327. var i = 0;
  23328. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23329. var flags;
  23330. var x = 0, y = 0;
  23331. i += 10;
  23332. if (numberOfContours < 0) {
  23333. // composite glyph
  23334. do {
  23335. flags = (code[i] << 8) | code[i + 1];
  23336. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  23337. i += 4;
  23338. var arg1, arg2;
  23339. if ((flags & 0x01)) {
  23340. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23341. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  23342. i += 4;
  23343. } else {
  23344. arg1 = code[i++]; arg2 = code[i++];
  23345. }
  23346. if ((flags & 0x02)) {
  23347. x = arg1;
  23348. y = arg2;
  23349. } else {
  23350. x = 0; y = 0; // TODO "they are points" ?
  23351. }
  23352. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  23353. if ((flags & 0x08)) {
  23354. scaleX =
  23355. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  23356. i += 2;
  23357. } else if ((flags & 0x40)) {
  23358. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  23359. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  23360. i += 4;
  23361. } else if ((flags & 0x80)) {
  23362. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  23363. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  23364. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  23365. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  23366. i += 8;
  23367. }
  23368. var subglyph = font.glyphs[glyphIndex];
  23369. if (subglyph) {
  23370. cmds.push({cmd: 'save'});
  23371. cmds.push({cmd: 'transform',
  23372. args: [scaleX, scale01, scale10, scaleY, x, y]});
  23373. compileGlyf(subglyph, cmds, font);
  23374. cmds.push({cmd: 'restore'});
  23375. }
  23376. } while ((flags & 0x20));
  23377. } else {
  23378. // simple glyph
  23379. var endPtsOfContours = [];
  23380. var j, jj;
  23381. for (j = 0; j < numberOfContours; j++) {
  23382. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  23383. i += 2;
  23384. }
  23385. var instructionLength = (code[i] << 8) | code[i + 1];
  23386. i += 2 + instructionLength; // skipping the instructions
  23387. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  23388. var points = [];
  23389. while (points.length < numberOfPoints) {
  23390. flags = code[i++];
  23391. var repeat = 1;
  23392. if ((flags & 0x08)) {
  23393. repeat += code[i++];
  23394. }
  23395. while (repeat-- > 0) {
  23396. points.push({flags: flags});
  23397. }
  23398. }
  23399. for (j = 0; j < numberOfPoints; j++) {
  23400. switch (points[j].flags & 0x12) {
  23401. case 0x00:
  23402. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23403. i += 2;
  23404. break;
  23405. case 0x02:
  23406. x -= code[i++];
  23407. break;
  23408. case 0x12:
  23409. x += code[i++];
  23410. break;
  23411. }
  23412. points[j].x = x;
  23413. }
  23414. for (j = 0; j < numberOfPoints; j++) {
  23415. switch (points[j].flags & 0x24) {
  23416. case 0x00:
  23417. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23418. i += 2;
  23419. break;
  23420. case 0x04:
  23421. y -= code[i++];
  23422. break;
  23423. case 0x24:
  23424. y += code[i++];
  23425. break;
  23426. }
  23427. points[j].y = y;
  23428. }
  23429. var startPoint = 0;
  23430. for (i = 0; i < numberOfContours; i++) {
  23431. var endPoint = endPtsOfContours[i];
  23432. // contours might have implicit points, which is located in the middle
  23433. // between two neighboring off-curve points
  23434. var contour = points.slice(startPoint, endPoint + 1);
  23435. if ((contour[0].flags & 1)) {
  23436. contour.push(contour[0]); // using start point at the contour end
  23437. } else if ((contour[contour.length - 1].flags & 1)) {
  23438. // first is off-curve point, trying to use one from the end
  23439. contour.unshift(contour[contour.length - 1]);
  23440. } else {
  23441. // start and end are off-curve points, creating implicit one
  23442. var p = {
  23443. flags: 1,
  23444. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  23445. y: (contour[0].y + contour[contour.length - 1].y) / 2
  23446. };
  23447. contour.unshift(p);
  23448. contour.push(p);
  23449. }
  23450. moveTo(contour[0].x, contour[0].y);
  23451. for (j = 1, jj = contour.length; j < jj; j++) {
  23452. if ((contour[j].flags & 1)) {
  23453. lineTo(contour[j].x, contour[j].y);
  23454. } else if ((contour[j + 1].flags & 1)){
  23455. quadraticCurveTo(contour[j].x, contour[j].y,
  23456. contour[j + 1].x, contour[j + 1].y);
  23457. j++;
  23458. } else {
  23459. quadraticCurveTo(contour[j].x, contour[j].y,
  23460. (contour[j].x + contour[j + 1].x) / 2,
  23461. (contour[j].y + contour[j + 1].y) / 2);
  23462. }
  23463. }
  23464. startPoint = endPoint + 1;
  23465. }
  23466. }
  23467. }
  23468. function compileCharString(code, cmds, font) {
  23469. var stack = [];
  23470. var x = 0, y = 0;
  23471. var stems = 0;
  23472. function moveTo(x, y) {
  23473. cmds.push({cmd: 'moveTo', args: [x, y]});
  23474. }
  23475. function lineTo(x, y) {
  23476. cmds.push({cmd: 'lineTo', args: [x, y]});
  23477. }
  23478. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  23479. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  23480. }
  23481. function parse(code) {
  23482. var i = 0;
  23483. while (i < code.length) {
  23484. var stackClean = false;
  23485. var v = code[i++];
  23486. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  23487. switch (v) {
  23488. case 1: // hstem
  23489. stems += stack.length >> 1;
  23490. stackClean = true;
  23491. break;
  23492. case 3: // vstem
  23493. stems += stack.length >> 1;
  23494. stackClean = true;
  23495. break;
  23496. case 4: // vmoveto
  23497. y += stack.pop();
  23498. moveTo(x, y);
  23499. stackClean = true;
  23500. break;
  23501. case 5: // rlineto
  23502. while (stack.length > 0) {
  23503. x += stack.shift();
  23504. y += stack.shift();
  23505. lineTo(x, y);
  23506. }
  23507. break;
  23508. case 6: // hlineto
  23509. while (stack.length > 0) {
  23510. x += stack.shift();
  23511. lineTo(x, y);
  23512. if (stack.length === 0) {
  23513. break;
  23514. }
  23515. y += stack.shift();
  23516. lineTo(x, y);
  23517. }
  23518. break;
  23519. case 7: // vlineto
  23520. while (stack.length > 0) {
  23521. y += stack.shift();
  23522. lineTo(x, y);
  23523. if (stack.length === 0) {
  23524. break;
  23525. }
  23526. x += stack.shift();
  23527. lineTo(x, y);
  23528. }
  23529. break;
  23530. case 8: // rrcurveto
  23531. while (stack.length > 0) {
  23532. xa = x + stack.shift(); ya = y + stack.shift();
  23533. xb = xa + stack.shift(); yb = ya + stack.shift();
  23534. x = xb + stack.shift(); y = yb + stack.shift();
  23535. bezierCurveTo(xa, ya, xb, yb, x, y);
  23536. }
  23537. break;
  23538. case 10: // callsubr
  23539. n = stack.pop() + font.subrsBias;
  23540. subrCode = font.subrs[n];
  23541. if (subrCode) {
  23542. parse(subrCode);
  23543. }
  23544. break;
  23545. case 11: // return
  23546. return;
  23547. case 12:
  23548. v = code[i++];
  23549. switch (v) {
  23550. case 34: // flex
  23551. xa = x + stack.shift();
  23552. xb = xa + stack.shift(); y1 = y + stack.shift();
  23553. x = xb + stack.shift();
  23554. bezierCurveTo(xa, y, xb, y1, x, y1);
  23555. xa = x + stack.shift();
  23556. xb = xa + stack.shift();
  23557. x = xb + stack.shift();
  23558. bezierCurveTo(xa, y1, xb, y, x, y);
  23559. break;
  23560. case 35: // flex
  23561. xa = x + stack.shift(); ya = y + stack.shift();
  23562. xb = xa + stack.shift(); yb = ya + stack.shift();
  23563. x = xb + stack.shift(); y = yb + stack.shift();
  23564. bezierCurveTo(xa, ya, xb, yb, x, y);
  23565. xa = x + stack.shift(); ya = y + stack.shift();
  23566. xb = xa + stack.shift(); yb = ya + stack.shift();
  23567. x = xb + stack.shift(); y = yb + stack.shift();
  23568. bezierCurveTo(xa, ya, xb, yb, x, y);
  23569. stack.pop(); // fd
  23570. break;
  23571. case 36: // hflex1
  23572. xa = x + stack.shift(); y1 = y + stack.shift();
  23573. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  23574. x = xb + stack.shift();
  23575. bezierCurveTo(xa, y1, xb, y2, x, y2);
  23576. xa = x + stack.shift();
  23577. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  23578. x = xb + stack.shift();
  23579. bezierCurveTo(xa, y2, xb, y3, x, y);
  23580. break;
  23581. case 37: // flex1
  23582. var x0 = x, y0 = y;
  23583. xa = x + stack.shift(); ya = y + stack.shift();
  23584. xb = xa + stack.shift(); yb = ya + stack.shift();
  23585. x = xb + stack.shift(); y = yb + stack.shift();
  23586. bezierCurveTo(xa, ya, xb, yb, x, y);
  23587. xa = x + stack.shift(); ya = y + stack.shift();
  23588. xb = xa + stack.shift(); yb = ya + stack.shift();
  23589. x = xb; y = yb;
  23590. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  23591. x += stack.shift();
  23592. } else {
  23593. y += stack.shift();
  23594. }
  23595. bezierCurveTo(xa, ya, xb, yb, x, y);
  23596. break;
  23597. default:
  23598. error('unknown operator: 12 ' + v);
  23599. }
  23600. break;
  23601. case 14: // endchar
  23602. if (stack.length >= 4) {
  23603. var achar = stack.pop();
  23604. var bchar = stack.pop();
  23605. y = stack.pop();
  23606. x = stack.pop();
  23607. cmds.push({cmd: 'save'});
  23608. cmds.push({cmd: 'translate', args: [x, y]});
  23609. var cmap = lookupCmap(font.cmap, String.fromCharCode(
  23610. font.glyphNameMap[StandardEncoding[achar]]));
  23611. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  23612. cmds.push({cmd: 'restore'});
  23613. cmap = lookupCmap(font.cmap, String.fromCharCode(
  23614. font.glyphNameMap[StandardEncoding[bchar]]));
  23615. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  23616. }
  23617. return;
  23618. case 18: // hstemhm
  23619. stems += stack.length >> 1;
  23620. stackClean = true;
  23621. break;
  23622. case 19: // hintmask
  23623. stems += stack.length >> 1;
  23624. i += (stems + 7) >> 3;
  23625. stackClean = true;
  23626. break;
  23627. case 20: // cntrmask
  23628. stems += stack.length >> 1;
  23629. i += (stems + 7) >> 3;
  23630. stackClean = true;
  23631. break;
  23632. case 21: // rmoveto
  23633. y += stack.pop();
  23634. x += stack.pop();
  23635. moveTo(x, y);
  23636. stackClean = true;
  23637. break;
  23638. case 22: // hmoveto
  23639. x += stack.pop();
  23640. moveTo(x, y);
  23641. stackClean = true;
  23642. break;
  23643. case 23: // vstemhm
  23644. stems += stack.length >> 1;
  23645. stackClean = true;
  23646. break;
  23647. case 24: // rcurveline
  23648. while (stack.length > 2) {
  23649. xa = x + stack.shift(); ya = y + stack.shift();
  23650. xb = xa + stack.shift(); yb = ya + stack.shift();
  23651. x = xb + stack.shift(); y = yb + stack.shift();
  23652. bezierCurveTo(xa, ya, xb, yb, x, y);
  23653. }
  23654. x += stack.shift();
  23655. y += stack.shift();
  23656. lineTo(x, y);
  23657. break;
  23658. case 25: // rlinecurve
  23659. while (stack.length > 6) {
  23660. x += stack.shift();
  23661. y += stack.shift();
  23662. lineTo(x, y);
  23663. }
  23664. xa = x + stack.shift(); ya = y + stack.shift();
  23665. xb = xa + stack.shift(); yb = ya + stack.shift();
  23666. x = xb + stack.shift(); y = yb + stack.shift();
  23667. bezierCurveTo(xa, ya, xb, yb, x, y);
  23668. break;
  23669. case 26: // vvcurveto
  23670. if (stack.length % 2) {
  23671. x += stack.shift();
  23672. }
  23673. while (stack.length > 0) {
  23674. xa = x; ya = y + stack.shift();
  23675. xb = xa + stack.shift(); yb = ya + stack.shift();
  23676. x = xb; y = yb + stack.shift();
  23677. bezierCurveTo(xa, ya, xb, yb, x, y);
  23678. }
  23679. break;
  23680. case 27: // hhcurveto
  23681. if (stack.length % 2) {
  23682. y += stack.shift();
  23683. }
  23684. while (stack.length > 0) {
  23685. xa = x + stack.shift(); ya = y;
  23686. xb = xa + stack.shift(); yb = ya + stack.shift();
  23687. x = xb + stack.shift(); y = yb;
  23688. bezierCurveTo(xa, ya, xb, yb, x, y);
  23689. }
  23690. break;
  23691. case 28:
  23692. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  23693. i += 2;
  23694. break;
  23695. case 29: // callgsubr
  23696. n = stack.pop() + font.gsubrsBias;
  23697. subrCode = font.gsubrs[n];
  23698. if (subrCode) {
  23699. parse(subrCode);
  23700. }
  23701. break;
  23702. case 30: // vhcurveto
  23703. while (stack.length > 0) {
  23704. xa = x; ya = y + stack.shift();
  23705. xb = xa + stack.shift(); yb = ya + stack.shift();
  23706. x = xb + stack.shift();
  23707. y = yb + (stack.length === 1 ? stack.shift() : 0);
  23708. bezierCurveTo(xa, ya, xb, yb, x, y);
  23709. if (stack.length === 0) {
  23710. break;
  23711. }
  23712. xa = x + stack.shift(); ya = y;
  23713. xb = xa + stack.shift(); yb = ya + stack.shift();
  23714. y = yb + stack.shift();
  23715. x = xb + (stack.length === 1 ? stack.shift() : 0);
  23716. bezierCurveTo(xa, ya, xb, yb, x, y);
  23717. }
  23718. break;
  23719. case 31: // hvcurveto
  23720. while (stack.length > 0) {
  23721. xa = x + stack.shift(); ya = y;
  23722. xb = xa + stack.shift(); yb = ya + stack.shift();
  23723. y = yb + stack.shift();
  23724. x = xb + (stack.length === 1 ? stack.shift() : 0);
  23725. bezierCurveTo(xa, ya, xb, yb, x, y);
  23726. if (stack.length === 0) {
  23727. break;
  23728. }
  23729. xa = x; ya = y + stack.shift();
  23730. xb = xa + stack.shift(); yb = ya + stack.shift();
  23731. x = xb + stack.shift();
  23732. y = yb + (stack.length === 1 ? stack.shift() : 0);
  23733. bezierCurveTo(xa, ya, xb, yb, x, y);
  23734. }
  23735. break;
  23736. default:
  23737. if (v < 32) {
  23738. error('unknown operator: ' + v);
  23739. }
  23740. if (v < 247) {
  23741. stack.push(v - 139);
  23742. } else if (v < 251) {
  23743. stack.push((v - 247) * 256 + code[i++] + 108);
  23744. } else if (v < 255) {
  23745. stack.push(-(v - 251) * 256 - code[i++] - 108);
  23746. } else {
  23747. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  23748. (code[i + 2] << 8) | code[i + 3]) / 65536);
  23749. i += 4;
  23750. }
  23751. break;
  23752. }
  23753. if (stackClean) {
  23754. stack.length = 0;
  23755. }
  23756. }
  23757. }
  23758. parse(code);
  23759. }
  23760. var noop = '';
  23761. function CompiledFont(fontMatrix) {
  23762. this.compiledGlyphs = Object.create(null);
  23763. this.compiledCharCodeToGlyphId = Object.create(null);
  23764. this.fontMatrix = fontMatrix;
  23765. }
  23766. CompiledFont.prototype = {
  23767. getPathJs: function (unicode) {
  23768. var cmap = lookupCmap(this.cmap, unicode);
  23769. var fn = this.compiledGlyphs[cmap.glyphId];
  23770. if (!fn) {
  23771. fn = this.compileGlyph(this.glyphs[cmap.glyphId]);
  23772. this.compiledGlyphs[cmap.glyphId] = fn;
  23773. }
  23774. if (this.compiledCharCodeToGlyphId[cmap.charCode] === undefined) {
  23775. this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
  23776. }
  23777. return fn;
  23778. },
  23779. compileGlyph: function (code) {
  23780. if (!code || code.length === 0 || code[0] === 14) {
  23781. return noop;
  23782. }
  23783. var cmds = [];
  23784. cmds.push({cmd: 'save'});
  23785. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  23786. cmds.push({cmd: 'scale', args: ['size', '-size']});
  23787. this.compileGlyphImpl(code, cmds);
  23788. cmds.push({cmd: 'restore'});
  23789. return cmds;
  23790. },
  23791. compileGlyphImpl: function () {
  23792. error('Children classes should implement this.');
  23793. },
  23794. hasBuiltPath: function (unicode) {
  23795. var cmap = lookupCmap(this.cmap, unicode);
  23796. return (this.compiledGlyphs[cmap.glyphId] !== undefined &&
  23797. this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined);
  23798. }
  23799. };
  23800. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  23801. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  23802. CompiledFont.call(this, fontMatrix);
  23803. this.glyphs = glyphs;
  23804. this.cmap = cmap;
  23805. }
  23806. Util.inherit(TrueTypeCompiled, CompiledFont, {
  23807. compileGlyphImpl: function (code, cmds) {
  23808. compileGlyf(code, cmds, this);
  23809. }
  23810. });
  23811. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  23812. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  23813. CompiledFont.call(this, fontMatrix);
  23814. this.glyphs = cffInfo.glyphs;
  23815. this.gsubrs = cffInfo.gsubrs || [];
  23816. this.subrs = cffInfo.subrs || [];
  23817. this.cmap = cmap;
  23818. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  23819. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  23820. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  23821. this.subrsBias = (this.subrs.length < 1240 ?
  23822. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  23823. }
  23824. Util.inherit(Type2Compiled, CompiledFont, {
  23825. compileGlyphImpl: function (code, cmds) {
  23826. compileCharString(code, cmds, this);
  23827. }
  23828. });
  23829. return {
  23830. create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
  23831. var data = new Uint8Array(font.data);
  23832. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  23833. var numTables = getUshort(data, 4);
  23834. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  23835. var tag = bytesToString(data.subarray(p, p + 4));
  23836. var offset = getLong(data, p + 8);
  23837. var length = getLong(data, p + 12);
  23838. switch (tag) {
  23839. case 'cmap':
  23840. cmap = parseCmap(data, offset, offset + length);
  23841. break;
  23842. case 'glyf':
  23843. glyf = data.subarray(offset, offset + length);
  23844. break;
  23845. case 'loca':
  23846. loca = data.subarray(offset, offset + length);
  23847. break;
  23848. case 'head':
  23849. unitsPerEm = getUshort(data, offset + 18);
  23850. indexToLocFormat = getUshort(data, offset + 50);
  23851. break;
  23852. case 'CFF ':
  23853. cff = parseCff(data, offset, offset + length, seacAnalysisEnabled);
  23854. break;
  23855. }
  23856. }
  23857. if (glyf) {
  23858. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  23859. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  23860. return new TrueTypeCompiled(
  23861. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  23862. } else {
  23863. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  23864. }
  23865. }
  23866. };
  23867. })();
  23868. exports.FontRendererFactory = FontRendererFactory;
  23869. }));
  23870. (function (root, factory) {
  23871. {
  23872. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  23873. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  23874. }
  23875. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  23876. var MissingDataException = sharedUtil.MissingDataException;
  23877. var StreamType = sharedUtil.StreamType;
  23878. var assert = sharedUtil.assert;
  23879. var error = sharedUtil.error;
  23880. var info = sharedUtil.info;
  23881. var isArray = sharedUtil.isArray;
  23882. var isInt = sharedUtil.isInt;
  23883. var isNum = sharedUtil.isNum;
  23884. var isString = sharedUtil.isString;
  23885. var warn = sharedUtil.warn;
  23886. var Cmd = corePrimitives.Cmd;
  23887. var Dict = corePrimitives.Dict;
  23888. var Name = corePrimitives.Name;
  23889. var Ref = corePrimitives.Ref;
  23890. var isCmd = corePrimitives.isCmd;
  23891. var isDict = corePrimitives.isDict;
  23892. var isName = corePrimitives.isName;
  23893. var Ascii85Stream = coreStream.Ascii85Stream;
  23894. var AsciiHexStream = coreStream.AsciiHexStream;
  23895. var CCITTFaxStream = coreStream.CCITTFaxStream;
  23896. var FlateStream = coreStream.FlateStream;
  23897. var Jbig2Stream = coreStream.Jbig2Stream;
  23898. var JpegStream = coreStream.JpegStream;
  23899. var JpxStream = coreStream.JpxStream;
  23900. var LZWStream = coreStream.LZWStream;
  23901. var NullStream = coreStream.NullStream;
  23902. var PredictorStream = coreStream.PredictorStream;
  23903. var RunLengthStream = coreStream.RunLengthStream;
  23904. var EOF = {};
  23905. function isEOF(v) {
  23906. return (v === EOF);
  23907. }
  23908. var MAX_LENGTH_TO_CACHE = 1000;
  23909. var Parser = (function ParserClosure() {
  23910. function Parser(lexer, allowStreams, xref, recoveryMode) {
  23911. this.lexer = lexer;
  23912. this.allowStreams = allowStreams;
  23913. this.xref = xref;
  23914. this.recoveryMode = recoveryMode || false;
  23915. this.imageCache = Object.create(null);
  23916. this.refill();
  23917. }
  23918. Parser.prototype = {
  23919. refill: function Parser_refill() {
  23920. this.buf1 = this.lexer.getObj();
  23921. this.buf2 = this.lexer.getObj();
  23922. },
  23923. shift: function Parser_shift() {
  23924. if (isCmd(this.buf2, 'ID')) {
  23925. this.buf1 = this.buf2;
  23926. this.buf2 = null;
  23927. } else {
  23928. this.buf1 = this.buf2;
  23929. this.buf2 = this.lexer.getObj();
  23930. }
  23931. },
  23932. tryShift: function Parser_tryShift() {
  23933. try {
  23934. this.shift();
  23935. return true;
  23936. } catch (e) {
  23937. if (e instanceof MissingDataException) {
  23938. throw e;
  23939. }
  23940. // Upon failure, the caller should reset this.lexer.pos to a known good
  23941. // state and call this.shift() twice to reset the buffers.
  23942. return false;
  23943. }
  23944. },
  23945. getObj: function Parser_getObj(cipherTransform) {
  23946. var buf1 = this.buf1;
  23947. this.shift();
  23948. if (buf1 instanceof Cmd) {
  23949. switch (buf1.cmd) {
  23950. case 'BI': // inline image
  23951. return this.makeInlineImage(cipherTransform);
  23952. case '[': // array
  23953. var array = [];
  23954. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  23955. array.push(this.getObj(cipherTransform));
  23956. }
  23957. if (isEOF(this.buf1)) {
  23958. if (!this.recoveryMode) {
  23959. error('End of file inside array');
  23960. }
  23961. return array;
  23962. }
  23963. this.shift();
  23964. return array;
  23965. case '<<': // dictionary or stream
  23966. var dict = new Dict(this.xref);
  23967. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  23968. if (!isName(this.buf1)) {
  23969. info('Malformed dictionary: key must be a name object');
  23970. this.shift();
  23971. continue;
  23972. }
  23973. var key = this.buf1.name;
  23974. this.shift();
  23975. if (isEOF(this.buf1)) {
  23976. break;
  23977. }
  23978. dict.set(key, this.getObj(cipherTransform));
  23979. }
  23980. if (isEOF(this.buf1)) {
  23981. if (!this.recoveryMode) {
  23982. error('End of file inside dictionary');
  23983. }
  23984. return dict;
  23985. }
  23986. // Stream objects are not allowed inside content streams or
  23987. // object streams.
  23988. if (isCmd(this.buf2, 'stream')) {
  23989. return (this.allowStreams ?
  23990. this.makeStream(dict, cipherTransform) : dict);
  23991. }
  23992. this.shift();
  23993. return dict;
  23994. default: // simple object
  23995. return buf1;
  23996. }
  23997. }
  23998. if (isInt(buf1)) { // indirect reference or integer
  23999. var num = buf1;
  24000. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  24001. var ref = new Ref(num, this.buf1);
  24002. this.shift();
  24003. this.shift();
  24004. return ref;
  24005. }
  24006. return num;
  24007. }
  24008. if (isString(buf1)) { // string
  24009. var str = buf1;
  24010. if (cipherTransform) {
  24011. str = cipherTransform.decryptString(str);
  24012. }
  24013. return str;
  24014. }
  24015. // simple object
  24016. return buf1;
  24017. },
  24018. /**
  24019. * Find the end of the stream by searching for the /EI\s/.
  24020. * @returns {number} The inline stream length.
  24021. */
  24022. findDefaultInlineStreamEnd:
  24023. function Parser_findDefaultInlineStreamEnd(stream) {
  24024. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  24025. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  24026. while ((ch = stream.getByte()) !== -1) {
  24027. if (state === 0) {
  24028. state = (ch === E) ? 1 : 0;
  24029. } else if (state === 1) {
  24030. state = (ch === I) ? 2 : 0;
  24031. } else {
  24032. assert(state === 2);
  24033. if (ch === SPACE || ch === LF || ch === CR) {
  24034. // Let's check the next five bytes are ASCII... just be sure.
  24035. n = 5;
  24036. followingBytes = stream.peekBytes(n);
  24037. for (i = 0; i < n; i++) {
  24038. ch = followingBytes[i];
  24039. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  24040. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  24041. // it's binary stuff. Resetting the state.
  24042. state = 0;
  24043. break;
  24044. }
  24045. }
  24046. if (state === 2) {
  24047. break; // Finished!
  24048. }
  24049. } else {
  24050. state = 0;
  24051. }
  24052. }
  24053. }
  24054. return ((stream.pos - 4) - startPos);
  24055. },
  24056. /**
  24057. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  24058. * @returns {number} The inline stream length.
  24059. */
  24060. findDCTDecodeInlineStreamEnd:
  24061. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  24062. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  24063. while ((b = stream.getByte()) !== -1) {
  24064. if (b !== 0xFF) { // Not a valid marker.
  24065. continue;
  24066. }
  24067. switch (stream.getByte()) {
  24068. case 0x00: // Byte stuffing.
  24069. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  24070. break;
  24071. case 0xFF: // Fill byte.
  24072. // Avoid skipping a valid marker, resetting the stream position.
  24073. stream.skip(-1);
  24074. break;
  24075. case 0xD9: // EOI
  24076. foundEOI = true;
  24077. break;
  24078. case 0xC0: // SOF0
  24079. case 0xC1: // SOF1
  24080. case 0xC2: // SOF2
  24081. case 0xC3: // SOF3
  24082. case 0xC5: // SOF5
  24083. case 0xC6: // SOF6
  24084. case 0xC7: // SOF7
  24085. case 0xC9: // SOF9
  24086. case 0xCA: // SOF10
  24087. case 0xCB: // SOF11
  24088. case 0xCD: // SOF13
  24089. case 0xCE: // SOF14
  24090. case 0xCF: // SOF15
  24091. case 0xC4: // DHT
  24092. case 0xCC: // DAC
  24093. case 0xDA: // SOS
  24094. case 0xDB: // DQT
  24095. case 0xDC: // DNL
  24096. case 0xDD: // DRI
  24097. case 0xDE: // DHP
  24098. case 0xDF: // EXP
  24099. case 0xE0: // APP0
  24100. case 0xE1: // APP1
  24101. case 0xE2: // APP2
  24102. case 0xE3: // APP3
  24103. case 0xE4: // APP4
  24104. case 0xE5: // APP5
  24105. case 0xE6: // APP6
  24106. case 0xE7: // APP7
  24107. case 0xE8: // APP8
  24108. case 0xE9: // APP9
  24109. case 0xEA: // APP10
  24110. case 0xEB: // APP11
  24111. case 0xEC: // APP12
  24112. case 0xED: // APP13
  24113. case 0xEE: // APP14
  24114. case 0xEF: // APP15
  24115. case 0xFE: // COM
  24116. // The marker should be followed by the length of the segment.
  24117. markerLength = stream.getUint16();
  24118. if (markerLength > 2) {
  24119. // |markerLength| contains the byte length of the marker segment,
  24120. // including its own length (2 bytes) and excluding the marker.
  24121. stream.skip(markerLength - 2); // Jump to the next marker.
  24122. } else {
  24123. // The marker length is invalid, resetting the stream position.
  24124. stream.skip(-2);
  24125. }
  24126. break;
  24127. }
  24128. if (foundEOI) {
  24129. break;
  24130. }
  24131. }
  24132. length = stream.pos - startPos;
  24133. if (b === -1) {
  24134. warn('Inline DCTDecode image stream: ' +
  24135. 'EOI marker not found, searching for /EI/ instead.');
  24136. stream.skip(-length); // Reset the stream position.
  24137. return this.findDefaultInlineStreamEnd(stream);
  24138. }
  24139. this.inlineStreamSkipEI(stream);
  24140. return length;
  24141. },
  24142. /**
  24143. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  24144. * @returns {number} The inline stream length.
  24145. */
  24146. findASCII85DecodeInlineStreamEnd:
  24147. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  24148. var TILDE = 0x7E, GT = 0x3E;
  24149. var startPos = stream.pos, ch, length;
  24150. while ((ch = stream.getByte()) !== -1) {
  24151. if (ch === TILDE && stream.peekByte() === GT) {
  24152. stream.skip();
  24153. break;
  24154. }
  24155. }
  24156. length = stream.pos - startPos;
  24157. if (ch === -1) {
  24158. warn('Inline ASCII85Decode 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. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  24168. * @returns {number} The inline stream length.
  24169. */
  24170. findASCIIHexDecodeInlineStreamEnd:
  24171. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  24172. var GT = 0x3E;
  24173. var startPos = stream.pos, ch, length;
  24174. while ((ch = stream.getByte()) !== -1) {
  24175. if (ch === GT) {
  24176. break;
  24177. }
  24178. }
  24179. length = stream.pos - startPos;
  24180. if (ch === -1) {
  24181. warn('Inline ASCIIHexDecode image stream: ' +
  24182. 'EOD marker not found, searching for /EI/ instead.');
  24183. stream.skip(-length); // Reset the stream position.
  24184. return this.findDefaultInlineStreamEnd(stream);
  24185. }
  24186. this.inlineStreamSkipEI(stream);
  24187. return length;
  24188. },
  24189. /**
  24190. * Skip over the /EI/ for streams where we search for an EOD marker.
  24191. */
  24192. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  24193. var E = 0x45, I = 0x49;
  24194. var state = 0, ch;
  24195. while ((ch = stream.getByte()) !== -1) {
  24196. if (state === 0) {
  24197. state = (ch === E) ? 1 : 0;
  24198. } else if (state === 1) {
  24199. state = (ch === I) ? 2 : 0;
  24200. } else if (state === 2) {
  24201. break;
  24202. }
  24203. }
  24204. },
  24205. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  24206. var lexer = this.lexer;
  24207. var stream = lexer.stream;
  24208. // Parse dictionary.
  24209. var dict = new Dict(this.xref);
  24210. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  24211. if (!isName(this.buf1)) {
  24212. error('Dictionary key must be a name object');
  24213. }
  24214. var key = this.buf1.name;
  24215. this.shift();
  24216. if (isEOF(this.buf1)) {
  24217. break;
  24218. }
  24219. dict.set(key, this.getObj(cipherTransform));
  24220. }
  24221. // Extract the name of the first (i.e. the current) image filter.
  24222. var filter = dict.get('Filter', 'F'), filterName;
  24223. if (isName(filter)) {
  24224. filterName = filter.name;
  24225. } else if (isArray(filter) && isName(filter[0])) {
  24226. filterName = filter[0].name;
  24227. }
  24228. // Parse image stream.
  24229. var startPos = stream.pos, length, i, ii;
  24230. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  24231. length = this.findDCTDecodeInlineStreamEnd(stream);
  24232. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  24233. length = this.findASCII85DecodeInlineStreamEnd(stream);
  24234. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  24235. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  24236. } else {
  24237. length = this.findDefaultInlineStreamEnd(stream);
  24238. }
  24239. var imageStream = stream.makeSubStream(startPos, length, dict);
  24240. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  24241. // adler32 checksum.
  24242. var adler32;
  24243. if (length < MAX_LENGTH_TO_CACHE) {
  24244. var imageBytes = imageStream.getBytes();
  24245. imageStream.reset();
  24246. var a = 1;
  24247. var b = 0;
  24248. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  24249. // No modulo required in the loop if imageBytes.length < 5552.
  24250. a += imageBytes[i] & 0xff;
  24251. b += a;
  24252. }
  24253. adler32 = ((b % 65521) << 16) | (a % 65521);
  24254. if (this.imageCache.adler32 === adler32) {
  24255. this.buf2 = Cmd.get('EI');
  24256. this.shift();
  24257. this.imageCache[adler32].reset();
  24258. return this.imageCache[adler32];
  24259. }
  24260. }
  24261. if (cipherTransform) {
  24262. imageStream = cipherTransform.createStream(imageStream, length);
  24263. }
  24264. imageStream = this.filter(imageStream, dict, length);
  24265. imageStream.dict = dict;
  24266. if (adler32 !== undefined) {
  24267. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  24268. this.imageCache[adler32] = imageStream;
  24269. }
  24270. this.buf2 = Cmd.get('EI');
  24271. this.shift();
  24272. return imageStream;
  24273. },
  24274. makeStream: function Parser_makeStream(dict, cipherTransform) {
  24275. var lexer = this.lexer;
  24276. var stream = lexer.stream;
  24277. // get stream start position
  24278. lexer.skipToNextLine();
  24279. var pos = stream.pos - 1;
  24280. // get length
  24281. var length = dict.get('Length');
  24282. if (!isInt(length)) {
  24283. info('Bad ' + length + ' attribute in stream');
  24284. length = 0;
  24285. }
  24286. // skip over the stream data
  24287. stream.pos = pos + length;
  24288. lexer.nextChar();
  24289. // Shift '>>' and check whether the new object marks the end of the stream
  24290. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  24291. this.shift(); // 'stream'
  24292. } else {
  24293. // bad stream length, scanning for endstream
  24294. stream.pos = pos;
  24295. var SCAN_BLOCK_SIZE = 2048;
  24296. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  24297. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  24298. 0x61, 0x6D];
  24299. var skipped = 0, found = false, i, j;
  24300. while (stream.pos < stream.end) {
  24301. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  24302. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  24303. if (scanLength <= 0) {
  24304. break;
  24305. }
  24306. found = false;
  24307. i = 0;
  24308. while (i < scanLength) {
  24309. j = 0;
  24310. while (j < ENDSTREAM_SIGNATURE_LENGTH &&
  24311. scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  24312. j++;
  24313. }
  24314. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  24315. found = true;
  24316. break;
  24317. }
  24318. i++;
  24319. }
  24320. if (found) {
  24321. skipped += i;
  24322. stream.pos += i;
  24323. break;
  24324. }
  24325. skipped += scanLength;
  24326. stream.pos += scanLength;
  24327. }
  24328. if (!found) {
  24329. error('Missing endstream');
  24330. }
  24331. length = skipped;
  24332. lexer.nextChar();
  24333. this.shift();
  24334. this.shift();
  24335. }
  24336. this.shift(); // 'endstream'
  24337. stream = stream.makeSubStream(pos, length, dict);
  24338. if (cipherTransform) {
  24339. stream = cipherTransform.createStream(stream, length);
  24340. }
  24341. stream = this.filter(stream, dict, length);
  24342. stream.dict = dict;
  24343. return stream;
  24344. },
  24345. filter: function Parser_filter(stream, dict, length) {
  24346. var filter = dict.get('Filter', 'F');
  24347. var params = dict.get('DecodeParms', 'DP');
  24348. if (isName(filter)) {
  24349. return this.makeFilter(stream, filter.name, length, params);
  24350. }
  24351. var maybeLength = length;
  24352. if (isArray(filter)) {
  24353. var filterArray = filter;
  24354. var paramsArray = params;
  24355. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  24356. filter = filterArray[i];
  24357. if (!isName(filter)) {
  24358. error('Bad filter name: ' + filter);
  24359. }
  24360. params = null;
  24361. if (isArray(paramsArray) && (i in paramsArray)) {
  24362. params = paramsArray[i];
  24363. }
  24364. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  24365. // after the first stream the length variable is invalid
  24366. maybeLength = null;
  24367. }
  24368. }
  24369. return stream;
  24370. },
  24371. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  24372. if (stream.dict.get('Length') === 0 && !maybeLength) {
  24373. warn('Empty "' + name + '" stream.');
  24374. return new NullStream(stream);
  24375. }
  24376. try {
  24377. if (params && this.xref) {
  24378. params = this.xref.fetchIfRef(params);
  24379. }
  24380. var xrefStreamStats = this.xref.stats.streamTypes;
  24381. if (name === 'FlateDecode' || name === 'Fl') {
  24382. xrefStreamStats[StreamType.FLATE] = true;
  24383. if (params) {
  24384. return new PredictorStream(new FlateStream(stream, maybeLength),
  24385. maybeLength, params);
  24386. }
  24387. return new FlateStream(stream, maybeLength);
  24388. }
  24389. if (name === 'LZWDecode' || name === 'LZW') {
  24390. xrefStreamStats[StreamType.LZW] = true;
  24391. var earlyChange = 1;
  24392. if (params) {
  24393. if (params.has('EarlyChange')) {
  24394. earlyChange = params.get('EarlyChange');
  24395. }
  24396. return new PredictorStream(
  24397. new LZWStream(stream, maybeLength, earlyChange),
  24398. maybeLength, params);
  24399. }
  24400. return new LZWStream(stream, maybeLength, earlyChange);
  24401. }
  24402. if (name === 'DCTDecode' || name === 'DCT') {
  24403. xrefStreamStats[StreamType.DCT] = true;
  24404. return new JpegStream(stream, maybeLength, stream.dict);
  24405. }
  24406. if (name === 'JPXDecode' || name === 'JPX') {
  24407. xrefStreamStats[StreamType.JPX] = true;
  24408. return new JpxStream(stream, maybeLength, stream.dict);
  24409. }
  24410. if (name === 'ASCII85Decode' || name === 'A85') {
  24411. xrefStreamStats[StreamType.A85] = true;
  24412. return new Ascii85Stream(stream, maybeLength);
  24413. }
  24414. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  24415. xrefStreamStats[StreamType.AHX] = true;
  24416. return new AsciiHexStream(stream, maybeLength);
  24417. }
  24418. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  24419. xrefStreamStats[StreamType.CCF] = true;
  24420. return new CCITTFaxStream(stream, maybeLength, params);
  24421. }
  24422. if (name === 'RunLengthDecode' || name === 'RL') {
  24423. xrefStreamStats[StreamType.RL] = true;
  24424. return new RunLengthStream(stream, maybeLength);
  24425. }
  24426. if (name === 'JBIG2Decode') {
  24427. xrefStreamStats[StreamType.JBIG] = true;
  24428. return new Jbig2Stream(stream, maybeLength, stream.dict);
  24429. }
  24430. warn('filter "' + name + '" not supported yet');
  24431. return stream;
  24432. } catch (ex) {
  24433. if (ex instanceof MissingDataException) {
  24434. throw ex;
  24435. }
  24436. warn('Invalid stream: \"' + ex + '\"');
  24437. return new NullStream(stream);
  24438. }
  24439. }
  24440. };
  24441. return Parser;
  24442. })();
  24443. var Lexer = (function LexerClosure() {
  24444. function Lexer(stream, knownCommands) {
  24445. this.stream = stream;
  24446. this.nextChar();
  24447. // While lexing, we build up many strings one char at a time. Using += for
  24448. // this can result in lots of garbage strings. It's better to build an
  24449. // array of single-char strings and then join() them together at the end.
  24450. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  24451. // purpose uses less memory than using a new array for each string.
  24452. this.strBuf = [];
  24453. // The PDFs might have "glued" commands with other commands, operands or
  24454. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  24455. // commands and their prefixes. The prefixes are built the following way:
  24456. // if there a command that is a prefix of the other valid command or
  24457. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  24458. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  24459. // other commands or literals as a prefix. The knowCommands is optional.
  24460. this.knownCommands = knownCommands;
  24461. }
  24462. // A '1' in this array means the character is white space. A '1' or
  24463. // '2' means the character ends a name or command.
  24464. var specialChars = [
  24465. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  24466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  24467. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  24468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  24469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  24470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  24471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  24472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  24473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  24474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  24475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  24476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  24477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  24478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  24479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  24480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  24481. ];
  24482. function toHexDigit(ch) {
  24483. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  24484. return ch & 0x0F;
  24485. }
  24486. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  24487. // 'A'-'F', 'a'-'f'
  24488. return (ch & 0x0F) + 9;
  24489. }
  24490. return -1;
  24491. }
  24492. Lexer.prototype = {
  24493. nextChar: function Lexer_nextChar() {
  24494. return (this.currentChar = this.stream.getByte());
  24495. },
  24496. peekChar: function Lexer_peekChar() {
  24497. return this.stream.peekByte();
  24498. },
  24499. getNumber: function Lexer_getNumber() {
  24500. var ch = this.currentChar;
  24501. var eNotation = false;
  24502. var divideBy = 0; // different from 0 if it's a floating point value
  24503. var sign = 1;
  24504. if (ch === 0x2D) { // '-'
  24505. sign = -1;
  24506. ch = this.nextChar();
  24507. if (ch === 0x2D) { // '-'
  24508. // Ignore double negative (this is consistent with Adobe Reader).
  24509. ch = this.nextChar();
  24510. }
  24511. } else if (ch === 0x2B) { // '+'
  24512. ch = this.nextChar();
  24513. }
  24514. if (ch === 0x2E) { // '.'
  24515. divideBy = 10;
  24516. ch = this.nextChar();
  24517. }
  24518. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  24519. error('Invalid number: ' + String.fromCharCode(ch));
  24520. return 0;
  24521. }
  24522. var baseValue = ch - 0x30; // '0'
  24523. var powerValue = 0;
  24524. var powerValueSign = 1;
  24525. while ((ch = this.nextChar()) >= 0) {
  24526. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  24527. var currentDigit = ch - 0x30; // '0'
  24528. if (eNotation) { // We are after an 'e' or 'E'
  24529. powerValue = powerValue * 10 + currentDigit;
  24530. } else {
  24531. if (divideBy !== 0) { // We are after a point
  24532. divideBy *= 10;
  24533. }
  24534. baseValue = baseValue * 10 + currentDigit;
  24535. }
  24536. } else if (ch === 0x2E) { // '.'
  24537. if (divideBy === 0) {
  24538. divideBy = 1;
  24539. } else {
  24540. // A number can have only one '.'
  24541. break;
  24542. }
  24543. } else if (ch === 0x2D) { // '-'
  24544. // ignore minus signs in the middle of numbers to match
  24545. // Adobe's behavior
  24546. warn('Badly formatted number');
  24547. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  24548. // 'E' can be either a scientific notation or the beginning of a new
  24549. // operator
  24550. ch = this.peekChar();
  24551. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  24552. powerValueSign = (ch === 0x2D) ? -1 : 1;
  24553. this.nextChar(); // Consume the sign character
  24554. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  24555. // The 'E' must be the beginning of a new operator
  24556. break;
  24557. }
  24558. eNotation = true;
  24559. } else {
  24560. // the last character doesn't belong to us
  24561. break;
  24562. }
  24563. }
  24564. if (divideBy !== 0) {
  24565. baseValue /= divideBy;
  24566. }
  24567. if (eNotation) {
  24568. baseValue *= Math.pow(10, powerValueSign * powerValue);
  24569. }
  24570. return sign * baseValue;
  24571. },
  24572. getString: function Lexer_getString() {
  24573. var numParen = 1;
  24574. var done = false;
  24575. var strBuf = this.strBuf;
  24576. strBuf.length = 0;
  24577. var ch = this.nextChar();
  24578. while (true) {
  24579. var charBuffered = false;
  24580. switch (ch | 0) {
  24581. case -1:
  24582. warn('Unterminated string');
  24583. done = true;
  24584. break;
  24585. case 0x28: // '('
  24586. ++numParen;
  24587. strBuf.push('(');
  24588. break;
  24589. case 0x29: // ')'
  24590. if (--numParen === 0) {
  24591. this.nextChar(); // consume strings ')'
  24592. done = true;
  24593. } else {
  24594. strBuf.push(')');
  24595. }
  24596. break;
  24597. case 0x5C: // '\\'
  24598. ch = this.nextChar();
  24599. switch (ch) {
  24600. case -1:
  24601. warn('Unterminated string');
  24602. done = true;
  24603. break;
  24604. case 0x6E: // 'n'
  24605. strBuf.push('\n');
  24606. break;
  24607. case 0x72: // 'r'
  24608. strBuf.push('\r');
  24609. break;
  24610. case 0x74: // 't'
  24611. strBuf.push('\t');
  24612. break;
  24613. case 0x62: // 'b'
  24614. strBuf.push('\b');
  24615. break;
  24616. case 0x66: // 'f'
  24617. strBuf.push('\f');
  24618. break;
  24619. case 0x5C: // '\'
  24620. case 0x28: // '('
  24621. case 0x29: // ')'
  24622. strBuf.push(String.fromCharCode(ch));
  24623. break;
  24624. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  24625. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  24626. var x = ch & 0x0F;
  24627. ch = this.nextChar();
  24628. charBuffered = true;
  24629. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  24630. x = (x << 3) + (ch & 0x0F);
  24631. ch = this.nextChar();
  24632. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  24633. charBuffered = false;
  24634. x = (x << 3) + (ch & 0x0F);
  24635. }
  24636. }
  24637. strBuf.push(String.fromCharCode(x));
  24638. break;
  24639. case 0x0D: // CR
  24640. if (this.peekChar() === 0x0A) { // LF
  24641. this.nextChar();
  24642. }
  24643. break;
  24644. case 0x0A: // LF
  24645. break;
  24646. default:
  24647. strBuf.push(String.fromCharCode(ch));
  24648. break;
  24649. }
  24650. break;
  24651. default:
  24652. strBuf.push(String.fromCharCode(ch));
  24653. break;
  24654. }
  24655. if (done) {
  24656. break;
  24657. }
  24658. if (!charBuffered) {
  24659. ch = this.nextChar();
  24660. }
  24661. }
  24662. return strBuf.join('');
  24663. },
  24664. getName: function Lexer_getName() {
  24665. var ch, previousCh;
  24666. var strBuf = this.strBuf;
  24667. strBuf.length = 0;
  24668. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  24669. if (ch === 0x23) { // '#'
  24670. ch = this.nextChar();
  24671. if (specialChars[ch]) {
  24672. warn('Lexer_getName: ' +
  24673. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  24674. strBuf.push('#');
  24675. break;
  24676. }
  24677. var x = toHexDigit(ch);
  24678. if (x !== -1) {
  24679. previousCh = ch;
  24680. ch = this.nextChar();
  24681. var x2 = toHexDigit(ch);
  24682. if (x2 === -1) {
  24683. warn('Lexer_getName: Illegal digit (' +
  24684. String.fromCharCode(ch) +') in hexadecimal number.');
  24685. strBuf.push('#', String.fromCharCode(previousCh));
  24686. if (specialChars[ch]) {
  24687. break;
  24688. }
  24689. strBuf.push(String.fromCharCode(ch));
  24690. continue;
  24691. }
  24692. strBuf.push(String.fromCharCode((x << 4) | x2));
  24693. } else {
  24694. strBuf.push('#', String.fromCharCode(ch));
  24695. }
  24696. } else {
  24697. strBuf.push(String.fromCharCode(ch));
  24698. }
  24699. }
  24700. if (strBuf.length > 127) {
  24701. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  24702. }
  24703. return Name.get(strBuf.join(''));
  24704. },
  24705. getHexString: function Lexer_getHexString() {
  24706. var strBuf = this.strBuf;
  24707. strBuf.length = 0;
  24708. var ch = this.currentChar;
  24709. var isFirstHex = true;
  24710. var firstDigit;
  24711. var secondDigit;
  24712. while (true) {
  24713. if (ch < 0) {
  24714. warn('Unterminated hex string');
  24715. break;
  24716. } else if (ch === 0x3E) { // '>'
  24717. this.nextChar();
  24718. break;
  24719. } else if (specialChars[ch] === 1) {
  24720. ch = this.nextChar();
  24721. continue;
  24722. } else {
  24723. if (isFirstHex) {
  24724. firstDigit = toHexDigit(ch);
  24725. if (firstDigit === -1) {
  24726. warn('Ignoring invalid character "' + ch + '" in hex string');
  24727. ch = this.nextChar();
  24728. continue;
  24729. }
  24730. } else {
  24731. secondDigit = toHexDigit(ch);
  24732. if (secondDigit === -1) {
  24733. warn('Ignoring invalid character "' + ch + '" in hex string');
  24734. ch = this.nextChar();
  24735. continue;
  24736. }
  24737. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  24738. }
  24739. isFirstHex = !isFirstHex;
  24740. ch = this.nextChar();
  24741. }
  24742. }
  24743. return strBuf.join('');
  24744. },
  24745. getObj: function Lexer_getObj() {
  24746. // skip whitespace and comments
  24747. var comment = false;
  24748. var ch = this.currentChar;
  24749. while (true) {
  24750. if (ch < 0) {
  24751. return EOF;
  24752. }
  24753. if (comment) {
  24754. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  24755. comment = false;
  24756. }
  24757. } else if (ch === 0x25) { // '%'
  24758. comment = true;
  24759. } else if (specialChars[ch] !== 1) {
  24760. break;
  24761. }
  24762. ch = this.nextChar();
  24763. }
  24764. // start reading token
  24765. switch (ch | 0) {
  24766. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  24767. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  24768. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  24769. return this.getNumber();
  24770. case 0x28: // '('
  24771. return this.getString();
  24772. case 0x2F: // '/'
  24773. return this.getName();
  24774. // array punctuation
  24775. case 0x5B: // '['
  24776. this.nextChar();
  24777. return Cmd.get('[');
  24778. case 0x5D: // ']'
  24779. this.nextChar();
  24780. return Cmd.get(']');
  24781. // hex string or dict punctuation
  24782. case 0x3C: // '<'
  24783. ch = this.nextChar();
  24784. if (ch === 0x3C) {
  24785. // dict punctuation
  24786. this.nextChar();
  24787. return Cmd.get('<<');
  24788. }
  24789. return this.getHexString();
  24790. // dict punctuation
  24791. case 0x3E: // '>'
  24792. ch = this.nextChar();
  24793. if (ch === 0x3E) {
  24794. this.nextChar();
  24795. return Cmd.get('>>');
  24796. }
  24797. return Cmd.get('>');
  24798. case 0x7B: // '{'
  24799. this.nextChar();
  24800. return Cmd.get('{');
  24801. case 0x7D: // '}'
  24802. this.nextChar();
  24803. return Cmd.get('}');
  24804. case 0x29: // ')'
  24805. error('Illegal character: ' + ch);
  24806. break;
  24807. }
  24808. // command
  24809. var str = String.fromCharCode(ch);
  24810. var knownCommands = this.knownCommands;
  24811. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  24812. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  24813. // stop if known command is found and next character does not make
  24814. // the str a command
  24815. var possibleCommand = str + String.fromCharCode(ch);
  24816. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  24817. break;
  24818. }
  24819. if (str.length === 128) {
  24820. error('Command token too long: ' + str.length);
  24821. }
  24822. str = possibleCommand;
  24823. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  24824. }
  24825. if (str === 'true') {
  24826. return true;
  24827. }
  24828. if (str === 'false') {
  24829. return false;
  24830. }
  24831. if (str === 'null') {
  24832. return null;
  24833. }
  24834. return Cmd.get(str);
  24835. },
  24836. skipToNextLine: function Lexer_skipToNextLine() {
  24837. var ch = this.currentChar;
  24838. while (ch >= 0) {
  24839. if (ch === 0x0D) { // CR
  24840. ch = this.nextChar();
  24841. if (ch === 0x0A) { // LF
  24842. this.nextChar();
  24843. }
  24844. break;
  24845. } else if (ch === 0x0A) { // LF
  24846. this.nextChar();
  24847. break;
  24848. }
  24849. ch = this.nextChar();
  24850. }
  24851. }
  24852. };
  24853. return Lexer;
  24854. })();
  24855. var Linearization = {
  24856. create: function LinearizationCreate(stream) {
  24857. function getInt(name, allowZeroValue) {
  24858. var obj = linDict.get(name);
  24859. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  24860. return obj;
  24861. }
  24862. throw new Error('The "' + name + '" parameter in the linearization ' +
  24863. 'dictionary is invalid.');
  24864. }
  24865. function getHints() {
  24866. var hints = linDict.get('H'), hintsLength, item;
  24867. if (isArray(hints) &&
  24868. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  24869. for (var index = 0; index < hintsLength; index++) {
  24870. if (!(isInt(item = hints[index]) && item > 0)) {
  24871. throw new Error('Hint (' + index +
  24872. ') in the linearization dictionary is invalid.');
  24873. }
  24874. }
  24875. return hints;
  24876. }
  24877. throw new Error('Hint array in the linearization dictionary is invalid.');
  24878. }
  24879. var parser = new Parser(new Lexer(stream), false, null);
  24880. var obj1 = parser.getObj();
  24881. var obj2 = parser.getObj();
  24882. var obj3 = parser.getObj();
  24883. var linDict = parser.getObj();
  24884. var obj, length;
  24885. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  24886. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  24887. return null; // No valid linearization dictionary found.
  24888. } else if ((length = getInt('L')) !== stream.length) {
  24889. throw new Error('The "L" parameter in the linearization dictionary ' +
  24890. 'does not equal the stream length.');
  24891. }
  24892. return {
  24893. length: length,
  24894. hints: getHints(),
  24895. objectNumberFirst: getInt('O'),
  24896. endFirst: getInt('E'),
  24897. numPages: getInt('N'),
  24898. mainXRefEntriesOffset: getInt('T'),
  24899. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  24900. };
  24901. }
  24902. };
  24903. exports.EOF = EOF;
  24904. exports.Lexer = Lexer;
  24905. exports.Linearization = Linearization;
  24906. exports.Parser = Parser;
  24907. exports.isEOF = isEOF;
  24908. }));
  24909. (function (root, factory) {
  24910. {
  24911. factory((root.pdfjsCoreType1Parser = {}), root.pdfjsSharedUtil,
  24912. root.pdfjsCoreStream, root.pdfjsCoreEncodings);
  24913. }
  24914. }(this, function (exports, sharedUtil, coreStream, coreEncodings) {
  24915. var warn = sharedUtil.warn;
  24916. var isSpace = sharedUtil.isSpace;
  24917. var Stream = coreStream.Stream;
  24918. var getEncoding = coreEncodings.getEncoding;
  24919. // Hinting is currently disabled due to unknown problems on windows
  24920. // in tracemonkey and various other pdfs with type1 fonts.
  24921. var HINTING_ENABLED = false;
  24922. /*
  24923. * CharStrings are encoded following the the CharString Encoding sequence
  24924. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  24925. * The value in a byte indicates a command, a number, or subsequent bytes
  24926. * that are to be interpreted in a special way.
  24927. *
  24928. * CharString Number Encoding:
  24929. * A CharString byte containing the values from 32 through 255 inclusive
  24930. * indicate an integer. These values are decoded in four ranges.
  24931. *
  24932. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  24933. * indicate the integer v - 139. Thus, the integer values from -107 through
  24934. * 107 inclusive may be encoded in single byte.
  24935. *
  24936. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  24937. * indicates an integer involving the next byte, w, according to the formula:
  24938. * [(v - 247) x 256] + w + 108
  24939. *
  24940. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  24941. * indicates an integer involving the next byte, w, according to the formula:
  24942. * -[(v - 251) * 256] - w - 108
  24943. *
  24944. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  24945. * are a two complement signed integer. The first of these bytes contains the
  24946. * highest order bits, the second byte contains the next higher order bits
  24947. * and the fourth byte contain the lowest order bits.
  24948. *
  24949. *
  24950. * CharString Command Encoding:
  24951. * CharStrings commands are encoded in 1 or 2 bytes.
  24952. *
  24953. * Single byte commands are encoded in 1 byte that contains a value between
  24954. * 0 and 31 inclusive.
  24955. * If a command byte contains the value 12, then the value in the next byte
  24956. * indicates a command. This "escape" mechanism allows many extra commands
  24957. * to be encoded and this encoding technique helps to minimize the length of
  24958. * the charStrings.
  24959. */
  24960. var Type1CharString = (function Type1CharStringClosure() {
  24961. var COMMAND_MAP = {
  24962. 'hstem': [1],
  24963. 'vstem': [3],
  24964. 'vmoveto': [4],
  24965. 'rlineto': [5],
  24966. 'hlineto': [6],
  24967. 'vlineto': [7],
  24968. 'rrcurveto': [8],
  24969. 'callsubr': [10],
  24970. 'flex': [12, 35],
  24971. 'drop' : [12, 18],
  24972. 'endchar': [14],
  24973. 'rmoveto': [21],
  24974. 'hmoveto': [22],
  24975. 'vhcurveto': [30],
  24976. 'hvcurveto': [31]
  24977. };
  24978. function Type1CharString() {
  24979. this.width = 0;
  24980. this.lsb = 0;
  24981. this.flexing = false;
  24982. this.output = [];
  24983. this.stack = [];
  24984. }
  24985. Type1CharString.prototype = {
  24986. convert: function Type1CharString_convert(encoded, subrs,
  24987. seacAnalysisEnabled) {
  24988. var count = encoded.length;
  24989. var error = false;
  24990. var wx, sbx, subrNumber;
  24991. for (var i = 0; i < count; i++) {
  24992. var value = encoded[i];
  24993. if (value < 32) {
  24994. if (value === 12) {
  24995. value = (value << 8) + encoded[++i];
  24996. }
  24997. switch (value) {
  24998. case 1: // hstem
  24999. if (!HINTING_ENABLED) {
  25000. this.stack = [];
  25001. break;
  25002. }
  25003. error = this.executeCommand(2, COMMAND_MAP.hstem);
  25004. break;
  25005. case 3: // vstem
  25006. if (!HINTING_ENABLED) {
  25007. this.stack = [];
  25008. break;
  25009. }
  25010. error = this.executeCommand(2, COMMAND_MAP.vstem);
  25011. break;
  25012. case 4: // vmoveto
  25013. if (this.flexing) {
  25014. if (this.stack.length < 1) {
  25015. error = true;
  25016. break;
  25017. }
  25018. // Add the dx for flex and but also swap the values so they are
  25019. // the right order.
  25020. var dy = this.stack.pop();
  25021. this.stack.push(0, dy);
  25022. break;
  25023. }
  25024. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  25025. break;
  25026. case 5: // rlineto
  25027. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  25028. break;
  25029. case 6: // hlineto
  25030. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  25031. break;
  25032. case 7: // vlineto
  25033. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  25034. break;
  25035. case 8: // rrcurveto
  25036. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  25037. break;
  25038. case 9: // closepath
  25039. // closepath is a Type1 command that does not take argument and is
  25040. // useless in Type2 and it can simply be ignored.
  25041. this.stack = [];
  25042. break;
  25043. case 10: // callsubr
  25044. if (this.stack.length < 1) {
  25045. error = true;
  25046. break;
  25047. }
  25048. subrNumber = this.stack.pop();
  25049. error = this.convert(subrs[subrNumber], subrs,
  25050. seacAnalysisEnabled);
  25051. break;
  25052. case 11: // return
  25053. return error;
  25054. case 13: // hsbw
  25055. if (this.stack.length < 2) {
  25056. error = true;
  25057. break;
  25058. }
  25059. // To convert to type2 we have to move the width value to the
  25060. // first part of the charstring and then use hmoveto with lsb.
  25061. wx = this.stack.pop();
  25062. sbx = this.stack.pop();
  25063. this.lsb = sbx;
  25064. this.width = wx;
  25065. this.stack.push(wx, sbx);
  25066. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  25067. break;
  25068. case 14: // endchar
  25069. this.output.push(COMMAND_MAP.endchar[0]);
  25070. break;
  25071. case 21: // rmoveto
  25072. if (this.flexing) {
  25073. break;
  25074. }
  25075. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  25076. break;
  25077. case 22: // hmoveto
  25078. if (this.flexing) {
  25079. // Add the dy for flex.
  25080. this.stack.push(0);
  25081. break;
  25082. }
  25083. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  25084. break;
  25085. case 30: // vhcurveto
  25086. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  25087. break;
  25088. case 31: // hvcurveto
  25089. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  25090. break;
  25091. case (12 << 8) + 0: // dotsection
  25092. // dotsection is a Type1 command to specify some hinting feature
  25093. // for dots that do not take a parameter and it can safely be
  25094. // ignored for Type2.
  25095. this.stack = [];
  25096. break;
  25097. case (12 << 8) + 1: // vstem3
  25098. if (!HINTING_ENABLED) {
  25099. this.stack = [];
  25100. break;
  25101. }
  25102. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  25103. // multiple parameters, so instead of returning [vh]stem3 take a
  25104. // shortcut and return [vhstem] instead.
  25105. error = this.executeCommand(2, COMMAND_MAP.vstem);
  25106. break;
  25107. case (12 << 8) + 2: // hstem3
  25108. if (!HINTING_ENABLED) {
  25109. this.stack = [];
  25110. break;
  25111. }
  25112. // See vstem3.
  25113. error = this.executeCommand(2, COMMAND_MAP.hstem);
  25114. break;
  25115. case (12 << 8) + 6: // seac
  25116. // seac is like type 2's special endchar but it doesn't use the
  25117. // first argument asb, so remove it.
  25118. if (seacAnalysisEnabled) {
  25119. this.seac = this.stack.splice(-4, 4);
  25120. error = this.executeCommand(0, COMMAND_MAP.endchar);
  25121. } else {
  25122. error = this.executeCommand(4, COMMAND_MAP.endchar);
  25123. }
  25124. break;
  25125. case (12 << 8) + 7: // sbw
  25126. if (this.stack.length < 4) {
  25127. error = true;
  25128. break;
  25129. }
  25130. // To convert to type2 we have to move the width value to the
  25131. // first part of the charstring and then use rmoveto with
  25132. // (dx, dy). The height argument will not be used for vmtx and
  25133. // vhea tables reconstruction -- ignoring it.
  25134. var wy = this.stack.pop();
  25135. wx = this.stack.pop();
  25136. var sby = this.stack.pop();
  25137. sbx = this.stack.pop();
  25138. this.lsb = sbx;
  25139. this.width = wx;
  25140. this.stack.push(wx, sbx, sby);
  25141. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  25142. break;
  25143. case (12 << 8) + 12: // div
  25144. if (this.stack.length < 2) {
  25145. error = true;
  25146. break;
  25147. }
  25148. var num2 = this.stack.pop();
  25149. var num1 = this.stack.pop();
  25150. this.stack.push(num1 / num2);
  25151. break;
  25152. case (12 << 8) + 16: // callothersubr
  25153. if (this.stack.length < 2) {
  25154. error = true;
  25155. break;
  25156. }
  25157. subrNumber = this.stack.pop();
  25158. var numArgs = this.stack.pop();
  25159. if (subrNumber === 0 && numArgs === 3) {
  25160. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  25161. this.stack.push(
  25162. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  25163. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  25164. flexArgs[4], // bcp2x
  25165. flexArgs[5], // bcp2y
  25166. flexArgs[6], // p2x
  25167. flexArgs[7], // p2y
  25168. flexArgs[8], // bcp3x
  25169. flexArgs[9], // bcp3y
  25170. flexArgs[10], // bcp4x
  25171. flexArgs[11], // bcp4y
  25172. flexArgs[12], // p3x
  25173. flexArgs[13], // p3y
  25174. flexArgs[14] // flexDepth
  25175. // 15 = finalx unused by flex
  25176. // 16 = finaly unused by flex
  25177. );
  25178. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  25179. this.flexing = false;
  25180. this.stack.push(flexArgs[15], flexArgs[16]);
  25181. } else if (subrNumber === 1 && numArgs === 0) {
  25182. this.flexing = true;
  25183. }
  25184. break;
  25185. case (12 << 8) + 17: // pop
  25186. // Ignore this since it is only used with othersubr.
  25187. break;
  25188. case (12 << 8) + 33: // setcurrentpoint
  25189. // Ignore for now.
  25190. this.stack = [];
  25191. break;
  25192. default:
  25193. warn('Unknown type 1 charstring command of "' + value + '"');
  25194. break;
  25195. }
  25196. if (error) {
  25197. break;
  25198. }
  25199. continue;
  25200. } else if (value <= 246) {
  25201. value = value - 139;
  25202. } else if (value <= 250) {
  25203. value = ((value - 247) * 256) + encoded[++i] + 108;
  25204. } else if (value <= 254) {
  25205. value = -((value - 251) * 256) - encoded[++i] - 108;
  25206. } else {
  25207. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  25208. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  25209. }
  25210. this.stack.push(value);
  25211. }
  25212. return error;
  25213. },
  25214. executeCommand: function(howManyArgs, command, keepStack) {
  25215. var stackLength = this.stack.length;
  25216. if (howManyArgs > stackLength) {
  25217. return true;
  25218. }
  25219. var start = stackLength - howManyArgs;
  25220. for (var i = start; i < stackLength; i++) {
  25221. var value = this.stack[i];
  25222. if (value === (value | 0)) { // int
  25223. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  25224. } else { // fixed point
  25225. value = (65536 * value) | 0;
  25226. this.output.push(255,
  25227. (value >> 24) & 0xFF,
  25228. (value >> 16) & 0xFF,
  25229. (value >> 8) & 0xFF,
  25230. value & 0xFF);
  25231. }
  25232. }
  25233. this.output.push.apply(this.output, command);
  25234. if (keepStack) {
  25235. this.stack.splice(start, howManyArgs);
  25236. } else {
  25237. this.stack.length = 0;
  25238. }
  25239. return false;
  25240. }
  25241. };
  25242. return Type1CharString;
  25243. })();
  25244. /*
  25245. * Type1Parser encapsulate the needed code for parsing a Type1 font
  25246. * program. Some of its logic depends on the Type2 charstrings
  25247. * structure.
  25248. * Note: this doesn't really parse the font since that would require evaluation
  25249. * of PostScript, but it is possible in most cases to extract what we need
  25250. * without a full parse.
  25251. */
  25252. var Type1Parser = (function Type1ParserClosure() {
  25253. /*
  25254. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  25255. * of Plaintext Bytes. The function took a key as a parameter which can be
  25256. * for decrypting the eexec block of for decoding charStrings.
  25257. */
  25258. var EEXEC_ENCRYPT_KEY = 55665;
  25259. var CHAR_STRS_ENCRYPT_KEY = 4330;
  25260. function isHexDigit(code) {
  25261. return code >= 48 && code <= 57 || // '0'-'9'
  25262. code >= 65 && code <= 70 || // 'A'-'F'
  25263. code >= 97 && code <= 102; // 'a'-'f'
  25264. }
  25265. function decrypt(data, key, discardNumber) {
  25266. if (discardNumber >= data.length) {
  25267. return new Uint8Array(0);
  25268. }
  25269. var r = key | 0, c1 = 52845, c2 = 22719, i, j;
  25270. for (i = 0; i < discardNumber; i++) {
  25271. r = ((data[i] + r) * c1 + c2) & ((1 << 16) - 1);
  25272. }
  25273. var count = data.length - discardNumber;
  25274. var decrypted = new Uint8Array(count);
  25275. for (i = discardNumber, j = 0; j < count; i++, j++) {
  25276. var value = data[i];
  25277. decrypted[j] = value ^ (r >> 8);
  25278. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  25279. }
  25280. return decrypted;
  25281. }
  25282. function decryptAscii(data, key, discardNumber) {
  25283. var r = key | 0, c1 = 52845, c2 = 22719;
  25284. var count = data.length, maybeLength = count >>> 1;
  25285. var decrypted = new Uint8Array(maybeLength);
  25286. var i, j;
  25287. for (i = 0, j = 0; i < count; i++) {
  25288. var digit1 = data[i];
  25289. if (!isHexDigit(digit1)) {
  25290. continue;
  25291. }
  25292. i++;
  25293. var digit2;
  25294. while (i < count && !isHexDigit(digit2 = data[i])) {
  25295. i++;
  25296. }
  25297. if (i < count) {
  25298. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  25299. decrypted[j++] = value ^ (r >> 8);
  25300. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  25301. }
  25302. }
  25303. return Array.prototype.slice.call(decrypted, discardNumber, j);
  25304. }
  25305. function isSpecial(c) {
  25306. return c === 0x2F || // '/'
  25307. c === 0x5B || c === 0x5D || // '[', ']'
  25308. c === 0x7B || c === 0x7D || // '{', '}'
  25309. c === 0x28 || c === 0x29; // '(', ')'
  25310. }
  25311. function Type1Parser(stream, encrypted, seacAnalysisEnabled) {
  25312. if (encrypted) {
  25313. var data = stream.getBytes();
  25314. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  25315. isHexDigit(data[2]) && isHexDigit(data[3]));
  25316. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  25317. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  25318. }
  25319. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  25320. this.stream = stream;
  25321. this.nextChar();
  25322. }
  25323. Type1Parser.prototype = {
  25324. readNumberArray: function Type1Parser_readNumberArray() {
  25325. this.getToken(); // read '[' or '{' (arrays can start with either)
  25326. var array = [];
  25327. while (true) {
  25328. var token = this.getToken();
  25329. if (token === null || token === ']' || token === '}') {
  25330. break;
  25331. }
  25332. array.push(parseFloat(token || 0));
  25333. }
  25334. return array;
  25335. },
  25336. readNumber: function Type1Parser_readNumber() {
  25337. var token = this.getToken();
  25338. return parseFloat(token || 0);
  25339. },
  25340. readInt: function Type1Parser_readInt() {
  25341. // Use '| 0' to prevent setting a double into length such as the double
  25342. // does not flow into the loop variable.
  25343. var token = this.getToken();
  25344. return parseInt(token || 0, 10) | 0;
  25345. },
  25346. readBoolean: function Type1Parser_readBoolean() {
  25347. var token = this.getToken();
  25348. // Use 1 and 0 since that's what type2 charstrings use.
  25349. return token === 'true' ? 1 : 0;
  25350. },
  25351. nextChar : function Type1_nextChar() {
  25352. return (this.currentChar = this.stream.getByte());
  25353. },
  25354. getToken: function Type1Parser_getToken() {
  25355. // Eat whitespace and comments.
  25356. var comment = false;
  25357. var ch = this.currentChar;
  25358. while (true) {
  25359. if (ch === -1) {
  25360. return null;
  25361. }
  25362. if (comment) {
  25363. if (ch === 0x0A || ch === 0x0D) {
  25364. comment = false;
  25365. }
  25366. } else if (ch === 0x25) { // '%'
  25367. comment = true;
  25368. } else if (!isSpace(ch)) {
  25369. break;
  25370. }
  25371. ch = this.nextChar();
  25372. }
  25373. if (isSpecial(ch)) {
  25374. this.nextChar();
  25375. return String.fromCharCode(ch);
  25376. }
  25377. var token = '';
  25378. do {
  25379. token += String.fromCharCode(ch);
  25380. ch = this.nextChar();
  25381. } while (ch >= 0 && !isSpace(ch) && !isSpecial(ch));
  25382. return token;
  25383. },
  25384. /*
  25385. * Returns an object containing a Subrs array and a CharStrings
  25386. * array extracted from and eexec encrypted block of data
  25387. */
  25388. extractFontProgram: function Type1Parser_extractFontProgram() {
  25389. var stream = this.stream;
  25390. var subrs = [], charstrings = [];
  25391. var privateData = Object.create(null);
  25392. privateData['lenIV'] = 4;
  25393. var program = {
  25394. subrs: [],
  25395. charstrings: [],
  25396. properties: {
  25397. 'privateData': privateData
  25398. }
  25399. };
  25400. var token, length, data, lenIV, encoded;
  25401. while ((token = this.getToken()) !== null) {
  25402. if (token !== '/') {
  25403. continue;
  25404. }
  25405. token = this.getToken();
  25406. switch (token) {
  25407. case 'CharStrings':
  25408. // The number immediately following CharStrings must be greater or
  25409. // equal to the number of CharStrings.
  25410. this.getToken();
  25411. this.getToken(); // read in 'dict'
  25412. this.getToken(); // read in 'dup'
  25413. this.getToken(); // read in 'begin'
  25414. while(true) {
  25415. token = this.getToken();
  25416. if (token === null || token === 'end') {
  25417. break;
  25418. }
  25419. if (token !== '/') {
  25420. continue;
  25421. }
  25422. var glyph = this.getToken();
  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 'ND' or '|-'
  25432. if (token === 'noaccess') {
  25433. this.getToken(); // read in 'def'
  25434. }
  25435. charstrings.push({
  25436. glyph: glyph,
  25437. encoded: encoded
  25438. });
  25439. }
  25440. break;
  25441. case 'Subrs':
  25442. var num = this.readInt();
  25443. this.getToken(); // read in 'array'
  25444. while ((token = this.getToken()) === 'dup') {
  25445. var index = this.readInt();
  25446. length = this.readInt();
  25447. this.getToken(); // read in 'RD' or '-|'
  25448. data = stream.makeSubStream(stream.pos, length);
  25449. lenIV = program.properties.privateData['lenIV'];
  25450. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  25451. // Skip past the required space and binary data.
  25452. stream.skip(length);
  25453. this.nextChar();
  25454. token = this.getToken(); // read in 'NP' or '|'
  25455. if (token === 'noaccess') {
  25456. this.getToken(); // read in 'put'
  25457. }
  25458. subrs[index] = encoded;
  25459. }
  25460. break;
  25461. case 'BlueValues':
  25462. case 'OtherBlues':
  25463. case 'FamilyBlues':
  25464. case 'FamilyOtherBlues':
  25465. var blueArray = this.readNumberArray();
  25466. // *Blue* values may contain invalid data: disables reading of
  25467. // those values when hinting is disabled.
  25468. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  25469. HINTING_ENABLED) {
  25470. program.properties.privateData[token] = blueArray;
  25471. }
  25472. break;
  25473. case 'StemSnapH':
  25474. case 'StemSnapV':
  25475. program.properties.privateData[token] = this.readNumberArray();
  25476. break;
  25477. case 'StdHW':
  25478. case 'StdVW':
  25479. program.properties.privateData[token] =
  25480. this.readNumberArray()[0];
  25481. break;
  25482. case 'BlueShift':
  25483. case 'lenIV':
  25484. case 'BlueFuzz':
  25485. case 'BlueScale':
  25486. case 'LanguageGroup':
  25487. case 'ExpansionFactor':
  25488. program.properties.privateData[token] = this.readNumber();
  25489. break;
  25490. case 'ForceBold':
  25491. program.properties.privateData[token] = this.readBoolean();
  25492. break;
  25493. }
  25494. }
  25495. for (var i = 0; i < charstrings.length; i++) {
  25496. glyph = charstrings[i].glyph;
  25497. encoded = charstrings[i].encoded;
  25498. var charString = new Type1CharString();
  25499. var error = charString.convert(encoded, subrs,
  25500. this.seacAnalysisEnabled);
  25501. var output = charString.output;
  25502. if (error) {
  25503. // It seems when FreeType encounters an error while evaluating a glyph
  25504. // that it completely ignores the glyph so we'll mimic that behaviour
  25505. // here and put an endchar to make the validator happy.
  25506. output = [14];
  25507. }
  25508. program.charstrings.push({
  25509. glyphName: glyph,
  25510. charstring: output,
  25511. width: charString.width,
  25512. lsb: charString.lsb,
  25513. seac: charString.seac
  25514. });
  25515. }
  25516. return program;
  25517. },
  25518. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  25519. var token;
  25520. while ((token = this.getToken()) !== null) {
  25521. if (token !== '/') {
  25522. continue;
  25523. }
  25524. token = this.getToken();
  25525. switch (token) {
  25526. case 'FontMatrix':
  25527. var matrix = this.readNumberArray();
  25528. properties.fontMatrix = matrix;
  25529. break;
  25530. case 'Encoding':
  25531. var encodingArg = this.getToken();
  25532. var encoding;
  25533. if (!/^\d+$/.test(encodingArg)) {
  25534. // encoding name is specified
  25535. encoding = getEncoding(encodingArg);
  25536. } else {
  25537. encoding = [];
  25538. var size = parseInt(encodingArg, 10) | 0;
  25539. this.getToken(); // read in 'array'
  25540. for (var j = 0; j < size; j++) {
  25541. token = this.getToken();
  25542. // skipping till first dup or def (e.g. ignoring for statement)
  25543. while (token !== 'dup' && token !== 'def') {
  25544. token = this.getToken();
  25545. if (token === null) {
  25546. return; // invalid header
  25547. }
  25548. }
  25549. if (token === 'def') {
  25550. break; // read all array data
  25551. }
  25552. var index = this.readInt();
  25553. this.getToken(); // read in '/'
  25554. var glyph = this.getToken();
  25555. encoding[index] = glyph;
  25556. this.getToken(); // read the in 'put'
  25557. }
  25558. }
  25559. properties.builtInEncoding = encoding;
  25560. break;
  25561. case 'FontBBox':
  25562. var fontBBox = this.readNumberArray();
  25563. // adjusting ascent/descent
  25564. properties.ascent = fontBBox[3];
  25565. properties.descent = fontBBox[1];
  25566. properties.ascentScaled = true;
  25567. break;
  25568. }
  25569. }
  25570. }
  25571. };
  25572. return Type1Parser;
  25573. })();
  25574. exports.Type1Parser = Type1Parser;
  25575. }));
  25576. (function (root, factory) {
  25577. {
  25578. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  25579. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  25580. }
  25581. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  25582. var Util = sharedUtil.Util;
  25583. var assert = sharedUtil.assert;
  25584. var warn = sharedUtil.warn;
  25585. var error = sharedUtil.error;
  25586. var isInt = sharedUtil.isInt;
  25587. var isString = sharedUtil.isString;
  25588. var MissingDataException = sharedUtil.MissingDataException;
  25589. var isName = corePrimitives.isName;
  25590. var isCmd = corePrimitives.isCmd;
  25591. var isStream = corePrimitives.isStream;
  25592. var StringStream = coreStream.StringStream;
  25593. var Lexer = coreParser.Lexer;
  25594. var isEOF = coreParser.isEOF;
  25595. var BUILT_IN_CMAPS = [
  25596. // << Start unicode maps.
  25597. 'Adobe-GB1-UCS2',
  25598. 'Adobe-CNS1-UCS2',
  25599. 'Adobe-Japan1-UCS2',
  25600. 'Adobe-Korea1-UCS2',
  25601. // >> End unicode maps.
  25602. '78-EUC-H',
  25603. '78-EUC-V',
  25604. '78-H',
  25605. '78-RKSJ-H',
  25606. '78-RKSJ-V',
  25607. '78-V',
  25608. '78ms-RKSJ-H',
  25609. '78ms-RKSJ-V',
  25610. '83pv-RKSJ-H',
  25611. '90ms-RKSJ-H',
  25612. '90ms-RKSJ-V',
  25613. '90msp-RKSJ-H',
  25614. '90msp-RKSJ-V',
  25615. '90pv-RKSJ-H',
  25616. '90pv-RKSJ-V',
  25617. 'Add-H',
  25618. 'Add-RKSJ-H',
  25619. 'Add-RKSJ-V',
  25620. 'Add-V',
  25621. 'Adobe-CNS1-0',
  25622. 'Adobe-CNS1-1',
  25623. 'Adobe-CNS1-2',
  25624. 'Adobe-CNS1-3',
  25625. 'Adobe-CNS1-4',
  25626. 'Adobe-CNS1-5',
  25627. 'Adobe-CNS1-6',
  25628. 'Adobe-GB1-0',
  25629. 'Adobe-GB1-1',
  25630. 'Adobe-GB1-2',
  25631. 'Adobe-GB1-3',
  25632. 'Adobe-GB1-4',
  25633. 'Adobe-GB1-5',
  25634. 'Adobe-Japan1-0',
  25635. 'Adobe-Japan1-1',
  25636. 'Adobe-Japan1-2',
  25637. 'Adobe-Japan1-3',
  25638. 'Adobe-Japan1-4',
  25639. 'Adobe-Japan1-5',
  25640. 'Adobe-Japan1-6',
  25641. 'Adobe-Korea1-0',
  25642. 'Adobe-Korea1-1',
  25643. 'Adobe-Korea1-2',
  25644. 'B5-H',
  25645. 'B5-V',
  25646. 'B5pc-H',
  25647. 'B5pc-V',
  25648. 'CNS-EUC-H',
  25649. 'CNS-EUC-V',
  25650. 'CNS1-H',
  25651. 'CNS1-V',
  25652. 'CNS2-H',
  25653. 'CNS2-V',
  25654. 'ETHK-B5-H',
  25655. 'ETHK-B5-V',
  25656. 'ETen-B5-H',
  25657. 'ETen-B5-V',
  25658. 'ETenms-B5-H',
  25659. 'ETenms-B5-V',
  25660. 'EUC-H',
  25661. 'EUC-V',
  25662. 'Ext-H',
  25663. 'Ext-RKSJ-H',
  25664. 'Ext-RKSJ-V',
  25665. 'Ext-V',
  25666. 'GB-EUC-H',
  25667. 'GB-EUC-V',
  25668. 'GB-H',
  25669. 'GB-V',
  25670. 'GBK-EUC-H',
  25671. 'GBK-EUC-V',
  25672. 'GBK2K-H',
  25673. 'GBK2K-V',
  25674. 'GBKp-EUC-H',
  25675. 'GBKp-EUC-V',
  25676. 'GBT-EUC-H',
  25677. 'GBT-EUC-V',
  25678. 'GBT-H',
  25679. 'GBT-V',
  25680. 'GBTpc-EUC-H',
  25681. 'GBTpc-EUC-V',
  25682. 'GBpc-EUC-H',
  25683. 'GBpc-EUC-V',
  25684. 'H',
  25685. 'HKdla-B5-H',
  25686. 'HKdla-B5-V',
  25687. 'HKdlb-B5-H',
  25688. 'HKdlb-B5-V',
  25689. 'HKgccs-B5-H',
  25690. 'HKgccs-B5-V',
  25691. 'HKm314-B5-H',
  25692. 'HKm314-B5-V',
  25693. 'HKm471-B5-H',
  25694. 'HKm471-B5-V',
  25695. 'HKscs-B5-H',
  25696. 'HKscs-B5-V',
  25697. 'Hankaku',
  25698. 'Hiragana',
  25699. 'KSC-EUC-H',
  25700. 'KSC-EUC-V',
  25701. 'KSC-H',
  25702. 'KSC-Johab-H',
  25703. 'KSC-Johab-V',
  25704. 'KSC-V',
  25705. 'KSCms-UHC-H',
  25706. 'KSCms-UHC-HW-H',
  25707. 'KSCms-UHC-HW-V',
  25708. 'KSCms-UHC-V',
  25709. 'KSCpc-EUC-H',
  25710. 'KSCpc-EUC-V',
  25711. 'Katakana',
  25712. 'NWP-H',
  25713. 'NWP-V',
  25714. 'RKSJ-H',
  25715. 'RKSJ-V',
  25716. 'Roman',
  25717. 'UniCNS-UCS2-H',
  25718. 'UniCNS-UCS2-V',
  25719. 'UniCNS-UTF16-H',
  25720. 'UniCNS-UTF16-V',
  25721. 'UniCNS-UTF32-H',
  25722. 'UniCNS-UTF32-V',
  25723. 'UniCNS-UTF8-H',
  25724. 'UniCNS-UTF8-V',
  25725. 'UniGB-UCS2-H',
  25726. 'UniGB-UCS2-V',
  25727. 'UniGB-UTF16-H',
  25728. 'UniGB-UTF16-V',
  25729. 'UniGB-UTF32-H',
  25730. 'UniGB-UTF32-V',
  25731. 'UniGB-UTF8-H',
  25732. 'UniGB-UTF8-V',
  25733. 'UniJIS-UCS2-H',
  25734. 'UniJIS-UCS2-HW-H',
  25735. 'UniJIS-UCS2-HW-V',
  25736. 'UniJIS-UCS2-V',
  25737. 'UniJIS-UTF16-H',
  25738. 'UniJIS-UTF16-V',
  25739. 'UniJIS-UTF32-H',
  25740. 'UniJIS-UTF32-V',
  25741. 'UniJIS-UTF8-H',
  25742. 'UniJIS-UTF8-V',
  25743. 'UniJIS2004-UTF16-H',
  25744. 'UniJIS2004-UTF16-V',
  25745. 'UniJIS2004-UTF32-H',
  25746. 'UniJIS2004-UTF32-V',
  25747. 'UniJIS2004-UTF8-H',
  25748. 'UniJIS2004-UTF8-V',
  25749. 'UniJISPro-UCS2-HW-V',
  25750. 'UniJISPro-UCS2-V',
  25751. 'UniJISPro-UTF8-V',
  25752. 'UniJISX0213-UTF32-H',
  25753. 'UniJISX0213-UTF32-V',
  25754. 'UniJISX02132004-UTF32-H',
  25755. 'UniJISX02132004-UTF32-V',
  25756. 'UniKS-UCS2-H',
  25757. 'UniKS-UCS2-V',
  25758. 'UniKS-UTF16-H',
  25759. 'UniKS-UTF16-V',
  25760. 'UniKS-UTF32-H',
  25761. 'UniKS-UTF32-V',
  25762. 'UniKS-UTF8-H',
  25763. 'UniKS-UTF8-V',
  25764. 'V',
  25765. 'WP-Symbol'];
  25766. // CMap, not to be confused with TrueType's cmap.
  25767. var CMap = (function CMapClosure() {
  25768. function CMap(builtInCMap) {
  25769. // Codespace ranges are stored as follows:
  25770. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  25771. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  25772. this.codespaceRanges = [[], [], [], []];
  25773. this.numCodespaceRanges = 0;
  25774. // Map entries have one of two forms.
  25775. // - cid chars are 16-bit unsigned integers, stored as integers.
  25776. // - bf chars are variable-length byte sequences, stored as strings, with
  25777. // one byte per character.
  25778. this._map = [];
  25779. this.name = '';
  25780. this.vertical = false;
  25781. this.useCMap = null;
  25782. this.builtInCMap = builtInCMap;
  25783. }
  25784. CMap.prototype = {
  25785. addCodespaceRange: function(n, low, high) {
  25786. this.codespaceRanges[n - 1].push(low, high);
  25787. this.numCodespaceRanges++;
  25788. },
  25789. mapCidRange: function(low, high, dstLow) {
  25790. while (low <= high) {
  25791. this._map[low++] = dstLow++;
  25792. }
  25793. },
  25794. mapBfRange: function(low, high, dstLow) {
  25795. var lastByte = dstLow.length - 1;
  25796. while (low <= high) {
  25797. this._map[low++] = dstLow;
  25798. // Only the last byte has to be incremented.
  25799. dstLow = dstLow.substr(0, lastByte) +
  25800. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  25801. }
  25802. },
  25803. mapBfRangeToArray: function(low, high, array) {
  25804. var i = 0, ii = array.length;
  25805. while (low <= high && i < ii) {
  25806. this._map[low] = array[i++];
  25807. ++low;
  25808. }
  25809. },
  25810. // This is used for both bf and cid chars.
  25811. mapOne: function(src, dst) {
  25812. this._map[src] = dst;
  25813. },
  25814. lookup: function(code) {
  25815. return this._map[code];
  25816. },
  25817. contains: function(code) {
  25818. return this._map[code] !== undefined;
  25819. },
  25820. forEach: function(callback) {
  25821. // Most maps have fewer than 65536 entries, and for those we use normal
  25822. // array iteration. But really sparse tables are possible -- e.g. with
  25823. // indices in the *billions*. For such tables we use for..in, which isn't
  25824. // ideal because it stringifies the indices for all present elements, but
  25825. // it does avoid iterating over every undefined entry.
  25826. var map = this._map;
  25827. var length = map.length;
  25828. var i;
  25829. if (length <= 0x10000) {
  25830. for (i = 0; i < length; i++) {
  25831. if (map[i] !== undefined) {
  25832. callback(i, map[i]);
  25833. }
  25834. }
  25835. } else {
  25836. for (i in this._map) {
  25837. callback(i, map[i]);
  25838. }
  25839. }
  25840. },
  25841. charCodeOf: function(value) {
  25842. return this._map.indexOf(value);
  25843. },
  25844. getMap: function() {
  25845. return this._map;
  25846. },
  25847. readCharCode: function(str, offset, out) {
  25848. var c = 0;
  25849. var codespaceRanges = this.codespaceRanges;
  25850. var codespaceRangesLen = this.codespaceRanges.length;
  25851. // 9.7.6.2 CMap Mapping
  25852. // The code length is at most 4.
  25853. for (var n = 0; n < codespaceRangesLen; n++) {
  25854. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  25855. // Check each codespace range to see if it falls within.
  25856. var codespaceRange = codespaceRanges[n];
  25857. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  25858. var low = codespaceRange[k++];
  25859. var high = codespaceRange[k++];
  25860. if (c >= low && c <= high) {
  25861. out.charcode = c;
  25862. out.length = n + 1;
  25863. return;
  25864. }
  25865. }
  25866. }
  25867. out.charcode = 0;
  25868. out.length = 1;
  25869. },
  25870. get length() {
  25871. return this._map.length;
  25872. },
  25873. get isIdentityCMap() {
  25874. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  25875. return false;
  25876. }
  25877. if (this._map.length !== 0x10000) {
  25878. return false;
  25879. }
  25880. for (var i = 0; i < 0x10000; i++) {
  25881. if (this._map[i] !== i) {
  25882. return false;
  25883. }
  25884. }
  25885. return true;
  25886. }
  25887. };
  25888. return CMap;
  25889. })();
  25890. // A special case of CMap, where the _map array implicitly has a length of
  25891. // 65536 and each element is equal to its index.
  25892. var IdentityCMap = (function IdentityCMapClosure() {
  25893. function IdentityCMap(vertical, n) {
  25894. CMap.call(this);
  25895. this.vertical = vertical;
  25896. this.addCodespaceRange(n, 0, 0xffff);
  25897. }
  25898. Util.inherit(IdentityCMap, CMap, {});
  25899. IdentityCMap.prototype = {
  25900. addCodespaceRange: CMap.prototype.addCodespaceRange,
  25901. mapCidRange: function(low, high, dstLow) {
  25902. error('should not call mapCidRange');
  25903. },
  25904. mapBfRange: function(low, high, dstLow) {
  25905. error('should not call mapBfRange');
  25906. },
  25907. mapBfRangeToArray: function(low, high, array) {
  25908. error('should not call mapBfRangeToArray');
  25909. },
  25910. mapOne: function(src, dst) {
  25911. error('should not call mapCidOne');
  25912. },
  25913. lookup: function(code) {
  25914. return (isInt(code) && code <= 0xffff) ? code : undefined;
  25915. },
  25916. contains: function(code) {
  25917. return isInt(code) && code <= 0xffff;
  25918. },
  25919. forEach: function(callback) {
  25920. for (var i = 0; i <= 0xffff; i++) {
  25921. callback(i, i);
  25922. }
  25923. },
  25924. charCodeOf: function(value) {
  25925. return (isInt(value) && value <= 0xffff) ? value : -1;
  25926. },
  25927. getMap: function() {
  25928. // Sometimes identity maps must be instantiated, but it's rare.
  25929. var map = new Array(0x10000);
  25930. for (var i = 0; i <= 0xffff; i++) {
  25931. map[i] = i;
  25932. }
  25933. return map;
  25934. },
  25935. readCharCode: CMap.prototype.readCharCode,
  25936. get length() {
  25937. return 0x10000;
  25938. },
  25939. get isIdentityCMap() {
  25940. error('should not access .isIdentityCMap');
  25941. }
  25942. };
  25943. return IdentityCMap;
  25944. })();
  25945. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  25946. function fetchBinaryData(url) {
  25947. return new Promise(function (resolve, reject) {
  25948. var request = new XMLHttpRequest();
  25949. request.open('GET', url, true);
  25950. request.responseType = 'arraybuffer';
  25951. request.onreadystatechange = function () {
  25952. if (request.readyState === XMLHttpRequest.DONE) {
  25953. if (!request.response || request.status !== 200 &&
  25954. request.status !== 0) {
  25955. reject(new Error('Unable to get binary cMap at: ' + url));
  25956. } else {
  25957. resolve(new Uint8Array(request.response));
  25958. }
  25959. }
  25960. };
  25961. request.send(null);
  25962. });
  25963. }
  25964. function hexToInt(a, size) {
  25965. var n = 0;
  25966. for (var i = 0; i <= size; i++) {
  25967. n = (n << 8) | a[i];
  25968. }
  25969. return n >>> 0;
  25970. }
  25971. function hexToStr(a, size) {
  25972. // This code is hot. Special-case some common values to avoid creating an
  25973. // object with subarray().
  25974. if (size === 1) {
  25975. return String.fromCharCode(a[0], a[1]);
  25976. }
  25977. if (size === 3) {
  25978. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  25979. }
  25980. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  25981. }
  25982. function addHex(a, b, size) {
  25983. var c = 0;
  25984. for (var i = size; i >= 0; i--) {
  25985. c += a[i] + b[i];
  25986. a[i] = c & 255;
  25987. c >>= 8;
  25988. }
  25989. }
  25990. function incHex(a, size) {
  25991. var c = 1;
  25992. for (var i = size; i >= 0 && c > 0; i--) {
  25993. c += a[i];
  25994. a[i] = c & 255;
  25995. c >>= 8;
  25996. }
  25997. }
  25998. var MAX_NUM_SIZE = 16;
  25999. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  26000. function BinaryCMapStream(data) {
  26001. this.buffer = data;
  26002. this.pos = 0;
  26003. this.end = data.length;
  26004. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  26005. }
  26006. BinaryCMapStream.prototype = {
  26007. readByte: function () {
  26008. if (this.pos >= this.end) {
  26009. return -1;
  26010. }
  26011. return this.buffer[this.pos++];
  26012. },
  26013. readNumber: function () {
  26014. var n = 0;
  26015. var last;
  26016. do {
  26017. var b = this.readByte();
  26018. if (b < 0) {
  26019. error('unexpected EOF in bcmap');
  26020. }
  26021. last = !(b & 0x80);
  26022. n = (n << 7) | (b & 0x7F);
  26023. } while (!last);
  26024. return n;
  26025. },
  26026. readSigned: function () {
  26027. var n = this.readNumber();
  26028. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  26029. },
  26030. readHex: function (num, size) {
  26031. num.set(this.buffer.subarray(this.pos,
  26032. this.pos + size + 1));
  26033. this.pos += size + 1;
  26034. },
  26035. readHexNumber: function (num, size) {
  26036. var last;
  26037. var stack = this.tmpBuf, sp = 0;
  26038. do {
  26039. var b = this.readByte();
  26040. if (b < 0) {
  26041. error('unexpected EOF in bcmap');
  26042. }
  26043. last = !(b & 0x80);
  26044. stack[sp++] = b & 0x7F;
  26045. } while (!last);
  26046. var i = size, buffer = 0, bufferSize = 0;
  26047. while (i >= 0) {
  26048. while (bufferSize < 8 && stack.length > 0) {
  26049. buffer = (stack[--sp] << bufferSize) | buffer;
  26050. bufferSize += 7;
  26051. }
  26052. num[i] = buffer & 255;
  26053. i--;
  26054. buffer >>= 8;
  26055. bufferSize -= 8;
  26056. }
  26057. },
  26058. readHexSigned: function (num, size) {
  26059. this.readHexNumber(num, size);
  26060. var sign = num[size] & 1 ? 255 : 0;
  26061. var c = 0;
  26062. for (var i = 0; i <= size; i++) {
  26063. c = ((c & 1) << 8) | num[i];
  26064. num[i] = (c >> 1) ^ sign;
  26065. }
  26066. },
  26067. readString: function () {
  26068. var len = this.readNumber();
  26069. var s = '';
  26070. for (var i = 0; i < len; i++) {
  26071. s += String.fromCharCode(this.readNumber());
  26072. }
  26073. return s;
  26074. }
  26075. };
  26076. function processBinaryCMap(url, cMap, extend) {
  26077. return fetchBinaryData(url).then(function (data) {
  26078. var stream = new BinaryCMapStream(data);
  26079. var header = stream.readByte();
  26080. cMap.vertical = !!(header & 1);
  26081. var useCMap = null;
  26082. var start = new Uint8Array(MAX_NUM_SIZE);
  26083. var end = new Uint8Array(MAX_NUM_SIZE);
  26084. var char = new Uint8Array(MAX_NUM_SIZE);
  26085. var charCode = new Uint8Array(MAX_NUM_SIZE);
  26086. var tmp = new Uint8Array(MAX_NUM_SIZE);
  26087. var code;
  26088. var b;
  26089. while ((b = stream.readByte()) >= 0) {
  26090. var type = b >> 5;
  26091. if (type === 7) { // metadata, e.g. comment or usecmap
  26092. switch (b & 0x1F) {
  26093. case 0:
  26094. stream.readString(); // skipping comment
  26095. break;
  26096. case 1:
  26097. useCMap = stream.readString();
  26098. break;
  26099. }
  26100. continue;
  26101. }
  26102. var sequence = !!(b & 0x10);
  26103. var dataSize = b & 15;
  26104. assert(dataSize + 1 <= MAX_NUM_SIZE);
  26105. var ucs2DataSize = 1;
  26106. var subitemsCount = stream.readNumber();
  26107. var i;
  26108. switch (type) {
  26109. case 0: // codespacerange
  26110. stream.readHex(start, dataSize);
  26111. stream.readHexNumber(end, dataSize);
  26112. addHex(end, start, dataSize);
  26113. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  26114. hexToInt(end, dataSize));
  26115. for (i = 1; i < subitemsCount; i++) {
  26116. incHex(end, dataSize);
  26117. stream.readHexNumber(start, dataSize);
  26118. addHex(start, end, dataSize);
  26119. stream.readHexNumber(end, dataSize);
  26120. addHex(end, start, dataSize);
  26121. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  26122. hexToInt(end, dataSize));
  26123. }
  26124. break;
  26125. case 1: // notdefrange
  26126. stream.readHex(start, dataSize);
  26127. stream.readHexNumber(end, dataSize);
  26128. addHex(end, start, dataSize);
  26129. code = stream.readNumber();
  26130. // undefined range, skipping
  26131. for (i = 1; i < subitemsCount; i++) {
  26132. incHex(end, dataSize);
  26133. stream.readHexNumber(start, dataSize);
  26134. addHex(start, end, dataSize);
  26135. stream.readHexNumber(end, dataSize);
  26136. addHex(end, start, dataSize);
  26137. code = stream.readNumber();
  26138. // nop
  26139. }
  26140. break;
  26141. case 2: // cidchar
  26142. stream.readHex(char, dataSize);
  26143. code = stream.readNumber();
  26144. cMap.mapOne(hexToInt(char, dataSize), code);
  26145. for (i = 1; i < subitemsCount; i++) {
  26146. incHex(char, dataSize);
  26147. if (!sequence) {
  26148. stream.readHexNumber(tmp, dataSize);
  26149. addHex(char, tmp, dataSize);
  26150. }
  26151. code = stream.readSigned() + (code + 1);
  26152. cMap.mapOne(hexToInt(char, dataSize), code);
  26153. }
  26154. break;
  26155. case 3: // cidrange
  26156. stream.readHex(start, dataSize);
  26157. stream.readHexNumber(end, dataSize);
  26158. addHex(end, start, dataSize);
  26159. code = stream.readNumber();
  26160. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  26161. code);
  26162. for (i = 1; i < subitemsCount; i++) {
  26163. incHex(end, dataSize);
  26164. if (!sequence) {
  26165. stream.readHexNumber(start, dataSize);
  26166. addHex(start, end, dataSize);
  26167. } else {
  26168. start.set(end);
  26169. }
  26170. stream.readHexNumber(end, dataSize);
  26171. addHex(end, start, dataSize);
  26172. code = stream.readNumber();
  26173. cMap.mapCidRange(hexToInt(start, dataSize),
  26174. hexToInt(end, dataSize), code);
  26175. }
  26176. break;
  26177. case 4: // bfchar
  26178. stream.readHex(char, ucs2DataSize);
  26179. stream.readHex(charCode, dataSize);
  26180. cMap.mapOne(hexToInt(char, ucs2DataSize),
  26181. hexToStr(charCode, dataSize));
  26182. for (i = 1; i < subitemsCount; i++) {
  26183. incHex(char, ucs2DataSize);
  26184. if (!sequence) {
  26185. stream.readHexNumber(tmp, ucs2DataSize);
  26186. addHex(char, tmp, ucs2DataSize);
  26187. }
  26188. incHex(charCode, dataSize);
  26189. stream.readHexSigned(tmp, dataSize);
  26190. addHex(charCode, tmp, dataSize);
  26191. cMap.mapOne(hexToInt(char, ucs2DataSize),
  26192. hexToStr(charCode, dataSize));
  26193. }
  26194. break;
  26195. case 5: // bfrange
  26196. stream.readHex(start, ucs2DataSize);
  26197. stream.readHexNumber(end, ucs2DataSize);
  26198. addHex(end, start, ucs2DataSize);
  26199. stream.readHex(charCode, dataSize);
  26200. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  26201. hexToInt(end, ucs2DataSize),
  26202. hexToStr(charCode, dataSize));
  26203. for (i = 1; i < subitemsCount; i++) {
  26204. incHex(end, ucs2DataSize);
  26205. if (!sequence) {
  26206. stream.readHexNumber(start, ucs2DataSize);
  26207. addHex(start, end, ucs2DataSize);
  26208. } else {
  26209. start.set(end);
  26210. }
  26211. stream.readHexNumber(end, ucs2DataSize);
  26212. addHex(end, start, ucs2DataSize);
  26213. stream.readHex(charCode, dataSize);
  26214. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  26215. hexToInt(end, ucs2DataSize),
  26216. hexToStr(charCode, dataSize));
  26217. }
  26218. break;
  26219. default:
  26220. error('Unknown type: ' + type);
  26221. break;
  26222. }
  26223. }
  26224. if (useCMap) {
  26225. return extend(useCMap);
  26226. }
  26227. return cMap;
  26228. });
  26229. }
  26230. function BinaryCMapReader() {}
  26231. BinaryCMapReader.prototype = {
  26232. read: processBinaryCMap
  26233. };
  26234. return BinaryCMapReader;
  26235. })();
  26236. var CMapFactory = (function CMapFactoryClosure() {
  26237. function strToInt(str) {
  26238. var a = 0;
  26239. for (var i = 0; i < str.length; i++) {
  26240. a = (a << 8) | str.charCodeAt(i);
  26241. }
  26242. return a >>> 0;
  26243. }
  26244. function expectString(obj) {
  26245. if (!isString(obj)) {
  26246. error('Malformed CMap: expected string.');
  26247. }
  26248. }
  26249. function expectInt(obj) {
  26250. if (!isInt(obj)) {
  26251. error('Malformed CMap: expected int.');
  26252. }
  26253. }
  26254. function parseBfChar(cMap, lexer) {
  26255. while (true) {
  26256. var obj = lexer.getObj();
  26257. if (isEOF(obj)) {
  26258. break;
  26259. }
  26260. if (isCmd(obj, 'endbfchar')) {
  26261. return;
  26262. }
  26263. expectString(obj);
  26264. var src = strToInt(obj);
  26265. obj = lexer.getObj();
  26266. // TODO are /dstName used?
  26267. expectString(obj);
  26268. var dst = obj;
  26269. cMap.mapOne(src, dst);
  26270. }
  26271. }
  26272. function parseBfRange(cMap, lexer) {
  26273. while (true) {
  26274. var obj = lexer.getObj();
  26275. if (isEOF(obj)) {
  26276. break;
  26277. }
  26278. if (isCmd(obj, 'endbfrange')) {
  26279. return;
  26280. }
  26281. expectString(obj);
  26282. var low = strToInt(obj);
  26283. obj = lexer.getObj();
  26284. expectString(obj);
  26285. var high = strToInt(obj);
  26286. obj = lexer.getObj();
  26287. if (isInt(obj) || isString(obj)) {
  26288. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  26289. cMap.mapBfRange(low, high, dstLow);
  26290. } else if (isCmd(obj, '[')) {
  26291. obj = lexer.getObj();
  26292. var array = [];
  26293. while (!isCmd(obj, ']') && !isEOF(obj)) {
  26294. array.push(obj);
  26295. obj = lexer.getObj();
  26296. }
  26297. cMap.mapBfRangeToArray(low, high, array);
  26298. } else {
  26299. break;
  26300. }
  26301. }
  26302. error('Invalid bf range.');
  26303. }
  26304. function parseCidChar(cMap, lexer) {
  26305. while (true) {
  26306. var obj = lexer.getObj();
  26307. if (isEOF(obj)) {
  26308. break;
  26309. }
  26310. if (isCmd(obj, 'endcidchar')) {
  26311. return;
  26312. }
  26313. expectString(obj);
  26314. var src = strToInt(obj);
  26315. obj = lexer.getObj();
  26316. expectInt(obj);
  26317. var dst = obj;
  26318. cMap.mapOne(src, dst);
  26319. }
  26320. }
  26321. function parseCidRange(cMap, lexer) {
  26322. while (true) {
  26323. var obj = lexer.getObj();
  26324. if (isEOF(obj)) {
  26325. break;
  26326. }
  26327. if (isCmd(obj, 'endcidrange')) {
  26328. return;
  26329. }
  26330. expectString(obj);
  26331. var low = strToInt(obj);
  26332. obj = lexer.getObj();
  26333. expectString(obj);
  26334. var high = strToInt(obj);
  26335. obj = lexer.getObj();
  26336. expectInt(obj);
  26337. var dstLow = obj;
  26338. cMap.mapCidRange(low, high, dstLow);
  26339. }
  26340. }
  26341. function parseCodespaceRange(cMap, lexer) {
  26342. while (true) {
  26343. var obj = lexer.getObj();
  26344. if (isEOF(obj)) {
  26345. break;
  26346. }
  26347. if (isCmd(obj, 'endcodespacerange')) {
  26348. return;
  26349. }
  26350. if (!isString(obj)) {
  26351. break;
  26352. }
  26353. var low = strToInt(obj);
  26354. obj = lexer.getObj();
  26355. if (!isString(obj)) {
  26356. break;
  26357. }
  26358. var high = strToInt(obj);
  26359. cMap.addCodespaceRange(obj.length, low, high);
  26360. }
  26361. error('Invalid codespace range.');
  26362. }
  26363. function parseWMode(cMap, lexer) {
  26364. var obj = lexer.getObj();
  26365. if (isInt(obj)) {
  26366. cMap.vertical = !!obj;
  26367. }
  26368. }
  26369. function parseCMapName(cMap, lexer) {
  26370. var obj = lexer.getObj();
  26371. if (isName(obj) && isString(obj.name)) {
  26372. cMap.name = obj.name;
  26373. }
  26374. }
  26375. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  26376. var previous;
  26377. var embededUseCMap;
  26378. objLoop: while (true) {
  26379. try {
  26380. var obj = lexer.getObj();
  26381. if (isEOF(obj)) {
  26382. break;
  26383. } else if (isName(obj)) {
  26384. if (obj.name === 'WMode') {
  26385. parseWMode(cMap, lexer);
  26386. } else if (obj.name === 'CMapName') {
  26387. parseCMapName(cMap, lexer);
  26388. }
  26389. previous = obj;
  26390. } else if (isCmd(obj)) {
  26391. switch (obj.cmd) {
  26392. case 'endcmap':
  26393. break objLoop;
  26394. case 'usecmap':
  26395. if (isName(previous)) {
  26396. embededUseCMap = previous.name;
  26397. }
  26398. break;
  26399. case 'begincodespacerange':
  26400. parseCodespaceRange(cMap, lexer);
  26401. break;
  26402. case 'beginbfchar':
  26403. parseBfChar(cMap, lexer);
  26404. break;
  26405. case 'begincidchar':
  26406. parseCidChar(cMap, lexer);
  26407. break;
  26408. case 'beginbfrange':
  26409. parseBfRange(cMap, lexer);
  26410. break;
  26411. case 'begincidrange':
  26412. parseCidRange(cMap, lexer);
  26413. break;
  26414. }
  26415. }
  26416. } catch (ex) {
  26417. if (ex instanceof MissingDataException) {
  26418. throw ex;
  26419. }
  26420. warn('Invalid cMap data: ' + ex);
  26421. continue;
  26422. }
  26423. }
  26424. if (!useCMap && embededUseCMap) {
  26425. // Load the usecmap definition from the file only if there wasn't one
  26426. // specified.
  26427. useCMap = embededUseCMap;
  26428. }
  26429. if (useCMap) {
  26430. return extendCMap(cMap, builtInCMapParams, useCMap);
  26431. }
  26432. return Promise.resolve(cMap);
  26433. }
  26434. function extendCMap(cMap, builtInCMapParams, useCMap) {
  26435. return createBuiltInCMap(useCMap, builtInCMapParams).then(
  26436. function(newCMap) {
  26437. cMap.useCMap = newCMap;
  26438. // If there aren't any code space ranges defined clone all the parent ones
  26439. // into this cMap.
  26440. if (cMap.numCodespaceRanges === 0) {
  26441. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  26442. for (var i = 0; i < useCodespaceRanges.length; i++) {
  26443. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  26444. }
  26445. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  26446. }
  26447. // Merge the map into the current one, making sure not to override
  26448. // any previously defined entries.
  26449. cMap.useCMap.forEach(function(key, value) {
  26450. if (!cMap.contains(key)) {
  26451. cMap.mapOne(key, cMap.useCMap.lookup(key));
  26452. }
  26453. });
  26454. return cMap;
  26455. });
  26456. }
  26457. function parseBinaryCMap(name, builtInCMapParams) {
  26458. var url = builtInCMapParams.url + name + '.bcmap';
  26459. var cMap = new CMap(true);
  26460. return new BinaryCMapReader().read(url, cMap, function (useCMap) {
  26461. return extendCMap(cMap, builtInCMapParams, useCMap);
  26462. });
  26463. }
  26464. function createBuiltInCMap(name, builtInCMapParams) {
  26465. if (name === 'Identity-H') {
  26466. return Promise.resolve(new IdentityCMap(false, 2));
  26467. } else if (name === 'Identity-V') {
  26468. return Promise.resolve(new IdentityCMap(true, 2));
  26469. }
  26470. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  26471. return Promise.reject(new Error('Unknown cMap name: ' + name));
  26472. }
  26473. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  26474. if (builtInCMapParams.packed) {
  26475. return parseBinaryCMap(name, builtInCMapParams);
  26476. }
  26477. return new Promise(function (resolve, reject) {
  26478. var url = builtInCMapParams.url + name;
  26479. var request = new XMLHttpRequest();
  26480. request.onreadystatechange = function () {
  26481. if (request.readyState === XMLHttpRequest.DONE) {
  26482. if (request.status === 200 || request.status === 0) {
  26483. var cMap = new CMap(true);
  26484. var lexer = new Lexer(new StringStream(request.responseText));
  26485. parseCMap(cMap, lexer, builtInCMapParams, null).then(
  26486. function (parsedCMap) {
  26487. resolve(parsedCMap);
  26488. });
  26489. } else {
  26490. reject(new Error('Unable to get cMap at: ' + url));
  26491. }
  26492. }
  26493. };
  26494. request.open('GET', url, true);
  26495. request.send(null);
  26496. });
  26497. }
  26498. return {
  26499. create: function (encoding, builtInCMapParams, useCMap) {
  26500. if (isName(encoding)) {
  26501. return createBuiltInCMap(encoding.name, builtInCMapParams);
  26502. } else if (isStream(encoding)) {
  26503. var cMap = new CMap();
  26504. var lexer = new Lexer(encoding);
  26505. return parseCMap(cMap, lexer, builtInCMapParams, useCMap).then(
  26506. function (parsedCMap) {
  26507. if (parsedCMap.isIdentityCMap) {
  26508. return createBuiltInCMap(parsedCMap.name, builtInCMapParams);
  26509. }
  26510. return parsedCMap;
  26511. });
  26512. }
  26513. return Promise.reject(new Error('Encoding required.'));
  26514. }
  26515. };
  26516. })();
  26517. exports.CMap = CMap;
  26518. exports.CMapFactory = CMapFactory;
  26519. exports.IdentityCMap = IdentityCMap;
  26520. }));
  26521. (function (root, factory) {
  26522. {
  26523. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  26524. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreGlyphList,
  26525. root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings,
  26526. root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode,
  26527. root.pdfjsCoreType1Parser, root.pdfjsCoreCFFParser);
  26528. }
  26529. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  26530. coreGlyphList, coreFontRenderer, coreEncodings,
  26531. coreStandardFonts, coreUnicode, coreType1Parser,
  26532. coreCFFParser) {
  26533. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  26534. var FontType = sharedUtil.FontType;
  26535. var assert = sharedUtil.assert;
  26536. var bytesToString = sharedUtil.bytesToString;
  26537. var error = sharedUtil.error;
  26538. var info = sharedUtil.info;
  26539. var isArray = sharedUtil.isArray;
  26540. var isInt = sharedUtil.isInt;
  26541. var isNum = sharedUtil.isNum;
  26542. var readUint32 = sharedUtil.readUint32;
  26543. var shadow = sharedUtil.shadow;
  26544. var string32 = sharedUtil.string32;
  26545. var warn = sharedUtil.warn;
  26546. var MissingDataException = sharedUtil.MissingDataException;
  26547. var isSpace = sharedUtil.isSpace;
  26548. var Stream = coreStream.Stream;
  26549. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  26550. var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
  26551. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  26552. var StandardEncoding = coreEncodings.StandardEncoding;
  26553. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  26554. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  26555. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  26556. var getEncoding = coreEncodings.getEncoding;
  26557. var getStdFontMap = coreStandardFonts.getStdFontMap;
  26558. var getNonStdFontMap = coreStandardFonts.getNonStdFontMap;
  26559. var getGlyphMapForStandardFonts = coreStandardFonts.getGlyphMapForStandardFonts;
  26560. var getSupplementalGlyphMapForArialBlack =
  26561. coreStandardFonts.getSupplementalGlyphMapForArialBlack;
  26562. var getUnicodeRangeFor = coreUnicode.getUnicodeRangeFor;
  26563. var mapSpecialUnicodeValues = coreUnicode.mapSpecialUnicodeValues;
  26564. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  26565. var Type1Parser = coreType1Parser.Type1Parser;
  26566. var CFFStandardStrings = coreCFFParser.CFFStandardStrings;
  26567. var CFFParser = coreCFFParser.CFFParser;
  26568. var CFFCompiler = coreCFFParser.CFFCompiler;
  26569. var CFF = coreCFFParser.CFF;
  26570. var CFFHeader = coreCFFParser.CFFHeader;
  26571. var CFFTopDict = coreCFFParser.CFFTopDict;
  26572. var CFFPrivateDict = coreCFFParser.CFFPrivateDict;
  26573. var CFFStrings = coreCFFParser.CFFStrings;
  26574. var CFFIndex = coreCFFParser.CFFIndex;
  26575. var CFFCharset = coreCFFParser.CFFCharset;
  26576. // Unicode Private Use Area
  26577. var PRIVATE_USE_OFFSET_START = 0xE000;
  26578. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  26579. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  26580. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  26581. // except for Type 3 fonts
  26582. var PDF_GLYPH_SPACE_UNITS = 1000;
  26583. // Accented charactars are not displayed properly on Windows, using this flag
  26584. // to control analysis of seac charstrings.
  26585. var SEAC_ANALYSIS_ENABLED = false;
  26586. var FontFlags = {
  26587. FixedPitch: 1,
  26588. Serif: 2,
  26589. Symbolic: 4,
  26590. Script: 8,
  26591. Nonsymbolic: 32,
  26592. Italic: 64,
  26593. AllCap: 65536,
  26594. SmallCap: 131072,
  26595. ForceBold: 262144
  26596. };
  26597. var MacStandardGlyphOrdering = [
  26598. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  26599. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  26600. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  26601. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  26602. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  26603. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  26604. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  26605. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  26606. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  26607. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  26608. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  26609. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  26610. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  26611. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  26612. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  26613. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  26614. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  26615. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  26616. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  26617. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  26618. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  26619. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  26620. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  26621. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  26622. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  26623. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  26624. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  26625. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  26626. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  26627. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  26628. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  26629. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  26630. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  26631. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  26632. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  26633. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  26634. function adjustWidths(properties) {
  26635. if (!properties.fontMatrix) {
  26636. return;
  26637. }
  26638. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  26639. return;
  26640. }
  26641. // adjusting width to fontMatrix scale
  26642. var scale = 0.001 / properties.fontMatrix[0];
  26643. var glyphsWidths = properties.widths;
  26644. for (var glyph in glyphsWidths) {
  26645. glyphsWidths[glyph] *= scale;
  26646. }
  26647. properties.defaultWidth *= scale;
  26648. }
  26649. function adjustToUnicode(properties, builtInEncoding) {
  26650. if (properties.hasIncludedToUnicodeMap) {
  26651. return; // The font dictionary has a `ToUnicode` entry.
  26652. }
  26653. if (properties.hasEncoding) {
  26654. return; // The font dictionary has an `Encoding` entry.
  26655. }
  26656. if (builtInEncoding === properties.defaultEncoding) {
  26657. return; // No point in trying to adjust `toUnicode` if the encodings match.
  26658. }
  26659. if (properties.toUnicode instanceof IdentityToUnicodeMap) {
  26660. return;
  26661. }
  26662. var toUnicode = [], glyphsUnicodeMap = getGlyphsUnicode();
  26663. for (var charCode in builtInEncoding) {
  26664. var glyphName = builtInEncoding[charCode];
  26665. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  26666. if (unicode !== -1) {
  26667. toUnicode[charCode] = String.fromCharCode(unicode);
  26668. }
  26669. }
  26670. properties.toUnicode.amend(toUnicode);
  26671. }
  26672. function getFontType(type, subtype) {
  26673. switch (type) {
  26674. case 'Type1':
  26675. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  26676. case 'CIDFontType0':
  26677. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  26678. FontType.CIDFONTTYPE0;
  26679. case 'OpenType':
  26680. return FontType.OPENTYPE;
  26681. case 'TrueType':
  26682. return FontType.TRUETYPE;
  26683. case 'CIDFontType2':
  26684. return FontType.CIDFONTTYPE2;
  26685. case 'MMType1':
  26686. return FontType.MMTYPE1;
  26687. case 'Type0':
  26688. return FontType.TYPE0;
  26689. default:
  26690. return FontType.UNKNOWN;
  26691. }
  26692. }
  26693. // Some bad PDF generators, e.g. Scribus PDF, include glyph names
  26694. // in a 'uniXXXX' format -- attempting to recover proper ones.
  26695. function recoverGlyphName(name, glyphsUnicodeMap) {
  26696. if (glyphsUnicodeMap[name] !== undefined) {
  26697. return name;
  26698. }
  26699. // The glyph name is non-standard, trying to recover.
  26700. var unicode = getUnicodeForGlyph(name, glyphsUnicodeMap);
  26701. if (unicode !== -1) {
  26702. for (var key in glyphsUnicodeMap) {
  26703. if (glyphsUnicodeMap[key] === unicode) {
  26704. return key;
  26705. }
  26706. }
  26707. }
  26708. info('Unable to recover a standard glyph name for: ' + name);
  26709. return name;
  26710. }
  26711. var Glyph = (function GlyphClosure() {
  26712. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  26713. isSpace, isInFont) {
  26714. this.fontChar = fontChar;
  26715. this.unicode = unicode;
  26716. this.accent = accent;
  26717. this.width = width;
  26718. this.vmetric = vmetric;
  26719. this.operatorListId = operatorListId;
  26720. this.isSpace = isSpace;
  26721. this.isInFont = isInFont;
  26722. }
  26723. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  26724. vmetric, operatorListId, isSpace,
  26725. isInFont) {
  26726. return this.fontChar === fontChar &&
  26727. this.unicode === unicode &&
  26728. this.accent === accent &&
  26729. this.width === width &&
  26730. this.vmetric === vmetric &&
  26731. this.operatorListId === operatorListId &&
  26732. this.isSpace === isSpace &&
  26733. this.isInFont === isInFont;
  26734. };
  26735. return Glyph;
  26736. })();
  26737. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  26738. function ToUnicodeMap(cmap) {
  26739. // The elements of this._map can be integers or strings, depending on how
  26740. // |cmap| was created.
  26741. this._map = cmap;
  26742. }
  26743. ToUnicodeMap.prototype = {
  26744. get length() {
  26745. return this._map.length;
  26746. },
  26747. forEach: function(callback) {
  26748. for (var charCode in this._map) {
  26749. callback(charCode, this._map[charCode].charCodeAt(0));
  26750. }
  26751. },
  26752. has: function(i) {
  26753. return this._map[i] !== undefined;
  26754. },
  26755. get: function(i) {
  26756. return this._map[i];
  26757. },
  26758. charCodeOf: function(v) {
  26759. return this._map.indexOf(v);
  26760. },
  26761. amend: function (map) {
  26762. for (var charCode in map) {
  26763. this._map[charCode] = map[charCode];
  26764. }
  26765. },
  26766. };
  26767. return ToUnicodeMap;
  26768. })();
  26769. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  26770. function IdentityToUnicodeMap(firstChar, lastChar) {
  26771. this.firstChar = firstChar;
  26772. this.lastChar = lastChar;
  26773. }
  26774. IdentityToUnicodeMap.prototype = {
  26775. get length() {
  26776. return (this.lastChar + 1) - this.firstChar;
  26777. },
  26778. forEach: function (callback) {
  26779. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  26780. callback(i, i);
  26781. }
  26782. },
  26783. has: function (i) {
  26784. return this.firstChar <= i && i <= this.lastChar;
  26785. },
  26786. get: function (i) {
  26787. if (this.firstChar <= i && i <= this.lastChar) {
  26788. return String.fromCharCode(i);
  26789. }
  26790. return undefined;
  26791. },
  26792. charCodeOf: function (v) {
  26793. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  26794. },
  26795. amend: function (map) {
  26796. error('Should not call amend()');
  26797. },
  26798. };
  26799. return IdentityToUnicodeMap;
  26800. })();
  26801. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  26802. function writeInt16(dest, offset, num) {
  26803. dest[offset] = (num >> 8) & 0xFF;
  26804. dest[offset + 1] = num & 0xFF;
  26805. }
  26806. function writeInt32(dest, offset, num) {
  26807. dest[offset] = (num >> 24) & 0xFF;
  26808. dest[offset + 1] = (num >> 16) & 0xFF;
  26809. dest[offset + 2] = (num >> 8) & 0xFF;
  26810. dest[offset + 3] = num & 0xFF;
  26811. }
  26812. function writeData(dest, offset, data) {
  26813. var i, ii;
  26814. if (data instanceof Uint8Array) {
  26815. dest.set(data, offset);
  26816. } else if (typeof data === 'string') {
  26817. for (i = 0, ii = data.length; i < ii; i++) {
  26818. dest[offset++] = data.charCodeAt(i) & 0xFF;
  26819. }
  26820. } else {
  26821. // treating everything else as array
  26822. for (i = 0, ii = data.length; i < ii; i++) {
  26823. dest[offset++] = data[i] & 0xFF;
  26824. }
  26825. }
  26826. }
  26827. function OpenTypeFileBuilder(sfnt) {
  26828. this.sfnt = sfnt;
  26829. this.tables = Object.create(null);
  26830. }
  26831. OpenTypeFileBuilder.getSearchParams =
  26832. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  26833. var maxPower2 = 1, log2 = 0;
  26834. while ((maxPower2 ^ entriesCount) > maxPower2) {
  26835. maxPower2 <<= 1;
  26836. log2++;
  26837. }
  26838. var searchRange = maxPower2 * entrySize;
  26839. return {
  26840. range: searchRange,
  26841. entry: log2,
  26842. rangeShift: entrySize * entriesCount - searchRange
  26843. };
  26844. };
  26845. var OTF_HEADER_SIZE = 12;
  26846. var OTF_TABLE_ENTRY_SIZE = 16;
  26847. OpenTypeFileBuilder.prototype = {
  26848. toArray: function OpenTypeFileBuilder_toArray() {
  26849. var sfnt = this.sfnt;
  26850. // Tables needs to be written by ascendant alphabetic order
  26851. var tables = this.tables;
  26852. var tablesNames = Object.keys(tables);
  26853. tablesNames.sort();
  26854. var numTables = tablesNames.length;
  26855. var i, j, jj, table, tableName;
  26856. // layout the tables data
  26857. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  26858. var tableOffsets = [offset];
  26859. for (i = 0; i < numTables; i++) {
  26860. table = tables[tablesNames[i]];
  26861. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  26862. offset += paddedLength;
  26863. tableOffsets.push(offset);
  26864. }
  26865. var file = new Uint8Array(offset);
  26866. // write the table data first (mostly for checksum)
  26867. for (i = 0; i < numTables; i++) {
  26868. table = tables[tablesNames[i]];
  26869. writeData(file, tableOffsets[i], table);
  26870. }
  26871. // sfnt version (4 bytes)
  26872. if (sfnt === 'true') {
  26873. // Windows hates the Mac TrueType sfnt version number
  26874. sfnt = string32(0x00010000);
  26875. }
  26876. file[0] = sfnt.charCodeAt(0) & 0xFF;
  26877. file[1] = sfnt.charCodeAt(1) & 0xFF;
  26878. file[2] = sfnt.charCodeAt(2) & 0xFF;
  26879. file[3] = sfnt.charCodeAt(3) & 0xFF;
  26880. // numTables (2 bytes)
  26881. writeInt16(file, 4, numTables);
  26882. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  26883. // searchRange (2 bytes)
  26884. writeInt16(file, 6, searchParams.range);
  26885. // entrySelector (2 bytes)
  26886. writeInt16(file, 8, searchParams.entry);
  26887. // rangeShift (2 bytes)
  26888. writeInt16(file, 10, searchParams.rangeShift);
  26889. offset = OTF_HEADER_SIZE;
  26890. // writing table entries
  26891. for (i = 0; i < numTables; i++) {
  26892. tableName = tablesNames[i];
  26893. file[offset] = tableName.charCodeAt(0) & 0xFF;
  26894. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  26895. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  26896. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  26897. // checksum
  26898. var checksum = 0;
  26899. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  26900. var quad = readUint32(file, j);
  26901. checksum = (checksum + quad) >>> 0;
  26902. }
  26903. writeInt32(file, offset + 4, checksum);
  26904. // offset
  26905. writeInt32(file, offset + 8, tableOffsets[i]);
  26906. // length
  26907. writeInt32(file, offset + 12, tables[tableName].length);
  26908. offset += OTF_TABLE_ENTRY_SIZE;
  26909. }
  26910. return file;
  26911. },
  26912. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  26913. if (tag in this.tables) {
  26914. throw new Error('Table ' + tag + ' already exists');
  26915. }
  26916. this.tables[tag] = data;
  26917. }
  26918. };
  26919. return OpenTypeFileBuilder;
  26920. })();
  26921. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  26922. // issues when they are painted on the canvas, e.g. complex-script shaping or
  26923. // control/whitespace characters. The ranges are listed in pairs: the first item
  26924. // is a code of the first problematic code, the second one is the next
  26925. // non-problematic code. The ranges must be in sorted order.
  26926. var ProblematicCharRanges = new Int32Array([
  26927. // Control characters.
  26928. 0x0000, 0x0020,
  26929. 0x007F, 0x00A1,
  26930. 0x00AD, 0x00AE,
  26931. // Chars that is used in complex-script shaping.
  26932. 0x0600, 0x0780,
  26933. 0x08A0, 0x10A0,
  26934. 0x1780, 0x1800,
  26935. 0x1C00, 0x1C50,
  26936. // General punctuation chars.
  26937. 0x2000, 0x2010,
  26938. 0x2011, 0x2012,
  26939. 0x2028, 0x2030,
  26940. 0x205F, 0x2070,
  26941. 0x25CC, 0x25CD,
  26942. 0x3000, 0x3001,
  26943. // Chars that is used in complex-script shaping.
  26944. 0xAA60, 0xAA80,
  26945. // Specials Unicode block.
  26946. 0xFFF0, 0x10000
  26947. ]);
  26948. /**
  26949. * 'Font' is the class the outside world should use, it encapsulate all the font
  26950. * decoding logics whatever type it is (assuming the font type is supported).
  26951. *
  26952. * For example to read a Type1 font and to attach it to the document:
  26953. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  26954. * type1Font.bind();
  26955. */
  26956. var Font = (function FontClosure() {
  26957. function Font(name, file, properties) {
  26958. var charCode, glyphName, unicode;
  26959. this.name = name;
  26960. this.loadedName = properties.loadedName;
  26961. this.isType3Font = properties.isType3Font;
  26962. this.sizes = [];
  26963. this.missingFile = false;
  26964. this.glyphCache = Object.create(null);
  26965. var names = name.split('+');
  26966. names = names.length > 1 ? names[1] : names[0];
  26967. names = names.split(/[-,_]/g)[0];
  26968. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  26969. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  26970. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  26971. var type = properties.type;
  26972. var subtype = properties.subtype;
  26973. this.type = type;
  26974. this.fallbackName = (this.isMonospace ? 'monospace' :
  26975. (this.isSerifFont ? 'serif' : 'sans-serif'));
  26976. this.differences = properties.differences;
  26977. this.widths = properties.widths;
  26978. this.defaultWidth = properties.defaultWidth;
  26979. this.composite = properties.composite;
  26980. this.wideChars = properties.wideChars;
  26981. this.cMap = properties.cMap;
  26982. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  26983. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  26984. this.fontMatrix = properties.fontMatrix;
  26985. this.bbox = properties.bbox;
  26986. this.toUnicode = properties.toUnicode;
  26987. this.toFontChar = [];
  26988. if (properties.type === 'Type3') {
  26989. for (charCode = 0; charCode < 256; charCode++) {
  26990. this.toFontChar[charCode] = (this.differences[charCode] ||
  26991. properties.defaultEncoding[charCode]);
  26992. }
  26993. this.fontType = FontType.TYPE3;
  26994. return;
  26995. }
  26996. this.cidEncoding = properties.cidEncoding;
  26997. this.vertical = properties.vertical;
  26998. if (this.vertical) {
  26999. this.vmetrics = properties.vmetrics;
  27000. this.defaultVMetrics = properties.defaultVMetrics;
  27001. }
  27002. var glyphsUnicodeMap;
  27003. if (!file || file.isEmpty) {
  27004. if (file) {
  27005. // Some bad PDF generators will include empty font files,
  27006. // attempting to recover by assuming that no file exists.
  27007. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  27008. }
  27009. this.missingFile = true;
  27010. // The file data is not specified. Trying to fix the font name
  27011. // to be used with the canvas.font.
  27012. var fontName = name.replace(/[,_]/g, '-');
  27013. var stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap();
  27014. var isStandardFont = !!stdFontMap[fontName] ||
  27015. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  27016. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  27017. this.bold = (fontName.search(/bold/gi) !== -1);
  27018. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  27019. (fontName.search(/italic/gi) !== -1));
  27020. // Use 'name' instead of 'fontName' here because the original
  27021. // name ArialBlack for example will be replaced by Helvetica.
  27022. this.black = (name.search(/Black/g) !== -1);
  27023. // if at least one width is present, remeasure all chars when exists
  27024. this.remeasure = Object.keys(this.widths).length > 0;
  27025. if (isStandardFont && type === 'CIDFontType2' &&
  27026. properties.cidEncoding.indexOf('Identity-') === 0) {
  27027. var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
  27028. // Standard fonts might be embedded as CID font without glyph mapping.
  27029. // Building one based on GlyphMapForStandardFonts.
  27030. var map = [];
  27031. for (charCode in GlyphMapForStandardFonts) {
  27032. map[+charCode] = GlyphMapForStandardFonts[charCode];
  27033. }
  27034. if (/ArialBlack/i.test(name)) {
  27035. var SupplementalGlyphMapForArialBlack =
  27036. getSupplementalGlyphMapForArialBlack();
  27037. for (charCode in SupplementalGlyphMapForArialBlack) {
  27038. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  27039. }
  27040. }
  27041. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  27042. if (!isIdentityUnicode) {
  27043. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  27044. map[+charCode] = unicodeCharCode;
  27045. });
  27046. }
  27047. this.toFontChar = map;
  27048. this.toUnicode = new ToUnicodeMap(map);
  27049. } else if (/Symbol/i.test(fontName)) {
  27050. this.toFontChar = buildToFontChar(SymbolSetEncoding, getGlyphsUnicode(),
  27051. properties.differences);
  27052. } else if (/Dingbats/i.test(fontName)) {
  27053. if (/Wingdings/i.test(name)) {
  27054. warn('Non-embedded Wingdings font, falling back to ZapfDingbats.');
  27055. }
  27056. this.toFontChar = buildToFontChar(ZapfDingbatsEncoding,
  27057. getDingbatsGlyphsUnicode(),
  27058. properties.differences);
  27059. } else if (isStandardFont) {
  27060. this.toFontChar = buildToFontChar(properties.defaultEncoding,
  27061. getGlyphsUnicode(),
  27062. properties.differences);
  27063. } else {
  27064. glyphsUnicodeMap = getGlyphsUnicode();
  27065. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  27066. if (!this.composite) {
  27067. glyphName = (properties.differences[charCode] ||
  27068. properties.defaultEncoding[charCode]);
  27069. unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  27070. if (unicode !== -1) {
  27071. unicodeCharCode = unicode;
  27072. }
  27073. }
  27074. this.toFontChar[charCode] = unicodeCharCode;
  27075. }.bind(this));
  27076. }
  27077. this.loadedName = fontName.split('-')[0];
  27078. this.loading = false;
  27079. this.fontType = getFontType(type, subtype);
  27080. return;
  27081. }
  27082. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  27083. if (subtype === 'Type1C') {
  27084. if (type !== 'Type1' && type !== 'MMType1') {
  27085. // Some TrueType fonts by mistake claim Type1C
  27086. if (isTrueTypeFile(file)) {
  27087. subtype = 'TrueType';
  27088. } else {
  27089. type = 'Type1';
  27090. }
  27091. } else if (isOpenTypeFile(file)) {
  27092. // Sometimes the type/subtype can be a complete lie (see issue7598.pdf).
  27093. type = subtype = 'OpenType';
  27094. }
  27095. }
  27096. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  27097. type = 'CIDFontType0';
  27098. }
  27099. if (subtype === 'OpenType') {
  27100. type = 'OpenType';
  27101. }
  27102. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  27103. if (type === 'CIDFontType0') {
  27104. if (isType1File(file)) {
  27105. subtype = 'CIDFontType0';
  27106. } else if (isOpenTypeFile(file)) {
  27107. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  27108. type = subtype = 'OpenType';
  27109. } else {
  27110. subtype = 'CIDFontType0C';
  27111. }
  27112. }
  27113. var data;
  27114. switch (type) {
  27115. case 'MMType1':
  27116. info('MMType1 font (' + name + '), falling back to Type1.');
  27117. /* falls through */
  27118. case 'Type1':
  27119. case 'CIDFontType0':
  27120. this.mimetype = 'font/opentype';
  27121. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  27122. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  27123. adjustWidths(properties);
  27124. // Wrap the CFF data inside an OTF font file
  27125. data = this.convert(name, cff, properties);
  27126. break;
  27127. case 'OpenType':
  27128. case 'TrueType':
  27129. case 'CIDFontType2':
  27130. this.mimetype = 'font/opentype';
  27131. // Repair the TrueType file. It is can be damaged in the point of
  27132. // view of the sanitizer
  27133. data = this.checkAndRepair(name, file, properties);
  27134. if (this.isOpenType) {
  27135. adjustWidths(properties);
  27136. type = 'OpenType';
  27137. }
  27138. break;
  27139. default:
  27140. error('Font ' + type + ' is not supported');
  27141. break;
  27142. }
  27143. this.data = data;
  27144. this.fontType = getFontType(type, subtype);
  27145. // Transfer some properties again that could change during font conversion
  27146. this.fontMatrix = properties.fontMatrix;
  27147. this.widths = properties.widths;
  27148. this.defaultWidth = properties.defaultWidth;
  27149. this.toUnicode = properties.toUnicode;
  27150. this.encoding = properties.baseEncoding;
  27151. this.seacMap = properties.seacMap;
  27152. this.loading = true;
  27153. }
  27154. Font.getFontID = (function () {
  27155. var ID = 1;
  27156. return function Font_getFontID() {
  27157. return String(ID++);
  27158. };
  27159. })();
  27160. function int16(b0, b1) {
  27161. return (b0 << 8) + b1;
  27162. }
  27163. function signedInt16(b0, b1) {
  27164. var value = (b0 << 8) + b1;
  27165. return value & (1 << 15) ? value - 0x10000 : value;
  27166. }
  27167. function int32(b0, b1, b2, b3) {
  27168. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  27169. }
  27170. function string16(value) {
  27171. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  27172. }
  27173. function safeString16(value) {
  27174. // clamp value to the 16-bit int range
  27175. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  27176. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  27177. }
  27178. function isTrueTypeFile(file) {
  27179. var header = file.peekBytes(4);
  27180. return readUint32(header, 0) === 0x00010000;
  27181. }
  27182. function isOpenTypeFile(file) {
  27183. var header = file.peekBytes(4);
  27184. return bytesToString(header) === 'OTTO';
  27185. }
  27186. function isType1File(file) {
  27187. var header = file.peekBytes(2);
  27188. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  27189. if (header[0] === 0x25 && header[1] === 0x21) {
  27190. return true;
  27191. }
  27192. // ... obviously some fonts violate that part of the specification,
  27193. // please refer to the comment in |Type1Font| below.
  27194. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  27195. return true;
  27196. }
  27197. return false;
  27198. }
  27199. function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
  27200. var toFontChar = [], unicode;
  27201. for (var i = 0, ii = encoding.length; i < ii; i++) {
  27202. unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap);
  27203. if (unicode !== -1) {
  27204. toFontChar[i] = unicode;
  27205. }
  27206. }
  27207. for (var charCode in differences) {
  27208. unicode = getUnicodeForGlyph(differences[charCode], glyphsUnicodeMap);
  27209. if (unicode !== -1) {
  27210. toFontChar[+charCode] = unicode;
  27211. }
  27212. }
  27213. return toFontChar;
  27214. }
  27215. /**
  27216. * Helper function for |adjustMapping|.
  27217. * @return {boolean}
  27218. */
  27219. function isProblematicUnicodeLocation(code) {
  27220. // Using binary search to find a range start.
  27221. var i = 0, j = ProblematicCharRanges.length - 1;
  27222. while (i < j) {
  27223. var c = (i + j + 1) >> 1;
  27224. if (code < ProblematicCharRanges[c]) {
  27225. j = c - 1;
  27226. } else {
  27227. i = c;
  27228. }
  27229. }
  27230. // Even index means code in problematic range.
  27231. return !(i & 1);
  27232. }
  27233. /**
  27234. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  27235. * with their unicode value. It also moves char codes that are in known
  27236. * problematic locations.
  27237. * @return {Object} Two properties:
  27238. * 'toFontChar' - maps original char codes(the value that will be read
  27239. * from commands such as show text) to the char codes that will be used in the
  27240. * font that we build
  27241. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  27242. */
  27243. function adjustMapping(charCodeToGlyphId, properties) {
  27244. var toUnicode = properties.toUnicode;
  27245. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  27246. var isIdentityUnicode =
  27247. properties.toUnicode instanceof IdentityToUnicodeMap;
  27248. var newMap = Object.create(null);
  27249. var toFontChar = [];
  27250. var usedFontCharCodes = [];
  27251. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  27252. for (var originalCharCode in charCodeToGlyphId) {
  27253. originalCharCode |= 0;
  27254. var glyphId = charCodeToGlyphId[originalCharCode];
  27255. var fontCharCode = originalCharCode;
  27256. // First try to map the value to a unicode position if a non identity map
  27257. // was created.
  27258. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  27259. var unicode = toUnicode.get(fontCharCode);
  27260. // TODO: Try to map ligatures to the correct spot.
  27261. if (unicode.length === 1) {
  27262. fontCharCode = unicode.charCodeAt(0);
  27263. }
  27264. }
  27265. // Try to move control characters, special characters and already mapped
  27266. // characters to the private use area since they will not be drawn by
  27267. // canvas if left in their current position. Also, move characters if the
  27268. // font was symbolic and there is only an identity unicode map since the
  27269. // characters probably aren't in the correct position (fixes an issue
  27270. // with firefox and thuluthfont).
  27271. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  27272. isProblematicUnicodeLocation(fontCharCode) ||
  27273. (isSymbolic && isIdentityUnicode)) &&
  27274. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  27275. // Loop to try and find a free spot in the private use area.
  27276. do {
  27277. fontCharCode = nextAvailableFontCharCode++;
  27278. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  27279. fontCharCode = 0xF020;
  27280. nextAvailableFontCharCode = fontCharCode + 1;
  27281. }
  27282. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  27283. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  27284. }
  27285. newMap[fontCharCode] = glyphId;
  27286. toFontChar[originalCharCode] = fontCharCode;
  27287. usedFontCharCodes[fontCharCode] = true;
  27288. }
  27289. return {
  27290. toFontChar: toFontChar,
  27291. charCodeToGlyphId: newMap,
  27292. nextAvailableFontCharCode: nextAvailableFontCharCode
  27293. };
  27294. }
  27295. function getRanges(glyphs, numGlyphs) {
  27296. // Array.sort() sorts by characters, not numerically, so convert to an
  27297. // array of characters.
  27298. var codes = [];
  27299. for (var charCode in glyphs) {
  27300. // Remove an invalid glyph ID mappings to make OTS happy.
  27301. if (glyphs[charCode] >= numGlyphs) {
  27302. continue;
  27303. }
  27304. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  27305. }
  27306. codes.sort(function fontGetRangesSort(a, b) {
  27307. return a.fontCharCode - b.fontCharCode;
  27308. });
  27309. // Split the sorted codes into ranges.
  27310. var ranges = [];
  27311. var length = codes.length;
  27312. for (var n = 0; n < length; ) {
  27313. var start = codes[n].fontCharCode;
  27314. var codeIndices = [codes[n].glyphId];
  27315. ++n;
  27316. var end = start;
  27317. while (n < length && end + 1 === codes[n].fontCharCode) {
  27318. codeIndices.push(codes[n].glyphId);
  27319. ++end;
  27320. ++n;
  27321. if (end === 0xFFFF) {
  27322. break;
  27323. }
  27324. }
  27325. ranges.push([start, end, codeIndices]);
  27326. }
  27327. return ranges;
  27328. }
  27329. function createCmapTable(glyphs, numGlyphs) {
  27330. var ranges = getRanges(glyphs, numGlyphs);
  27331. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  27332. var cmap = '\x00\x00' + // version
  27333. string16(numTables) + // numTables
  27334. '\x00\x03' + // platformID
  27335. '\x00\x01' + // encodingID
  27336. string32(4 + numTables * 8); // start of the table record
  27337. var i, ii, j, jj;
  27338. for (i = ranges.length - 1; i >= 0; --i) {
  27339. if (ranges[i][0] <= 0xFFFF) { break; }
  27340. }
  27341. var bmpLength = i + 1;
  27342. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  27343. ranges[i][1] = 0xFFFE;
  27344. }
  27345. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  27346. var segCount = bmpLength + trailingRangesCount;
  27347. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  27348. // Fill up the 4 parallel arrays describing the segments.
  27349. var startCount = '';
  27350. var endCount = '';
  27351. var idDeltas = '';
  27352. var idRangeOffsets = '';
  27353. var glyphsIds = '';
  27354. var bias = 0;
  27355. var range, start, end, codes;
  27356. for (i = 0, ii = bmpLength; i < ii; i++) {
  27357. range = ranges[i];
  27358. start = range[0];
  27359. end = range[1];
  27360. startCount += string16(start);
  27361. endCount += string16(end);
  27362. codes = range[2];
  27363. var contiguous = true;
  27364. for (j = 1, jj = codes.length; j < jj; ++j) {
  27365. if (codes[j] !== codes[j - 1] + 1) {
  27366. contiguous = false;
  27367. break;
  27368. }
  27369. }
  27370. if (!contiguous) {
  27371. var offset = (segCount - i) * 2 + bias * 2;
  27372. bias += (end - start + 1);
  27373. idDeltas += string16(0);
  27374. idRangeOffsets += string16(offset);
  27375. for (j = 0, jj = codes.length; j < jj; ++j) {
  27376. glyphsIds += string16(codes[j]);
  27377. }
  27378. } else {
  27379. var startCode = codes[0];
  27380. idDeltas += string16((startCode - start) & 0xFFFF);
  27381. idRangeOffsets += string16(0);
  27382. }
  27383. }
  27384. if (trailingRangesCount > 0) {
  27385. endCount += '\xFF\xFF';
  27386. startCount += '\xFF\xFF';
  27387. idDeltas += '\x00\x01';
  27388. idRangeOffsets += '\x00\x00';
  27389. }
  27390. var format314 = '\x00\x00' + // language
  27391. string16(2 * segCount) +
  27392. string16(searchParams.range) +
  27393. string16(searchParams.entry) +
  27394. string16(searchParams.rangeShift) +
  27395. endCount + '\x00\x00' + startCount +
  27396. idDeltas + idRangeOffsets + glyphsIds;
  27397. var format31012 = '';
  27398. var header31012 = '';
  27399. if (numTables > 1) {
  27400. cmap += '\x00\x03' + // platformID
  27401. '\x00\x0A' + // encodingID
  27402. string32(4 + numTables * 8 +
  27403. 4 + format314.length); // start of the table record
  27404. format31012 = '';
  27405. for (i = 0, ii = ranges.length; i < ii; i++) {
  27406. range = ranges[i];
  27407. start = range[0];
  27408. codes = range[2];
  27409. var code = codes[0];
  27410. for (j = 1, jj = codes.length; j < jj; ++j) {
  27411. if (codes[j] !== codes[j - 1] + 1) {
  27412. end = range[0] + j - 1;
  27413. format31012 += string32(start) + // startCharCode
  27414. string32(end) + // endCharCode
  27415. string32(code); // startGlyphID
  27416. start = end + 1;
  27417. code = codes[j];
  27418. }
  27419. }
  27420. format31012 += string32(start) + // startCharCode
  27421. string32(range[1]) + // endCharCode
  27422. string32(code); // startGlyphID
  27423. }
  27424. header31012 = '\x00\x0C' + // format
  27425. '\x00\x00' + // reserved
  27426. string32(format31012.length + 16) + // length
  27427. '\x00\x00\x00\x00' + // language
  27428. string32(format31012.length / 12); // nGroups
  27429. }
  27430. return cmap + '\x00\x04' + // format
  27431. string16(format314.length + 4) + // length
  27432. format314 + header31012 + format31012;
  27433. }
  27434. function validateOS2Table(os2) {
  27435. var stream = new Stream(os2.data);
  27436. var version = stream.getUint16();
  27437. // TODO verify all OS/2 tables fields, but currently we validate only those
  27438. // that give us issues
  27439. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  27440. var selection = stream.getUint16();
  27441. if (version < 4 && (selection & 0x0300)) {
  27442. return false;
  27443. }
  27444. var firstChar = stream.getUint16();
  27445. var lastChar = stream.getUint16();
  27446. if (firstChar > lastChar) {
  27447. return false;
  27448. }
  27449. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  27450. var usWinAscent = stream.getUint16();
  27451. if (usWinAscent === 0) { // makes font unreadable by windows
  27452. return false;
  27453. }
  27454. // OS/2 appears to be valid, resetting some fields
  27455. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  27456. return true;
  27457. }
  27458. function createOS2Table(properties, charstrings, override) {
  27459. override = override || {
  27460. unitsPerEm: 0,
  27461. yMax: 0,
  27462. yMin: 0,
  27463. ascent: 0,
  27464. descent: 0
  27465. };
  27466. var ulUnicodeRange1 = 0;
  27467. var ulUnicodeRange2 = 0;
  27468. var ulUnicodeRange3 = 0;
  27469. var ulUnicodeRange4 = 0;
  27470. var firstCharIndex = null;
  27471. var lastCharIndex = 0;
  27472. if (charstrings) {
  27473. for (var code in charstrings) {
  27474. code |= 0;
  27475. if (firstCharIndex > code || !firstCharIndex) {
  27476. firstCharIndex = code;
  27477. }
  27478. if (lastCharIndex < code) {
  27479. lastCharIndex = code;
  27480. }
  27481. var position = getUnicodeRangeFor(code);
  27482. if (position < 32) {
  27483. ulUnicodeRange1 |= 1 << position;
  27484. } else if (position < 64) {
  27485. ulUnicodeRange2 |= 1 << position - 32;
  27486. } else if (position < 96) {
  27487. ulUnicodeRange3 |= 1 << position - 64;
  27488. } else if (position < 123) {
  27489. ulUnicodeRange4 |= 1 << position - 96;
  27490. } else {
  27491. error('Unicode ranges Bits > 123 are reserved for internal usage');
  27492. }
  27493. }
  27494. } else {
  27495. // TODO
  27496. firstCharIndex = 0;
  27497. lastCharIndex = 255;
  27498. }
  27499. var bbox = properties.bbox || [0, 0, 0, 0];
  27500. var unitsPerEm = (override.unitsPerEm ||
  27501. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  27502. // if the font units differ to the PDF glyph space units
  27503. // then scale up the values
  27504. var scale = (properties.ascentScaled ? 1.0 :
  27505. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  27506. var typoAscent = (override.ascent ||
  27507. Math.round(scale * (properties.ascent || bbox[3])));
  27508. var typoDescent = (override.descent ||
  27509. Math.round(scale * (properties.descent || bbox[1])));
  27510. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  27511. typoDescent = -typoDescent; // fixing incorrect descent
  27512. }
  27513. var winAscent = override.yMax || typoAscent;
  27514. var winDescent = -override.yMin || -typoDescent;
  27515. return '\x00\x03' + // version
  27516. '\x02\x24' + // xAvgCharWidth
  27517. '\x01\xF4' + // usWeightClass
  27518. '\x00\x05' + // usWidthClass
  27519. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  27520. '\x02\x8A' + // ySubscriptXSize
  27521. '\x02\xBB' + // ySubscriptYSize
  27522. '\x00\x00' + // ySubscriptXOffset
  27523. '\x00\x8C' + // ySubscriptYOffset
  27524. '\x02\x8A' + // ySuperScriptXSize
  27525. '\x02\xBB' + // ySuperScriptYSize
  27526. '\x00\x00' + // ySuperScriptXOffset
  27527. '\x01\xDF' + // ySuperScriptYOffset
  27528. '\x00\x31' + // yStrikeOutSize
  27529. '\x01\x02' + // yStrikeOutPosition
  27530. '\x00\x00' + // sFamilyClass
  27531. '\x00\x00\x06' +
  27532. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  27533. '\x00\x00\x00\x00\x00\x00' + // Panose
  27534. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  27535. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  27536. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  27537. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  27538. '\x2A\x32\x31\x2A' + // achVendID
  27539. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  27540. string16(firstCharIndex ||
  27541. properties.firstChar) + // usFirstCharIndex
  27542. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  27543. string16(typoAscent) + // sTypoAscender
  27544. string16(typoDescent) + // sTypoDescender
  27545. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  27546. string16(winAscent) + // usWinAscent
  27547. string16(winDescent) + // usWinDescent
  27548. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  27549. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  27550. string16(properties.xHeight) + // sxHeight
  27551. string16(properties.capHeight) + // sCapHeight
  27552. string16(0) + // usDefaultChar
  27553. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  27554. '\x00\x03'; // usMaxContext
  27555. }
  27556. function createPostTable(properties) {
  27557. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  27558. return ('\x00\x03\x00\x00' + // Version number
  27559. string32(angle) + // italicAngle
  27560. '\x00\x00' + // underlinePosition
  27561. '\x00\x00' + // underlineThickness
  27562. string32(properties.fixedPitch) + // isFixedPitch
  27563. '\x00\x00\x00\x00' + // minMemType42
  27564. '\x00\x00\x00\x00' + // maxMemType42
  27565. '\x00\x00\x00\x00' + // minMemType1
  27566. '\x00\x00\x00\x00'); // maxMemType1
  27567. }
  27568. function createNameTable(name, proto) {
  27569. if (!proto) {
  27570. proto = [[], []]; // no strings and unicode strings
  27571. }
  27572. var strings = [
  27573. proto[0][0] || 'Original licence', // 0.Copyright
  27574. proto[0][1] || name, // 1.Font family
  27575. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  27576. proto[0][3] || 'uniqueID', // 3.Unique ID
  27577. proto[0][4] || name, // 4.Full font name
  27578. proto[0][5] || 'Version 0.11', // 5.Version
  27579. proto[0][6] || '', // 6.Postscript name
  27580. proto[0][7] || 'Unknown', // 7.Trademark
  27581. proto[0][8] || 'Unknown', // 8.Manufacturer
  27582. proto[0][9] || 'Unknown' // 9.Designer
  27583. ];
  27584. // Mac want 1-byte per character strings while Windows want
  27585. // 2-bytes per character, so duplicate the names table
  27586. var stringsUnicode = [];
  27587. var i, ii, j, jj, str;
  27588. for (i = 0, ii = strings.length; i < ii; i++) {
  27589. str = proto[1][i] || strings[i];
  27590. var strBufUnicode = [];
  27591. for (j = 0, jj = str.length; j < jj; j++) {
  27592. strBufUnicode.push(string16(str.charCodeAt(j)));
  27593. }
  27594. stringsUnicode.push(strBufUnicode.join(''));
  27595. }
  27596. var names = [strings, stringsUnicode];
  27597. var platforms = ['\x00\x01', '\x00\x03'];
  27598. var encodings = ['\x00\x00', '\x00\x01'];
  27599. var languages = ['\x00\x00', '\x04\x09'];
  27600. var namesRecordCount = strings.length * platforms.length;
  27601. var nameTable =
  27602. '\x00\x00' + // format
  27603. string16(namesRecordCount) + // Number of names Record
  27604. string16(namesRecordCount * 12 + 6); // Storage
  27605. // Build the name records field
  27606. var strOffset = 0;
  27607. for (i = 0, ii = platforms.length; i < ii; i++) {
  27608. var strs = names[i];
  27609. for (j = 0, jj = strs.length; j < jj; j++) {
  27610. str = strs[j];
  27611. var nameRecord =
  27612. platforms[i] + // platform ID
  27613. encodings[i] + // encoding ID
  27614. languages[i] + // language ID
  27615. string16(j) + // name ID
  27616. string16(str.length) +
  27617. string16(strOffset);
  27618. nameTable += nameRecord;
  27619. strOffset += str.length;
  27620. }
  27621. }
  27622. nameTable += strings.join('') + stringsUnicode.join('');
  27623. return nameTable;
  27624. }
  27625. Font.prototype = {
  27626. name: null,
  27627. font: null,
  27628. mimetype: null,
  27629. encoding: null,
  27630. get renderer() {
  27631. var renderer = FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
  27632. return shadow(this, 'renderer', renderer);
  27633. },
  27634. exportData: function Font_exportData() {
  27635. // TODO remove enumerating of the properties, e.g. hardcode exact names.
  27636. var data = {};
  27637. for (var i in this) {
  27638. if (this.hasOwnProperty(i)) {
  27639. data[i] = this[i];
  27640. }
  27641. }
  27642. return data;
  27643. },
  27644. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  27645. function readTableEntry(file) {
  27646. var tag = bytesToString(file.getBytes(4));
  27647. var checksum = file.getInt32() >>> 0;
  27648. var offset = file.getInt32() >>> 0;
  27649. var length = file.getInt32() >>> 0;
  27650. // Read the table associated data
  27651. var previousPosition = file.pos;
  27652. file.pos = file.start ? file.start : 0;
  27653. file.skip(offset);
  27654. var data = file.getBytes(length);
  27655. file.pos = previousPosition;
  27656. if (tag === 'head') {
  27657. // clearing checksum adjustment
  27658. data[8] = data[9] = data[10] = data[11] = 0;
  27659. data[17] |= 0x20; //Set font optimized for cleartype flag
  27660. }
  27661. return {
  27662. tag: tag,
  27663. checksum: checksum,
  27664. length: length,
  27665. offset: offset,
  27666. data: data
  27667. };
  27668. }
  27669. function readOpenTypeHeader(ttf) {
  27670. return {
  27671. version: bytesToString(ttf.getBytes(4)),
  27672. numTables: ttf.getUint16(),
  27673. searchRange: ttf.getUint16(),
  27674. entrySelector: ttf.getUint16(),
  27675. rangeShift: ttf.getUint16()
  27676. };
  27677. }
  27678. /**
  27679. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  27680. * PDF spec
  27681. */
  27682. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  27683. if (!cmap) {
  27684. warn('No cmap table available.');
  27685. return {
  27686. platformId: -1,
  27687. encodingId: -1,
  27688. mappings: [],
  27689. hasShortCmap: false
  27690. };
  27691. }
  27692. var segment;
  27693. var start = (font.start ? font.start : 0) + cmap.offset;
  27694. font.pos = start;
  27695. var version = font.getUint16();
  27696. var numTables = font.getUint16();
  27697. var potentialTable;
  27698. var canBreak = false;
  27699. // There's an order of preference in terms of which cmap subtable to
  27700. // use:
  27701. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  27702. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  27703. // The following takes advantage of the fact that the tables are sorted
  27704. // to work.
  27705. for (var i = 0; i < numTables; i++) {
  27706. var platformId = font.getUint16();
  27707. var encodingId = font.getUint16();
  27708. var offset = font.getInt32() >>> 0;
  27709. var useTable = false;
  27710. if (platformId === 0 && encodingId === 0) {
  27711. useTable = true;
  27712. // Continue the loop since there still may be a higher priority
  27713. // table.
  27714. } else if (platformId === 1 && encodingId === 0) {
  27715. useTable = true;
  27716. // Continue the loop since there still may be a higher priority
  27717. // table.
  27718. } else if (platformId === 3 && encodingId === 1 &&
  27719. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  27720. useTable = true;
  27721. if (!isSymbolicFont) {
  27722. canBreak = true;
  27723. }
  27724. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  27725. useTable = true;
  27726. canBreak = true;
  27727. }
  27728. if (useTable) {
  27729. potentialTable = {
  27730. platformId: platformId,
  27731. encodingId: encodingId,
  27732. offset: offset
  27733. };
  27734. }
  27735. if (canBreak) {
  27736. break;
  27737. }
  27738. }
  27739. if (potentialTable) {
  27740. font.pos = start + potentialTable.offset;
  27741. }
  27742. if (!potentialTable || font.peekByte() === -1) {
  27743. warn('Could not find a preferred cmap table.');
  27744. return {
  27745. platformId: -1,
  27746. encodingId: -1,
  27747. mappings: [],
  27748. hasShortCmap: false
  27749. };
  27750. }
  27751. var format = font.getUint16();
  27752. var length = font.getUint16();
  27753. var language = font.getUint16();
  27754. var hasShortCmap = false;
  27755. var mappings = [];
  27756. var j, glyphId;
  27757. // TODO(mack): refactor this cmap subtable reading logic out
  27758. if (format === 0) {
  27759. for (j = 0; j < 256; j++) {
  27760. var index = font.getByte();
  27761. if (!index) {
  27762. continue;
  27763. }
  27764. mappings.push({
  27765. charCode: j,
  27766. glyphId: index
  27767. });
  27768. }
  27769. hasShortCmap = true;
  27770. } else if (format === 4) {
  27771. // re-creating the table in format 4 since the encoding
  27772. // might be changed
  27773. var segCount = (font.getUint16() >> 1);
  27774. font.getBytes(6); // skipping range fields
  27775. var segIndex, segments = [];
  27776. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27777. segments.push({ end: font.getUint16() });
  27778. }
  27779. font.getUint16();
  27780. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27781. segments[segIndex].start = font.getUint16();
  27782. }
  27783. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27784. segments[segIndex].delta = font.getUint16();
  27785. }
  27786. var offsetsCount = 0;
  27787. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27788. segment = segments[segIndex];
  27789. var rangeOffset = font.getUint16();
  27790. if (!rangeOffset) {
  27791. segment.offsetIndex = -1;
  27792. continue;
  27793. }
  27794. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  27795. segment.offsetIndex = offsetIndex;
  27796. offsetsCount = Math.max(offsetsCount, offsetIndex +
  27797. segment.end - segment.start + 1);
  27798. }
  27799. var offsets = [];
  27800. for (j = 0; j < offsetsCount; j++) {
  27801. offsets.push(font.getUint16());
  27802. }
  27803. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27804. segment = segments[segIndex];
  27805. start = segment.start;
  27806. var end = segment.end;
  27807. var delta = segment.delta;
  27808. offsetIndex = segment.offsetIndex;
  27809. for (j = start; j <= end; j++) {
  27810. if (j === 0xFFFF) {
  27811. continue;
  27812. }
  27813. glyphId = (offsetIndex < 0 ?
  27814. j : offsets[offsetIndex + j - start]);
  27815. glyphId = (glyphId + delta) & 0xFFFF;
  27816. if (glyphId === 0) {
  27817. continue;
  27818. }
  27819. mappings.push({
  27820. charCode: j,
  27821. glyphId: glyphId
  27822. });
  27823. }
  27824. }
  27825. } else if (format === 6) {
  27826. // Format 6 is a 2-bytes dense mapping, which means the font data
  27827. // lives glue together even if they are pretty far in the unicode
  27828. // table. (This looks weird, so I can have missed something), this
  27829. // works on Linux but seems to fails on Mac so let's rewrite the
  27830. // cmap table to a 3-1-4 style
  27831. var firstCode = font.getUint16();
  27832. var entryCount = font.getUint16();
  27833. for (j = 0; j < entryCount; j++) {
  27834. glyphId = font.getUint16();
  27835. var charCode = firstCode + j;
  27836. mappings.push({
  27837. charCode: charCode,
  27838. glyphId: glyphId
  27839. });
  27840. }
  27841. } else {
  27842. warn('cmap table has unsupported format: ' + format);
  27843. return {
  27844. platformId: -1,
  27845. encodingId: -1,
  27846. mappings: [],
  27847. hasShortCmap: false
  27848. };
  27849. }
  27850. // removing duplicate entries
  27851. mappings.sort(function (a, b) {
  27852. return a.charCode - b.charCode;
  27853. });
  27854. for (i = 1; i < mappings.length; i++) {
  27855. if (mappings[i - 1].charCode === mappings[i].charCode) {
  27856. mappings.splice(i, 1);
  27857. i--;
  27858. }
  27859. }
  27860. return {
  27861. platformId: potentialTable.platformId,
  27862. encodingId: potentialTable.encodingId,
  27863. mappings: mappings,
  27864. hasShortCmap: hasShortCmap
  27865. };
  27866. }
  27867. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  27868. if (!header) {
  27869. if (metrics) {
  27870. metrics.data = null;
  27871. }
  27872. return;
  27873. }
  27874. font.pos = (font.start ? font.start : 0) + header.offset;
  27875. font.pos += header.length - 2;
  27876. var numOfMetrics = font.getUint16();
  27877. if (numOfMetrics > numGlyphs) {
  27878. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  27879. 'greater than the numGlyphs (' + numGlyphs + ')');
  27880. // Reduce numOfMetrics if it is greater than numGlyphs
  27881. numOfMetrics = numGlyphs;
  27882. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  27883. header.data[35] = numOfMetrics & 0x00ff;
  27884. }
  27885. var numOfSidebearings = numGlyphs - numOfMetrics;
  27886. var numMissing = numOfSidebearings -
  27887. ((metrics.length - numOfMetrics * 4) >> 1);
  27888. if (numMissing > 0) {
  27889. // For each missing glyph, we set both the width and lsb to 0 (zero).
  27890. // Since we need to add two properties for each glyph, this explains
  27891. // the use of |numMissing * 2| when initializing the typed array.
  27892. var entries = new Uint8Array(metrics.length + numMissing * 2);
  27893. entries.set(metrics.data);
  27894. metrics.data = entries;
  27895. }
  27896. }
  27897. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  27898. hintsValid) {
  27899. if (sourceEnd - sourceStart <= 12) {
  27900. // glyph with data less than 12 is invalid one
  27901. return 0;
  27902. }
  27903. var glyf = source.subarray(sourceStart, sourceEnd);
  27904. var contoursCount = (glyf[0] << 8) | glyf[1];
  27905. if (contoursCount & 0x8000) {
  27906. // complex glyph, writing as is
  27907. dest.set(glyf, destStart);
  27908. return glyf.length;
  27909. }
  27910. var i, j = 10, flagsCount = 0;
  27911. for (i = 0; i < contoursCount; i++) {
  27912. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  27913. flagsCount = endPoint + 1;
  27914. j += 2;
  27915. }
  27916. // skipping instructions
  27917. var instructionsStart = j;
  27918. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  27919. j += 2 + instructionsLength;
  27920. var instructionsEnd = j;
  27921. // validating flags
  27922. var coordinatesLength = 0;
  27923. for (i = 0; i < flagsCount; i++) {
  27924. var flag = glyf[j++];
  27925. if (flag & 0xC0) {
  27926. // reserved flags must be zero, cleaning up
  27927. glyf[j - 1] = flag & 0x3F;
  27928. }
  27929. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  27930. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  27931. coordinatesLength += xyLength;
  27932. if (flag & 8) {
  27933. var repeat = glyf[j++];
  27934. i += repeat;
  27935. coordinatesLength += repeat * xyLength;
  27936. }
  27937. }
  27938. // glyph without coordinates will be rejected
  27939. if (coordinatesLength === 0) {
  27940. return 0;
  27941. }
  27942. var glyphDataLength = j + coordinatesLength;
  27943. if (glyphDataLength > glyf.length) {
  27944. // not enough data for coordinates
  27945. return 0;
  27946. }
  27947. if (!hintsValid && instructionsLength > 0) {
  27948. dest.set(glyf.subarray(0, instructionsStart), destStart);
  27949. dest.set([0, 0], destStart + instructionsStart);
  27950. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  27951. destStart + instructionsStart + 2);
  27952. glyphDataLength -= instructionsLength;
  27953. if (glyf.length - glyphDataLength > 3) {
  27954. glyphDataLength = (glyphDataLength + 3) & ~3;
  27955. }
  27956. return glyphDataLength;
  27957. }
  27958. if (glyf.length - glyphDataLength > 3) {
  27959. // truncating and aligning to 4 bytes the long glyph data
  27960. glyphDataLength = (glyphDataLength + 3) & ~3;
  27961. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  27962. return glyphDataLength;
  27963. }
  27964. // glyph data is fine
  27965. dest.set(glyf, destStart);
  27966. return glyf.length;
  27967. }
  27968. function sanitizeHead(head, numGlyphs, locaLength) {
  27969. var data = head.data;
  27970. // Validate version:
  27971. // Should always be 0x00010000
  27972. var version = int32(data[0], data[1], data[2], data[3]);
  27973. if (version >> 16 !== 1) {
  27974. info('Attempting to fix invalid version in head table: ' + version);
  27975. data[0] = 0;
  27976. data[1] = 1;
  27977. data[2] = 0;
  27978. data[3] = 0;
  27979. }
  27980. var indexToLocFormat = int16(data[50], data[51]);
  27981. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  27982. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  27983. indexToLocFormat);
  27984. // The value of indexToLocFormat should be 0 if the loca table
  27985. // consists of short offsets, and should be 1 if the loca table
  27986. // consists of long offsets.
  27987. //
  27988. // The number of entries in the loca table should be numGlyphs + 1.
  27989. //
  27990. // Using this information, we can work backwards to deduce if the
  27991. // size of each offset in the loca table, and thus figure out the
  27992. // appropriate value for indexToLocFormat.
  27993. var numGlyphsPlusOne = numGlyphs + 1;
  27994. if (locaLength === numGlyphsPlusOne << 1) {
  27995. // 0x0000 indicates the loca table consists of short offsets
  27996. data[50] = 0;
  27997. data[51] = 0;
  27998. } else if (locaLength === numGlyphsPlusOne << 2) {
  27999. // 0x0001 indicates the loca table consists of long offsets
  28000. data[50] = 0;
  28001. data[51] = 1;
  28002. } else {
  28003. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  28004. }
  28005. }
  28006. }
  28007. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  28008. isGlyphLocationsLong, hintsValid,
  28009. dupFirstEntry) {
  28010. var itemSize, itemDecode, itemEncode;
  28011. if (isGlyphLocationsLong) {
  28012. itemSize = 4;
  28013. itemDecode = function fontItemDecodeLong(data, offset) {
  28014. return (data[offset] << 24) | (data[offset + 1] << 16) |
  28015. (data[offset + 2] << 8) | data[offset + 3];
  28016. };
  28017. itemEncode = function fontItemEncodeLong(data, offset, value) {
  28018. data[offset] = (value >>> 24) & 0xFF;
  28019. data[offset + 1] = (value >> 16) & 0xFF;
  28020. data[offset + 2] = (value >> 8) & 0xFF;
  28021. data[offset + 3] = value & 0xFF;
  28022. };
  28023. } else {
  28024. itemSize = 2;
  28025. itemDecode = function fontItemDecode(data, offset) {
  28026. return (data[offset] << 9) | (data[offset + 1] << 1);
  28027. };
  28028. itemEncode = function fontItemEncode(data, offset, value) {
  28029. data[offset] = (value >> 9) & 0xFF;
  28030. data[offset + 1] = (value >> 1) & 0xFF;
  28031. };
  28032. }
  28033. var locaData = loca.data;
  28034. var locaDataSize = itemSize * (1 + numGlyphs);
  28035. // is loca.data too short or long?
  28036. if (locaData.length !== locaDataSize) {
  28037. locaData = new Uint8Array(locaDataSize);
  28038. locaData.set(loca.data.subarray(0, locaDataSize));
  28039. loca.data = locaData;
  28040. }
  28041. // removing the invalid glyphs
  28042. var oldGlyfData = glyf.data;
  28043. var oldGlyfDataLength = oldGlyfData.length;
  28044. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  28045. var startOffset = itemDecode(locaData, 0);
  28046. var writeOffset = 0;
  28047. var missingGlyphData = Object.create(null);
  28048. itemEncode(locaData, 0, writeOffset);
  28049. var i, j;
  28050. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  28051. var endOffset = itemDecode(locaData, j);
  28052. if (endOffset > oldGlyfDataLength &&
  28053. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  28054. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  28055. // the glyf table size, which makes last glyph out of range.
  28056. endOffset = oldGlyfDataLength;
  28057. }
  28058. if (endOffset > oldGlyfDataLength) {
  28059. // glyph end offset points outside glyf data, rejecting the glyph
  28060. itemEncode(locaData, j, writeOffset);
  28061. startOffset = endOffset;
  28062. continue;
  28063. }
  28064. if (startOffset === endOffset) {
  28065. missingGlyphData[i] = true;
  28066. }
  28067. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  28068. newGlyfData, writeOffset, hintsValid);
  28069. writeOffset += newLength;
  28070. itemEncode(locaData, j, writeOffset);
  28071. startOffset = endOffset;
  28072. }
  28073. if (writeOffset === 0) {
  28074. // glyf table cannot be empty -- redoing the glyf and loca tables
  28075. // to have single glyph with one point
  28076. var simpleGlyph = new Uint8Array(
  28077. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  28078. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  28079. itemEncode(locaData, j, simpleGlyph.length);
  28080. }
  28081. glyf.data = simpleGlyph;
  28082. return missingGlyphData;
  28083. }
  28084. if (dupFirstEntry) {
  28085. var firstEntryLength = itemDecode(locaData, itemSize);
  28086. if (newGlyfData.length > firstEntryLength + writeOffset) {
  28087. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  28088. } else {
  28089. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  28090. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  28091. }
  28092. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  28093. itemEncode(loca.data, locaData.length - itemSize,
  28094. writeOffset + firstEntryLength);
  28095. } else {
  28096. glyf.data = newGlyfData.subarray(0, writeOffset);
  28097. }
  28098. return missingGlyphData;
  28099. }
  28100. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  28101. var start = (font.start ? font.start : 0) + post.offset;
  28102. font.pos = start;
  28103. var length = post.length, end = start + length;
  28104. var version = font.getInt32();
  28105. // skip rest to the tables
  28106. font.getBytes(28);
  28107. var glyphNames;
  28108. var valid = true;
  28109. var i;
  28110. switch (version) {
  28111. case 0x00010000:
  28112. glyphNames = MacStandardGlyphOrdering;
  28113. break;
  28114. case 0x00020000:
  28115. var numGlyphs = font.getUint16();
  28116. if (numGlyphs !== maxpNumGlyphs) {
  28117. valid = false;
  28118. break;
  28119. }
  28120. var glyphNameIndexes = [];
  28121. for (i = 0; i < numGlyphs; ++i) {
  28122. var index = font.getUint16();
  28123. if (index >= 32768) {
  28124. valid = false;
  28125. break;
  28126. }
  28127. glyphNameIndexes.push(index);
  28128. }
  28129. if (!valid) {
  28130. break;
  28131. }
  28132. var customNames = [];
  28133. var strBuf = [];
  28134. while (font.pos < end) {
  28135. var stringLength = font.getByte();
  28136. strBuf.length = stringLength;
  28137. for (i = 0; i < stringLength; ++i) {
  28138. strBuf[i] = String.fromCharCode(font.getByte());
  28139. }
  28140. customNames.push(strBuf.join(''));
  28141. }
  28142. glyphNames = [];
  28143. for (i = 0; i < numGlyphs; ++i) {
  28144. var j = glyphNameIndexes[i];
  28145. if (j < 258) {
  28146. glyphNames.push(MacStandardGlyphOrdering[j]);
  28147. continue;
  28148. }
  28149. glyphNames.push(customNames[j - 258]);
  28150. }
  28151. break;
  28152. case 0x00030000:
  28153. break;
  28154. default:
  28155. warn('Unknown/unsupported post table version ' + version);
  28156. valid = false;
  28157. if (properties.defaultEncoding) {
  28158. glyphNames = properties.defaultEncoding;
  28159. }
  28160. break;
  28161. }
  28162. properties.glyphNames = glyphNames;
  28163. return valid;
  28164. }
  28165. function readNameTable(nameTable) {
  28166. var start = (font.start ? font.start : 0) + nameTable.offset;
  28167. font.pos = start;
  28168. var names = [[], []];
  28169. var length = nameTable.length, end = start + length;
  28170. var format = font.getUint16();
  28171. var FORMAT_0_HEADER_LENGTH = 6;
  28172. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  28173. // unsupported name table format or table "too" small
  28174. return names;
  28175. }
  28176. var numRecords = font.getUint16();
  28177. var stringsStart = font.getUint16();
  28178. var records = [];
  28179. var NAME_RECORD_LENGTH = 12;
  28180. var i, ii;
  28181. for (i = 0; i < numRecords &&
  28182. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  28183. var r = {
  28184. platform: font.getUint16(),
  28185. encoding: font.getUint16(),
  28186. language: font.getUint16(),
  28187. name: font.getUint16(),
  28188. length: font.getUint16(),
  28189. offset: font.getUint16()
  28190. };
  28191. // using only Macintosh and Windows platform/encoding names
  28192. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  28193. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  28194. records.push(r);
  28195. }
  28196. }
  28197. for (i = 0, ii = records.length; i < ii; i++) {
  28198. var record = records[i];
  28199. if (record.length <= 0) {
  28200. continue; // Nothing to process, ignoring.
  28201. }
  28202. var pos = start + stringsStart + record.offset;
  28203. if (pos + record.length > end) {
  28204. continue; // outside of name table, ignoring
  28205. }
  28206. font.pos = pos;
  28207. var nameIndex = record.name;
  28208. if (record.encoding) {
  28209. // unicode
  28210. var str = '';
  28211. for (var j = 0, jj = record.length; j < jj; j += 2) {
  28212. str += String.fromCharCode(font.getUint16());
  28213. }
  28214. names[1][nameIndex] = str;
  28215. } else {
  28216. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  28217. }
  28218. }
  28219. return names;
  28220. }
  28221. var TTOpsStackDeltas = [
  28222. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  28223. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  28224. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  28225. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  28226. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  28227. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  28228. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  28229. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  28230. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  28231. // 0xC0-DF == -1 and 0xE0-FF == -2
  28232. function sanitizeTTProgram(table, ttContext) {
  28233. var data = table.data;
  28234. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  28235. var stack = [];
  28236. var callstack = [];
  28237. var functionsCalled = [];
  28238. var tooComplexToFollowFunctions =
  28239. ttContext.tooComplexToFollowFunctions;
  28240. var inFDEF = false, ifLevel = 0, inELSE = 0;
  28241. for (var ii = data.length; i < ii;) {
  28242. var op = data[i++];
  28243. // The TrueType instruction set docs can be found at
  28244. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  28245. if (op === 0x40) { // NPUSHB - pushes n bytes
  28246. n = data[i++];
  28247. if (inFDEF || inELSE) {
  28248. i += n;
  28249. } else {
  28250. for (j = 0; j < n; j++) {
  28251. stack.push(data[i++]);
  28252. }
  28253. }
  28254. } else if (op === 0x41) { // NPUSHW - pushes n words
  28255. n = data[i++];
  28256. if (inFDEF || inELSE) {
  28257. i += n * 2;
  28258. } else {
  28259. for (j = 0; j < n; j++) {
  28260. b = data[i++];
  28261. stack.push((b << 8) | data[i++]);
  28262. }
  28263. }
  28264. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  28265. n = op - 0xB0 + 1;
  28266. if (inFDEF || inELSE) {
  28267. i += n;
  28268. } else {
  28269. for (j = 0; j < n; j++) {
  28270. stack.push(data[i++]);
  28271. }
  28272. }
  28273. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  28274. n = op - 0xB8 + 1;
  28275. if (inFDEF || inELSE) {
  28276. i += n * 2;
  28277. } else {
  28278. for (j = 0; j < n; j++) {
  28279. b = data[i++];
  28280. stack.push((b << 8) | data[i++]);
  28281. }
  28282. }
  28283. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  28284. if (!inFDEF && !inELSE) {
  28285. // collecting inforamtion about which functions are used
  28286. funcId = stack[stack.length - 1];
  28287. ttContext.functionsUsed[funcId] = true;
  28288. if (funcId in ttContext.functionsStackDeltas) {
  28289. stack.length += ttContext.functionsStackDeltas[funcId];
  28290. } else if (funcId in ttContext.functionsDefined &&
  28291. functionsCalled.indexOf(funcId) < 0) {
  28292. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  28293. functionsCalled.push(funcId);
  28294. pc = ttContext.functionsDefined[funcId];
  28295. if (!pc) {
  28296. warn('TT: CALL non-existent function');
  28297. ttContext.hintsValid = false;
  28298. return;
  28299. }
  28300. data = pc.data;
  28301. i = pc.i;
  28302. }
  28303. }
  28304. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  28305. if (inFDEF || inELSE) {
  28306. warn('TT: nested FDEFs not allowed');
  28307. tooComplexToFollowFunctions = true;
  28308. }
  28309. inFDEF = true;
  28310. // collecting inforamtion about which functions are defined
  28311. lastDeff = i;
  28312. funcId = stack.pop();
  28313. ttContext.functionsDefined[funcId] = {data: data, i: i};
  28314. } else if (op === 0x2D) { // ENDF - end of function
  28315. if (inFDEF) {
  28316. inFDEF = false;
  28317. lastEndf = i;
  28318. } else {
  28319. pc = callstack.pop();
  28320. if (!pc) {
  28321. warn('TT: ENDF bad stack');
  28322. ttContext.hintsValid = false;
  28323. return;
  28324. }
  28325. funcId = functionsCalled.pop();
  28326. data = pc.data;
  28327. i = pc.i;
  28328. ttContext.functionsStackDeltas[funcId] =
  28329. stack.length - pc.stackTop;
  28330. }
  28331. } else if (op === 0x89) { // IDEF - instruction definition
  28332. if (inFDEF || inELSE) {
  28333. warn('TT: nested IDEFs not allowed');
  28334. tooComplexToFollowFunctions = true;
  28335. }
  28336. inFDEF = true;
  28337. // recording it as a function to track ENDF
  28338. lastDeff = i;
  28339. } else if (op === 0x58) { // IF
  28340. ++ifLevel;
  28341. } else if (op === 0x1B) { // ELSE
  28342. inELSE = ifLevel;
  28343. } else if (op === 0x59) { // EIF
  28344. if (inELSE === ifLevel) {
  28345. inELSE = 0;
  28346. }
  28347. --ifLevel;
  28348. } else if (op === 0x1C) { // JMPR
  28349. if (!inFDEF && !inELSE) {
  28350. var offset = stack[stack.length - 1];
  28351. // only jumping forward to prevent infinite loop
  28352. if (offset > 0) {
  28353. i += offset - 1;
  28354. }
  28355. }
  28356. }
  28357. // Adjusting stack not extactly, but just enough to get function id
  28358. if (!inFDEF && !inELSE) {
  28359. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  28360. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  28361. if (op >= 0x71 && op <= 0x75) {
  28362. n = stack.pop();
  28363. if (n === n) {
  28364. stackDelta = -n * 2;
  28365. }
  28366. }
  28367. while (stackDelta < 0 && stack.length > 0) {
  28368. stack.pop();
  28369. stackDelta++;
  28370. }
  28371. while (stackDelta > 0) {
  28372. stack.push(NaN); // pushing any number into stack
  28373. stackDelta--;
  28374. }
  28375. }
  28376. }
  28377. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  28378. var content = [data];
  28379. if (i > data.length) {
  28380. content.push(new Uint8Array(i - data.length));
  28381. }
  28382. if (lastDeff > lastEndf) {
  28383. warn('TT: complementing a missing function tail');
  28384. // new function definition started, but not finished
  28385. // complete function by [CLEAR, ENDF]
  28386. content.push(new Uint8Array([0x22, 0x2D]));
  28387. }
  28388. foldTTTable(table, content);
  28389. }
  28390. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  28391. if (ttContext.tooComplexToFollowFunctions) {
  28392. return;
  28393. }
  28394. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  28395. warn('TT: more functions defined than expected');
  28396. ttContext.hintsValid = false;
  28397. return;
  28398. }
  28399. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  28400. if (j > maxFunctionDefs) {
  28401. warn('TT: invalid function id: ' + j);
  28402. ttContext.hintsValid = false;
  28403. return;
  28404. }
  28405. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  28406. warn('TT: undefined function: ' + j);
  28407. ttContext.hintsValid = false;
  28408. return;
  28409. }
  28410. }
  28411. }
  28412. function foldTTTable(table, content) {
  28413. if (content.length > 1) {
  28414. // concatenating the content items
  28415. var newLength = 0;
  28416. var j, jj;
  28417. for (j = 0, jj = content.length; j < jj; j++) {
  28418. newLength += content[j].length;
  28419. }
  28420. newLength = (newLength + 3) & ~3;
  28421. var result = new Uint8Array(newLength);
  28422. var pos = 0;
  28423. for (j = 0, jj = content.length; j < jj; j++) {
  28424. result.set(content[j], pos);
  28425. pos += content[j].length;
  28426. }
  28427. table.data = result;
  28428. table.length = newLength;
  28429. }
  28430. }
  28431. function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) {
  28432. var ttContext = {
  28433. functionsDefined: [],
  28434. functionsUsed: [],
  28435. functionsStackDeltas: [],
  28436. tooComplexToFollowFunctions: false,
  28437. hintsValid: true
  28438. };
  28439. if (fpgm) {
  28440. sanitizeTTProgram(fpgm, ttContext);
  28441. }
  28442. if (prep) {
  28443. sanitizeTTProgram(prep, ttContext);
  28444. }
  28445. if (fpgm) {
  28446. checkInvalidFunctions(ttContext, maxFunctionDefs);
  28447. }
  28448. if (cvt && (cvt.length & 1)) {
  28449. var cvtData = new Uint8Array(cvt.length + 1);
  28450. cvtData.set(cvt.data);
  28451. cvt.data = cvtData;
  28452. }
  28453. return ttContext.hintsValid;
  28454. }
  28455. // The following steps modify the original font data, making copy
  28456. font = new Stream(new Uint8Array(font.getBytes()));
  28457. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  28458. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  28459. var header = readOpenTypeHeader(font);
  28460. var numTables = header.numTables;
  28461. var cff, cffFile;
  28462. var tables = Object.create(null);
  28463. tables['OS/2'] = null;
  28464. tables['cmap'] = null;
  28465. tables['head'] = null;
  28466. tables['hhea'] = null;
  28467. tables['hmtx'] = null;
  28468. tables['maxp'] = null;
  28469. tables['name'] = null;
  28470. tables['post'] = null;
  28471. var table;
  28472. for (var i = 0; i < numTables; i++) {
  28473. table = readTableEntry(font);
  28474. if (VALID_TABLES.indexOf(table.tag) < 0) {
  28475. continue; // skipping table if it's not a required or optional table
  28476. }
  28477. if (table.length === 0) {
  28478. continue; // skipping empty tables
  28479. }
  28480. tables[table.tag] = table;
  28481. }
  28482. var isTrueType = !tables['CFF '];
  28483. if (!isTrueType) {
  28484. // OpenType font
  28485. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  28486. !tables['head'] || !tables['hhea'] || !tables['maxp'] ||
  28487. !tables['post']) {
  28488. // no major tables: throwing everything at CFFFont
  28489. cffFile = new Stream(tables['CFF '].data);
  28490. cff = new CFFFont(cffFile, properties);
  28491. adjustWidths(properties);
  28492. return this.convert(name, cff, properties);
  28493. }
  28494. delete tables['glyf'];
  28495. delete tables['loca'];
  28496. delete tables['fpgm'];
  28497. delete tables['prep'];
  28498. delete tables['cvt '];
  28499. this.isOpenType = true;
  28500. } else {
  28501. if (!tables['loca']) {
  28502. error('Required "loca" table is not found');
  28503. }
  28504. if (!tables['glyf']) {
  28505. warn('Required "glyf" table is not found -- trying to recover.');
  28506. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  28507. tables['glyf'] = {
  28508. tag: 'glyf',
  28509. data: new Uint8Array(0),
  28510. };
  28511. }
  28512. this.isOpenType = false;
  28513. }
  28514. if (!tables['maxp']) {
  28515. error('Required "maxp" table is not found');
  28516. }
  28517. font.pos = (font.start || 0) + tables['maxp'].offset;
  28518. var version = font.getInt32();
  28519. var numGlyphs = font.getUint16();
  28520. var maxFunctionDefs = 0;
  28521. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  28522. // maxZones can be invalid
  28523. font.pos += 8;
  28524. var maxZones = font.getUint16();
  28525. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  28526. tables['maxp'].data[14] = 0;
  28527. tables['maxp'].data[15] = 2;
  28528. }
  28529. font.pos += 4;
  28530. maxFunctionDefs = font.getUint16();
  28531. }
  28532. var dupFirstEntry = false;
  28533. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  28534. properties.toUnicode.get(0) > '\u0000') {
  28535. // oracle's defect (see 3427), duplicating first entry
  28536. dupFirstEntry = true;
  28537. numGlyphs++;
  28538. tables['maxp'].data[4] = numGlyphs >> 8;
  28539. tables['maxp'].data[5] = numGlyphs & 255;
  28540. }
  28541. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'],
  28542. tables['cvt '], maxFunctionDefs);
  28543. if (!hintsValid) {
  28544. delete tables['fpgm'];
  28545. delete tables['prep'];
  28546. delete tables['cvt '];
  28547. }
  28548. // Ensure the hmtx table contains the advance width and
  28549. // sidebearings information for numGlyphs in the maxp table
  28550. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  28551. if (!tables['head']) {
  28552. error('Required "head" table is not found');
  28553. }
  28554. sanitizeHead(tables['head'], numGlyphs,
  28555. isTrueType ? tables['loca'].length : 0);
  28556. var missingGlyphs = Object.create(null);
  28557. if (isTrueType) {
  28558. var isGlyphLocationsLong = int16(tables['head'].data[50],
  28559. tables['head'].data[51]);
  28560. missingGlyphs = sanitizeGlyphLocations(tables['loca'], tables['glyf'],
  28561. numGlyphs, isGlyphLocationsLong,
  28562. hintsValid, dupFirstEntry);
  28563. }
  28564. if (!tables['hhea']) {
  28565. error('Required "hhea" table is not found');
  28566. }
  28567. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  28568. // Sometimes it's 0. That needs to be fixed
  28569. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  28570. tables['hhea'].data[10] = 0xFF;
  28571. tables['hhea'].data[11] = 0xFF;
  28572. }
  28573. // Extract some more font properties from the OpenType head and
  28574. // hhea tables; yMin and descent value are always negative.
  28575. var metricsOverride = {
  28576. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  28577. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  28578. yMin: signedInt16(tables['head'].data[38], tables['head'].data[39]),
  28579. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  28580. descent: signedInt16(tables['hhea'].data[6], tables['hhea'].data[7])
  28581. };
  28582. // PDF FontDescriptor metrics lie -- using data from actual font.
  28583. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  28584. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  28585. // The 'post' table has glyphs names.
  28586. if (tables['post']) {
  28587. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  28588. if (!valid) {
  28589. tables['post'] = null;
  28590. }
  28591. }
  28592. var charCodeToGlyphId = [], charCode;
  28593. var toUnicode = properties.toUnicode, widths = properties.widths;
  28594. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  28595. toUnicode.length === 0x10000);
  28596. // Helper function to try to skip mapping of empty glyphs.
  28597. // Note: In some cases, just relying on the glyph data doesn't work,
  28598. // hence we also use a few heuristics to fix various PDF files.
  28599. function hasGlyph(glyphId, charCode, widthCode) {
  28600. if (!missingGlyphs[glyphId]) {
  28601. return true;
  28602. }
  28603. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  28604. return true;
  28605. }
  28606. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  28607. return true;
  28608. }
  28609. return false;
  28610. }
  28611. if (properties.type === 'CIDFontType2') {
  28612. var cidToGidMap = properties.cidToGidMap || [];
  28613. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  28614. properties.cMap.forEach(function(charCode, cid) {
  28615. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  28616. var glyphId = -1;
  28617. if (isCidToGidMapEmpty) {
  28618. glyphId = cid;
  28619. } else if (cidToGidMap[cid] !== undefined) {
  28620. glyphId = cidToGidMap[cid];
  28621. }
  28622. if (glyphId >= 0 && glyphId < numGlyphs &&
  28623. hasGlyph(glyphId, charCode, cid)) {
  28624. charCodeToGlyphId[charCode] = glyphId;
  28625. }
  28626. });
  28627. if (dupFirstEntry && (isCidToGidMapEmpty || !charCodeToGlyphId[0])) {
  28628. // We don't duplicate the first entry in the `charCodeToGlyphId` map
  28629. // if the font has a `CIDToGIDMap` which has already mapped the first
  28630. // entry to a non-zero `glyphId` (fixes issue7544.pdf).
  28631. charCodeToGlyphId[0] = numGlyphs - 1;
  28632. }
  28633. } else {
  28634. // Most of the following logic in this code branch is based on the
  28635. // 9.6.6.4 of the PDF spec.
  28636. var cmapTable = readCmapTable(tables['cmap'], font, this.isSymbolicFont,
  28637. properties.hasEncoding);
  28638. var cmapPlatformId = cmapTable.platformId;
  28639. var cmapEncodingId = cmapTable.encodingId;
  28640. var cmapMappings = cmapTable.mappings;
  28641. var cmapMappingsLength = cmapMappings.length;
  28642. // The spec seems to imply that if the font is symbolic the encoding
  28643. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  28644. // where the the font is symbolic and it has an encoding.
  28645. if (properties.hasEncoding &&
  28646. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  28647. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  28648. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  28649. !!getEncoding(properties.baseEncodingName))) { // Temporary hack
  28650. // When no preferred cmap table was found and |baseEncodingName| is
  28651. // one of the predefined encodings, we seem to obtain a better
  28652. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  28653. // TODO: Note that this is a hack which should be removed as soon as
  28654. // we have proper support for more exotic cmap tables.
  28655. var baseEncoding = [];
  28656. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  28657. properties.baseEncodingName === 'WinAnsiEncoding') {
  28658. baseEncoding = getEncoding(properties.baseEncodingName);
  28659. }
  28660. var glyphsUnicodeMap = getGlyphsUnicode();
  28661. for (charCode = 0; charCode < 256; charCode++) {
  28662. var glyphName, standardGlyphName;
  28663. if (this.differences && charCode in this.differences) {
  28664. glyphName = this.differences[charCode];
  28665. } else if (charCode in baseEncoding &&
  28666. baseEncoding[charCode] !== '') {
  28667. glyphName = baseEncoding[charCode];
  28668. } else {
  28669. glyphName = StandardEncoding[charCode];
  28670. }
  28671. if (!glyphName) {
  28672. continue;
  28673. }
  28674. // Ensure that non-standard glyph names are resolved to valid ones.
  28675. standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  28676. var unicodeOrCharCode, isUnicode = false;
  28677. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  28678. unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName];
  28679. isUnicode = true;
  28680. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  28681. // TODO: the encoding needs to be updated with mac os table.
  28682. unicodeOrCharCode = MacRomanEncoding.indexOf(standardGlyphName);
  28683. }
  28684. var found = false;
  28685. for (i = 0; i < cmapMappingsLength; ++i) {
  28686. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  28687. continue;
  28688. }
  28689. var code = isUnicode ? charCode : unicodeOrCharCode;
  28690. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  28691. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  28692. found = true;
  28693. break;
  28694. }
  28695. }
  28696. if (!found && properties.glyphNames) {
  28697. // Try to map using the post table.
  28698. var glyphId = properties.glyphNames.indexOf(glyphName);
  28699. // The post table ought to use the same kind of glyph names as the
  28700. // `differences` array, but check the standard ones as a fallback.
  28701. if (glyphId === -1 && standardGlyphName !== glyphName) {
  28702. glyphId = properties.glyphNames.indexOf(standardGlyphName);
  28703. }
  28704. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  28705. charCodeToGlyphId[charCode] = glyphId;
  28706. found = true;
  28707. }
  28708. }
  28709. if (!found) {
  28710. charCodeToGlyphId[charCode] = 0; // notdef
  28711. }
  28712. }
  28713. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  28714. // Default Unicode semantics, use the charcodes as is.
  28715. for (i = 0; i < cmapMappingsLength; ++i) {
  28716. charCodeToGlyphId[cmapMappings[i].charCode] =
  28717. cmapMappings[i].glyphId;
  28718. }
  28719. } else {
  28720. // For (3, 0) cmap tables:
  28721. // The charcode key being stored in charCodeToGlyphId is the lower
  28722. // byte of the two-byte charcodes of the cmap table since according to
  28723. // the spec: 'each byte from the string shall be prepended with the
  28724. // high byte of the range [of charcodes in the cmap table], to form
  28725. // a two-byte character, which shall be used to select the
  28726. // associated glyph description from the subtable'.
  28727. //
  28728. // For (1, 0) cmap tables:
  28729. // 'single bytes from the string shall be used to look up the
  28730. // associated glyph descriptions from the subtable'. This means
  28731. // charcodes in the cmap will be single bytes, so no-op since
  28732. // glyph.charCode & 0xFF === glyph.charCode
  28733. for (i = 0; i < cmapMappingsLength; ++i) {
  28734. charCode = cmapMappings[i].charCode & 0xFF;
  28735. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  28736. }
  28737. }
  28738. }
  28739. if (charCodeToGlyphId.length === 0) {
  28740. // defines at least one glyph
  28741. charCodeToGlyphId[0] = 0;
  28742. }
  28743. // Converting glyphs and ids into font's cmap table
  28744. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  28745. this.toFontChar = newMapping.toFontChar;
  28746. tables['cmap'] = {
  28747. tag: 'cmap',
  28748. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  28749. };
  28750. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  28751. tables['OS/2'] = {
  28752. tag: 'OS/2',
  28753. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  28754. metricsOverride)
  28755. };
  28756. }
  28757. // Rewrite the 'post' table if needed
  28758. if (!tables['post']) {
  28759. tables['post'] = {
  28760. tag: 'post',
  28761. data: createPostTable(properties)
  28762. };
  28763. }
  28764. if (!isTrueType) {
  28765. try {
  28766. // Trying to repair CFF file
  28767. cffFile = new Stream(tables['CFF '].data);
  28768. var parser = new CFFParser(cffFile, properties,
  28769. SEAC_ANALYSIS_ENABLED);
  28770. cff = parser.parse();
  28771. var compiler = new CFFCompiler(cff);
  28772. tables['CFF '].data = compiler.compile();
  28773. } catch (e) {
  28774. warn('Failed to compile font ' + properties.loadedName);
  28775. }
  28776. }
  28777. // Re-creating 'name' table
  28778. if (!tables['name']) {
  28779. tables['name'] = {
  28780. tag: 'name',
  28781. data: createNameTable(this.name)
  28782. };
  28783. } else {
  28784. // ... using existing 'name' table as prototype
  28785. var namePrototype = readNameTable(tables['name']);
  28786. tables['name'].data = createNameTable(name, namePrototype);
  28787. }
  28788. var builder = new OpenTypeFileBuilder(header.version);
  28789. for (var tableTag in tables) {
  28790. builder.addTable(tableTag, tables[tableTag].data);
  28791. }
  28792. return builder.toArray();
  28793. },
  28794. convert: function Font_convert(fontName, font, properties) {
  28795. // TODO: Check the charstring widths to determine this.
  28796. properties.fixedPitch = false;
  28797. if (properties.builtInEncoding) {
  28798. // For Type1 fonts that do not include either `ToUnicode` or `Encoding`
  28799. // data, attempt to use the `builtInEncoding` to improve text selection.
  28800. adjustToUnicode(properties, properties.builtInEncoding);
  28801. }
  28802. var mapping = font.getGlyphMapping(properties);
  28803. var newMapping = adjustMapping(mapping, properties);
  28804. this.toFontChar = newMapping.toFontChar;
  28805. var numGlyphs = font.numGlyphs;
  28806. function getCharCodes(charCodeToGlyphId, glyphId) {
  28807. var charCodes = null;
  28808. for (var charCode in charCodeToGlyphId) {
  28809. if (glyphId === charCodeToGlyphId[charCode]) {
  28810. if (!charCodes) {
  28811. charCodes = [];
  28812. }
  28813. charCodes.push(charCode | 0);
  28814. }
  28815. }
  28816. return charCodes;
  28817. }
  28818. function createCharCode(charCodeToGlyphId, glyphId) {
  28819. for (var charCode in charCodeToGlyphId) {
  28820. if (glyphId === charCodeToGlyphId[charCode]) {
  28821. return charCode | 0;
  28822. }
  28823. }
  28824. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  28825. glyphId;
  28826. return newMapping.nextAvailableFontCharCode++;
  28827. }
  28828. var seacs = font.seacs;
  28829. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  28830. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  28831. var charset = font.getCharset();
  28832. var seacMap = Object.create(null);
  28833. for (var glyphId in seacs) {
  28834. glyphId |= 0;
  28835. var seac = seacs[glyphId];
  28836. var baseGlyphName = StandardEncoding[seac[2]];
  28837. var accentGlyphName = StandardEncoding[seac[3]];
  28838. var baseGlyphId = charset.indexOf(baseGlyphName);
  28839. var accentGlyphId = charset.indexOf(accentGlyphName);
  28840. if (baseGlyphId < 0 || accentGlyphId < 0) {
  28841. continue;
  28842. }
  28843. var accentOffset = {
  28844. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  28845. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  28846. };
  28847. var charCodes = getCharCodes(mapping, glyphId);
  28848. if (!charCodes) {
  28849. // There's no point in mapping it if the char code was never mapped
  28850. // to begin with.
  28851. continue;
  28852. }
  28853. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  28854. var charCode = charCodes[i];
  28855. // Find a fontCharCode that maps to the base and accent glyphs.
  28856. // If one doesn't exists, create it.
  28857. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  28858. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  28859. baseGlyphId);
  28860. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  28861. accentGlyphId);
  28862. seacMap[charCode] = {
  28863. baseFontCharCode: baseFontCharCode,
  28864. accentFontCharCode: accentFontCharCode,
  28865. accentOffset: accentOffset
  28866. };
  28867. }
  28868. }
  28869. properties.seacMap = seacMap;
  28870. }
  28871. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  28872. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  28873. // PostScript Font Program
  28874. builder.addTable('CFF ', font.data);
  28875. // OS/2 and Windows Specific metrics
  28876. builder.addTable('OS/2', createOS2Table(properties,
  28877. newMapping.charCodeToGlyphId));
  28878. // Character to glyphs mapping
  28879. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  28880. numGlyphs));
  28881. // Font header
  28882. builder.addTable('head',
  28883. '\x00\x01\x00\x00' + // Version number
  28884. '\x00\x00\x10\x00' + // fontRevision
  28885. '\x00\x00\x00\x00' + // checksumAdjustement
  28886. '\x5F\x0F\x3C\xF5' + // magicNumber
  28887. '\x00\x00' + // Flags
  28888. safeString16(unitsPerEm) + // unitsPerEM
  28889. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  28890. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  28891. '\x00\x00' + // xMin
  28892. safeString16(properties.descent) + // yMin
  28893. '\x0F\xFF' + // xMax
  28894. safeString16(properties.ascent) + // yMax
  28895. string16(properties.italicAngle ? 2 : 0) + // macStyle
  28896. '\x00\x11' + // lowestRecPPEM
  28897. '\x00\x00' + // fontDirectionHint
  28898. '\x00\x00' + // indexToLocFormat
  28899. '\x00\x00'); // glyphDataFormat
  28900. // Horizontal header
  28901. builder.addTable('hhea',
  28902. '\x00\x01\x00\x00' + // Version number
  28903. safeString16(properties.ascent) + // Typographic Ascent
  28904. safeString16(properties.descent) + // Typographic Descent
  28905. '\x00\x00' + // Line Gap
  28906. '\xFF\xFF' + // advanceWidthMax
  28907. '\x00\x00' + // minLeftSidebearing
  28908. '\x00\x00' + // minRightSidebearing
  28909. '\x00\x00' + // xMaxExtent
  28910. safeString16(properties.capHeight) + // caretSlopeRise
  28911. safeString16(Math.tan(properties.italicAngle) *
  28912. properties.xHeight) + // caretSlopeRun
  28913. '\x00\x00' + // caretOffset
  28914. '\x00\x00' + // -reserved-
  28915. '\x00\x00' + // -reserved-
  28916. '\x00\x00' + // -reserved-
  28917. '\x00\x00' + // -reserved-
  28918. '\x00\x00' + // metricDataFormat
  28919. string16(numGlyphs)); // Number of HMetrics
  28920. // Horizontal metrics
  28921. builder.addTable('hmtx', (function fontFieldsHmtx() {
  28922. var charstrings = font.charstrings;
  28923. var cffWidths = font.cff ? font.cff.widths : null;
  28924. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  28925. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  28926. var width = 0;
  28927. if (charstrings) {
  28928. var charstring = charstrings[i - 1];
  28929. width = 'width' in charstring ? charstring.width : 0;
  28930. } else if (cffWidths) {
  28931. width = Math.ceil(cffWidths[i] || 0);
  28932. }
  28933. hmtx += string16(width) + string16(0);
  28934. }
  28935. return hmtx;
  28936. })());
  28937. // Maximum profile
  28938. builder.addTable('maxp',
  28939. '\x00\x00\x50\x00' + // Version number
  28940. string16(numGlyphs)); // Num of glyphs
  28941. // Naming tables
  28942. builder.addTable('name', createNameTable(fontName));
  28943. // PostScript information
  28944. builder.addTable('post', createPostTable(properties));
  28945. return builder.toArray();
  28946. },
  28947. get spaceWidth() {
  28948. if ('_shadowWidth' in this) {
  28949. return this._shadowWidth;
  28950. }
  28951. // trying to estimate space character width
  28952. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i', 'I'];
  28953. var width;
  28954. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  28955. var glyphName = possibleSpaceReplacements[i];
  28956. // if possible, getting width by glyph name
  28957. if (glyphName in this.widths) {
  28958. width = this.widths[glyphName];
  28959. break;
  28960. }
  28961. var glyphsUnicodeMap = getGlyphsUnicode();
  28962. var glyphUnicode = glyphsUnicodeMap[glyphName];
  28963. // finding the charcode via unicodeToCID map
  28964. var charcode = 0;
  28965. if (this.composite) {
  28966. if (this.cMap.contains(glyphUnicode)) {
  28967. charcode = this.cMap.lookup(glyphUnicode);
  28968. }
  28969. }
  28970. // ... via toUnicode map
  28971. if (!charcode && this.toUnicode) {
  28972. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  28973. }
  28974. // setting it to unicode if negative or undefined
  28975. if (charcode <= 0) {
  28976. charcode = glyphUnicode;
  28977. }
  28978. // trying to get width via charcode
  28979. width = this.widths[charcode];
  28980. if (width) {
  28981. break; // the non-zero width found
  28982. }
  28983. }
  28984. width = width || this.defaultWidth;
  28985. // Do not shadow the property here. See discussion:
  28986. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  28987. this._shadowWidth = width;
  28988. return width;
  28989. },
  28990. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  28991. var fontCharCode, width, operatorListId;
  28992. var widthCode = charcode;
  28993. if (this.cMap && this.cMap.contains(charcode)) {
  28994. widthCode = this.cMap.lookup(charcode);
  28995. }
  28996. width = this.widths[widthCode];
  28997. width = isNum(width) ? width : this.defaultWidth;
  28998. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  28999. var unicode = this.toUnicode.get(charcode) || charcode;
  29000. if (typeof unicode === 'number') {
  29001. unicode = String.fromCharCode(unicode);
  29002. }
  29003. var isInFont = charcode in this.toFontChar;
  29004. // First try the toFontChar map, if it's not there then try falling
  29005. // back to the char code.
  29006. fontCharCode = this.toFontChar[charcode] || charcode;
  29007. if (this.missingFile) {
  29008. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  29009. }
  29010. if (this.isType3Font) {
  29011. // Font char code in this case is actually a glyph name.
  29012. operatorListId = fontCharCode;
  29013. }
  29014. var accent = null;
  29015. if (this.seacMap && this.seacMap[charcode]) {
  29016. isInFont = true;
  29017. var seac = this.seacMap[charcode];
  29018. fontCharCode = seac.baseFontCharCode;
  29019. accent = {
  29020. fontChar: String.fromCharCode(seac.accentFontCharCode),
  29021. offset: seac.accentOffset
  29022. };
  29023. }
  29024. var fontChar = String.fromCharCode(fontCharCode);
  29025. var glyph = this.glyphCache[charcode];
  29026. if (!glyph ||
  29027. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  29028. operatorListId, isSpace, isInFont)) {
  29029. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  29030. operatorListId, isSpace, isInFont);
  29031. this.glyphCache[charcode] = glyph;
  29032. }
  29033. return glyph;
  29034. },
  29035. charsToGlyphs: function Font_charsToGlyphs(chars) {
  29036. var charsCache = this.charsCache;
  29037. var glyphs, glyph, charcode;
  29038. // if we translated this string before, just grab it from the cache
  29039. if (charsCache) {
  29040. glyphs = charsCache[chars];
  29041. if (glyphs) {
  29042. return glyphs;
  29043. }
  29044. }
  29045. // lazily create the translation cache
  29046. if (!charsCache) {
  29047. charsCache = this.charsCache = Object.create(null);
  29048. }
  29049. glyphs = [];
  29050. var charsCacheKey = chars;
  29051. var i = 0, ii;
  29052. if (this.cMap) {
  29053. // composite fonts have multi-byte strings convert the string from
  29054. // single-byte to multi-byte
  29055. var c = Object.create(null);
  29056. while (i < chars.length) {
  29057. this.cMap.readCharCode(chars, i, c);
  29058. charcode = c.charcode;
  29059. var length = c.length;
  29060. i += length;
  29061. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  29062. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  29063. glyph = this.charToGlyph(charcode, isSpace);
  29064. glyphs.push(glyph);
  29065. }
  29066. } else {
  29067. for (i = 0, ii = chars.length; i < ii; ++i) {
  29068. charcode = chars.charCodeAt(i);
  29069. glyph = this.charToGlyph(charcode, charcode === 0x20);
  29070. glyphs.push(glyph);
  29071. }
  29072. }
  29073. // Enter the translated string into the cache
  29074. return (charsCache[charsCacheKey] = glyphs);
  29075. }
  29076. };
  29077. return Font;
  29078. })();
  29079. var ErrorFont = (function ErrorFontClosure() {
  29080. function ErrorFont(error) {
  29081. this.error = error;
  29082. this.loadedName = 'g_font_error';
  29083. this.loading = false;
  29084. }
  29085. ErrorFont.prototype = {
  29086. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  29087. return [];
  29088. },
  29089. exportData: function ErrorFont_exportData() {
  29090. return {error: this.error};
  29091. }
  29092. };
  29093. return ErrorFont;
  29094. })();
  29095. /**
  29096. * Shared logic for building a char code to glyph id mapping for Type1 and
  29097. * simple CFF fonts. See section 9.6.6.2 of the spec.
  29098. * @param {Object} properties Font properties object.
  29099. * @param {Object} builtInEncoding The encoding contained within the actual font
  29100. * data.
  29101. * @param {Array} glyphNames Array of glyph names where the index is the
  29102. * glyph ID.
  29103. * @returns {Object} A char code to glyph ID map.
  29104. */
  29105. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  29106. var charCodeToGlyphId = Object.create(null);
  29107. var glyphId, charCode, baseEncoding;
  29108. if (properties.baseEncodingName) {
  29109. // If a valid base encoding name was used, the mapping is initialized with
  29110. // that.
  29111. baseEncoding = getEncoding(properties.baseEncodingName);
  29112. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  29113. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  29114. if (glyphId >= 0) {
  29115. charCodeToGlyphId[charCode] = glyphId;
  29116. } else {
  29117. charCodeToGlyphId[charCode] = 0; // notdef
  29118. }
  29119. }
  29120. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  29121. // For a symbolic font the encoding should be the fonts built-in
  29122. // encoding.
  29123. for (charCode in builtInEncoding) {
  29124. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  29125. }
  29126. } else {
  29127. // For non-symbolic fonts that don't have a base encoding the standard
  29128. // encoding should be used.
  29129. baseEncoding = StandardEncoding;
  29130. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  29131. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  29132. if (glyphId >= 0) {
  29133. charCodeToGlyphId[charCode] = glyphId;
  29134. } else {
  29135. charCodeToGlyphId[charCode] = 0; // notdef
  29136. }
  29137. }
  29138. }
  29139. // Lastly, merge in the differences.
  29140. var differences = properties.differences, glyphsUnicodeMap;
  29141. if (differences) {
  29142. for (charCode in differences) {
  29143. var glyphName = differences[charCode];
  29144. glyphId = glyphNames.indexOf(glyphName);
  29145. if (glyphId === -1) {
  29146. if (!glyphsUnicodeMap) {
  29147. glyphsUnicodeMap = getGlyphsUnicode();
  29148. }
  29149. var standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  29150. if (standardGlyphName !== glyphName) {
  29151. glyphId = glyphNames.indexOf(standardGlyphName);
  29152. }
  29153. }
  29154. if (glyphId >= 0) {
  29155. charCodeToGlyphId[charCode] = glyphId;
  29156. } else {
  29157. charCodeToGlyphId[charCode] = 0; // notdef
  29158. }
  29159. }
  29160. }
  29161. return charCodeToGlyphId;
  29162. }
  29163. // Type1Font is also a CIDFontType0.
  29164. var Type1Font = (function Type1FontClosure() {
  29165. function findBlock(streamBytes, signature, startIndex) {
  29166. var streamBytesLength = streamBytes.length;
  29167. var signatureLength = signature.length;
  29168. var scanLength = streamBytesLength - signatureLength;
  29169. var i = startIndex, j, found = false;
  29170. while (i < scanLength) {
  29171. j = 0;
  29172. while (j < signatureLength && streamBytes[i + j] === signature[j]) {
  29173. j++;
  29174. }
  29175. if (j >= signatureLength) { // `signature` found, skip over whitespace.
  29176. i += j;
  29177. while (i < streamBytesLength && isSpace(streamBytes[i])) {
  29178. i++;
  29179. }
  29180. found = true;
  29181. break;
  29182. }
  29183. i++;
  29184. }
  29185. return {
  29186. found: found,
  29187. length: i,
  29188. };
  29189. }
  29190. function getHeaderBlock(stream, suggestedLength) {
  29191. var EEXEC_SIGNATURE = [0x65, 0x65, 0x78, 0x65, 0x63];
  29192. var streamStartPos = stream.pos; // Save the initial stream position.
  29193. var headerBytes, headerBytesLength, block;
  29194. try {
  29195. headerBytes = stream.getBytes(suggestedLength);
  29196. headerBytesLength = headerBytes.length;
  29197. } catch (ex) {
  29198. if (ex instanceof MissingDataException) {
  29199. throw ex;
  29200. }
  29201. // Ignore errors if the `suggestedLength` is huge enough that a Uint8Array
  29202. // cannot hold the result of `getBytes`, and fallback to simply checking
  29203. // the entire stream (fixes issue3928.pdf).
  29204. }
  29205. if (headerBytesLength === suggestedLength) {
  29206. // Most of the time `suggestedLength` is correct, so to speed things up we
  29207. // initially only check the last few bytes to see if the header was found.
  29208. // Otherwise we (potentially) check the entire stream to prevent errors in
  29209. // `Type1Parser` (fixes issue5686.pdf).
  29210. block = findBlock(headerBytes, EEXEC_SIGNATURE,
  29211. suggestedLength - 2 * EEXEC_SIGNATURE.length);
  29212. if (block.found && block.length === suggestedLength) {
  29213. return {
  29214. stream: new Stream(headerBytes),
  29215. length: suggestedLength,
  29216. };
  29217. }
  29218. }
  29219. warn('Invalid "Length1" property in Type1 font -- trying to recover.');
  29220. stream.pos = streamStartPos; // Reset the stream position.
  29221. var SCAN_BLOCK_LENGTH = 2048;
  29222. var actualLength;
  29223. while (true) {
  29224. var scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
  29225. block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
  29226. if (block.length === 0) {
  29227. break;
  29228. }
  29229. stream.pos += block.length; // Update the stream position.
  29230. if (block.found) {
  29231. actualLength = stream.pos - streamStartPos;
  29232. break;
  29233. }
  29234. }
  29235. stream.pos = streamStartPos; // Reset the stream position.
  29236. if (actualLength) {
  29237. return {
  29238. stream: new Stream(stream.getBytes(actualLength)),
  29239. length: actualLength,
  29240. };
  29241. }
  29242. warn('Unable to recover "Length1" property in Type1 font -- using as is.');
  29243. return {
  29244. stream: new Stream(stream.getBytes(suggestedLength)),
  29245. length: suggestedLength,
  29246. };
  29247. }
  29248. function getEexecBlock(stream, suggestedLength) {
  29249. // We should ideally parse the eexec block to ensure that `suggestedLength`
  29250. // is correct, so we don't truncate the block data if it's too small.
  29251. // However, this would also require checking if the fixed-content portion
  29252. // exists (using the 'Length3' property), and ensuring that it's valid.
  29253. //
  29254. // Given that `suggestedLength` almost always is correct, all the validation
  29255. // would require a great deal of unnecessary parsing for most fonts.
  29256. // To save time, we always fetch the entire stream instead, which also avoid
  29257. // issues if `suggestedLength` is huge (see comment in `getHeaderBlock`).
  29258. //
  29259. // NOTE: This means that the function can include the fixed-content portion
  29260. // in the returned eexec block. In practice this does *not* seem to matter,
  29261. // since `Type1Parser_extractFontProgram` will skip over any non-commands.
  29262. var eexecBytes = stream.getBytes();
  29263. return {
  29264. stream: new Stream(eexecBytes),
  29265. length: eexecBytes.length,
  29266. };
  29267. }
  29268. function Type1Font(name, file, properties) {
  29269. // Some bad generators embed pfb file as is, we have to strip 6-byte header.
  29270. // Also, length1 and length2 might be off by 6 bytes as well.
  29271. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  29272. var PFB_HEADER_SIZE = 6;
  29273. var headerBlockLength = properties.length1;
  29274. var eexecBlockLength = properties.length2;
  29275. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  29276. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  29277. if (pfbHeaderPresent) {
  29278. file.skip(PFB_HEADER_SIZE);
  29279. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  29280. (pfbHeader[3] << 8) | pfbHeader[2];
  29281. }
  29282. // Get the data block containing glyphs and subrs information
  29283. var headerBlock = getHeaderBlock(file, headerBlockLength);
  29284. headerBlockLength = headerBlock.length;
  29285. var headerBlockParser = new Type1Parser(headerBlock.stream, false,
  29286. SEAC_ANALYSIS_ENABLED);
  29287. headerBlockParser.extractFontHeader(properties);
  29288. if (pfbHeaderPresent) {
  29289. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  29290. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  29291. (pfbHeader[3] << 8) | pfbHeader[2];
  29292. }
  29293. // Decrypt the data blocks and retrieve it's content
  29294. var eexecBlock = getEexecBlock(file, eexecBlockLength);
  29295. eexecBlockLength = eexecBlock.length;
  29296. var eexecBlockParser = new Type1Parser(eexecBlock.stream, true,
  29297. SEAC_ANALYSIS_ENABLED);
  29298. var data = eexecBlockParser.extractFontProgram();
  29299. for (var info in data.properties) {
  29300. properties[info] = data.properties[info];
  29301. }
  29302. var charstrings = data.charstrings;
  29303. var type2Charstrings = this.getType2Charstrings(charstrings);
  29304. var subrs = this.getType2Subrs(data.subrs);
  29305. this.charstrings = charstrings;
  29306. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  29307. subrs, properties);
  29308. this.seacs = this.getSeacs(data.charstrings);
  29309. }
  29310. Type1Font.prototype = {
  29311. get numGlyphs() {
  29312. return this.charstrings.length + 1;
  29313. },
  29314. getCharset: function Type1Font_getCharset() {
  29315. var charset = ['.notdef'];
  29316. var charstrings = this.charstrings;
  29317. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  29318. charset.push(charstrings[glyphId].glyphName);
  29319. }
  29320. return charset;
  29321. },
  29322. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  29323. var charstrings = this.charstrings;
  29324. var glyphNames = ['.notdef'], glyphId;
  29325. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  29326. glyphNames.push(charstrings[glyphId].glyphName);
  29327. }
  29328. var encoding = properties.builtInEncoding;
  29329. if (encoding) {
  29330. var builtInEncoding = Object.create(null);
  29331. for (var charCode in encoding) {
  29332. glyphId = glyphNames.indexOf(encoding[charCode]);
  29333. if (glyphId >= 0) {
  29334. builtInEncoding[charCode] = glyphId;
  29335. }
  29336. }
  29337. }
  29338. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  29339. },
  29340. getSeacs: function Type1Font_getSeacs(charstrings) {
  29341. var i, ii;
  29342. var seacMap = [];
  29343. for (i = 0, ii = charstrings.length; i < ii; i++) {
  29344. var charstring = charstrings[i];
  29345. if (charstring.seac) {
  29346. // Offset by 1 for .notdef
  29347. seacMap[i + 1] = charstring.seac;
  29348. }
  29349. }
  29350. return seacMap;
  29351. },
  29352. getType2Charstrings: function Type1Font_getType2Charstrings(
  29353. type1Charstrings) {
  29354. var type2Charstrings = [];
  29355. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  29356. type2Charstrings.push(type1Charstrings[i].charstring);
  29357. }
  29358. return type2Charstrings;
  29359. },
  29360. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  29361. var bias = 0;
  29362. var count = type1Subrs.length;
  29363. if (count < 1133) {
  29364. bias = 107;
  29365. } else if (count < 33769) {
  29366. bias = 1131;
  29367. } else {
  29368. bias = 32768;
  29369. }
  29370. // Add a bunch of empty subrs to deal with the Type2 bias
  29371. var type2Subrs = [];
  29372. var i;
  29373. for (i = 0; i < bias; i++) {
  29374. type2Subrs.push([0x0B]);
  29375. }
  29376. for (i = 0; i < count; i++) {
  29377. type2Subrs.push(type1Subrs[i]);
  29378. }
  29379. return type2Subrs;
  29380. },
  29381. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs,
  29382. properties) {
  29383. var cff = new CFF();
  29384. cff.header = new CFFHeader(1, 0, 4, 4);
  29385. cff.names = [name];
  29386. var topDict = new CFFTopDict();
  29387. // CFF strings IDs 0...390 are predefined names, so refering
  29388. // to entries in our own String INDEX starts at SID 391.
  29389. topDict.setByName('version', 391);
  29390. topDict.setByName('Notice', 392);
  29391. topDict.setByName('FullName', 393);
  29392. topDict.setByName('FamilyName', 394);
  29393. topDict.setByName('Weight', 395);
  29394. topDict.setByName('Encoding', null); // placeholder
  29395. topDict.setByName('FontMatrix', properties.fontMatrix);
  29396. topDict.setByName('FontBBox', properties.bbox);
  29397. topDict.setByName('charset', null); // placeholder
  29398. topDict.setByName('CharStrings', null); // placeholder
  29399. topDict.setByName('Private', null); // placeholder
  29400. cff.topDict = topDict;
  29401. var strings = new CFFStrings();
  29402. strings.add('Version 0.11'); // Version
  29403. strings.add('See original notice'); // Notice
  29404. strings.add(name); // FullName
  29405. strings.add(name); // FamilyName
  29406. strings.add('Medium'); // Weight
  29407. cff.strings = strings;
  29408. cff.globalSubrIndex = new CFFIndex();
  29409. var count = glyphs.length;
  29410. var charsetArray = [0];
  29411. var i, ii;
  29412. for (i = 0; i < count; i++) {
  29413. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  29414. // TODO: Insert the string and correctly map it. Previously it was
  29415. // thought mapping names that aren't in the standard strings to .notdef
  29416. // was fine, however in issue818 when mapping them all to .notdef the
  29417. // adieresis glyph no longer worked.
  29418. if (index === -1) {
  29419. index = 0;
  29420. }
  29421. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  29422. }
  29423. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  29424. var charStringsIndex = new CFFIndex();
  29425. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  29426. for (i = 0; i < count; i++) {
  29427. var glyph = glyphs[i];
  29428. // If the CharString outline is empty, replace it with .notdef to
  29429. // prevent OTS from rejecting the font (fixes bug1252420.pdf).
  29430. if (glyph.length === 0) {
  29431. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  29432. continue;
  29433. }
  29434. charStringsIndex.add(glyph);
  29435. }
  29436. cff.charStrings = charStringsIndex;
  29437. var privateDict = new CFFPrivateDict();
  29438. privateDict.setByName('Subrs', null); // placeholder
  29439. var fields = [
  29440. 'BlueValues',
  29441. 'OtherBlues',
  29442. 'FamilyBlues',
  29443. 'FamilyOtherBlues',
  29444. 'StemSnapH',
  29445. 'StemSnapV',
  29446. 'BlueShift',
  29447. 'BlueFuzz',
  29448. 'BlueScale',
  29449. 'LanguageGroup',
  29450. 'ExpansionFactor',
  29451. 'ForceBold',
  29452. 'StdHW',
  29453. 'StdVW'
  29454. ];
  29455. for (i = 0, ii = fields.length; i < ii; i++) {
  29456. var field = fields[i];
  29457. if (!(field in properties.privateData)) {
  29458. continue;
  29459. }
  29460. var value = properties.privateData[field];
  29461. if (isArray(value)) {
  29462. // All of the private dictionary array data in CFF must be stored as
  29463. // "delta-encoded" numbers.
  29464. for (var j = value.length - 1; j > 0; j--) {
  29465. value[j] -= value[j - 1]; // ... difference from previous value
  29466. }
  29467. }
  29468. privateDict.setByName(field, value);
  29469. }
  29470. cff.topDict.privateDict = privateDict;
  29471. var subrIndex = new CFFIndex();
  29472. for (i = 0, ii = subrs.length; i < ii; i++) {
  29473. subrIndex.add(subrs[i]);
  29474. }
  29475. privateDict.subrsIndex = subrIndex;
  29476. var compiler = new CFFCompiler(cff);
  29477. return compiler.compile();
  29478. }
  29479. };
  29480. return Type1Font;
  29481. })();
  29482. var CFFFont = (function CFFFontClosure() {
  29483. function CFFFont(file, properties) {
  29484. this.properties = properties;
  29485. var parser = new CFFParser(file, properties, SEAC_ANALYSIS_ENABLED);
  29486. this.cff = parser.parse();
  29487. var compiler = new CFFCompiler(this.cff);
  29488. this.seacs = this.cff.seacs;
  29489. try {
  29490. this.data = compiler.compile();
  29491. } catch (e) {
  29492. warn('Failed to compile font ' + properties.loadedName);
  29493. // There may have just been an issue with the compiler, set the data
  29494. // anyway and hope the font loaded.
  29495. this.data = file;
  29496. }
  29497. }
  29498. CFFFont.prototype = {
  29499. get numGlyphs() {
  29500. return this.cff.charStrings.count;
  29501. },
  29502. getCharset: function CFFFont_getCharset() {
  29503. return this.cff.charset.charset;
  29504. },
  29505. getGlyphMapping: function CFFFont_getGlyphMapping() {
  29506. var cff = this.cff;
  29507. var properties = this.properties;
  29508. var charsets = cff.charset.charset;
  29509. var charCodeToGlyphId;
  29510. var glyphId;
  29511. if (properties.composite) {
  29512. charCodeToGlyphId = Object.create(null);
  29513. if (cff.isCIDFont) {
  29514. // If the font is actually a CID font then we should use the charset
  29515. // to map CIDs to GIDs.
  29516. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  29517. var cid = charsets[glyphId];
  29518. var charCode = properties.cMap.charCodeOf(cid);
  29519. charCodeToGlyphId[charCode] = glyphId;
  29520. }
  29521. } else {
  29522. // If it is NOT actually a CID font then CIDs should be mapped
  29523. // directly to GIDs.
  29524. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  29525. charCodeToGlyphId[glyphId] = glyphId;
  29526. }
  29527. }
  29528. return charCodeToGlyphId;
  29529. }
  29530. var encoding = cff.encoding ? cff.encoding.encoding : null;
  29531. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  29532. return charCodeToGlyphId;
  29533. }
  29534. };
  29535. return CFFFont;
  29536. })();
  29537. // Workaround for seac on Windows.
  29538. (function checkSeacSupport() {
  29539. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  29540. SEAC_ANALYSIS_ENABLED = true;
  29541. }
  29542. })();
  29543. // Workaround for Private Use Area characters in Chrome on Windows
  29544. // http://code.google.com/p/chromium/issues/detail?id=122465
  29545. // https://github.com/mozilla/pdf.js/issues/1689
  29546. (function checkChromeWindows() {
  29547. if (typeof navigator !== 'undefined' &&
  29548. /Windows.*Chrome/.test(navigator.userAgent)) {
  29549. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  29550. }
  29551. })();
  29552. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  29553. exports.ErrorFont = ErrorFont;
  29554. exports.Font = Font;
  29555. exports.FontFlags = FontFlags;
  29556. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  29557. exports.ToUnicodeMap = ToUnicodeMap;
  29558. exports.getFontType = getFontType;
  29559. }));
  29560. (function (root, factory) {
  29561. {
  29562. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  29563. root.pdfjsCoreParser);
  29564. }
  29565. }(this, function (exports, sharedUtil, coreParser) {
  29566. var error = sharedUtil.error;
  29567. var isSpace = sharedUtil.isSpace;
  29568. var EOF = coreParser.EOF;
  29569. var PostScriptParser = (function PostScriptParserClosure() {
  29570. function PostScriptParser(lexer) {
  29571. this.lexer = lexer;
  29572. this.operators = [];
  29573. this.token = null;
  29574. this.prev = null;
  29575. }
  29576. PostScriptParser.prototype = {
  29577. nextToken: function PostScriptParser_nextToken() {
  29578. this.prev = this.token;
  29579. this.token = this.lexer.getToken();
  29580. },
  29581. accept: function PostScriptParser_accept(type) {
  29582. if (this.token.type === type) {
  29583. this.nextToken();
  29584. return true;
  29585. }
  29586. return false;
  29587. },
  29588. expect: function PostScriptParser_expect(type) {
  29589. if (this.accept(type)) {
  29590. return true;
  29591. }
  29592. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  29593. type + '.');
  29594. },
  29595. parse: function PostScriptParser_parse() {
  29596. this.nextToken();
  29597. this.expect(PostScriptTokenTypes.LBRACE);
  29598. this.parseBlock();
  29599. this.expect(PostScriptTokenTypes.RBRACE);
  29600. return this.operators;
  29601. },
  29602. parseBlock: function PostScriptParser_parseBlock() {
  29603. while (true) {
  29604. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  29605. this.operators.push(this.prev.value);
  29606. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  29607. this.operators.push(this.prev.value);
  29608. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29609. this.parseCondition();
  29610. } else {
  29611. return;
  29612. }
  29613. }
  29614. },
  29615. parseCondition: function PostScriptParser_parseCondition() {
  29616. // Add two place holders that will be updated later
  29617. var conditionLocation = this.operators.length;
  29618. this.operators.push(null, null);
  29619. this.parseBlock();
  29620. this.expect(PostScriptTokenTypes.RBRACE);
  29621. if (this.accept(PostScriptTokenTypes.IF)) {
  29622. // The true block is right after the 'if' so it just falls through on
  29623. // true else it jumps and skips the true block.
  29624. this.operators[conditionLocation] = this.operators.length;
  29625. this.operators[conditionLocation + 1] = 'jz';
  29626. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29627. var jumpLocation = this.operators.length;
  29628. this.operators.push(null, null);
  29629. var endOfTrue = this.operators.length;
  29630. this.parseBlock();
  29631. this.expect(PostScriptTokenTypes.RBRACE);
  29632. this.expect(PostScriptTokenTypes.IFELSE);
  29633. // The jump is added at the end of the true block to skip the false
  29634. // block.
  29635. this.operators[jumpLocation] = this.operators.length;
  29636. this.operators[jumpLocation + 1] = 'j';
  29637. this.operators[conditionLocation] = endOfTrue;
  29638. this.operators[conditionLocation + 1] = 'jz';
  29639. } else {
  29640. error('PS Function: error parsing conditional.');
  29641. }
  29642. }
  29643. };
  29644. return PostScriptParser;
  29645. })();
  29646. var PostScriptTokenTypes = {
  29647. LBRACE: 0,
  29648. RBRACE: 1,
  29649. NUMBER: 2,
  29650. OPERATOR: 3,
  29651. IF: 4,
  29652. IFELSE: 5
  29653. };
  29654. var PostScriptToken = (function PostScriptTokenClosure() {
  29655. function PostScriptToken(type, value) {
  29656. this.type = type;
  29657. this.value = value;
  29658. }
  29659. var opCache = Object.create(null);
  29660. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  29661. var opValue = opCache[op];
  29662. if (opValue) {
  29663. return opValue;
  29664. }
  29665. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  29666. };
  29667. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  29668. '{');
  29669. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  29670. '}');
  29671. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  29672. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  29673. 'IFELSE');
  29674. return PostScriptToken;
  29675. })();
  29676. var PostScriptLexer = (function PostScriptLexerClosure() {
  29677. function PostScriptLexer(stream) {
  29678. this.stream = stream;
  29679. this.nextChar();
  29680. this.strBuf = [];
  29681. }
  29682. PostScriptLexer.prototype = {
  29683. nextChar: function PostScriptLexer_nextChar() {
  29684. return (this.currentChar = this.stream.getByte());
  29685. },
  29686. getToken: function PostScriptLexer_getToken() {
  29687. var comment = false;
  29688. var ch = this.currentChar;
  29689. // skip comments
  29690. while (true) {
  29691. if (ch < 0) {
  29692. return EOF;
  29693. }
  29694. if (comment) {
  29695. if (ch === 0x0A || ch === 0x0D) {
  29696. comment = false;
  29697. }
  29698. } else if (ch === 0x25) { // '%'
  29699. comment = true;
  29700. } else if (!isSpace(ch)) {
  29701. break;
  29702. }
  29703. ch = this.nextChar();
  29704. }
  29705. switch (ch | 0) {
  29706. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29707. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29708. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29709. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  29710. this.getNumber());
  29711. case 0x7B: // '{'
  29712. this.nextChar();
  29713. return PostScriptToken.LBRACE;
  29714. case 0x7D: // '}'
  29715. this.nextChar();
  29716. return PostScriptToken.RBRACE;
  29717. }
  29718. // operator
  29719. var strBuf = this.strBuf;
  29720. strBuf.length = 0;
  29721. strBuf[0] = String.fromCharCode(ch);
  29722. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  29723. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  29724. strBuf.push(String.fromCharCode(ch));
  29725. }
  29726. var str = strBuf.join('');
  29727. switch (str.toLowerCase()) {
  29728. case 'if':
  29729. return PostScriptToken.IF;
  29730. case 'ifelse':
  29731. return PostScriptToken.IFELSE;
  29732. default:
  29733. return PostScriptToken.getOperator(str);
  29734. }
  29735. },
  29736. getNumber: function PostScriptLexer_getNumber() {
  29737. var ch = this.currentChar;
  29738. var strBuf = this.strBuf;
  29739. strBuf.length = 0;
  29740. strBuf[0] = String.fromCharCode(ch);
  29741. while ((ch = this.nextChar()) >= 0) {
  29742. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  29743. ch === 0x2D || ch === 0x2E) { // '-', '.'
  29744. strBuf.push(String.fromCharCode(ch));
  29745. } else {
  29746. break;
  29747. }
  29748. }
  29749. var value = parseFloat(strBuf.join(''));
  29750. if (isNaN(value)) {
  29751. error('Invalid floating point number: ' + value);
  29752. }
  29753. return value;
  29754. }
  29755. };
  29756. return PostScriptLexer;
  29757. })();
  29758. exports.PostScriptLexer = PostScriptLexer;
  29759. exports.PostScriptParser = PostScriptParser;
  29760. }));
  29761. (function (root, factory) {
  29762. {
  29763. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  29764. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  29765. }
  29766. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  29767. var error = sharedUtil.error;
  29768. var info = sharedUtil.info;
  29769. var isArray = sharedUtil.isArray;
  29770. var isBool = sharedUtil.isBool;
  29771. var isDict = corePrimitives.isDict;
  29772. var isStream = corePrimitives.isStream;
  29773. var PostScriptLexer = corePsParser.PostScriptLexer;
  29774. var PostScriptParser = corePsParser.PostScriptParser;
  29775. var PDFFunction = (function PDFFunctionClosure() {
  29776. var CONSTRUCT_SAMPLED = 0;
  29777. var CONSTRUCT_INTERPOLATED = 2;
  29778. var CONSTRUCT_STICHED = 3;
  29779. var CONSTRUCT_POSTSCRIPT = 4;
  29780. return {
  29781. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  29782. str) {
  29783. var i, ii;
  29784. var length = 1;
  29785. for (i = 0, ii = size.length; i < ii; i++) {
  29786. length *= size[i];
  29787. }
  29788. length *= outputSize;
  29789. var array = new Array(length);
  29790. var codeSize = 0;
  29791. var codeBuf = 0;
  29792. // 32 is a valid bps so shifting won't work
  29793. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  29794. var strBytes = str.getBytes((length * bps + 7) / 8);
  29795. var strIdx = 0;
  29796. for (i = 0; i < length; i++) {
  29797. while (codeSize < bps) {
  29798. codeBuf <<= 8;
  29799. codeBuf |= strBytes[strIdx++];
  29800. codeSize += 8;
  29801. }
  29802. codeSize -= bps;
  29803. array[i] = (codeBuf >> codeSize) * sampleMul;
  29804. codeBuf &= (1 << codeSize) - 1;
  29805. }
  29806. return array;
  29807. },
  29808. getIR: function PDFFunction_getIR(xref, fn) {
  29809. var dict = fn.dict;
  29810. if (!dict) {
  29811. dict = fn;
  29812. }
  29813. var types = [this.constructSampled,
  29814. null,
  29815. this.constructInterpolated,
  29816. this.constructStiched,
  29817. this.constructPostScript];
  29818. var typeNum = dict.get('FunctionType');
  29819. var typeFn = types[typeNum];
  29820. if (!typeFn) {
  29821. error('Unknown type of function');
  29822. }
  29823. return typeFn.call(this, fn, dict, xref);
  29824. },
  29825. fromIR: function PDFFunction_fromIR(IR) {
  29826. var type = IR[0];
  29827. switch (type) {
  29828. case CONSTRUCT_SAMPLED:
  29829. return this.constructSampledFromIR(IR);
  29830. case CONSTRUCT_INTERPOLATED:
  29831. return this.constructInterpolatedFromIR(IR);
  29832. case CONSTRUCT_STICHED:
  29833. return this.constructStichedFromIR(IR);
  29834. //case CONSTRUCT_POSTSCRIPT:
  29835. default:
  29836. return this.constructPostScriptFromIR(IR);
  29837. }
  29838. },
  29839. parse: function PDFFunction_parse(xref, fn) {
  29840. var IR = this.getIR(xref, fn);
  29841. return this.fromIR(IR);
  29842. },
  29843. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  29844. if (!isArray(fnObj)) {
  29845. // not an array -- parsing as regular function
  29846. return this.parse(xref, fnObj);
  29847. }
  29848. var fnArray = [];
  29849. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  29850. var obj = xref.fetchIfRef(fnObj[j]);
  29851. fnArray.push(PDFFunction.parse(xref, obj));
  29852. }
  29853. return function (src, srcOffset, dest, destOffset) {
  29854. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  29855. fnArray[i](src, srcOffset, dest, destOffset + i);
  29856. }
  29857. };
  29858. },
  29859. constructSampled: function PDFFunction_constructSampled(str, dict) {
  29860. function toMultiArray(arr) {
  29861. var inputLength = arr.length;
  29862. var out = [];
  29863. var index = 0;
  29864. for (var i = 0; i < inputLength; i += 2) {
  29865. out[index] = [arr[i], arr[i + 1]];
  29866. ++index;
  29867. }
  29868. return out;
  29869. }
  29870. var domain = dict.getArray('Domain');
  29871. var range = dict.getArray('Range');
  29872. if (!domain || !range) {
  29873. error('No domain or range');
  29874. }
  29875. var inputSize = domain.length / 2;
  29876. var outputSize = range.length / 2;
  29877. domain = toMultiArray(domain);
  29878. range = toMultiArray(range);
  29879. var size = dict.get('Size');
  29880. var bps = dict.get('BitsPerSample');
  29881. var order = dict.get('Order') || 1;
  29882. if (order !== 1) {
  29883. // No description how cubic spline interpolation works in PDF32000:2008
  29884. // As in poppler, ignoring order, linear interpolation may work as good
  29885. info('No support for cubic spline interpolation: ' + order);
  29886. }
  29887. var encode = dict.getArray('Encode');
  29888. if (!encode) {
  29889. encode = [];
  29890. for (var i = 0; i < inputSize; ++i) {
  29891. encode.push(0);
  29892. encode.push(size[i] - 1);
  29893. }
  29894. }
  29895. encode = toMultiArray(encode);
  29896. var decode = dict.getArray('Decode');
  29897. if (!decode) {
  29898. decode = range;
  29899. } else {
  29900. decode = toMultiArray(decode);
  29901. }
  29902. var samples = this.getSampleArray(size, outputSize, bps, str);
  29903. return [
  29904. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  29905. outputSize, Math.pow(2, bps) - 1, range
  29906. ];
  29907. },
  29908. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  29909. // See chapter 3, page 109 of the PDF reference
  29910. function interpolate(x, xmin, xmax, ymin, ymax) {
  29911. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  29912. }
  29913. return function constructSampledFromIRResult(src, srcOffset,
  29914. dest, destOffset) {
  29915. // See chapter 3, page 110 of the PDF reference.
  29916. var m = IR[1];
  29917. var domain = IR[2];
  29918. var encode = IR[3];
  29919. var decode = IR[4];
  29920. var samples = IR[5];
  29921. var size = IR[6];
  29922. var n = IR[7];
  29923. //var mask = IR[8];
  29924. var range = IR[9];
  29925. // Building the cube vertices: its part and sample index
  29926. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  29927. var cubeVertices = 1 << m;
  29928. var cubeN = new Float64Array(cubeVertices);
  29929. var cubeVertex = new Uint32Array(cubeVertices);
  29930. var i, j;
  29931. for (j = 0; j < cubeVertices; j++) {
  29932. cubeN[j] = 1;
  29933. }
  29934. var k = n, pos = 1;
  29935. // Map x_i to y_j for 0 <= i < m using the sampled function.
  29936. for (i = 0; i < m; ++i) {
  29937. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  29938. var domain_2i = domain[i][0];
  29939. var domain_2i_1 = domain[i][1];
  29940. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  29941. domain_2i_1);
  29942. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  29943. // Encode_2i, Encode_2i+1)
  29944. var e = interpolate(xi, domain_2i, domain_2i_1,
  29945. encode[i][0], encode[i][1]);
  29946. // e_i' = min(max(e_i, 0), Size_i - 1)
  29947. var size_i = size[i];
  29948. e = Math.min(Math.max(e, 0), size_i - 1);
  29949. // Adjusting the cube: N and vertex sample index
  29950. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  29951. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  29952. var n1 = e - e0; // (e - e0) / (e1 - e0);
  29953. var offset0 = e0 * k;
  29954. var offset1 = offset0 + k; // e1 * k
  29955. for (j = 0; j < cubeVertices; j++) {
  29956. if (j & pos) {
  29957. cubeN[j] *= n1;
  29958. cubeVertex[j] += offset1;
  29959. } else {
  29960. cubeN[j] *= n0;
  29961. cubeVertex[j] += offset0;
  29962. }
  29963. }
  29964. k *= size_i;
  29965. pos <<= 1;
  29966. }
  29967. for (j = 0; j < n; ++j) {
  29968. // Sum all cube vertices' samples portions
  29969. var rj = 0;
  29970. for (i = 0; i < cubeVertices; i++) {
  29971. rj += samples[cubeVertex[i] + j] * cubeN[i];
  29972. }
  29973. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  29974. // Decode_2j, Decode_2j+1)
  29975. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  29976. // y_j = min(max(r_j, range_2j), range_2j+1)
  29977. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  29978. range[j][1]);
  29979. }
  29980. };
  29981. },
  29982. constructInterpolated: function PDFFunction_constructInterpolated(str,
  29983. dict) {
  29984. var c0 = dict.getArray('C0') || [0];
  29985. var c1 = dict.getArray('C1') || [1];
  29986. var n = dict.get('N');
  29987. if (!isArray(c0) || !isArray(c1)) {
  29988. error('Illegal dictionary for interpolated function');
  29989. }
  29990. var length = c0.length;
  29991. var diff = [];
  29992. for (var i = 0; i < length; ++i) {
  29993. diff.push(c1[i] - c0[i]);
  29994. }
  29995. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  29996. },
  29997. constructInterpolatedFromIR:
  29998. function PDFFunction_constructInterpolatedFromIR(IR) {
  29999. var c0 = IR[1];
  30000. var diff = IR[2];
  30001. var n = IR[3];
  30002. var length = diff.length;
  30003. return function constructInterpolatedFromIRResult(src, srcOffset,
  30004. dest, destOffset) {
  30005. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  30006. for (var j = 0; j < length; ++j) {
  30007. dest[destOffset + j] = c0[j] + (x * diff[j]);
  30008. }
  30009. };
  30010. },
  30011. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  30012. var domain = dict.getArray('Domain');
  30013. if (!domain) {
  30014. error('No domain');
  30015. }
  30016. var inputSize = domain.length / 2;
  30017. if (inputSize !== 1) {
  30018. error('Bad domain for stiched function');
  30019. }
  30020. var fnRefs = dict.get('Functions');
  30021. var fns = [];
  30022. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  30023. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  30024. }
  30025. var bounds = dict.getArray('Bounds');
  30026. var encode = dict.getArray('Encode');
  30027. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  30028. },
  30029. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  30030. var domain = IR[1];
  30031. var bounds = IR[2];
  30032. var encode = IR[3];
  30033. var fnsIR = IR[4];
  30034. var fns = [];
  30035. var tmpBuf = new Float32Array(1);
  30036. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  30037. fns.push(PDFFunction.fromIR(fnsIR[i]));
  30038. }
  30039. return function constructStichedFromIRResult(src, srcOffset,
  30040. dest, destOffset) {
  30041. var clip = function constructStichedFromIRClip(v, min, max) {
  30042. if (v > max) {
  30043. v = max;
  30044. } else if (v < min) {
  30045. v = min;
  30046. }
  30047. return v;
  30048. };
  30049. // clip to domain
  30050. var v = clip(src[srcOffset], domain[0], domain[1]);
  30051. // calculate which bound the value is in
  30052. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  30053. if (v < bounds[i]) {
  30054. break;
  30055. }
  30056. }
  30057. // encode value into domain of function
  30058. var dmin = domain[0];
  30059. if (i > 0) {
  30060. dmin = bounds[i - 1];
  30061. }
  30062. var dmax = domain[1];
  30063. if (i < bounds.length) {
  30064. dmax = bounds[i];
  30065. }
  30066. var rmin = encode[2 * i];
  30067. var rmax = encode[2 * i + 1];
  30068. // Prevent the value from becoming NaN as a result
  30069. // of division by zero (fixes issue6113.pdf).
  30070. tmpBuf[0] = dmin === dmax ? rmin :
  30071. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  30072. // call the appropriate function
  30073. fns[i](tmpBuf, 0, dest, destOffset);
  30074. };
  30075. },
  30076. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  30077. xref) {
  30078. var domain = dict.getArray('Domain');
  30079. var range = dict.getArray('Range');
  30080. if (!domain) {
  30081. error('No domain.');
  30082. }
  30083. if (!range) {
  30084. error('No range.');
  30085. }
  30086. var lexer = new PostScriptLexer(fn);
  30087. var parser = new PostScriptParser(lexer);
  30088. var code = parser.parse();
  30089. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  30090. },
  30091. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  30092. IR) {
  30093. var domain = IR[1];
  30094. var range = IR[2];
  30095. var code = IR[3];
  30096. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  30097. if (compiled) {
  30098. // Compiled function consists of simple expressions such as addition,
  30099. // subtraction, Math.max, and also contains 'var' and 'return'
  30100. // statements. See the generation in the PostScriptCompiler below.
  30101. /*jshint -W054 */
  30102. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  30103. }
  30104. info('Unable to compile PS function');
  30105. var numOutputs = range.length >> 1;
  30106. var numInputs = domain.length >> 1;
  30107. var evaluator = new PostScriptEvaluator(code);
  30108. // Cache the values for a big speed up, the cache size is limited though
  30109. // since the number of possible values can be huge from a PS function.
  30110. var cache = Object.create(null);
  30111. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  30112. // seen in our tests.
  30113. var MAX_CACHE_SIZE = 2048 * 4;
  30114. var cache_available = MAX_CACHE_SIZE;
  30115. var tmpBuf = new Float32Array(numInputs);
  30116. return function constructPostScriptFromIRResult(src, srcOffset,
  30117. dest, destOffset) {
  30118. var i, value;
  30119. var key = '';
  30120. var input = tmpBuf;
  30121. for (i = 0; i < numInputs; i++) {
  30122. value = src[srcOffset + i];
  30123. input[i] = value;
  30124. key += value + '_';
  30125. }
  30126. var cachedValue = cache[key];
  30127. if (cachedValue !== undefined) {
  30128. dest.set(cachedValue, destOffset);
  30129. return;
  30130. }
  30131. var output = new Float32Array(numOutputs);
  30132. var stack = evaluator.execute(input);
  30133. var stackIndex = stack.length - numOutputs;
  30134. for (i = 0; i < numOutputs; i++) {
  30135. value = stack[stackIndex + i];
  30136. var bound = range[i * 2];
  30137. if (value < bound) {
  30138. value = bound;
  30139. } else {
  30140. bound = range[i * 2 +1];
  30141. if (value > bound) {
  30142. value = bound;
  30143. }
  30144. }
  30145. output[i] = value;
  30146. }
  30147. if (cache_available > 0) {
  30148. cache_available--;
  30149. cache[key] = output;
  30150. }
  30151. dest.set(output, destOffset);
  30152. };
  30153. }
  30154. };
  30155. })();
  30156. function isPDFFunction(v) {
  30157. var fnDict;
  30158. if (typeof v !== 'object') {
  30159. return false;
  30160. } else if (isDict(v)) {
  30161. fnDict = v;
  30162. } else if (isStream(v)) {
  30163. fnDict = v.dict;
  30164. } else {
  30165. return false;
  30166. }
  30167. return fnDict.has('FunctionType');
  30168. }
  30169. var PostScriptStack = (function PostScriptStackClosure() {
  30170. var MAX_STACK_SIZE = 100;
  30171. function PostScriptStack(initialStack) {
  30172. this.stack = !initialStack ? [] :
  30173. Array.prototype.slice.call(initialStack, 0);
  30174. }
  30175. PostScriptStack.prototype = {
  30176. push: function PostScriptStack_push(value) {
  30177. if (this.stack.length >= MAX_STACK_SIZE) {
  30178. error('PostScript function stack overflow.');
  30179. }
  30180. this.stack.push(value);
  30181. },
  30182. pop: function PostScriptStack_pop() {
  30183. if (this.stack.length <= 0) {
  30184. error('PostScript function stack underflow.');
  30185. }
  30186. return this.stack.pop();
  30187. },
  30188. copy: function PostScriptStack_copy(n) {
  30189. if (this.stack.length + n >= MAX_STACK_SIZE) {
  30190. error('PostScript function stack overflow.');
  30191. }
  30192. var stack = this.stack;
  30193. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  30194. stack.push(stack[i]);
  30195. }
  30196. },
  30197. index: function PostScriptStack_index(n) {
  30198. this.push(this.stack[this.stack.length - n - 1]);
  30199. },
  30200. // rotate the last n stack elements p times
  30201. roll: function PostScriptStack_roll(n, p) {
  30202. var stack = this.stack;
  30203. var l = stack.length - n;
  30204. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  30205. for (i = l, j = r; i < j; i++, j--) {
  30206. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30207. }
  30208. for (i = l, j = c - 1; i < j; i++, j--) {
  30209. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30210. }
  30211. for (i = c, j = r; i < j; i++, j--) {
  30212. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30213. }
  30214. }
  30215. };
  30216. return PostScriptStack;
  30217. })();
  30218. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  30219. function PostScriptEvaluator(operators) {
  30220. this.operators = operators;
  30221. }
  30222. PostScriptEvaluator.prototype = {
  30223. execute: function PostScriptEvaluator_execute(initialStack) {
  30224. var stack = new PostScriptStack(initialStack);
  30225. var counter = 0;
  30226. var operators = this.operators;
  30227. var length = operators.length;
  30228. var operator, a, b;
  30229. while (counter < length) {
  30230. operator = operators[counter++];
  30231. if (typeof operator === 'number') {
  30232. // Operator is really an operand and should be pushed to the stack.
  30233. stack.push(operator);
  30234. continue;
  30235. }
  30236. switch (operator) {
  30237. // non standard ps operators
  30238. case 'jz': // jump if false
  30239. b = stack.pop();
  30240. a = stack.pop();
  30241. if (!a) {
  30242. counter = b;
  30243. }
  30244. break;
  30245. case 'j': // jump
  30246. a = stack.pop();
  30247. counter = a;
  30248. break;
  30249. // all ps operators in alphabetical order (excluding if/ifelse)
  30250. case 'abs':
  30251. a = stack.pop();
  30252. stack.push(Math.abs(a));
  30253. break;
  30254. case 'add':
  30255. b = stack.pop();
  30256. a = stack.pop();
  30257. stack.push(a + b);
  30258. break;
  30259. case 'and':
  30260. b = stack.pop();
  30261. a = stack.pop();
  30262. if (isBool(a) && isBool(b)) {
  30263. stack.push(a && b);
  30264. } else {
  30265. stack.push(a & b);
  30266. }
  30267. break;
  30268. case 'atan':
  30269. a = stack.pop();
  30270. stack.push(Math.atan(a));
  30271. break;
  30272. case 'bitshift':
  30273. b = stack.pop();
  30274. a = stack.pop();
  30275. if (a > 0) {
  30276. stack.push(a << b);
  30277. } else {
  30278. stack.push(a >> b);
  30279. }
  30280. break;
  30281. case 'ceiling':
  30282. a = stack.pop();
  30283. stack.push(Math.ceil(a));
  30284. break;
  30285. case 'copy':
  30286. a = stack.pop();
  30287. stack.copy(a);
  30288. break;
  30289. case 'cos':
  30290. a = stack.pop();
  30291. stack.push(Math.cos(a));
  30292. break;
  30293. case 'cvi':
  30294. a = stack.pop() | 0;
  30295. stack.push(a);
  30296. break;
  30297. case 'cvr':
  30298. // noop
  30299. break;
  30300. case 'div':
  30301. b = stack.pop();
  30302. a = stack.pop();
  30303. stack.push(a / b);
  30304. break;
  30305. case 'dup':
  30306. stack.copy(1);
  30307. break;
  30308. case 'eq':
  30309. b = stack.pop();
  30310. a = stack.pop();
  30311. stack.push(a === b);
  30312. break;
  30313. case 'exch':
  30314. stack.roll(2, 1);
  30315. break;
  30316. case 'exp':
  30317. b = stack.pop();
  30318. a = stack.pop();
  30319. stack.push(Math.pow(a, b));
  30320. break;
  30321. case 'false':
  30322. stack.push(false);
  30323. break;
  30324. case 'floor':
  30325. a = stack.pop();
  30326. stack.push(Math.floor(a));
  30327. break;
  30328. case 'ge':
  30329. b = stack.pop();
  30330. a = stack.pop();
  30331. stack.push(a >= b);
  30332. break;
  30333. case 'gt':
  30334. b = stack.pop();
  30335. a = stack.pop();
  30336. stack.push(a > b);
  30337. break;
  30338. case 'idiv':
  30339. b = stack.pop();
  30340. a = stack.pop();
  30341. stack.push((a / b) | 0);
  30342. break;
  30343. case 'index':
  30344. a = stack.pop();
  30345. stack.index(a);
  30346. break;
  30347. case 'le':
  30348. b = stack.pop();
  30349. a = stack.pop();
  30350. stack.push(a <= b);
  30351. break;
  30352. case 'ln':
  30353. a = stack.pop();
  30354. stack.push(Math.log(a));
  30355. break;
  30356. case 'log':
  30357. a = stack.pop();
  30358. stack.push(Math.log(a) / Math.LN10);
  30359. break;
  30360. case 'lt':
  30361. b = stack.pop();
  30362. a = stack.pop();
  30363. stack.push(a < b);
  30364. break;
  30365. case 'mod':
  30366. b = stack.pop();
  30367. a = stack.pop();
  30368. stack.push(a % b);
  30369. break;
  30370. case 'mul':
  30371. b = stack.pop();
  30372. a = stack.pop();
  30373. stack.push(a * b);
  30374. break;
  30375. case 'ne':
  30376. b = stack.pop();
  30377. a = stack.pop();
  30378. stack.push(a !== b);
  30379. break;
  30380. case 'neg':
  30381. a = stack.pop();
  30382. stack.push(-a);
  30383. break;
  30384. case 'not':
  30385. a = stack.pop();
  30386. if (isBool(a)) {
  30387. stack.push(!a);
  30388. } else {
  30389. stack.push(~a);
  30390. }
  30391. break;
  30392. case 'or':
  30393. b = stack.pop();
  30394. a = stack.pop();
  30395. if (isBool(a) && isBool(b)) {
  30396. stack.push(a || b);
  30397. } else {
  30398. stack.push(a | b);
  30399. }
  30400. break;
  30401. case 'pop':
  30402. stack.pop();
  30403. break;
  30404. case 'roll':
  30405. b = stack.pop();
  30406. a = stack.pop();
  30407. stack.roll(a, b);
  30408. break;
  30409. case 'round':
  30410. a = stack.pop();
  30411. stack.push(Math.round(a));
  30412. break;
  30413. case 'sin':
  30414. a = stack.pop();
  30415. stack.push(Math.sin(a));
  30416. break;
  30417. case 'sqrt':
  30418. a = stack.pop();
  30419. stack.push(Math.sqrt(a));
  30420. break;
  30421. case 'sub':
  30422. b = stack.pop();
  30423. a = stack.pop();
  30424. stack.push(a - b);
  30425. break;
  30426. case 'true':
  30427. stack.push(true);
  30428. break;
  30429. case 'truncate':
  30430. a = stack.pop();
  30431. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  30432. stack.push(a);
  30433. break;
  30434. case 'xor':
  30435. b = stack.pop();
  30436. a = stack.pop();
  30437. if (isBool(a) && isBool(b)) {
  30438. stack.push(a !== b);
  30439. } else {
  30440. stack.push(a ^ b);
  30441. }
  30442. break;
  30443. default:
  30444. error('Unknown operator ' + operator);
  30445. break;
  30446. }
  30447. }
  30448. return stack.stack;
  30449. }
  30450. };
  30451. return PostScriptEvaluator;
  30452. })();
  30453. // Most of the PDFs functions consist of simple operations such as:
  30454. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  30455. //
  30456. // We can compile most of such programs, and at the same moment, we can
  30457. // optimize some expressions using basic math properties. Keeping track of
  30458. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  30459. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  30460. function AstNode(type) {
  30461. this.type = type;
  30462. }
  30463. AstNode.prototype.visit = function (visitor) {
  30464. throw new Error('abstract method');
  30465. };
  30466. function AstArgument(index, min, max) {
  30467. AstNode.call(this, 'args');
  30468. this.index = index;
  30469. this.min = min;
  30470. this.max = max;
  30471. }
  30472. AstArgument.prototype = Object.create(AstNode.prototype);
  30473. AstArgument.prototype.visit = function (visitor) {
  30474. visitor.visitArgument(this);
  30475. };
  30476. function AstLiteral(number) {
  30477. AstNode.call(this, 'literal');
  30478. this.number = number;
  30479. this.min = number;
  30480. this.max = number;
  30481. }
  30482. AstLiteral.prototype = Object.create(AstNode.prototype);
  30483. AstLiteral.prototype.visit = function (visitor) {
  30484. visitor.visitLiteral(this);
  30485. };
  30486. function AstBinaryOperation(op, arg1, arg2, min, max) {
  30487. AstNode.call(this, 'binary');
  30488. this.op = op;
  30489. this.arg1 = arg1;
  30490. this.arg2 = arg2;
  30491. this.min = min;
  30492. this.max = max;
  30493. }
  30494. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  30495. AstBinaryOperation.prototype.visit = function (visitor) {
  30496. visitor.visitBinaryOperation(this);
  30497. };
  30498. function AstMin(arg, max) {
  30499. AstNode.call(this, 'max');
  30500. this.arg = arg;
  30501. this.min = arg.min;
  30502. this.max = max;
  30503. }
  30504. AstMin.prototype = Object.create(AstNode.prototype);
  30505. AstMin.prototype.visit = function (visitor) {
  30506. visitor.visitMin(this);
  30507. };
  30508. function AstVariable(index, min, max) {
  30509. AstNode.call(this, 'var');
  30510. this.index = index;
  30511. this.min = min;
  30512. this.max = max;
  30513. }
  30514. AstVariable.prototype = Object.create(AstNode.prototype);
  30515. AstVariable.prototype.visit = function (visitor) {
  30516. visitor.visitVariable(this);
  30517. };
  30518. function AstVariableDefinition(variable, arg) {
  30519. AstNode.call(this, 'definition');
  30520. this.variable = variable;
  30521. this.arg = arg;
  30522. }
  30523. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  30524. AstVariableDefinition.prototype.visit = function (visitor) {
  30525. visitor.visitVariableDefinition(this);
  30526. };
  30527. function ExpressionBuilderVisitor() {
  30528. this.parts = [];
  30529. }
  30530. ExpressionBuilderVisitor.prototype = {
  30531. visitArgument: function (arg) {
  30532. this.parts.push('Math.max(', arg.min, ', Math.min(',
  30533. arg.max, ', src[srcOffset + ', arg.index, ']))');
  30534. },
  30535. visitVariable: function (variable) {
  30536. this.parts.push('v', variable.index);
  30537. },
  30538. visitLiteral: function (literal) {
  30539. this.parts.push(literal.number);
  30540. },
  30541. visitBinaryOperation: function (operation) {
  30542. this.parts.push('(');
  30543. operation.arg1.visit(this);
  30544. this.parts.push(' ', operation.op, ' ');
  30545. operation.arg2.visit(this);
  30546. this.parts.push(')');
  30547. },
  30548. visitVariableDefinition: function (definition) {
  30549. this.parts.push('var ');
  30550. definition.variable.visit(this);
  30551. this.parts.push(' = ');
  30552. definition.arg.visit(this);
  30553. this.parts.push(';');
  30554. },
  30555. visitMin: function (max) {
  30556. this.parts.push('Math.min(');
  30557. max.arg.visit(this);
  30558. this.parts.push(', ', max.max, ')');
  30559. },
  30560. toString: function () {
  30561. return this.parts.join('');
  30562. }
  30563. };
  30564. function buildAddOperation(num1, num2) {
  30565. if (num2.type === 'literal' && num2.number === 0) {
  30566. // optimization: second operand is 0
  30567. return num1;
  30568. }
  30569. if (num1.type === 'literal' && num1.number === 0) {
  30570. // optimization: first operand is 0
  30571. return num2;
  30572. }
  30573. if (num2.type === 'literal' && num1.type === 'literal') {
  30574. // optimization: operands operand are literals
  30575. return new AstLiteral(num1.number + num2.number);
  30576. }
  30577. return new AstBinaryOperation('+', num1, num2,
  30578. num1.min + num2.min, num1.max + num2.max);
  30579. }
  30580. function buildMulOperation(num1, num2) {
  30581. if (num2.type === 'literal') {
  30582. // optimization: second operands is a literal...
  30583. if (num2.number === 0) {
  30584. return new AstLiteral(0); // and it's 0
  30585. } else if (num2.number === 1) {
  30586. return num1; // and it's 1
  30587. } else if (num1.type === 'literal') {
  30588. // ... and first operands is a literal too
  30589. return new AstLiteral(num1.number * num2.number);
  30590. }
  30591. }
  30592. if (num1.type === 'literal') {
  30593. // optimization: first operands is a literal...
  30594. if (num1.number === 0) {
  30595. return new AstLiteral(0); // and it's 0
  30596. } else if (num1.number === 1) {
  30597. return num2; // and it's 1
  30598. }
  30599. }
  30600. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  30601. num1.max * num2.min, num1.max * num2.max);
  30602. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  30603. num1.max * num2.min, num1.max * num2.max);
  30604. return new AstBinaryOperation('*', num1, num2, min, max);
  30605. }
  30606. function buildSubOperation(num1, num2) {
  30607. if (num2.type === 'literal') {
  30608. // optimization: second operands is a literal...
  30609. if (num2.number === 0) {
  30610. return num1; // ... and it's 0
  30611. } else if (num1.type === 'literal') {
  30612. // ... and first operands is a literal too
  30613. return new AstLiteral(num1.number - num2.number);
  30614. }
  30615. }
  30616. if (num2.type === 'binary' && num2.op === '-' &&
  30617. num1.type === 'literal' && num1.number === 1 &&
  30618. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  30619. // optimization for case: 1 - (1 - x)
  30620. return num2.arg2;
  30621. }
  30622. return new AstBinaryOperation('-', num1, num2,
  30623. num1.min - num2.max, num1.max - num2.min);
  30624. }
  30625. function buildMinOperation(num1, max) {
  30626. if (num1.min >= max) {
  30627. // optimization: num1 min value is not less than required max
  30628. return new AstLiteral(max); // just returning max
  30629. } else if (num1.max <= max) {
  30630. // optimization: num1 max value is not greater than required max
  30631. return num1; // just returning an argument
  30632. }
  30633. return new AstMin(num1, max);
  30634. }
  30635. function PostScriptCompiler() {}
  30636. PostScriptCompiler.prototype = {
  30637. compile: function PostScriptCompiler_compile(code, domain, range) {
  30638. var stack = [];
  30639. var i, ii;
  30640. var instructions = [];
  30641. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  30642. var lastRegister = 0;
  30643. var n, j;
  30644. var num1, num2, ast1, ast2, tmpVar, item;
  30645. for (i = 0; i < inputSize; i++) {
  30646. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  30647. }
  30648. for (i = 0, ii = code.length; i < ii; i++) {
  30649. item = code[i];
  30650. if (typeof item === 'number') {
  30651. stack.push(new AstLiteral(item));
  30652. continue;
  30653. }
  30654. switch (item) {
  30655. case 'add':
  30656. if (stack.length < 2) {
  30657. return null;
  30658. }
  30659. num2 = stack.pop();
  30660. num1 = stack.pop();
  30661. stack.push(buildAddOperation(num1, num2));
  30662. break;
  30663. case 'cvr':
  30664. if (stack.length < 1) {
  30665. return null;
  30666. }
  30667. break;
  30668. case 'mul':
  30669. if (stack.length < 2) {
  30670. return null;
  30671. }
  30672. num2 = stack.pop();
  30673. num1 = stack.pop();
  30674. stack.push(buildMulOperation(num1, num2));
  30675. break;
  30676. case 'sub':
  30677. if (stack.length < 2) {
  30678. return null;
  30679. }
  30680. num2 = stack.pop();
  30681. num1 = stack.pop();
  30682. stack.push(buildSubOperation(num1, num2));
  30683. break;
  30684. case 'exch':
  30685. if (stack.length < 2) {
  30686. return null;
  30687. }
  30688. ast1 = stack.pop(); ast2 = stack.pop();
  30689. stack.push(ast1, ast2);
  30690. break;
  30691. case 'pop':
  30692. if (stack.length < 1) {
  30693. return null;
  30694. }
  30695. stack.pop();
  30696. break;
  30697. case 'index':
  30698. if (stack.length < 1) {
  30699. return null;
  30700. }
  30701. num1 = stack.pop();
  30702. if (num1.type !== 'literal') {
  30703. return null;
  30704. }
  30705. n = num1.number;
  30706. if (n < 0 || (n|0) !== n || stack.length < n) {
  30707. return null;
  30708. }
  30709. ast1 = stack[stack.length - n - 1];
  30710. if (ast1.type === 'literal' || ast1.type === 'var') {
  30711. stack.push(ast1);
  30712. break;
  30713. }
  30714. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  30715. stack[stack.length - n - 1] = tmpVar;
  30716. stack.push(tmpVar);
  30717. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  30718. break;
  30719. case 'dup':
  30720. if (stack.length < 1) {
  30721. return null;
  30722. }
  30723. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  30724. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  30725. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  30726. // special case of the commands sequence for the min operation
  30727. num1 = stack.pop();
  30728. stack.push(buildMinOperation(num1, code[i + 1]));
  30729. i += 6;
  30730. break;
  30731. }
  30732. ast1 = stack[stack.length - 1];
  30733. if (ast1.type === 'literal' || ast1.type === 'var') {
  30734. // we don't have to save into intermediate variable a literal or
  30735. // variable.
  30736. stack.push(ast1);
  30737. break;
  30738. }
  30739. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  30740. stack[stack.length - 1] = tmpVar;
  30741. stack.push(tmpVar);
  30742. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  30743. break;
  30744. case 'roll':
  30745. if (stack.length < 2) {
  30746. return null;
  30747. }
  30748. num2 = stack.pop();
  30749. num1 = stack.pop();
  30750. if (num2.type !== 'literal' || num1.type !== 'literal') {
  30751. // both roll operands must be numbers
  30752. return null;
  30753. }
  30754. j = num2.number;
  30755. n = num1.number;
  30756. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  30757. // ... and integers
  30758. return null;
  30759. }
  30760. j = ((j % n) + n) % n;
  30761. if (j === 0) {
  30762. break; // just skipping -- there are nothing to rotate
  30763. }
  30764. Array.prototype.push.apply(stack,
  30765. stack.splice(stack.length - n, n - j));
  30766. break;
  30767. default:
  30768. return null; // unsupported operator
  30769. }
  30770. }
  30771. if (stack.length !== outputSize) {
  30772. return null;
  30773. }
  30774. var result = [];
  30775. instructions.forEach(function (instruction) {
  30776. var statementBuilder = new ExpressionBuilderVisitor();
  30777. instruction.visit(statementBuilder);
  30778. result.push(statementBuilder.toString());
  30779. });
  30780. stack.forEach(function (expr, i) {
  30781. var statementBuilder = new ExpressionBuilderVisitor();
  30782. expr.visit(statementBuilder);
  30783. var min = range[i * 2], max = range[i * 2 + 1];
  30784. var out = [statementBuilder.toString()];
  30785. if (min > expr.min) {
  30786. out.unshift('Math.max(', min, ', ');
  30787. out.push(')');
  30788. }
  30789. if (max < expr.max) {
  30790. out.unshift('Math.min(', max, ', ');
  30791. out.push(')');
  30792. }
  30793. out.unshift('dest[destOffset + ', i, '] = ');
  30794. out.push(';');
  30795. result.push(out.join(''));
  30796. });
  30797. return result.join('\n');
  30798. }
  30799. };
  30800. return PostScriptCompiler;
  30801. })();
  30802. exports.isPDFFunction = isPDFFunction;
  30803. exports.PDFFunction = PDFFunction;
  30804. exports.PostScriptEvaluator = PostScriptEvaluator;
  30805. exports.PostScriptCompiler = PostScriptCompiler;
  30806. }));
  30807. (function (root, factory) {
  30808. {
  30809. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  30810. root.pdfjsCorePrimitives, root.pdfjsCoreFunction);
  30811. }
  30812. }(this, function (exports, sharedUtil, corePrimitives, coreFunction) {
  30813. var error = sharedUtil.error;
  30814. var info = sharedUtil.info;
  30815. var isArray = sharedUtil.isArray;
  30816. var isString = sharedUtil.isString;
  30817. var shadow = sharedUtil.shadow;
  30818. var warn = sharedUtil.warn;
  30819. var isDict = corePrimitives.isDict;
  30820. var isName = corePrimitives.isName;
  30821. var isStream = corePrimitives.isStream;
  30822. var PDFFunction = coreFunction.PDFFunction;
  30823. var ColorSpace = (function ColorSpaceClosure() {
  30824. /**
  30825. * Resizes an RGB image with 3 components.
  30826. * @param {TypedArray} src - The source buffer.
  30827. * @param {Number} bpc - Number of bits per component.
  30828. * @param {Number} w1 - Original width.
  30829. * @param {Number} h1 - Original height.
  30830. * @param {Number} w2 - New width.
  30831. * @param {Number} h2 - New height.
  30832. * @param {Number} alpha01 - Size reserved for the alpha channel.
  30833. * @param {TypedArray} dest - The destination buffer.
  30834. */
  30835. function resizeRgbImage(src, bpc, w1, h1, w2, h2, alpha01, dest) {
  30836. var COMPONENTS = 3;
  30837. alpha01 = alpha01 !== 1 ? 0 : alpha01;
  30838. var xRatio = w1 / w2;
  30839. var yRatio = h1 / h2;
  30840. var i, j, py, newIndex = 0, oldIndex;
  30841. var xScaled = new Uint16Array(w2);
  30842. var w1Scanline = w1 * COMPONENTS;
  30843. for (i = 0; i < w2; i++) {
  30844. xScaled[i] = Math.floor(i * xRatio) * COMPONENTS;
  30845. }
  30846. for (i = 0; i < h2; i++) {
  30847. py = Math.floor(i * yRatio) * w1Scanline;
  30848. for (j = 0; j < w2; j++) {
  30849. oldIndex = py + xScaled[j];
  30850. dest[newIndex++] = src[oldIndex++];
  30851. dest[newIndex++] = src[oldIndex++];
  30852. dest[newIndex++] = src[oldIndex++];
  30853. newIndex += alpha01;
  30854. }
  30855. }
  30856. }
  30857. // Constructor should define this.numComps, this.defaultColor, this.name
  30858. function ColorSpace() {
  30859. error('should not call ColorSpace constructor');
  30860. }
  30861. ColorSpace.prototype = {
  30862. /**
  30863. * Converts the color value to the RGB color. The color components are
  30864. * located in the src array starting from the srcOffset. Returns the array
  30865. * of the rgb components, each value ranging from [0,255].
  30866. */
  30867. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  30868. var rgb = new Uint8Array(3);
  30869. this.getRgbItem(src, srcOffset, rgb, 0);
  30870. return rgb;
  30871. },
  30872. /**
  30873. * Converts the color value to the RGB color, similar to the getRgb method.
  30874. * The result placed into the dest array starting from the destOffset.
  30875. */
  30876. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  30877. dest, destOffset) {
  30878. error('Should not call ColorSpace.getRgbItem');
  30879. },
  30880. /**
  30881. * Converts the specified number of the color values to the RGB colors.
  30882. * The colors are located in the src array starting from the srcOffset.
  30883. * The result is placed into the dest array starting from the destOffset.
  30884. * The src array items shall be in [0,2^bits) range, the dest array items
  30885. * will be in [0,255] range. alpha01 indicates how many alpha components
  30886. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  30887. * array).
  30888. */
  30889. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  30890. dest, destOffset, bits,
  30891. alpha01) {
  30892. error('Should not call ColorSpace.getRgbBuffer');
  30893. },
  30894. /**
  30895. * Determines the number of bytes required to store the result of the
  30896. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  30897. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  30898. */
  30899. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  30900. alpha01) {
  30901. error('Should not call ColorSpace.getOutputLength');
  30902. },
  30903. /**
  30904. * Returns true if source data will be equal the result/output data.
  30905. */
  30906. isPassthrough: function ColorSpace_isPassthrough(bits) {
  30907. return false;
  30908. },
  30909. /**
  30910. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  30911. * how many alpha components there are in the dest array; it will be either
  30912. * 0 (RGB array) or 1 (RGBA array).
  30913. */
  30914. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  30915. originalHeight, width, height,
  30916. actualHeight, bpc, comps, alpha01) {
  30917. var count = originalWidth * originalHeight;
  30918. var rgbBuf = null;
  30919. var numComponentColors = 1 << bpc;
  30920. var needsResizing = originalHeight !== height || originalWidth !== width;
  30921. var i, ii;
  30922. if (this.isPassthrough(bpc)) {
  30923. rgbBuf = comps;
  30924. } else if (this.numComps === 1 && count > numComponentColors &&
  30925. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  30926. // Optimization: create a color map when there is just one component and
  30927. // we are converting more colors than the size of the color map. We
  30928. // don't build the map if the colorspace is gray or rgb since those
  30929. // methods are faster than building a map. This mainly offers big speed
  30930. // ups for indexed and alternate colorspaces.
  30931. //
  30932. // TODO it may be worth while to cache the color map. While running
  30933. // testing I never hit a cache so I will leave that out for now (perhaps
  30934. // we are reparsing colorspaces too much?).
  30935. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  30936. new Uint16Array(numComponentColors);
  30937. var key;
  30938. for (i = 0; i < numComponentColors; i++) {
  30939. allColors[i] = i;
  30940. }
  30941. var colorMap = new Uint8Array(numComponentColors * 3);
  30942. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  30943. /* alpha01 = */ 0);
  30944. var destPos, rgbPos;
  30945. if (!needsResizing) {
  30946. // Fill in the RGB values directly into |dest|.
  30947. destPos = 0;
  30948. for (i = 0; i < count; ++i) {
  30949. key = comps[i] * 3;
  30950. dest[destPos++] = colorMap[key];
  30951. dest[destPos++] = colorMap[key + 1];
  30952. dest[destPos++] = colorMap[key + 2];
  30953. destPos += alpha01;
  30954. }
  30955. } else {
  30956. rgbBuf = new Uint8Array(count * 3);
  30957. rgbPos = 0;
  30958. for (i = 0; i < count; ++i) {
  30959. key = comps[i] * 3;
  30960. rgbBuf[rgbPos++] = colorMap[key];
  30961. rgbBuf[rgbPos++] = colorMap[key + 1];
  30962. rgbBuf[rgbPos++] = colorMap[key + 2];
  30963. }
  30964. }
  30965. } else {
  30966. if (!needsResizing) {
  30967. // Fill in the RGB values directly into |dest|.
  30968. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  30969. alpha01);
  30970. } else {
  30971. rgbBuf = new Uint8Array(count * 3);
  30972. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  30973. /* alpha01 = */ 0);
  30974. }
  30975. }
  30976. if (rgbBuf) {
  30977. if (needsResizing) {
  30978. resizeRgbImage(rgbBuf, bpc, originalWidth, originalHeight,
  30979. width, height, alpha01, dest);
  30980. } else {
  30981. rgbPos = 0;
  30982. destPos = 0;
  30983. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  30984. dest[destPos++] = rgbBuf[rgbPos++];
  30985. dest[destPos++] = rgbBuf[rgbPos++];
  30986. dest[destPos++] = rgbBuf[rgbPos++];
  30987. destPos += alpha01;
  30988. }
  30989. }
  30990. }
  30991. },
  30992. /**
  30993. * True if the colorspace has components in the default range of [0, 1].
  30994. * This should be true for all colorspaces except for lab color spaces
  30995. * which are [0,100], [-128, 127], [-128, 127].
  30996. */
  30997. usesZeroToOneRange: true
  30998. };
  30999. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  31000. var IR = ColorSpace.parseToIR(cs, xref, res);
  31001. if (IR instanceof AlternateCS) {
  31002. return IR;
  31003. }
  31004. return ColorSpace.fromIR(IR);
  31005. };
  31006. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  31007. var name = isArray(IR) ? IR[0] : IR;
  31008. var whitePoint, blackPoint, gamma;
  31009. switch (name) {
  31010. case 'DeviceGrayCS':
  31011. return this.singletons.gray;
  31012. case 'DeviceRgbCS':
  31013. return this.singletons.rgb;
  31014. case 'DeviceCmykCS':
  31015. return this.singletons.cmyk;
  31016. case 'CalGrayCS':
  31017. whitePoint = IR[1];
  31018. blackPoint = IR[2];
  31019. gamma = IR[3];
  31020. return new CalGrayCS(whitePoint, blackPoint, gamma);
  31021. case 'CalRGBCS':
  31022. whitePoint = IR[1];
  31023. blackPoint = IR[2];
  31024. gamma = IR[3];
  31025. var matrix = IR[4];
  31026. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  31027. case 'PatternCS':
  31028. var basePatternCS = IR[1];
  31029. if (basePatternCS) {
  31030. basePatternCS = ColorSpace.fromIR(basePatternCS);
  31031. }
  31032. return new PatternCS(basePatternCS);
  31033. case 'IndexedCS':
  31034. var baseIndexedCS = IR[1];
  31035. var hiVal = IR[2];
  31036. var lookup = IR[3];
  31037. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  31038. case 'AlternateCS':
  31039. var numComps = IR[1];
  31040. var alt = IR[2];
  31041. var tintFnIR = IR[3];
  31042. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  31043. PDFFunction.fromIR(tintFnIR));
  31044. case 'LabCS':
  31045. whitePoint = IR[1];
  31046. blackPoint = IR[2];
  31047. var range = IR[3];
  31048. return new LabCS(whitePoint, blackPoint, range);
  31049. default:
  31050. error('Unknown name ' + name);
  31051. }
  31052. return null;
  31053. };
  31054. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  31055. if (isName(cs)) {
  31056. var colorSpaces = res.get('ColorSpace');
  31057. if (isDict(colorSpaces)) {
  31058. var refcs = colorSpaces.get(cs.name);
  31059. if (refcs) {
  31060. cs = refcs;
  31061. }
  31062. }
  31063. }
  31064. cs = xref.fetchIfRef(cs);
  31065. var mode;
  31066. if (isName(cs)) {
  31067. mode = cs.name;
  31068. this.mode = mode;
  31069. switch (mode) {
  31070. case 'DeviceGray':
  31071. case 'G':
  31072. return 'DeviceGrayCS';
  31073. case 'DeviceRGB':
  31074. case 'RGB':
  31075. return 'DeviceRgbCS';
  31076. case 'DeviceCMYK':
  31077. case 'CMYK':
  31078. return 'DeviceCmykCS';
  31079. case 'Pattern':
  31080. return ['PatternCS', null];
  31081. default:
  31082. error('unrecognized colorspace ' + mode);
  31083. }
  31084. } else if (isArray(cs)) {
  31085. mode = xref.fetchIfRef(cs[0]).name;
  31086. this.mode = mode;
  31087. var numComps, params, alt, whitePoint, blackPoint, gamma;
  31088. switch (mode) {
  31089. case 'DeviceGray':
  31090. case 'G':
  31091. return 'DeviceGrayCS';
  31092. case 'DeviceRGB':
  31093. case 'RGB':
  31094. return 'DeviceRgbCS';
  31095. case 'DeviceCMYK':
  31096. case 'CMYK':
  31097. return 'DeviceCmykCS';
  31098. case 'CalGray':
  31099. params = xref.fetchIfRef(cs[1]);
  31100. whitePoint = params.getArray('WhitePoint');
  31101. blackPoint = params.getArray('BlackPoint');
  31102. gamma = params.get('Gamma');
  31103. return ['CalGrayCS', whitePoint, blackPoint, gamma];
  31104. case 'CalRGB':
  31105. params = xref.fetchIfRef(cs[1]);
  31106. whitePoint = params.getArray('WhitePoint');
  31107. blackPoint = params.getArray('BlackPoint');
  31108. gamma = params.getArray('Gamma');
  31109. var matrix = params.getArray('Matrix');
  31110. return ['CalRGBCS', whitePoint, blackPoint, gamma, matrix];
  31111. case 'ICCBased':
  31112. var stream = xref.fetchIfRef(cs[1]);
  31113. var dict = stream.dict;
  31114. numComps = dict.get('N');
  31115. alt = dict.get('Alternate');
  31116. if (alt) {
  31117. var altIR = ColorSpace.parseToIR(alt, xref, res);
  31118. // Parse the /Alternate CS to ensure that the number of components
  31119. // are correct, and also (indirectly) that it is not a PatternCS.
  31120. var altCS = ColorSpace.fromIR(altIR);
  31121. if (altCS.numComps === numComps) {
  31122. return altIR;
  31123. }
  31124. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  31125. }
  31126. if (numComps === 1) {
  31127. return 'DeviceGrayCS';
  31128. } else if (numComps === 3) {
  31129. return 'DeviceRgbCS';
  31130. } else if (numComps === 4) {
  31131. return 'DeviceCmykCS';
  31132. }
  31133. break;
  31134. case 'Pattern':
  31135. var basePatternCS = cs[1] || null;
  31136. if (basePatternCS) {
  31137. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  31138. }
  31139. return ['PatternCS', basePatternCS];
  31140. case 'Indexed':
  31141. case 'I':
  31142. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  31143. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  31144. var lookup = xref.fetchIfRef(cs[3]);
  31145. if (isStream(lookup)) {
  31146. lookup = lookup.getBytes();
  31147. }
  31148. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  31149. case 'Separation':
  31150. case 'DeviceN':
  31151. var name = xref.fetchIfRef(cs[1]);
  31152. numComps = 1;
  31153. if (isName(name)) {
  31154. numComps = 1;
  31155. } else if (isArray(name)) {
  31156. numComps = name.length;
  31157. }
  31158. alt = ColorSpace.parseToIR(cs[2], xref, res);
  31159. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  31160. return ['AlternateCS', numComps, alt, tintFnIR];
  31161. case 'Lab':
  31162. params = xref.fetchIfRef(cs[1]);
  31163. whitePoint = params.getArray('WhitePoint');
  31164. blackPoint = params.getArray('BlackPoint');
  31165. var range = params.getArray('Range');
  31166. return ['LabCS', whitePoint, blackPoint, range];
  31167. default:
  31168. error('unimplemented color space object "' + mode + '"');
  31169. }
  31170. } else {
  31171. error('unrecognized color space object: "' + cs + '"');
  31172. }
  31173. return null;
  31174. };
  31175. /**
  31176. * Checks if a decode map matches the default decode map for a color space.
  31177. * This handles the general decode maps where there are two values per
  31178. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  31179. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  31180. * slightly different.
  31181. * @param {Array} decode Decode map (usually from an image).
  31182. * @param {Number} n Number of components the color space has.
  31183. */
  31184. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  31185. if (!isArray(decode)) {
  31186. return true;
  31187. }
  31188. if (n * 2 !== decode.length) {
  31189. warn('The decode map is not the correct length');
  31190. return true;
  31191. }
  31192. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  31193. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  31194. return false;
  31195. }
  31196. }
  31197. return true;
  31198. };
  31199. ColorSpace.singletons = {
  31200. get gray() {
  31201. return shadow(this, 'gray', new DeviceGrayCS());
  31202. },
  31203. get rgb() {
  31204. return shadow(this, 'rgb', new DeviceRgbCS());
  31205. },
  31206. get cmyk() {
  31207. return shadow(this, 'cmyk', new DeviceCmykCS());
  31208. }
  31209. };
  31210. return ColorSpace;
  31211. })();
  31212. /**
  31213. * Alternate color space handles both Separation and DeviceN color spaces. A
  31214. * Separation color space is actually just a DeviceN with one color component.
  31215. * Both color spaces use a tinting function to convert colors to a base color
  31216. * space.
  31217. */
  31218. var AlternateCS = (function AlternateCSClosure() {
  31219. function AlternateCS(numComps, base, tintFn) {
  31220. this.name = 'Alternate';
  31221. this.numComps = numComps;
  31222. this.defaultColor = new Float32Array(numComps);
  31223. for (var i = 0; i < numComps; ++i) {
  31224. this.defaultColor[i] = 1;
  31225. }
  31226. this.base = base;
  31227. this.tintFn = tintFn;
  31228. this.tmpBuf = new Float32Array(base.numComps);
  31229. }
  31230. AlternateCS.prototype = {
  31231. getRgb: ColorSpace.prototype.getRgb,
  31232. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  31233. dest, destOffset) {
  31234. var tmpBuf = this.tmpBuf;
  31235. this.tintFn(src, srcOffset, tmpBuf, 0);
  31236. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  31237. },
  31238. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  31239. dest, destOffset, bits,
  31240. alpha01) {
  31241. var tintFn = this.tintFn;
  31242. var base = this.base;
  31243. var scale = 1 / ((1 << bits) - 1);
  31244. var baseNumComps = base.numComps;
  31245. var usesZeroToOneRange = base.usesZeroToOneRange;
  31246. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  31247. alpha01 === 0;
  31248. var pos = isPassthrough ? destOffset : 0;
  31249. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  31250. var numComps = this.numComps;
  31251. var scaled = new Float32Array(numComps);
  31252. var tinted = new Float32Array(baseNumComps);
  31253. var i, j;
  31254. if (usesZeroToOneRange) {
  31255. for (i = 0; i < count; i++) {
  31256. for (j = 0; j < numComps; j++) {
  31257. scaled[j] = src[srcOffset++] * scale;
  31258. }
  31259. tintFn(scaled, 0, tinted, 0);
  31260. for (j = 0; j < baseNumComps; j++) {
  31261. baseBuf[pos++] = tinted[j] * 255;
  31262. }
  31263. }
  31264. } else {
  31265. for (i = 0; i < count; i++) {
  31266. for (j = 0; j < numComps; j++) {
  31267. scaled[j] = src[srcOffset++] * scale;
  31268. }
  31269. tintFn(scaled, 0, tinted, 0);
  31270. base.getRgbItem(tinted, 0, baseBuf, pos);
  31271. pos += baseNumComps;
  31272. }
  31273. }
  31274. if (!isPassthrough) {
  31275. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  31276. }
  31277. },
  31278. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  31279. alpha01) {
  31280. return this.base.getOutputLength(inputLength *
  31281. this.base.numComps / this.numComps,
  31282. alpha01);
  31283. },
  31284. isPassthrough: ColorSpace.prototype.isPassthrough,
  31285. fillRgb: ColorSpace.prototype.fillRgb,
  31286. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  31287. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31288. },
  31289. usesZeroToOneRange: true
  31290. };
  31291. return AlternateCS;
  31292. })();
  31293. var PatternCS = (function PatternCSClosure() {
  31294. function PatternCS(baseCS) {
  31295. this.name = 'Pattern';
  31296. this.base = baseCS;
  31297. }
  31298. PatternCS.prototype = {};
  31299. return PatternCS;
  31300. })();
  31301. var IndexedCS = (function IndexedCSClosure() {
  31302. function IndexedCS(base, highVal, lookup) {
  31303. this.name = 'Indexed';
  31304. this.numComps = 1;
  31305. this.defaultColor = new Uint8Array([0]);
  31306. this.base = base;
  31307. this.highVal = highVal;
  31308. var baseNumComps = base.numComps;
  31309. var length = baseNumComps * highVal;
  31310. var lookupArray;
  31311. if (isStream(lookup)) {
  31312. lookupArray = new Uint8Array(length);
  31313. var bytes = lookup.getBytes(length);
  31314. lookupArray.set(bytes);
  31315. } else if (isString(lookup)) {
  31316. lookupArray = new Uint8Array(length);
  31317. for (var i = 0; i < length; ++i) {
  31318. lookupArray[i] = lookup.charCodeAt(i);
  31319. }
  31320. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  31321. lookupArray = lookup;
  31322. } else {
  31323. error('Unrecognized lookup table: ' + lookup);
  31324. }
  31325. this.lookup = lookupArray;
  31326. }
  31327. IndexedCS.prototype = {
  31328. getRgb: ColorSpace.prototype.getRgb,
  31329. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  31330. dest, destOffset) {
  31331. var numComps = this.base.numComps;
  31332. var start = src[srcOffset] * numComps;
  31333. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  31334. },
  31335. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  31336. dest, destOffset, bits,
  31337. alpha01) {
  31338. var base = this.base;
  31339. var numComps = base.numComps;
  31340. var outputDelta = base.getOutputLength(numComps, alpha01);
  31341. var lookup = this.lookup;
  31342. for (var i = 0; i < count; ++i) {
  31343. var lookupPos = src[srcOffset++] * numComps;
  31344. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  31345. destOffset += outputDelta;
  31346. }
  31347. },
  31348. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  31349. return this.base.getOutputLength(inputLength * this.base.numComps,
  31350. alpha01);
  31351. },
  31352. isPassthrough: ColorSpace.prototype.isPassthrough,
  31353. fillRgb: ColorSpace.prototype.fillRgb,
  31354. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  31355. // indexed color maps shouldn't be changed
  31356. return true;
  31357. },
  31358. usesZeroToOneRange: true
  31359. };
  31360. return IndexedCS;
  31361. })();
  31362. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  31363. function DeviceGrayCS() {
  31364. this.name = 'DeviceGray';
  31365. this.numComps = 1;
  31366. this.defaultColor = new Float32Array([0]);
  31367. }
  31368. DeviceGrayCS.prototype = {
  31369. getRgb: ColorSpace.prototype.getRgb,
  31370. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  31371. dest, destOffset) {
  31372. var c = (src[srcOffset] * 255) | 0;
  31373. c = c < 0 ? 0 : c > 255 ? 255 : c;
  31374. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  31375. },
  31376. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  31377. dest, destOffset, bits,
  31378. alpha01) {
  31379. var scale = 255 / ((1 << bits) - 1);
  31380. var j = srcOffset, q = destOffset;
  31381. for (var i = 0; i < count; ++i) {
  31382. var c = (scale * src[j++]) | 0;
  31383. dest[q++] = c;
  31384. dest[q++] = c;
  31385. dest[q++] = c;
  31386. q += alpha01;
  31387. }
  31388. },
  31389. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  31390. alpha01) {
  31391. return inputLength * (3 + alpha01);
  31392. },
  31393. isPassthrough: ColorSpace.prototype.isPassthrough,
  31394. fillRgb: ColorSpace.prototype.fillRgb,
  31395. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  31396. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31397. },
  31398. usesZeroToOneRange: true
  31399. };
  31400. return DeviceGrayCS;
  31401. })();
  31402. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  31403. function DeviceRgbCS() {
  31404. this.name = 'DeviceRGB';
  31405. this.numComps = 3;
  31406. this.defaultColor = new Float32Array([0, 0, 0]);
  31407. }
  31408. DeviceRgbCS.prototype = {
  31409. getRgb: ColorSpace.prototype.getRgb,
  31410. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  31411. dest, destOffset) {
  31412. var r = (src[srcOffset] * 255) | 0;
  31413. var g = (src[srcOffset + 1] * 255) | 0;
  31414. var b = (src[srcOffset + 2] * 255) | 0;
  31415. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  31416. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  31417. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  31418. },
  31419. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  31420. dest, destOffset, bits,
  31421. alpha01) {
  31422. if (bits === 8 && alpha01 === 0) {
  31423. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  31424. return;
  31425. }
  31426. var scale = 255 / ((1 << bits) - 1);
  31427. var j = srcOffset, q = destOffset;
  31428. for (var i = 0; i < count; ++i) {
  31429. dest[q++] = (scale * src[j++]) | 0;
  31430. dest[q++] = (scale * src[j++]) | 0;
  31431. dest[q++] = (scale * src[j++]) | 0;
  31432. q += alpha01;
  31433. }
  31434. },
  31435. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  31436. alpha01) {
  31437. return (inputLength * (3 + alpha01) / 3) | 0;
  31438. },
  31439. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  31440. return bits === 8;
  31441. },
  31442. fillRgb: ColorSpace.prototype.fillRgb,
  31443. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  31444. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31445. },
  31446. usesZeroToOneRange: true
  31447. };
  31448. return DeviceRgbCS;
  31449. })();
  31450. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  31451. // The coefficients below was found using numerical analysis: the method of
  31452. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  31453. // where color_value is the tabular value from the table of sampled RGB colors
  31454. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  31455. // CMYK color conversion using the estimation below:
  31456. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  31457. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  31458. var c = src[srcOffset + 0] * srcScale;
  31459. var m = src[srcOffset + 1] * srcScale;
  31460. var y = src[srcOffset + 2] * srcScale;
  31461. var k = src[srcOffset + 3] * srcScale;
  31462. var r =
  31463. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  31464. 18.82290502165302 * y + 212.25662451639585 * k +
  31465. -285.2331026137004) +
  31466. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  31467. -17.873870861415444 * k - 5.497006427196366) +
  31468. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  31469. 17.5119270841813) +
  31470. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  31471. var g =
  31472. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  31473. 6.871425592049007 * y + 31.159100130055922 * k +
  31474. -79.2970844816548) +
  31475. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  31476. 131.35250912493976 * k - 190.9453302588951) +
  31477. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  31478. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  31479. var b =
  31480. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  31481. 30.89978309703729 * y - 0.23883238689178934 * k +
  31482. -14.183576799673286) +
  31483. m * (10.49593273432072 * m + 63.02378494754052 * y +
  31484. 50.606957656360734 * k - 112.23884253719248) +
  31485. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  31486. -193.58209356861505) +
  31487. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  31488. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  31489. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  31490. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  31491. }
  31492. function DeviceCmykCS() {
  31493. this.name = 'DeviceCMYK';
  31494. this.numComps = 4;
  31495. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  31496. }
  31497. DeviceCmykCS.prototype = {
  31498. getRgb: ColorSpace.prototype.getRgb,
  31499. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  31500. dest, destOffset) {
  31501. convertToRgb(src, srcOffset, 1, dest, destOffset);
  31502. },
  31503. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  31504. dest, destOffset, bits,
  31505. alpha01) {
  31506. var scale = 1 / ((1 << bits) - 1);
  31507. for (var i = 0; i < count; i++) {
  31508. convertToRgb(src, srcOffset, scale, dest, destOffset);
  31509. srcOffset += 4;
  31510. destOffset += 3 + alpha01;
  31511. }
  31512. },
  31513. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  31514. alpha01) {
  31515. return (inputLength / 4 * (3 + alpha01)) | 0;
  31516. },
  31517. isPassthrough: ColorSpace.prototype.isPassthrough,
  31518. fillRgb: ColorSpace.prototype.fillRgb,
  31519. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  31520. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31521. },
  31522. usesZeroToOneRange: true
  31523. };
  31524. return DeviceCmykCS;
  31525. })();
  31526. //
  31527. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  31528. //
  31529. var CalGrayCS = (function CalGrayCSClosure() {
  31530. function CalGrayCS(whitePoint, blackPoint, gamma) {
  31531. this.name = 'CalGray';
  31532. this.numComps = 1;
  31533. this.defaultColor = new Float32Array([0]);
  31534. if (!whitePoint) {
  31535. error('WhitePoint missing - required for color space CalGray');
  31536. }
  31537. blackPoint = blackPoint || [0, 0, 0];
  31538. gamma = gamma || 1;
  31539. // Translate arguments to spec variables.
  31540. this.XW = whitePoint[0];
  31541. this.YW = whitePoint[1];
  31542. this.ZW = whitePoint[2];
  31543. this.XB = blackPoint[0];
  31544. this.YB = blackPoint[1];
  31545. this.ZB = blackPoint[2];
  31546. this.G = gamma;
  31547. // Validate variables as per spec.
  31548. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  31549. error('Invalid WhitePoint components for ' + this.name +
  31550. ', no fallback available');
  31551. }
  31552. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  31553. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  31554. this.XB = this.YB = this.ZB = 0;
  31555. }
  31556. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  31557. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  31558. ', ZB: ' + this.ZB + ', only default values are supported.');
  31559. }
  31560. if (this.G < 1) {
  31561. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  31562. ', falling back to default');
  31563. this.G = 1;
  31564. }
  31565. }
  31566. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  31567. // A represents a gray component of a calibrated gray space.
  31568. // A <---> AG in the spec
  31569. var A = src[srcOffset] * scale;
  31570. var AG = Math.pow(A, cs.G);
  31571. // Computes L as per spec. ( = cs.YW * AG )
  31572. // Except if other than default BlackPoint values are used.
  31573. var L = cs.YW * AG;
  31574. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  31575. // Convert values to rgb range [0, 255].
  31576. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  31577. dest[destOffset] = val;
  31578. dest[destOffset + 1] = val;
  31579. dest[destOffset + 2] = val;
  31580. }
  31581. CalGrayCS.prototype = {
  31582. getRgb: ColorSpace.prototype.getRgb,
  31583. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  31584. dest, destOffset) {
  31585. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  31586. },
  31587. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  31588. dest, destOffset, bits,
  31589. alpha01) {
  31590. var scale = 1 / ((1 << bits) - 1);
  31591. for (var i = 0; i < count; ++i) {
  31592. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  31593. srcOffset += 1;
  31594. destOffset += 3 + alpha01;
  31595. }
  31596. },
  31597. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  31598. return inputLength * (3 + alpha01);
  31599. },
  31600. isPassthrough: ColorSpace.prototype.isPassthrough,
  31601. fillRgb: ColorSpace.prototype.fillRgb,
  31602. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  31603. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31604. },
  31605. usesZeroToOneRange: true
  31606. };
  31607. return CalGrayCS;
  31608. })();
  31609. //
  31610. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  31611. //
  31612. var CalRGBCS = (function CalRGBCSClosure() {
  31613. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  31614. // matrices.
  31615. var BRADFORD_SCALE_MATRIX = new Float32Array([
  31616. 0.8951, 0.2664, -0.1614,
  31617. -0.7502, 1.7135, 0.0367,
  31618. 0.0389, -0.0685, 1.0296]);
  31619. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  31620. 0.9869929, -0.1470543, 0.1599627,
  31621. 0.4323053, 0.5183603, 0.0492912,
  31622. -0.0085287, 0.0400428, 0.9684867]);
  31623. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  31624. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  31625. 3.2404542, -1.5371385, -0.4985314,
  31626. -0.9692660, 1.8760108, 0.0415560,
  31627. 0.0556434, -0.2040259, 1.0572252]);
  31628. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  31629. var tempNormalizeMatrix = new Float32Array(3);
  31630. var tempConvertMatrix1 = new Float32Array(3);
  31631. var tempConvertMatrix2 = new Float32Array(3);
  31632. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  31633. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  31634. this.name = 'CalRGB';
  31635. this.numComps = 3;
  31636. this.defaultColor = new Float32Array(3);
  31637. if (!whitePoint) {
  31638. error('WhitePoint missing - required for color space CalRGB');
  31639. }
  31640. blackPoint = blackPoint || new Float32Array(3);
  31641. gamma = gamma || new Float32Array([1, 1, 1]);
  31642. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  31643. // Translate arguments to spec variables.
  31644. var XW = whitePoint[0];
  31645. var YW = whitePoint[1];
  31646. var ZW = whitePoint[2];
  31647. this.whitePoint = whitePoint;
  31648. var XB = blackPoint[0];
  31649. var YB = blackPoint[1];
  31650. var ZB = blackPoint[2];
  31651. this.blackPoint = blackPoint;
  31652. this.GR = gamma[0];
  31653. this.GG = gamma[1];
  31654. this.GB = gamma[2];
  31655. this.MXA = matrix[0];
  31656. this.MYA = matrix[1];
  31657. this.MZA = matrix[2];
  31658. this.MXB = matrix[3];
  31659. this.MYB = matrix[4];
  31660. this.MZB = matrix[5];
  31661. this.MXC = matrix[6];
  31662. this.MYC = matrix[7];
  31663. this.MZC = matrix[8];
  31664. // Validate variables as per spec.
  31665. if (XW < 0 || ZW < 0 || YW !== 1) {
  31666. error('Invalid WhitePoint components for ' + this.name +
  31667. ', no fallback available');
  31668. }
  31669. if (XB < 0 || YB < 0 || ZB < 0) {
  31670. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  31671. ', ' + ZB + '], falling back to default');
  31672. this.blackPoint = new Float32Array(3);
  31673. }
  31674. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  31675. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  31676. '] for ' + this.name + ', falling back to default');
  31677. this.GR = this.GG = this.GB = 1;
  31678. }
  31679. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  31680. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  31681. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  31682. info('Invalid Matrix for ' + this.name + ' [' +
  31683. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  31684. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  31685. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  31686. '], falling back to default');
  31687. this.MXA = this.MYB = this.MZC = 1;
  31688. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  31689. }
  31690. }
  31691. function matrixProduct(a, b, result) {
  31692. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  31693. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  31694. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  31695. }
  31696. function convertToFlat(sourceWhitePoint, LMS, result) {
  31697. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  31698. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  31699. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  31700. }
  31701. function convertToD65(sourceWhitePoint, LMS, result) {
  31702. var D65X = 0.95047;
  31703. var D65Y = 1;
  31704. var D65Z = 1.08883;
  31705. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  31706. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  31707. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  31708. }
  31709. function sRGBTransferFunction(color) {
  31710. // See http://en.wikipedia.org/wiki/SRGB.
  31711. if (color <= 0.0031308){
  31712. return adjustToRange(0, 1, 12.92 * color);
  31713. }
  31714. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  31715. }
  31716. function adjustToRange(min, max, value) {
  31717. return Math.max(min, Math.min(max, value));
  31718. }
  31719. function decodeL(L) {
  31720. if (L < 0) {
  31721. return -decodeL(-L);
  31722. }
  31723. if (L > 8.0) {
  31724. return Math.pow(((L + 16) / 116), 3);
  31725. }
  31726. return L * DECODE_L_CONSTANT;
  31727. }
  31728. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  31729. // In case the blackPoint is already the default blackPoint then there is
  31730. // no need to do compensation.
  31731. if (sourceBlackPoint[0] === 0 &&
  31732. sourceBlackPoint[1] === 0 &&
  31733. sourceBlackPoint[2] === 0) {
  31734. result[0] = XYZ_Flat[0];
  31735. result[1] = XYZ_Flat[1];
  31736. result[2] = XYZ_Flat[2];
  31737. return;
  31738. }
  31739. // For the blackPoint calculation details, please see
  31740. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  31741. // AdobeBPC.pdf.
  31742. // The destination blackPoint is the default blackPoint [0, 0, 0].
  31743. var zeroDecodeL = decodeL(0);
  31744. var X_DST = zeroDecodeL;
  31745. var X_SRC = decodeL(sourceBlackPoint[0]);
  31746. var Y_DST = zeroDecodeL;
  31747. var Y_SRC = decodeL(sourceBlackPoint[1]);
  31748. var Z_DST = zeroDecodeL;
  31749. var Z_SRC = decodeL(sourceBlackPoint[2]);
  31750. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  31751. var X_Offset = 1 - X_Scale;
  31752. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  31753. var Y_Offset = 1 - Y_Scale;
  31754. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  31755. var Z_Offset = 1 - Z_Scale;
  31756. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  31757. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  31758. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  31759. }
  31760. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  31761. // In case the whitePoint is already flat then there is no need to do
  31762. // normalization.
  31763. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  31764. result[0] = XYZ_In[0];
  31765. result[1] = XYZ_In[1];
  31766. result[2] = XYZ_In[2];
  31767. return;
  31768. }
  31769. var LMS = result;
  31770. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  31771. var LMS_Flat = tempNormalizeMatrix;
  31772. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  31773. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  31774. }
  31775. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  31776. var LMS = result;
  31777. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  31778. var LMS_D65 = tempNormalizeMatrix;
  31779. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  31780. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  31781. }
  31782. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  31783. // A, B and C represent a red, green and blue components of a calibrated
  31784. // rgb space.
  31785. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  31786. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  31787. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  31788. // A <---> AGR in the spec
  31789. // B <---> BGG in the spec
  31790. // C <---> CGB in the spec
  31791. var AGR = Math.pow(A, cs.GR);
  31792. var BGG = Math.pow(B, cs.GG);
  31793. var CGB = Math.pow(C, cs.GB);
  31794. // Computes intermediate variables L, M, N as per spec.
  31795. // To decode X, Y, Z values map L, M, N directly to them.
  31796. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  31797. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  31798. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  31799. // The following calculations are based on this document:
  31800. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  31801. // AdobeBPC.pdf.
  31802. var XYZ = tempConvertMatrix1;
  31803. XYZ[0] = X;
  31804. XYZ[1] = Y;
  31805. XYZ[2] = Z;
  31806. var XYZ_Flat = tempConvertMatrix2;
  31807. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  31808. var XYZ_Black = tempConvertMatrix1;
  31809. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  31810. var XYZ_D65 = tempConvertMatrix2;
  31811. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  31812. var SRGB = tempConvertMatrix1;
  31813. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  31814. var sR = sRGBTransferFunction(SRGB[0]);
  31815. var sG = sRGBTransferFunction(SRGB[1]);
  31816. var sB = sRGBTransferFunction(SRGB[2]);
  31817. // Convert the values to rgb range [0, 255].
  31818. dest[destOffset] = Math.round(sR * 255);
  31819. dest[destOffset + 1] = Math.round(sG * 255);
  31820. dest[destOffset + 2] = Math.round(sB * 255);
  31821. }
  31822. CalRGBCS.prototype = {
  31823. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  31824. var rgb = new Uint8Array(3);
  31825. this.getRgbItem(src, srcOffset, rgb, 0);
  31826. return rgb;
  31827. },
  31828. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  31829. dest, destOffset) {
  31830. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  31831. },
  31832. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  31833. dest, destOffset, bits,
  31834. alpha01) {
  31835. var scale = 1 / ((1 << bits) - 1);
  31836. for (var i = 0; i < count; ++i) {
  31837. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  31838. srcOffset += 3;
  31839. destOffset += 3 + alpha01;
  31840. }
  31841. },
  31842. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  31843. return (inputLength * (3 + alpha01) / 3) | 0;
  31844. },
  31845. isPassthrough: ColorSpace.prototype.isPassthrough,
  31846. fillRgb: ColorSpace.prototype.fillRgb,
  31847. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  31848. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31849. },
  31850. usesZeroToOneRange: true
  31851. };
  31852. return CalRGBCS;
  31853. })();
  31854. //
  31855. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  31856. //
  31857. var LabCS = (function LabCSClosure() {
  31858. function LabCS(whitePoint, blackPoint, range) {
  31859. this.name = 'Lab';
  31860. this.numComps = 3;
  31861. this.defaultColor = new Float32Array([0, 0, 0]);
  31862. if (!whitePoint) {
  31863. error('WhitePoint missing - required for color space Lab');
  31864. }
  31865. blackPoint = blackPoint || [0, 0, 0];
  31866. range = range || [-100, 100, -100, 100];
  31867. // Translate args to spec variables
  31868. this.XW = whitePoint[0];
  31869. this.YW = whitePoint[1];
  31870. this.ZW = whitePoint[2];
  31871. this.amin = range[0];
  31872. this.amax = range[1];
  31873. this.bmin = range[2];
  31874. this.bmax = range[3];
  31875. // These are here just for completeness - the spec doesn't offer any
  31876. // formulas that use BlackPoint in Lab
  31877. this.XB = blackPoint[0];
  31878. this.YB = blackPoint[1];
  31879. this.ZB = blackPoint[2];
  31880. // Validate vars as per spec
  31881. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  31882. error('Invalid WhitePoint components, no fallback available');
  31883. }
  31884. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  31885. info('Invalid BlackPoint, falling back to default');
  31886. this.XB = this.YB = this.ZB = 0;
  31887. }
  31888. if (this.amin > this.amax || this.bmin > this.bmax) {
  31889. info('Invalid Range, falling back to defaults');
  31890. this.amin = -100;
  31891. this.amax = 100;
  31892. this.bmin = -100;
  31893. this.bmax = 100;
  31894. }
  31895. }
  31896. // Function g(x) from spec
  31897. function fn_g(x) {
  31898. if (x >= 6 / 29) {
  31899. return x * x * x;
  31900. } else {
  31901. return (108 / 841) * (x - 4 / 29);
  31902. }
  31903. }
  31904. function decode(value, high1, low2, high2) {
  31905. return low2 + (value) * (high2 - low2) / (high1);
  31906. }
  31907. // If decoding is needed maxVal should be 2^bits per component - 1.
  31908. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  31909. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  31910. // not the usual [0, 1]. If a command like setFillColor is used the src
  31911. // values will already be within the correct range. However, if we are
  31912. // converting an image we have to map the values to the correct range given
  31913. // above.
  31914. // Ls,as,bs <---> L*,a*,b* in the spec
  31915. var Ls = src[srcOffset];
  31916. var as = src[srcOffset + 1];
  31917. var bs = src[srcOffset + 2];
  31918. if (maxVal !== false) {
  31919. Ls = decode(Ls, maxVal, 0, 100);
  31920. as = decode(as, maxVal, cs.amin, cs.amax);
  31921. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  31922. }
  31923. // Adjust limits of 'as' and 'bs'
  31924. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  31925. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  31926. // Computes intermediate variables X,Y,Z as per spec
  31927. var M = (Ls + 16) / 116;
  31928. var L = M + (as / 500);
  31929. var N = M - (bs / 200);
  31930. var X = cs.XW * fn_g(L);
  31931. var Y = cs.YW * fn_g(M);
  31932. var Z = cs.ZW * fn_g(N);
  31933. var r, g, b;
  31934. // Using different conversions for D50 and D65 white points,
  31935. // per http://www.color.org/srgb.pdf
  31936. if (cs.ZW < 1) {
  31937. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  31938. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  31939. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  31940. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  31941. } else {
  31942. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  31943. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  31944. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  31945. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  31946. }
  31947. // clamp color values to [0,1] range then convert to [0,255] range.
  31948. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  31949. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  31950. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  31951. }
  31952. LabCS.prototype = {
  31953. getRgb: ColorSpace.prototype.getRgb,
  31954. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  31955. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  31956. },
  31957. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  31958. dest, destOffset, bits,
  31959. alpha01) {
  31960. var maxVal = (1 << bits) - 1;
  31961. for (var i = 0; i < count; i++) {
  31962. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  31963. srcOffset += 3;
  31964. destOffset += 3 + alpha01;
  31965. }
  31966. },
  31967. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  31968. return (inputLength * (3 + alpha01) / 3) | 0;
  31969. },
  31970. isPassthrough: ColorSpace.prototype.isPassthrough,
  31971. fillRgb: ColorSpace.prototype.fillRgb,
  31972. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  31973. // XXX: Decoding is handled with the lab conversion because of the strange
  31974. // ranges that are used.
  31975. return true;
  31976. },
  31977. usesZeroToOneRange: false
  31978. };
  31979. return LabCS;
  31980. })();
  31981. exports.ColorSpace = ColorSpace;
  31982. }));
  31983. (function (root, factory) {
  31984. {
  31985. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  31986. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  31987. root.pdfjsCoreJpx);
  31988. }
  31989. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  31990. coreStream, coreJpx) {
  31991. var ImageKind = sharedUtil.ImageKind;
  31992. var assert = sharedUtil.assert;
  31993. var error = sharedUtil.error;
  31994. var info = sharedUtil.info;
  31995. var isArray = sharedUtil.isArray;
  31996. var warn = sharedUtil.warn;
  31997. var Name = corePrimitives.Name;
  31998. var isStream = corePrimitives.isStream;
  31999. var ColorSpace = coreColorSpace.ColorSpace;
  32000. var DecodeStream = coreStream.DecodeStream;
  32001. var JpegStream = coreStream.JpegStream;
  32002. var JpxImage = coreJpx.JpxImage;
  32003. var PDFImage = (function PDFImageClosure() {
  32004. /**
  32005. * Decodes the image using native decoder if possible. Resolves the promise
  32006. * when the image data is ready.
  32007. */
  32008. function handleImageData(image, nativeDecoder) {
  32009. if (nativeDecoder && nativeDecoder.canDecode(image)) {
  32010. return nativeDecoder.decode(image);
  32011. } else {
  32012. return Promise.resolve(image);
  32013. }
  32014. }
  32015. /**
  32016. * Decode and clamp a value. The formula is different from the spec because we
  32017. * don't decode to float range [0,1], we decode it in the [0,max] range.
  32018. */
  32019. function decodeAndClamp(value, addend, coefficient, max) {
  32020. value = addend + value * coefficient;
  32021. // Clamp the value to the range
  32022. return (value < 0 ? 0 : (value > max ? max : value));
  32023. }
  32024. /**
  32025. * Resizes an image mask with 1 component.
  32026. * @param {TypedArray} src - The source buffer.
  32027. * @param {Number} bpc - Number of bits per component.
  32028. * @param {Number} w1 - Original width.
  32029. * @param {Number} h1 - Original height.
  32030. * @param {Number} w2 - New width.
  32031. * @param {Number} h2 - New height.
  32032. * @returns {TypedArray} The resized image mask buffer.
  32033. */
  32034. function resizeImageMask(src, bpc, w1, h1, w2, h2) {
  32035. var length = w2 * h2;
  32036. var dest = (bpc <= 8 ? new Uint8Array(length) :
  32037. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  32038. var xRatio = w1 / w2;
  32039. var yRatio = h1 / h2;
  32040. var i, j, py, newIndex = 0, oldIndex;
  32041. var xScaled = new Uint16Array(w2);
  32042. var w1Scanline = w1;
  32043. for (i = 0; i < w2; i++) {
  32044. xScaled[i] = Math.floor(i * xRatio);
  32045. }
  32046. for (i = 0; i < h2; i++) {
  32047. py = Math.floor(i * yRatio) * w1Scanline;
  32048. for (j = 0; j < w2; j++) {
  32049. oldIndex = py + xScaled[j];
  32050. dest[newIndex++] = src[oldIndex];
  32051. }
  32052. }
  32053. return dest;
  32054. }
  32055. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  32056. this.image = image;
  32057. var dict = image.dict;
  32058. if (dict.has('Filter')) {
  32059. var filter = dict.get('Filter').name;
  32060. if (filter === 'JPXDecode') {
  32061. var jpxImage = new JpxImage();
  32062. jpxImage.parseImageProperties(image.stream);
  32063. image.stream.reset();
  32064. image.bitsPerComponent = jpxImage.bitsPerComponent;
  32065. image.numComps = jpxImage.componentsCount;
  32066. } else if (filter === 'JBIG2Decode') {
  32067. image.bitsPerComponent = 1;
  32068. image.numComps = 1;
  32069. }
  32070. }
  32071. // TODO cache rendered images?
  32072. this.width = dict.get('Width', 'W');
  32073. this.height = dict.get('Height', 'H');
  32074. if (this.width < 1 || this.height < 1) {
  32075. error('Invalid image width: ' + this.width + ' or height: ' +
  32076. this.height);
  32077. }
  32078. this.interpolate = dict.get('Interpolate', 'I') || false;
  32079. this.imageMask = dict.get('ImageMask', 'IM') || false;
  32080. this.matte = dict.get('Matte') || false;
  32081. var bitsPerComponent = image.bitsPerComponent;
  32082. if (!bitsPerComponent) {
  32083. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  32084. if (!bitsPerComponent) {
  32085. if (this.imageMask) {
  32086. bitsPerComponent = 1;
  32087. } else {
  32088. error('Bits per component missing in image: ' + this.imageMask);
  32089. }
  32090. }
  32091. }
  32092. this.bpc = bitsPerComponent;
  32093. if (!this.imageMask) {
  32094. var colorSpace = dict.get('ColorSpace', 'CS');
  32095. if (!colorSpace) {
  32096. info('JPX images (which do not require color spaces)');
  32097. switch (image.numComps) {
  32098. case 1:
  32099. colorSpace = Name.get('DeviceGray');
  32100. break;
  32101. case 3:
  32102. colorSpace = Name.get('DeviceRGB');
  32103. break;
  32104. case 4:
  32105. colorSpace = Name.get('DeviceCMYK');
  32106. break;
  32107. default:
  32108. error('JPX images with ' + this.numComps +
  32109. ' color components not supported.');
  32110. }
  32111. }
  32112. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  32113. this.numComps = this.colorSpace.numComps;
  32114. }
  32115. this.decode = dict.getArray('Decode', 'D');
  32116. this.needsDecode = false;
  32117. if (this.decode &&
  32118. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  32119. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  32120. this.needsDecode = true;
  32121. // Do some preprocessing to avoid more math.
  32122. var max = (1 << bitsPerComponent) - 1;
  32123. this.decodeCoefficients = [];
  32124. this.decodeAddends = [];
  32125. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  32126. var dmin = this.decode[i];
  32127. var dmax = this.decode[i + 1];
  32128. this.decodeCoefficients[j] = dmax - dmin;
  32129. this.decodeAddends[j] = max * dmin;
  32130. }
  32131. }
  32132. if (smask) {
  32133. this.smask = new PDFImage(xref, res, smask, false);
  32134. } else if (mask) {
  32135. if (isStream(mask)) {
  32136. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  32137. if (!imageMask) {
  32138. warn('Ignoring /Mask in image without /ImageMask.');
  32139. } else {
  32140. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  32141. }
  32142. } else {
  32143. // Color key mask (just an array).
  32144. this.mask = mask;
  32145. }
  32146. }
  32147. }
  32148. /**
  32149. * Handles processing of image data and returns the Promise that is resolved
  32150. * with a PDFImage when the image is ready to be used.
  32151. */
  32152. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  32153. res, image, inline,
  32154. nativeDecoder) {
  32155. var imagePromise = handleImageData(image, nativeDecoder);
  32156. var smaskPromise;
  32157. var maskPromise;
  32158. var smask = image.dict.get('SMask');
  32159. var mask = image.dict.get('Mask');
  32160. if (smask) {
  32161. smaskPromise = handleImageData(smask, nativeDecoder);
  32162. maskPromise = Promise.resolve(null);
  32163. } else {
  32164. smaskPromise = Promise.resolve(null);
  32165. if (mask) {
  32166. if (isStream(mask)) {
  32167. maskPromise = handleImageData(mask, nativeDecoder);
  32168. } else if (isArray(mask)) {
  32169. maskPromise = Promise.resolve(mask);
  32170. } else {
  32171. warn('Unsupported mask format.');
  32172. maskPromise = Promise.resolve(null);
  32173. }
  32174. } else {
  32175. maskPromise = Promise.resolve(null);
  32176. }
  32177. }
  32178. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  32179. function(results) {
  32180. var imageData = results[0];
  32181. var smaskData = results[1];
  32182. var maskData = results[2];
  32183. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  32184. });
  32185. };
  32186. PDFImage.createMask =
  32187. function PDFImage_createMask(imgArray, width, height,
  32188. imageIsFromDecodeStream, inverseDecode) {
  32189. // |imgArray| might not contain full data for every pixel of the mask, so
  32190. // we need to distinguish between |computedLength| and |actualLength|.
  32191. // In particular, if inverseDecode is true, then the array we return must
  32192. // have a length of |computedLength|.
  32193. var computedLength = ((width + 7) >> 3) * height;
  32194. var actualLength = imgArray.byteLength;
  32195. var haveFullData = computedLength === actualLength;
  32196. var data, i;
  32197. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  32198. // imgArray came from a DecodeStream and its data is in an appropriate
  32199. // form, so we can just transfer it.
  32200. data = imgArray;
  32201. } else if (!inverseDecode) {
  32202. data = new Uint8Array(actualLength);
  32203. data.set(imgArray);
  32204. } else {
  32205. data = new Uint8Array(computedLength);
  32206. data.set(imgArray);
  32207. for (i = actualLength; i < computedLength; i++) {
  32208. data[i] = 0xff;
  32209. }
  32210. }
  32211. // If necessary, invert the original mask data (but not any extra we might
  32212. // have added above). It's safe to modify the array -- whether it's the
  32213. // original or a copy, we're about to transfer it anyway, so nothing else
  32214. // in this thread can be relying on its contents.
  32215. if (inverseDecode) {
  32216. for (i = 0; i < actualLength; i++) {
  32217. data[i] = ~data[i];
  32218. }
  32219. }
  32220. return {data: data, width: width, height: height};
  32221. };
  32222. PDFImage.prototype = {
  32223. get drawWidth() {
  32224. return Math.max(this.width,
  32225. this.smask && this.smask.width || 0,
  32226. this.mask && this.mask.width || 0);
  32227. },
  32228. get drawHeight() {
  32229. return Math.max(this.height,
  32230. this.smask && this.smask.height || 0,
  32231. this.mask && this.mask.height || 0);
  32232. },
  32233. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  32234. var bpc = this.bpc;
  32235. var numComps = this.numComps;
  32236. var decodeAddends = this.decodeAddends;
  32237. var decodeCoefficients = this.decodeCoefficients;
  32238. var max = (1 << bpc) - 1;
  32239. var i, ii;
  32240. if (bpc === 1) {
  32241. // If the buffer needed decode that means it just needs to be inverted.
  32242. for (i = 0, ii = buffer.length; i < ii; i++) {
  32243. buffer[i] = +!(buffer[i]);
  32244. }
  32245. return;
  32246. }
  32247. var index = 0;
  32248. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  32249. for (var j = 0; j < numComps; j++) {
  32250. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  32251. decodeCoefficients[j], max);
  32252. index++;
  32253. }
  32254. }
  32255. },
  32256. getComponents: function PDFImage_getComponents(buffer) {
  32257. var bpc = this.bpc;
  32258. // This image doesn't require any extra work.
  32259. if (bpc === 8) {
  32260. return buffer;
  32261. }
  32262. var width = this.width;
  32263. var height = this.height;
  32264. var numComps = this.numComps;
  32265. var length = width * height * numComps;
  32266. var bufferPos = 0;
  32267. var output = (bpc <= 8 ? new Uint8Array(length) :
  32268. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  32269. var rowComps = width * numComps;
  32270. var max = (1 << bpc) - 1;
  32271. var i = 0, ii, buf;
  32272. if (bpc === 1) {
  32273. // Optimization for reading 1 bpc images.
  32274. var mask, loop1End, loop2End;
  32275. for (var j = 0; j < height; j++) {
  32276. loop1End = i + (rowComps & ~7);
  32277. loop2End = i + rowComps;
  32278. // unroll loop for all full bytes
  32279. while (i < loop1End) {
  32280. buf = buffer[bufferPos++];
  32281. output[i] = (buf >> 7) & 1;
  32282. output[i + 1] = (buf >> 6) & 1;
  32283. output[i + 2] = (buf >> 5) & 1;
  32284. output[i + 3] = (buf >> 4) & 1;
  32285. output[i + 4] = (buf >> 3) & 1;
  32286. output[i + 5] = (buf >> 2) & 1;
  32287. output[i + 6] = (buf >> 1) & 1;
  32288. output[i + 7] = buf & 1;
  32289. i += 8;
  32290. }
  32291. // handle remaining bits
  32292. if (i < loop2End) {
  32293. buf = buffer[bufferPos++];
  32294. mask = 128;
  32295. while (i < loop2End) {
  32296. output[i++] = +!!(buf & mask);
  32297. mask >>= 1;
  32298. }
  32299. }
  32300. }
  32301. } else {
  32302. // The general case that handles all other bpc values.
  32303. var bits = 0;
  32304. buf = 0;
  32305. for (i = 0, ii = length; i < ii; ++i) {
  32306. if (i % rowComps === 0) {
  32307. buf = 0;
  32308. bits = 0;
  32309. }
  32310. while (bits < bpc) {
  32311. buf = (buf << 8) | buffer[bufferPos++];
  32312. bits += 8;
  32313. }
  32314. var remainingBits = bits - bpc;
  32315. var value = buf >> remainingBits;
  32316. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  32317. buf = buf & ((1 << remainingBits) - 1);
  32318. bits = remainingBits;
  32319. }
  32320. }
  32321. return output;
  32322. },
  32323. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  32324. actualHeight, image) {
  32325. var smask = this.smask;
  32326. var mask = this.mask;
  32327. var alphaBuf, sw, sh, i, ii, j;
  32328. if (smask) {
  32329. sw = smask.width;
  32330. sh = smask.height;
  32331. alphaBuf = new Uint8Array(sw * sh);
  32332. smask.fillGrayBuffer(alphaBuf);
  32333. if (sw !== width || sh !== height) {
  32334. alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh,
  32335. width, height);
  32336. }
  32337. } else if (mask) {
  32338. if (mask instanceof PDFImage) {
  32339. sw = mask.width;
  32340. sh = mask.height;
  32341. alphaBuf = new Uint8Array(sw * sh);
  32342. mask.numComps = 1;
  32343. mask.fillGrayBuffer(alphaBuf);
  32344. // Need to invert values in rgbaBuf
  32345. for (i = 0, ii = sw * sh; i < ii; ++i) {
  32346. alphaBuf[i] = 255 - alphaBuf[i];
  32347. }
  32348. if (sw !== width || sh !== height) {
  32349. alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh,
  32350. width, height);
  32351. }
  32352. } else if (isArray(mask)) {
  32353. // Color key mask: if any of the components are outside the range
  32354. // then they should be painted.
  32355. alphaBuf = new Uint8Array(width * height);
  32356. var numComps = this.numComps;
  32357. for (i = 0, ii = width * height; i < ii; ++i) {
  32358. var opacity = 0;
  32359. var imageOffset = i * numComps;
  32360. for (j = 0; j < numComps; ++j) {
  32361. var color = image[imageOffset + j];
  32362. var maskOffset = j * 2;
  32363. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  32364. opacity = 255;
  32365. break;
  32366. }
  32367. }
  32368. alphaBuf[i] = opacity;
  32369. }
  32370. } else {
  32371. error('Unknown mask format.');
  32372. }
  32373. }
  32374. if (alphaBuf) {
  32375. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  32376. rgbaBuf[j] = alphaBuf[i];
  32377. }
  32378. } else {
  32379. // No mask.
  32380. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  32381. rgbaBuf[j] = 255;
  32382. }
  32383. }
  32384. },
  32385. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  32386. var matte = this.smask && this.smask.matte;
  32387. if (!matte) {
  32388. return;
  32389. }
  32390. var matteRgb = this.colorSpace.getRgb(matte, 0);
  32391. var matteR = matteRgb[0];
  32392. var matteG = matteRgb[1];
  32393. var matteB = matteRgb[2];
  32394. var length = width * height * 4;
  32395. var r, g, b;
  32396. for (var i = 0; i < length; i += 4) {
  32397. var alpha = buffer[i + 3];
  32398. if (alpha === 0) {
  32399. // according formula we have to get Infinity in all components
  32400. // making it white (typical paper color) should be okay
  32401. buffer[i] = 255;
  32402. buffer[i + 1] = 255;
  32403. buffer[i + 2] = 255;
  32404. continue;
  32405. }
  32406. var k = 255 / alpha;
  32407. r = (buffer[i] - matteR) * k + matteR;
  32408. g = (buffer[i + 1] - matteG) * k + matteG;
  32409. b = (buffer[i + 2] - matteB) * k + matteB;
  32410. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  32411. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  32412. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  32413. }
  32414. },
  32415. createImageData: function PDFImage_createImageData(forceRGBA) {
  32416. var drawWidth = this.drawWidth;
  32417. var drawHeight = this.drawHeight;
  32418. var imgData = { // other fields are filled in below
  32419. width: drawWidth,
  32420. height: drawHeight
  32421. };
  32422. var numComps = this.numComps;
  32423. var originalWidth = this.width;
  32424. var originalHeight = this.height;
  32425. var bpc = this.bpc;
  32426. // Rows start at byte boundary.
  32427. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  32428. var imgArray;
  32429. if (!forceRGBA) {
  32430. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  32431. // without any complications, we pass a same-sized copy to the main
  32432. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  32433. // of memory for many scanned documents. It's also much faster.
  32434. //
  32435. // Similarly, if it is a 24-bit-per pixel RGB image without any
  32436. // complications, we avoid expanding by 1.333x to RGBA form.
  32437. var kind;
  32438. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  32439. kind = ImageKind.GRAYSCALE_1BPP;
  32440. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  32441. !this.needsDecode) {
  32442. kind = ImageKind.RGB_24BPP;
  32443. }
  32444. if (kind && !this.smask && !this.mask &&
  32445. drawWidth === originalWidth && drawHeight === originalHeight) {
  32446. imgData.kind = kind;
  32447. imgArray = this.getImageBytes(originalHeight * rowBytes);
  32448. // If imgArray came from a DecodeStream, we're safe to transfer it
  32449. // (and thus detach its underlying buffer) because it will constitute
  32450. // the entire DecodeStream's data. But if it came from a Stream, we
  32451. // need to copy it because it'll only be a portion of the Stream's
  32452. // data, and the rest will be read later on.
  32453. if (this.image instanceof DecodeStream) {
  32454. imgData.data = imgArray;
  32455. } else {
  32456. var newArray = new Uint8Array(imgArray.length);
  32457. newArray.set(imgArray);
  32458. imgData.data = newArray;
  32459. }
  32460. if (this.needsDecode) {
  32461. // Invert the buffer (which must be grayscale if we reached here).
  32462. assert(kind === ImageKind.GRAYSCALE_1BPP);
  32463. var buffer = imgData.data;
  32464. for (var i = 0, ii = buffer.length; i < ii; i++) {
  32465. buffer[i] ^= 0xff;
  32466. }
  32467. }
  32468. return imgData;
  32469. }
  32470. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  32471. (this.colorSpace.name === 'DeviceGray' ||
  32472. this.colorSpace.name === 'DeviceRGB' ||
  32473. this.colorSpace.name === 'DeviceCMYK')) {
  32474. imgData.kind = ImageKind.RGB_24BPP;
  32475. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  32476. drawWidth, drawHeight, true);
  32477. return imgData;
  32478. }
  32479. }
  32480. imgArray = this.getImageBytes(originalHeight * rowBytes);
  32481. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  32482. var actualHeight = 0 | (imgArray.length / rowBytes *
  32483. drawHeight / originalHeight);
  32484. var comps = this.getComponents(imgArray);
  32485. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  32486. // more compact RGB_24BPP form if allowable.
  32487. var alpha01, maybeUndoPreblend;
  32488. if (!forceRGBA && !this.smask && !this.mask) {
  32489. imgData.kind = ImageKind.RGB_24BPP;
  32490. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  32491. alpha01 = 0;
  32492. maybeUndoPreblend = false;
  32493. } else {
  32494. imgData.kind = ImageKind.RGBA_32BPP;
  32495. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  32496. alpha01 = 1;
  32497. maybeUndoPreblend = true;
  32498. // Color key masking (opacity) must be performed before decoding.
  32499. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  32500. comps);
  32501. }
  32502. if (this.needsDecode) {
  32503. this.decodeBuffer(comps);
  32504. }
  32505. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  32506. drawWidth, drawHeight, actualHeight, bpc, comps,
  32507. alpha01);
  32508. if (maybeUndoPreblend) {
  32509. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  32510. }
  32511. return imgData;
  32512. },
  32513. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  32514. var numComps = this.numComps;
  32515. if (numComps !== 1) {
  32516. error('Reading gray scale from a color image: ' + numComps);
  32517. }
  32518. var width = this.width;
  32519. var height = this.height;
  32520. var bpc = this.bpc;
  32521. // rows start at byte boundary
  32522. var rowBytes = (width * numComps * bpc + 7) >> 3;
  32523. var imgArray = this.getImageBytes(height * rowBytes);
  32524. var comps = this.getComponents(imgArray);
  32525. var i, length;
  32526. if (bpc === 1) {
  32527. // inline decoding (= inversion) for 1 bpc images
  32528. length = width * height;
  32529. if (this.needsDecode) {
  32530. // invert and scale to {0, 255}
  32531. for (i = 0; i < length; ++i) {
  32532. buffer[i] = (comps[i] - 1) & 255;
  32533. }
  32534. } else {
  32535. // scale to {0, 255}
  32536. for (i = 0; i < length; ++i) {
  32537. buffer[i] = (-comps[i]) & 255;
  32538. }
  32539. }
  32540. return;
  32541. }
  32542. if (this.needsDecode) {
  32543. this.decodeBuffer(comps);
  32544. }
  32545. length = width * height;
  32546. // we aren't using a colorspace so we need to scale the value
  32547. var scale = 255 / ((1 << bpc) - 1);
  32548. for (i = 0; i < length; ++i) {
  32549. buffer[i] = (scale * comps[i]) | 0;
  32550. }
  32551. },
  32552. getImageBytes: function PDFImage_getImageBytes(length,
  32553. drawWidth, drawHeight,
  32554. forceRGB) {
  32555. this.image.reset();
  32556. this.image.drawWidth = drawWidth || this.width;
  32557. this.image.drawHeight = drawHeight || this.height;
  32558. this.image.forceRGB = !!forceRGB;
  32559. return this.image.getBytes(length);
  32560. }
  32561. };
  32562. return PDFImage;
  32563. })();
  32564. exports.PDFImage = PDFImage;
  32565. }));
  32566. (function (root, factory) {
  32567. {
  32568. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  32569. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  32570. root.pdfjsCoreChunkedStream, root.pdfjsCoreColorSpace);
  32571. }
  32572. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  32573. coreChunkedStream, coreColorSpace) {
  32574. var InvalidPDFException = sharedUtil.InvalidPDFException;
  32575. var MissingDataException = sharedUtil.MissingDataException;
  32576. var XRefParseException = sharedUtil.XRefParseException;
  32577. var assert = sharedUtil.assert;
  32578. var bytesToString = sharedUtil.bytesToString;
  32579. var createPromiseCapability = sharedUtil.createPromiseCapability;
  32580. var error = sharedUtil.error;
  32581. var info = sharedUtil.info;
  32582. var isArray = sharedUtil.isArray;
  32583. var isInt = sharedUtil.isInt;
  32584. var isString = sharedUtil.isString;
  32585. var shadow = sharedUtil.shadow;
  32586. var stringToPDFString = sharedUtil.stringToPDFString;
  32587. var stringToUTF8String = sharedUtil.stringToUTF8String;
  32588. var warn = sharedUtil.warn;
  32589. var isValidUrl = sharedUtil.isValidUrl;
  32590. var Util = sharedUtil.Util;
  32591. var Ref = corePrimitives.Ref;
  32592. var RefSet = corePrimitives.RefSet;
  32593. var RefSetCache = corePrimitives.RefSetCache;
  32594. var isName = corePrimitives.isName;
  32595. var isCmd = corePrimitives.isCmd;
  32596. var isDict = corePrimitives.isDict;
  32597. var isRef = corePrimitives.isRef;
  32598. var isRefsEqual = corePrimitives.isRefsEqual;
  32599. var isStream = corePrimitives.isStream;
  32600. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  32601. var Lexer = coreParser.Lexer;
  32602. var Parser = coreParser.Parser;
  32603. var ChunkedStream = coreChunkedStream.ChunkedStream;
  32604. var ColorSpace = coreColorSpace.ColorSpace;
  32605. var Catalog = (function CatalogClosure() {
  32606. function Catalog(pdfManager, xref, pageFactory) {
  32607. this.pdfManager = pdfManager;
  32608. this.xref = xref;
  32609. this.catDict = xref.getCatalogObj();
  32610. this.fontCache = new RefSetCache();
  32611. assert(isDict(this.catDict),
  32612. 'catalog object is not a dictionary');
  32613. // TODO refactor to move getPage() to the PDFDocument.
  32614. this.pageFactory = pageFactory;
  32615. this.pagePromises = [];
  32616. }
  32617. Catalog.prototype = {
  32618. get metadata() {
  32619. var streamRef = this.catDict.getRaw('Metadata');
  32620. if (!isRef(streamRef)) {
  32621. return shadow(this, 'metadata', null);
  32622. }
  32623. var encryptMetadata = (!this.xref.encrypt ? false :
  32624. this.xref.encrypt.encryptMetadata);
  32625. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  32626. var metadata;
  32627. if (stream && isDict(stream.dict)) {
  32628. var type = stream.dict.get('Type');
  32629. var subtype = stream.dict.get('Subtype');
  32630. if (isName(type, 'Metadata') && isName(subtype, 'XML')) {
  32631. // XXX: This should examine the charset the XML document defines,
  32632. // however since there are currently no real means to decode
  32633. // arbitrary charsets, let's just hope that the author of the PDF
  32634. // was reasonable enough to stick with the XML default charset,
  32635. // which is UTF-8.
  32636. try {
  32637. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  32638. } catch (e) {
  32639. info('Skipping invalid metadata.');
  32640. }
  32641. }
  32642. }
  32643. return shadow(this, 'metadata', metadata);
  32644. },
  32645. get toplevelPagesDict() {
  32646. var pagesObj = this.catDict.get('Pages');
  32647. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  32648. // shadow the prototype getter
  32649. return shadow(this, 'toplevelPagesDict', pagesObj);
  32650. },
  32651. get documentOutline() {
  32652. var obj = null;
  32653. try {
  32654. obj = this.readDocumentOutline();
  32655. } catch (ex) {
  32656. if (ex instanceof MissingDataException) {
  32657. throw ex;
  32658. }
  32659. warn('Unable to read document outline');
  32660. }
  32661. return shadow(this, 'documentOutline', obj);
  32662. },
  32663. readDocumentOutline: function Catalog_readDocumentOutline() {
  32664. var obj = this.catDict.get('Outlines');
  32665. if (!isDict(obj)) {
  32666. return null;
  32667. }
  32668. obj = obj.getRaw('First');
  32669. if (!isRef(obj)) {
  32670. return null;
  32671. }
  32672. var root = { items: [] };
  32673. var queue = [{obj: obj, parent: root}];
  32674. // To avoid recursion, keep track of the already processed items.
  32675. var processed = new RefSet();
  32676. processed.put(obj);
  32677. var xref = this.xref, blackColor = new Uint8Array(3);
  32678. while (queue.length > 0) {
  32679. var i = queue.shift();
  32680. var outlineDict = xref.fetchIfRef(i.obj);
  32681. if (outlineDict === null) {
  32682. continue;
  32683. }
  32684. assert(outlineDict.has('Title'), 'Invalid outline item');
  32685. var actionDict = outlineDict.get('A'), dest = null, url = null;
  32686. if (actionDict) {
  32687. var destEntry = actionDict.get('D');
  32688. if (destEntry) {
  32689. dest = destEntry;
  32690. } else {
  32691. var uriEntry = actionDict.get('URI');
  32692. if (isString(uriEntry) && isValidUrl(uriEntry, false)) {
  32693. url = uriEntry;
  32694. }
  32695. }
  32696. } else if (outlineDict.has('Dest')) {
  32697. dest = outlineDict.getRaw('Dest');
  32698. if (isName(dest)) {
  32699. dest = dest.name;
  32700. }
  32701. }
  32702. var title = outlineDict.get('Title');
  32703. var flags = outlineDict.get('F') || 0;
  32704. var color = outlineDict.getArray('C'), rgbColor = blackColor;
  32705. // We only need to parse the color when it's valid, and non-default.
  32706. if (isArray(color) && color.length === 3 &&
  32707. (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
  32708. rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
  32709. }
  32710. var outlineItem = {
  32711. dest: dest,
  32712. url: url,
  32713. title: stringToPDFString(title),
  32714. color: rgbColor,
  32715. count: outlineDict.get('Count'),
  32716. bold: !!(flags & 2),
  32717. italic: !!(flags & 1),
  32718. items: []
  32719. };
  32720. i.parent.items.push(outlineItem);
  32721. obj = outlineDict.getRaw('First');
  32722. if (isRef(obj) && !processed.has(obj)) {
  32723. queue.push({obj: obj, parent: outlineItem});
  32724. processed.put(obj);
  32725. }
  32726. obj = outlineDict.getRaw('Next');
  32727. if (isRef(obj) && !processed.has(obj)) {
  32728. queue.push({obj: obj, parent: i.parent});
  32729. processed.put(obj);
  32730. }
  32731. }
  32732. return (root.items.length > 0 ? root.items : null);
  32733. },
  32734. get numPages() {
  32735. var obj = this.toplevelPagesDict.get('Count');
  32736. assert(
  32737. isInt(obj),
  32738. 'page count in top level pages object is not an integer'
  32739. );
  32740. // shadow the prototype getter
  32741. return shadow(this, 'num', obj);
  32742. },
  32743. get destinations() {
  32744. function fetchDestination(dest) {
  32745. return isDict(dest) ? dest.get('D') : dest;
  32746. }
  32747. var xref = this.xref;
  32748. var dests = {}, nameTreeRef, nameDictionaryRef;
  32749. var obj = this.catDict.get('Names');
  32750. if (obj && obj.has('Dests')) {
  32751. nameTreeRef = obj.getRaw('Dests');
  32752. } else if (this.catDict.has('Dests')) {
  32753. nameDictionaryRef = this.catDict.get('Dests');
  32754. }
  32755. if (nameDictionaryRef) {
  32756. // reading simple destination dictionary
  32757. obj = nameDictionaryRef;
  32758. obj.forEach(function catalogForEach(key, value) {
  32759. if (!value) {
  32760. return;
  32761. }
  32762. dests[key] = fetchDestination(value);
  32763. });
  32764. }
  32765. if (nameTreeRef) {
  32766. var nameTree = new NameTree(nameTreeRef, xref);
  32767. var names = nameTree.getAll();
  32768. for (var name in names) {
  32769. dests[name] = fetchDestination(names[name]);
  32770. }
  32771. }
  32772. return shadow(this, 'destinations', dests);
  32773. },
  32774. getDestination: function Catalog_getDestination(destinationId) {
  32775. function fetchDestination(dest) {
  32776. return isDict(dest) ? dest.get('D') : dest;
  32777. }
  32778. var xref = this.xref;
  32779. var dest = null, nameTreeRef, nameDictionaryRef;
  32780. var obj = this.catDict.get('Names');
  32781. if (obj && obj.has('Dests')) {
  32782. nameTreeRef = obj.getRaw('Dests');
  32783. } else if (this.catDict.has('Dests')) {
  32784. nameDictionaryRef = this.catDict.get('Dests');
  32785. }
  32786. if (nameDictionaryRef) { // Simple destination dictionary.
  32787. var value = nameDictionaryRef.get(destinationId);
  32788. if (value) {
  32789. dest = fetchDestination(value);
  32790. }
  32791. }
  32792. if (nameTreeRef) {
  32793. var nameTree = new NameTree(nameTreeRef, xref);
  32794. dest = fetchDestination(nameTree.get(destinationId));
  32795. }
  32796. return dest;
  32797. },
  32798. get pageLabels() {
  32799. var obj = null;
  32800. try {
  32801. obj = this.readPageLabels();
  32802. } catch (ex) {
  32803. if (ex instanceof MissingDataException) {
  32804. throw ex;
  32805. }
  32806. warn('Unable to read page labels.');
  32807. }
  32808. return shadow(this, 'pageLabels', obj);
  32809. },
  32810. readPageLabels: function Catalog_readPageLabels() {
  32811. var obj = this.catDict.getRaw('PageLabels');
  32812. if (!obj) {
  32813. return null;
  32814. }
  32815. var pageLabels = new Array(this.numPages);
  32816. var style = null;
  32817. var prefix = '';
  32818. var start = 1;
  32819. var numberTree = new NumberTree(obj, this.xref);
  32820. var nums = numberTree.getAll();
  32821. var currentLabel = '', currentIndex = 1;
  32822. for (var i = 0, ii = this.numPages; i < ii; i++) {
  32823. if (i in nums) {
  32824. var labelDict = nums[i];
  32825. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  32826. var type = labelDict.get('Type');
  32827. assert(!type || isName(type, 'PageLabel'),
  32828. 'Invalid type in PageLabel dictionary.');
  32829. var s = labelDict.get('S');
  32830. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  32831. style = (s ? s.name : null);
  32832. prefix = labelDict.get('P') || '';
  32833. assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
  32834. start = labelDict.get('St') || 1;
  32835. assert(isInt(start), 'Invalid start in PageLabel dictionary.');
  32836. currentIndex = start;
  32837. }
  32838. switch (style) {
  32839. case 'D':
  32840. currentLabel = currentIndex;
  32841. break;
  32842. case 'R':
  32843. case 'r':
  32844. currentLabel = Util.toRoman(currentIndex, style === 'r');
  32845. break;
  32846. case 'A':
  32847. case 'a':
  32848. var LIMIT = 26; // Use only the characters A--Z, or a--z.
  32849. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  32850. var baseCharCode = (style === 'a' ? A_LOWER_CASE : A_UPPER_CASE);
  32851. var letterIndex = currentIndex - 1;
  32852. var character = String.fromCharCode(baseCharCode +
  32853. (letterIndex % LIMIT));
  32854. var charBuf = [];
  32855. for (var j = 0, jj = (letterIndex / LIMIT) | 0; j <= jj; j++) {
  32856. charBuf.push(character);
  32857. }
  32858. currentLabel = charBuf.join('');
  32859. break;
  32860. default:
  32861. assert(!style,
  32862. 'Invalid style "' + style + '" in PageLabel dictionary.');
  32863. }
  32864. pageLabels[i] = prefix + currentLabel;
  32865. currentLabel = '';
  32866. currentIndex++;
  32867. }
  32868. return pageLabels;
  32869. },
  32870. get attachments() {
  32871. var xref = this.xref;
  32872. var attachments = null, nameTreeRef;
  32873. var obj = this.catDict.get('Names');
  32874. if (obj) {
  32875. nameTreeRef = obj.getRaw('EmbeddedFiles');
  32876. }
  32877. if (nameTreeRef) {
  32878. var nameTree = new NameTree(nameTreeRef, xref);
  32879. var names = nameTree.getAll();
  32880. for (var name in names) {
  32881. var fs = new FileSpec(names[name], xref);
  32882. if (!attachments) {
  32883. attachments = Object.create(null);
  32884. }
  32885. attachments[stringToPDFString(name)] = fs.serializable;
  32886. }
  32887. }
  32888. return shadow(this, 'attachments', attachments);
  32889. },
  32890. get javaScript() {
  32891. var xref = this.xref;
  32892. var obj = this.catDict.get('Names');
  32893. var javaScript = [];
  32894. function appendIfJavaScriptDict(jsDict) {
  32895. var type = jsDict.get('S');
  32896. if (!isName(type, 'JavaScript')) {
  32897. return;
  32898. }
  32899. var js = jsDict.get('JS');
  32900. if (isStream(js)) {
  32901. js = bytesToString(js.getBytes());
  32902. } else if (!isString(js)) {
  32903. return;
  32904. }
  32905. javaScript.push(stringToPDFString(js));
  32906. }
  32907. if (obj && obj.has('JavaScript')) {
  32908. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  32909. var names = nameTree.getAll();
  32910. for (var name in names) {
  32911. // We don't really use the JavaScript right now. This code is
  32912. // defensive so we don't cause errors on document load.
  32913. var jsDict = names[name];
  32914. if (isDict(jsDict)) {
  32915. appendIfJavaScriptDict(jsDict);
  32916. }
  32917. }
  32918. }
  32919. // Append OpenAction actions to javaScript array
  32920. var openactionDict = this.catDict.get('OpenAction');
  32921. if (isDict(openactionDict, 'Action')) {
  32922. var actionType = openactionDict.get('S');
  32923. if (isName(actionType, 'Named')) {
  32924. // The named Print action is not a part of the PDF 1.7 specification,
  32925. // but is supported by many PDF readers/writers (including Adobe's).
  32926. var action = openactionDict.get('N');
  32927. if (isName(action, 'Print')) {
  32928. javaScript.push('print({});');
  32929. }
  32930. } else {
  32931. appendIfJavaScriptDict(openactionDict);
  32932. }
  32933. }
  32934. return shadow(this, 'javaScript', javaScript);
  32935. },
  32936. cleanup: function Catalog_cleanup() {
  32937. var promises = [];
  32938. this.fontCache.forEach(function (promise) {
  32939. promises.push(promise);
  32940. });
  32941. return Promise.all(promises).then(function (translatedFonts) {
  32942. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  32943. var font = translatedFonts[i].dict;
  32944. delete font.translated;
  32945. }
  32946. this.fontCache.clear();
  32947. }.bind(this));
  32948. },
  32949. getPage: function Catalog_getPage(pageIndex) {
  32950. if (!(pageIndex in this.pagePromises)) {
  32951. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  32952. function (a) {
  32953. var dict = a[0];
  32954. var ref = a[1];
  32955. return this.pageFactory.createPage(pageIndex, dict, ref,
  32956. this.fontCache);
  32957. }.bind(this)
  32958. );
  32959. }
  32960. return this.pagePromises[pageIndex];
  32961. },
  32962. getPageDict: function Catalog_getPageDict(pageIndex) {
  32963. var capability = createPromiseCapability();
  32964. var nodesToVisit = [this.catDict.getRaw('Pages')];
  32965. var currentPageIndex = 0;
  32966. var xref = this.xref;
  32967. var checkAllKids = false;
  32968. function next() {
  32969. while (nodesToVisit.length) {
  32970. var currentNode = nodesToVisit.pop();
  32971. if (isRef(currentNode)) {
  32972. xref.fetchAsync(currentNode).then(function (obj) {
  32973. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  32974. if (pageIndex === currentPageIndex) {
  32975. capability.resolve([obj, currentNode]);
  32976. } else {
  32977. currentPageIndex++;
  32978. next();
  32979. }
  32980. return;
  32981. }
  32982. nodesToVisit.push(obj);
  32983. next();
  32984. }, capability.reject);
  32985. return;
  32986. }
  32987. // Must be a child page dictionary.
  32988. assert(
  32989. isDict(currentNode),
  32990. 'page dictionary kid reference points to wrong type of object'
  32991. );
  32992. var count = currentNode.get('Count');
  32993. // If the current node doesn't have any children, avoid getting stuck
  32994. // in an empty node further down in the tree (see issue5644.pdf).
  32995. if (count === 0) {
  32996. checkAllKids = true;
  32997. }
  32998. // Skip nodes where the page can't be.
  32999. if (currentPageIndex + count <= pageIndex) {
  33000. currentPageIndex += count;
  33001. continue;
  33002. }
  33003. var kids = currentNode.get('Kids');
  33004. assert(isArray(kids), 'page dictionary kids object is not an array');
  33005. if (!checkAllKids && count === kids.length) {
  33006. // Nodes that don't have the page have been skipped and this is the
  33007. // bottom of the tree which means the page requested must be a
  33008. // descendant of this pages node. Ideally we would just resolve the
  33009. // promise with the page ref here, but there is the case where more
  33010. // pages nodes could link to single a page (see issue 3666 pdf). To
  33011. // handle this push it back on the queue so if it is a pages node it
  33012. // will be descended into.
  33013. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  33014. currentPageIndex = pageIndex;
  33015. continue;
  33016. } else {
  33017. for (var last = kids.length - 1; last >= 0; last--) {
  33018. nodesToVisit.push(kids[last]);
  33019. }
  33020. }
  33021. }
  33022. capability.reject('Page index ' + pageIndex + ' not found.');
  33023. }
  33024. next();
  33025. return capability.promise;
  33026. },
  33027. getPageIndex: function Catalog_getPageIndex(pageRef) {
  33028. // The page tree nodes have the count of all the leaves below them. To get
  33029. // how many pages are before we just have to walk up the tree and keep
  33030. // adding the count of siblings to the left of the node.
  33031. var xref = this.xref;
  33032. function pagesBeforeRef(kidRef) {
  33033. var total = 0;
  33034. var parentRef;
  33035. return xref.fetchAsync(kidRef).then(function (node) {
  33036. if (isRefsEqual(kidRef, pageRef) && !isDict(node, 'Page') &&
  33037. !(isDict(node) && !node.has('Type') && node.has('Contents'))) {
  33038. throw new Error('The reference does not point to a /Page Dict.');
  33039. }
  33040. if (!node) {
  33041. return null;
  33042. }
  33043. assert(isDict(node), 'node must be a Dict.');
  33044. parentRef = node.getRaw('Parent');
  33045. return node.getAsync('Parent');
  33046. }).then(function (parent) {
  33047. if (!parent) {
  33048. return null;
  33049. }
  33050. assert(isDict(parent), 'parent must be a Dict.');
  33051. return parent.getAsync('Kids');
  33052. }).then(function (kids) {
  33053. if (!kids) {
  33054. return null;
  33055. }
  33056. var kidPromises = [];
  33057. var found = false;
  33058. for (var i = 0; i < kids.length; i++) {
  33059. var kid = kids[i];
  33060. assert(isRef(kid), 'kid must be a Ref.');
  33061. if (kid.num === kidRef.num) {
  33062. found = true;
  33063. break;
  33064. }
  33065. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  33066. if (kid.has('Count')) {
  33067. var count = kid.get('Count');
  33068. total += count;
  33069. } else { // page leaf node
  33070. total++;
  33071. }
  33072. }));
  33073. }
  33074. if (!found) {
  33075. error('kid ref not found in parents kids');
  33076. }
  33077. return Promise.all(kidPromises).then(function () {
  33078. return [total, parentRef];
  33079. });
  33080. });
  33081. }
  33082. var total = 0;
  33083. function next(ref) {
  33084. return pagesBeforeRef(ref).then(function (args) {
  33085. if (!args) {
  33086. return total;
  33087. }
  33088. var count = args[0];
  33089. var parentRef = args[1];
  33090. total += count;
  33091. return next(parentRef);
  33092. });
  33093. }
  33094. return next(pageRef);
  33095. }
  33096. };
  33097. return Catalog;
  33098. })();
  33099. var XRef = (function XRefClosure() {
  33100. function XRef(stream, password) {
  33101. this.stream = stream;
  33102. this.entries = [];
  33103. this.xrefstms = Object.create(null);
  33104. // prepare the XRef cache
  33105. this.cache = [];
  33106. this.password = password;
  33107. this.stats = {
  33108. streamTypes: [],
  33109. fontTypes: []
  33110. };
  33111. }
  33112. XRef.prototype = {
  33113. setStartXRef: function XRef_setStartXRef(startXRef) {
  33114. // Store the starting positions of xref tables as we process them
  33115. // so we can recover from missing data errors
  33116. this.startXRefQueue = [startXRef];
  33117. },
  33118. parse: function XRef_parse(recoveryMode) {
  33119. var trailerDict;
  33120. if (!recoveryMode) {
  33121. trailerDict = this.readXRef();
  33122. } else {
  33123. warn('Indexing all PDF objects');
  33124. trailerDict = this.indexObjects();
  33125. }
  33126. trailerDict.assignXref(this);
  33127. this.trailer = trailerDict;
  33128. var encrypt = trailerDict.get('Encrypt');
  33129. if (encrypt) {
  33130. var ids = trailerDict.get('ID');
  33131. var fileId = (ids && ids.length) ? ids[0] : '';
  33132. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  33133. this.password);
  33134. }
  33135. // get the root dictionary (catalog) object
  33136. if (!(this.root = trailerDict.get('Root'))) {
  33137. error('Invalid root reference');
  33138. }
  33139. },
  33140. processXRefTable: function XRef_processXRefTable(parser) {
  33141. if (!('tableState' in this)) {
  33142. // Stores state of the table as we process it so we can resume
  33143. // from middle of table in case of missing data error
  33144. this.tableState = {
  33145. entryNum: 0,
  33146. streamPos: parser.lexer.stream.pos,
  33147. parserBuf1: parser.buf1,
  33148. parserBuf2: parser.buf2
  33149. };
  33150. }
  33151. var obj = this.readXRefTable(parser);
  33152. // Sanity check
  33153. if (!isCmd(obj, 'trailer')) {
  33154. error('Invalid XRef table: could not find trailer dictionary');
  33155. }
  33156. // Read trailer dictionary, e.g.
  33157. // trailer
  33158. // << /Size 22
  33159. // /Root 20R
  33160. // /Info 10R
  33161. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  33162. // >>
  33163. // The parser goes through the entire stream << ... >> and provides
  33164. // a getter interface for the key-value table
  33165. var dict = parser.getObj();
  33166. // The pdflib PDF generator can generate a nested trailer dictionary
  33167. if (!isDict(dict) && dict.dict) {
  33168. dict = dict.dict;
  33169. }
  33170. if (!isDict(dict)) {
  33171. error('Invalid XRef table: could not parse trailer dictionary');
  33172. }
  33173. delete this.tableState;
  33174. return dict;
  33175. },
  33176. readXRefTable: function XRef_readXRefTable(parser) {
  33177. // Example of cross-reference table:
  33178. // xref
  33179. // 0 1 <-- subsection header (first obj #, obj count)
  33180. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  33181. // 23 2 <-- subsection header ... and so on ...
  33182. // 0000025518 00002 n
  33183. // 0000025635 00000 n
  33184. // trailer
  33185. // ...
  33186. var stream = parser.lexer.stream;
  33187. var tableState = this.tableState;
  33188. stream.pos = tableState.streamPos;
  33189. parser.buf1 = tableState.parserBuf1;
  33190. parser.buf2 = tableState.parserBuf2;
  33191. // Outer loop is over subsection headers
  33192. var obj;
  33193. while (true) {
  33194. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  33195. if (isCmd(obj = parser.getObj(), 'trailer')) {
  33196. break;
  33197. }
  33198. tableState.firstEntryNum = obj;
  33199. tableState.entryCount = parser.getObj();
  33200. }
  33201. var first = tableState.firstEntryNum;
  33202. var count = tableState.entryCount;
  33203. if (!isInt(first) || !isInt(count)) {
  33204. error('Invalid XRef table: wrong types in subsection header');
  33205. }
  33206. // Inner loop is over objects themselves
  33207. for (var i = tableState.entryNum; i < count; i++) {
  33208. tableState.streamPos = stream.pos;
  33209. tableState.entryNum = i;
  33210. tableState.parserBuf1 = parser.buf1;
  33211. tableState.parserBuf2 = parser.buf2;
  33212. var entry = {};
  33213. entry.offset = parser.getObj();
  33214. entry.gen = parser.getObj();
  33215. var type = parser.getObj();
  33216. if (isCmd(type, 'f')) {
  33217. entry.free = true;
  33218. } else if (isCmd(type, 'n')) {
  33219. entry.uncompressed = true;
  33220. }
  33221. // Validate entry obj
  33222. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  33223. !(entry.free || entry.uncompressed)) {
  33224. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  33225. }
  33226. // The first xref table entry, i.e. obj 0, should be free. Attempting
  33227. // to adjust an incorrect first obj # (fixes issue 3248 and 7229).
  33228. if (i === 0 && entry.free && first === 1) {
  33229. first = 0;
  33230. }
  33231. if (!this.entries[i + first]) {
  33232. this.entries[i + first] = entry;
  33233. }
  33234. }
  33235. tableState.entryNum = 0;
  33236. tableState.streamPos = stream.pos;
  33237. tableState.parserBuf1 = parser.buf1;
  33238. tableState.parserBuf2 = parser.buf2;
  33239. delete tableState.firstEntryNum;
  33240. delete tableState.entryCount;
  33241. }
  33242. // Sanity check: as per spec, first object must be free
  33243. if (this.entries[0] && !this.entries[0].free) {
  33244. error('Invalid XRef table: unexpected first object');
  33245. }
  33246. return obj;
  33247. },
  33248. processXRefStream: function XRef_processXRefStream(stream) {
  33249. if (!('streamState' in this)) {
  33250. // Stores state of the stream as we process it so we can resume
  33251. // from middle of stream in case of missing data error
  33252. var streamParameters = stream.dict;
  33253. var byteWidths = streamParameters.get('W');
  33254. var range = streamParameters.get('Index');
  33255. if (!range) {
  33256. range = [0, streamParameters.get('Size')];
  33257. }
  33258. this.streamState = {
  33259. entryRanges: range,
  33260. byteWidths: byteWidths,
  33261. entryNum: 0,
  33262. streamPos: stream.pos
  33263. };
  33264. }
  33265. this.readXRefStream(stream);
  33266. delete this.streamState;
  33267. return stream.dict;
  33268. },
  33269. readXRefStream: function XRef_readXRefStream(stream) {
  33270. var i, j;
  33271. var streamState = this.streamState;
  33272. stream.pos = streamState.streamPos;
  33273. var byteWidths = streamState.byteWidths;
  33274. var typeFieldWidth = byteWidths[0];
  33275. var offsetFieldWidth = byteWidths[1];
  33276. var generationFieldWidth = byteWidths[2];
  33277. var entryRanges = streamState.entryRanges;
  33278. while (entryRanges.length > 0) {
  33279. var first = entryRanges[0];
  33280. var n = entryRanges[1];
  33281. if (!isInt(first) || !isInt(n)) {
  33282. error('Invalid XRef range fields: ' + first + ', ' + n);
  33283. }
  33284. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  33285. !isInt(generationFieldWidth)) {
  33286. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  33287. }
  33288. for (i = streamState.entryNum; i < n; ++i) {
  33289. streamState.entryNum = i;
  33290. streamState.streamPos = stream.pos;
  33291. var type = 0, offset = 0, generation = 0;
  33292. for (j = 0; j < typeFieldWidth; ++j) {
  33293. type = (type << 8) | stream.getByte();
  33294. }
  33295. // if type field is absent, its default value is 1
  33296. if (typeFieldWidth === 0) {
  33297. type = 1;
  33298. }
  33299. for (j = 0; j < offsetFieldWidth; ++j) {
  33300. offset = (offset << 8) | stream.getByte();
  33301. }
  33302. for (j = 0; j < generationFieldWidth; ++j) {
  33303. generation = (generation << 8) | stream.getByte();
  33304. }
  33305. var entry = {};
  33306. entry.offset = offset;
  33307. entry.gen = generation;
  33308. switch (type) {
  33309. case 0:
  33310. entry.free = true;
  33311. break;
  33312. case 1:
  33313. entry.uncompressed = true;
  33314. break;
  33315. case 2:
  33316. break;
  33317. default:
  33318. error('Invalid XRef entry type: ' + type);
  33319. }
  33320. if (!this.entries[first + i]) {
  33321. this.entries[first + i] = entry;
  33322. }
  33323. }
  33324. streamState.entryNum = 0;
  33325. streamState.streamPos = stream.pos;
  33326. entryRanges.splice(0, 2);
  33327. }
  33328. },
  33329. indexObjects: function XRef_indexObjects() {
  33330. // Simple scan through the PDF content to find objects,
  33331. // trailers and XRef streams.
  33332. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  33333. var PERCENT = 0x25, LT = 0x3C;
  33334. function readToken(data, offset) {
  33335. var token = '', ch = data[offset];
  33336. while (ch !== LF && ch !== CR && ch !== LT) {
  33337. if (++offset >= data.length) {
  33338. break;
  33339. }
  33340. token += String.fromCharCode(ch);
  33341. ch = data[offset];
  33342. }
  33343. return token;
  33344. }
  33345. function skipUntil(data, offset, what) {
  33346. var length = what.length, dataLength = data.length;
  33347. var skipped = 0;
  33348. // finding byte sequence
  33349. while (offset < dataLength) {
  33350. var i = 0;
  33351. while (i < length && data[offset + i] === what[i]) {
  33352. ++i;
  33353. }
  33354. if (i >= length) {
  33355. break; // sequence found
  33356. }
  33357. offset++;
  33358. skipped++;
  33359. }
  33360. return skipped;
  33361. }
  33362. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  33363. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  33364. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  33365. 101, 102]);
  33366. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  33367. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  33368. // Clear out any existing entries, since they may be bogus.
  33369. this.entries.length = 0;
  33370. var stream = this.stream;
  33371. stream.pos = 0;
  33372. var buffer = stream.getBytes();
  33373. var position = stream.start, length = buffer.length;
  33374. var trailers = [], xrefStms = [];
  33375. while (position < length) {
  33376. var ch = buffer[position];
  33377. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  33378. ++position;
  33379. continue;
  33380. }
  33381. if (ch === PERCENT) { // %-comment
  33382. do {
  33383. ++position;
  33384. if (position >= length) {
  33385. break;
  33386. }
  33387. ch = buffer[position];
  33388. } while (ch !== LF && ch !== CR);
  33389. continue;
  33390. }
  33391. var token = readToken(buffer, position);
  33392. var m;
  33393. if (token.indexOf('xref') === 0 &&
  33394. (token.length === 4 || /\s/.test(token[4]))) {
  33395. position += skipUntil(buffer, position, trailerBytes);
  33396. trailers.push(position);
  33397. position += skipUntil(buffer, position, startxrefBytes);
  33398. } else if ((m = objRegExp.exec(token))) {
  33399. if (typeof this.entries[m[1]] === 'undefined') {
  33400. this.entries[m[1]] = {
  33401. offset: position - stream.start,
  33402. gen: m[2] | 0,
  33403. uncompressed: true
  33404. };
  33405. }
  33406. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  33407. var content = buffer.subarray(position, position + contentLength);
  33408. // checking XRef stream suspect
  33409. // (it shall have '/XRef' and next char is not a letter)
  33410. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  33411. if (xrefTagOffset < contentLength &&
  33412. content[xrefTagOffset + 5] < 64) {
  33413. xrefStms.push(position - stream.start);
  33414. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  33415. }
  33416. position += contentLength;
  33417. } else if (token.indexOf('trailer') === 0 &&
  33418. (token.length === 7 || /\s/.test(token[7]))) {
  33419. trailers.push(position);
  33420. position += skipUntil(buffer, position, startxrefBytes);
  33421. } else {
  33422. position += token.length + 1;
  33423. }
  33424. }
  33425. // reading XRef streams
  33426. var i, ii;
  33427. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  33428. this.startXRefQueue.push(xrefStms[i]);
  33429. this.readXRef(/* recoveryMode */ true);
  33430. }
  33431. // finding main trailer
  33432. var dict;
  33433. for (i = 0, ii = trailers.length; i < ii; ++i) {
  33434. stream.pos = trailers[i];
  33435. var parser = new Parser(new Lexer(stream), /* allowStreams = */ true,
  33436. /* xref = */ this, /* recoveryMode = */ true);
  33437. var obj = parser.getObj();
  33438. if (!isCmd(obj, 'trailer')) {
  33439. continue;
  33440. }
  33441. // read the trailer dictionary
  33442. dict = parser.getObj();
  33443. if (!isDict(dict)) {
  33444. continue;
  33445. }
  33446. // taking the first one with 'ID'
  33447. if (dict.has('ID')) {
  33448. return dict;
  33449. }
  33450. }
  33451. // no tailer with 'ID', taking last one (if exists)
  33452. if (dict) {
  33453. return dict;
  33454. }
  33455. // nothing helps
  33456. // calling error() would reject worker with an UnknownErrorException.
  33457. throw new InvalidPDFException('Invalid PDF structure');
  33458. },
  33459. readXRef: function XRef_readXRef(recoveryMode) {
  33460. var stream = this.stream;
  33461. try {
  33462. while (this.startXRefQueue.length) {
  33463. var startXRef = this.startXRefQueue[0];
  33464. stream.pos = startXRef + stream.start;
  33465. var parser = new Parser(new Lexer(stream), true, this);
  33466. var obj = parser.getObj();
  33467. var dict;
  33468. // Get dictionary
  33469. if (isCmd(obj, 'xref')) {
  33470. // Parse end-of-file XRef
  33471. dict = this.processXRefTable(parser);
  33472. if (!this.topDict) {
  33473. this.topDict = dict;
  33474. }
  33475. // Recursively get other XRefs 'XRefStm', if any
  33476. obj = dict.get('XRefStm');
  33477. if (isInt(obj)) {
  33478. var pos = obj;
  33479. // ignore previously loaded xref streams
  33480. // (possible infinite recursion)
  33481. if (!(pos in this.xrefstms)) {
  33482. this.xrefstms[pos] = 1;
  33483. this.startXRefQueue.push(pos);
  33484. }
  33485. }
  33486. } else if (isInt(obj)) {
  33487. // Parse in-stream XRef
  33488. if (!isInt(parser.getObj()) ||
  33489. !isCmd(parser.getObj(), 'obj') ||
  33490. !isStream(obj = parser.getObj())) {
  33491. error('Invalid XRef stream');
  33492. }
  33493. dict = this.processXRefStream(obj);
  33494. if (!this.topDict) {
  33495. this.topDict = dict;
  33496. }
  33497. if (!dict) {
  33498. error('Failed to read XRef stream');
  33499. }
  33500. } else {
  33501. error('Invalid XRef stream header');
  33502. }
  33503. // Recursively get previous dictionary, if any
  33504. obj = dict.get('Prev');
  33505. if (isInt(obj)) {
  33506. this.startXRefQueue.push(obj);
  33507. } else if (isRef(obj)) {
  33508. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  33509. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  33510. this.startXRefQueue.push(obj.num);
  33511. }
  33512. this.startXRefQueue.shift();
  33513. }
  33514. return this.topDict;
  33515. } catch (e) {
  33516. if (e instanceof MissingDataException) {
  33517. throw e;
  33518. }
  33519. info('(while reading XRef): ' + e);
  33520. }
  33521. if (recoveryMode) {
  33522. return;
  33523. }
  33524. throw new XRefParseException();
  33525. },
  33526. getEntry: function XRef_getEntry(i) {
  33527. var xrefEntry = this.entries[i];
  33528. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  33529. return xrefEntry;
  33530. }
  33531. return null;
  33532. },
  33533. fetchIfRef: function XRef_fetchIfRef(obj) {
  33534. if (!isRef(obj)) {
  33535. return obj;
  33536. }
  33537. return this.fetch(obj);
  33538. },
  33539. fetch: function XRef_fetch(ref, suppressEncryption) {
  33540. assert(isRef(ref), 'ref object is not a reference');
  33541. var num = ref.num;
  33542. if (num in this.cache) {
  33543. var cacheEntry = this.cache[num];
  33544. return cacheEntry;
  33545. }
  33546. var xrefEntry = this.getEntry(num);
  33547. // the referenced entry can be free
  33548. if (xrefEntry === null) {
  33549. return (this.cache[num] = null);
  33550. }
  33551. if (xrefEntry.uncompressed) {
  33552. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  33553. } else {
  33554. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  33555. }
  33556. if (isDict(xrefEntry)){
  33557. xrefEntry.objId = ref.toString();
  33558. } else if (isStream(xrefEntry)) {
  33559. xrefEntry.dict.objId = ref.toString();
  33560. }
  33561. return xrefEntry;
  33562. },
  33563. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  33564. suppressEncryption) {
  33565. var gen = ref.gen;
  33566. var num = ref.num;
  33567. if (xrefEntry.gen !== gen) {
  33568. error('inconsistent generation in XRef');
  33569. }
  33570. var stream = this.stream.makeSubStream(xrefEntry.offset +
  33571. this.stream.start);
  33572. var parser = new Parser(new Lexer(stream), true, this);
  33573. var obj1 = parser.getObj();
  33574. var obj2 = parser.getObj();
  33575. var obj3 = parser.getObj();
  33576. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  33577. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  33578. !isCmd(obj3)) {
  33579. error('bad XRef entry');
  33580. }
  33581. if (!isCmd(obj3, 'obj')) {
  33582. // some bad PDFs use "obj1234" and really mean 1234
  33583. if (obj3.cmd.indexOf('obj') === 0) {
  33584. num = parseInt(obj3.cmd.substring(3), 10);
  33585. if (!isNaN(num)) {
  33586. return num;
  33587. }
  33588. }
  33589. error('bad XRef entry');
  33590. }
  33591. if (this.encrypt && !suppressEncryption) {
  33592. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  33593. } else {
  33594. xrefEntry = parser.getObj();
  33595. }
  33596. if (!isStream(xrefEntry)) {
  33597. this.cache[num] = xrefEntry;
  33598. }
  33599. return xrefEntry;
  33600. },
  33601. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  33602. suppressEncryption) {
  33603. var tableOffset = xrefEntry.offset;
  33604. var stream = this.fetch(new Ref(tableOffset, 0));
  33605. if (!isStream(stream)) {
  33606. error('bad ObjStm stream');
  33607. }
  33608. var first = stream.dict.get('First');
  33609. var n = stream.dict.get('N');
  33610. if (!isInt(first) || !isInt(n)) {
  33611. error('invalid first and n parameters for ObjStm stream');
  33612. }
  33613. var parser = new Parser(new Lexer(stream), false, this);
  33614. parser.allowStreams = true;
  33615. var i, entries = [], num, nums = [];
  33616. // read the object numbers to populate cache
  33617. for (i = 0; i < n; ++i) {
  33618. num = parser.getObj();
  33619. if (!isInt(num)) {
  33620. error('invalid object number in the ObjStm stream: ' + num);
  33621. }
  33622. nums.push(num);
  33623. var offset = parser.getObj();
  33624. if (!isInt(offset)) {
  33625. error('invalid object offset in the ObjStm stream: ' + offset);
  33626. }
  33627. }
  33628. // read stream objects for cache
  33629. for (i = 0; i < n; ++i) {
  33630. entries.push(parser.getObj());
  33631. // The ObjStm should not contain 'endobj'. If it's present, skip over it
  33632. // to support corrupt PDFs (fixes issue 5241, bug 898610, bug 1037816).
  33633. if (isCmd(parser.buf1, 'endobj')) {
  33634. parser.shift();
  33635. }
  33636. num = nums[i];
  33637. var entry = this.entries[num];
  33638. if (entry && entry.offset === tableOffset && entry.gen === i) {
  33639. this.cache[num] = entries[i];
  33640. }
  33641. }
  33642. xrefEntry = entries[xrefEntry.gen];
  33643. if (xrefEntry === undefined) {
  33644. error('bad XRef entry for compressed object');
  33645. }
  33646. return xrefEntry;
  33647. },
  33648. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  33649. if (!isRef(obj)) {
  33650. return Promise.resolve(obj);
  33651. }
  33652. return this.fetchAsync(obj);
  33653. },
  33654. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  33655. var streamManager = this.stream.manager;
  33656. var xref = this;
  33657. return new Promise(function tryFetch(resolve, reject) {
  33658. try {
  33659. resolve(xref.fetch(ref, suppressEncryption));
  33660. } catch (e) {
  33661. if (e instanceof MissingDataException) {
  33662. streamManager.requestRange(e.begin, e.end).then(function () {
  33663. tryFetch(resolve, reject);
  33664. }, reject);
  33665. return;
  33666. }
  33667. reject(e);
  33668. }
  33669. });
  33670. },
  33671. getCatalogObj: function XRef_getCatalogObj() {
  33672. return this.root;
  33673. }
  33674. };
  33675. return XRef;
  33676. })();
  33677. /**
  33678. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  33679. * see the specification (7.9.6 and 7.9.7) for additional details.
  33680. * TODO: implement all the Dict functions and make this more efficient.
  33681. */
  33682. var NameOrNumberTree = (function NameOrNumberTreeClosure() {
  33683. function NameOrNumberTree(root, xref) {
  33684. throw new Error('Cannot initialize NameOrNumberTree.');
  33685. }
  33686. NameOrNumberTree.prototype = {
  33687. getAll: function NameOrNumberTree_getAll() {
  33688. var dict = Object.create(null);
  33689. if (!this.root) {
  33690. return dict;
  33691. }
  33692. var xref = this.xref;
  33693. // Reading Name/Number tree.
  33694. var processed = new RefSet();
  33695. processed.put(this.root);
  33696. var queue = [this.root];
  33697. while (queue.length > 0) {
  33698. var i, n;
  33699. var obj = xref.fetchIfRef(queue.shift());
  33700. if (!isDict(obj)) {
  33701. continue;
  33702. }
  33703. if (obj.has('Kids')) {
  33704. var kids = obj.get('Kids');
  33705. for (i = 0, n = kids.length; i < n; i++) {
  33706. var kid = kids[i];
  33707. assert(!processed.has(kid),
  33708. 'Duplicate entry in "' + this._type + '" tree.');
  33709. queue.push(kid);
  33710. processed.put(kid);
  33711. }
  33712. continue;
  33713. }
  33714. var entries = obj.get(this._type);
  33715. if (isArray(entries)) {
  33716. for (i = 0, n = entries.length; i < n; i += 2) {
  33717. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  33718. }
  33719. }
  33720. }
  33721. return dict;
  33722. },
  33723. get: function NameOrNumberTree_get(key) {
  33724. if (!this.root) {
  33725. return null;
  33726. }
  33727. var xref = this.xref;
  33728. var kidsOrEntries = xref.fetchIfRef(this.root);
  33729. var loopCount = 0;
  33730. var MAX_LEVELS = 10;
  33731. var l, r, m;
  33732. // Perform a binary search to quickly find the entry that
  33733. // contains the key we are looking for.
  33734. while (kidsOrEntries.has('Kids')) {
  33735. if (++loopCount > MAX_LEVELS) {
  33736. warn('Search depth limit reached for "' + this._type + '" tree.');
  33737. return null;
  33738. }
  33739. var kids = kidsOrEntries.get('Kids');
  33740. if (!isArray(kids)) {
  33741. return null;
  33742. }
  33743. l = 0;
  33744. r = kids.length - 1;
  33745. while (l <= r) {
  33746. m = (l + r) >> 1;
  33747. var kid = xref.fetchIfRef(kids[m]);
  33748. var limits = kid.get('Limits');
  33749. if (key < xref.fetchIfRef(limits[0])) {
  33750. r = m - 1;
  33751. } else if (key > xref.fetchIfRef(limits[1])) {
  33752. l = m + 1;
  33753. } else {
  33754. kidsOrEntries = xref.fetchIfRef(kids[m]);
  33755. break;
  33756. }
  33757. }
  33758. if (l > r) {
  33759. return null;
  33760. }
  33761. }
  33762. // If we get here, then we have found the right entry. Now go through the
  33763. // entries in the dictionary until we find the key we're looking for.
  33764. var entries = kidsOrEntries.get(this._type);
  33765. if (isArray(entries)) {
  33766. // Perform a binary search to reduce the lookup time.
  33767. l = 0;
  33768. r = entries.length - 2;
  33769. while (l <= r) {
  33770. // Check only even indices (0, 2, 4, ...) because the
  33771. // odd indices contain the actual data.
  33772. m = (l + r) & ~1;
  33773. var currentKey = xref.fetchIfRef(entries[m]);
  33774. if (key < currentKey) {
  33775. r = m - 2;
  33776. } else if (key > currentKey) {
  33777. l = m + 2;
  33778. } else {
  33779. return xref.fetchIfRef(entries[m + 1]);
  33780. }
  33781. }
  33782. }
  33783. return null;
  33784. }
  33785. };
  33786. return NameOrNumberTree;
  33787. })();
  33788. var NameTree = (function NameTreeClosure() {
  33789. function NameTree(root, xref) {
  33790. this.root = root;
  33791. this.xref = xref;
  33792. this._type = 'Names';
  33793. }
  33794. Util.inherit(NameTree, NameOrNumberTree, {});
  33795. return NameTree;
  33796. })();
  33797. var NumberTree = (function NumberTreeClosure() {
  33798. function NumberTree(root, xref) {
  33799. this.root = root;
  33800. this.xref = xref;
  33801. this._type = 'Nums';
  33802. }
  33803. Util.inherit(NumberTree, NameOrNumberTree, {});
  33804. return NumberTree;
  33805. })();
  33806. /**
  33807. * "A PDF file can refer to the contents of another file by using a File
  33808. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  33809. * NOTE: Only embedded files are supported (as part of the attachments support)
  33810. * TODO: support the 'URL' file system (with caching if !/V), portable
  33811. * collections attributes and related files (/RF)
  33812. */
  33813. var FileSpec = (function FileSpecClosure() {
  33814. function FileSpec(root, xref) {
  33815. if (!root || !isDict(root)) {
  33816. return;
  33817. }
  33818. this.xref = xref;
  33819. this.root = root;
  33820. if (root.has('FS')) {
  33821. this.fs = root.get('FS');
  33822. }
  33823. this.description = root.has('Desc') ?
  33824. stringToPDFString(root.get('Desc')) :
  33825. '';
  33826. if (root.has('RF')) {
  33827. warn('Related file specifications are not supported');
  33828. }
  33829. this.contentAvailable = true;
  33830. if (!root.has('EF')) {
  33831. this.contentAvailable = false;
  33832. warn('Non-embedded file specifications are not supported');
  33833. }
  33834. }
  33835. function pickPlatformItem(dict) {
  33836. // Look for the filename in this order:
  33837. // UF, F, Unix, Mac, DOS
  33838. if (dict.has('UF')) {
  33839. return dict.get('UF');
  33840. } else if (dict.has('F')) {
  33841. return dict.get('F');
  33842. } else if (dict.has('Unix')) {
  33843. return dict.get('Unix');
  33844. } else if (dict.has('Mac')) {
  33845. return dict.get('Mac');
  33846. } else if (dict.has('DOS')) {
  33847. return dict.get('DOS');
  33848. } else {
  33849. return null;
  33850. }
  33851. }
  33852. FileSpec.prototype = {
  33853. get filename() {
  33854. if (!this._filename && this.root) {
  33855. var filename = pickPlatformItem(this.root) || 'unnamed';
  33856. this._filename = stringToPDFString(filename).
  33857. replace(/\\\\/g, '\\').
  33858. replace(/\\\//g, '/').
  33859. replace(/\\/g, '/');
  33860. }
  33861. return this._filename;
  33862. },
  33863. get content() {
  33864. if (!this.contentAvailable) {
  33865. return null;
  33866. }
  33867. if (!this.contentRef && this.root) {
  33868. this.contentRef = pickPlatformItem(this.root.get('EF'));
  33869. }
  33870. var content = null;
  33871. if (this.contentRef) {
  33872. var xref = this.xref;
  33873. var fileObj = xref.fetchIfRef(this.contentRef);
  33874. if (fileObj && isStream(fileObj)) {
  33875. content = fileObj.getBytes();
  33876. } else {
  33877. warn('Embedded file specification points to non-existing/invalid ' +
  33878. 'content');
  33879. }
  33880. } else {
  33881. warn('Embedded file specification does not have a content');
  33882. }
  33883. return content;
  33884. },
  33885. get serializable() {
  33886. return {
  33887. filename: this.filename,
  33888. content: this.content
  33889. };
  33890. }
  33891. };
  33892. return FileSpec;
  33893. })();
  33894. /**
  33895. * A helper for loading missing data in object graphs. It traverses the graph
  33896. * depth first and queues up any objects that have missing data. Once it has
  33897. * has traversed as many objects that are available it attempts to bundle the
  33898. * missing data requests and then resume from the nodes that weren't ready.
  33899. *
  33900. * NOTE: It provides protection from circular references by keeping track of
  33901. * of loaded references. However, you must be careful not to load any graphs
  33902. * that have references to the catalog or other pages since that will cause the
  33903. * entire PDF document object graph to be traversed.
  33904. */
  33905. var ObjectLoader = (function() {
  33906. function mayHaveChildren(value) {
  33907. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  33908. }
  33909. function addChildren(node, nodesToVisit) {
  33910. var value;
  33911. if (isDict(node) || isStream(node)) {
  33912. var map;
  33913. if (isDict(node)) {
  33914. map = node.map;
  33915. } else {
  33916. map = node.dict.map;
  33917. }
  33918. for (var key in map) {
  33919. value = map[key];
  33920. if (mayHaveChildren(value)) {
  33921. nodesToVisit.push(value);
  33922. }
  33923. }
  33924. } else if (isArray(node)) {
  33925. for (var i = 0, ii = node.length; i < ii; i++) {
  33926. value = node[i];
  33927. if (mayHaveChildren(value)) {
  33928. nodesToVisit.push(value);
  33929. }
  33930. }
  33931. }
  33932. }
  33933. function ObjectLoader(obj, keys, xref) {
  33934. this.obj = obj;
  33935. this.keys = keys;
  33936. this.xref = xref;
  33937. this.refSet = null;
  33938. this.capability = null;
  33939. }
  33940. ObjectLoader.prototype = {
  33941. load: function ObjectLoader_load() {
  33942. var keys = this.keys;
  33943. this.capability = createPromiseCapability();
  33944. // Don't walk the graph if all the data is already loaded.
  33945. if (!(this.xref.stream instanceof ChunkedStream) ||
  33946. this.xref.stream.getMissingChunks().length === 0) {
  33947. this.capability.resolve();
  33948. return this.capability.promise;
  33949. }
  33950. this.refSet = new RefSet();
  33951. // Setup the initial nodes to visit.
  33952. var nodesToVisit = [];
  33953. for (var i = 0; i < keys.length; i++) {
  33954. nodesToVisit.push(this.obj[keys[i]]);
  33955. }
  33956. this._walk(nodesToVisit);
  33957. return this.capability.promise;
  33958. },
  33959. _walk: function ObjectLoader_walk(nodesToVisit) {
  33960. var nodesToRevisit = [];
  33961. var pendingRequests = [];
  33962. // DFS walk of the object graph.
  33963. while (nodesToVisit.length) {
  33964. var currentNode = nodesToVisit.pop();
  33965. // Only references or chunked streams can cause missing data exceptions.
  33966. if (isRef(currentNode)) {
  33967. // Skip nodes that have already been visited.
  33968. if (this.refSet.has(currentNode)) {
  33969. continue;
  33970. }
  33971. try {
  33972. var ref = currentNode;
  33973. this.refSet.put(ref);
  33974. currentNode = this.xref.fetch(currentNode);
  33975. } catch (e) {
  33976. if (!(e instanceof MissingDataException)) {
  33977. throw e;
  33978. }
  33979. nodesToRevisit.push(currentNode);
  33980. pendingRequests.push({ begin: e.begin, end: e.end });
  33981. }
  33982. }
  33983. if (currentNode && currentNode.getBaseStreams) {
  33984. var baseStreams = currentNode.getBaseStreams();
  33985. var foundMissingData = false;
  33986. for (var i = 0; i < baseStreams.length; i++) {
  33987. var stream = baseStreams[i];
  33988. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  33989. foundMissingData = true;
  33990. pendingRequests.push({
  33991. begin: stream.start,
  33992. end: stream.end
  33993. });
  33994. }
  33995. }
  33996. if (foundMissingData) {
  33997. nodesToRevisit.push(currentNode);
  33998. }
  33999. }
  34000. addChildren(currentNode, nodesToVisit);
  34001. }
  34002. if (pendingRequests.length) {
  34003. this.xref.stream.manager.requestRanges(pendingRequests).then(
  34004. function pendingRequestCallback() {
  34005. nodesToVisit = nodesToRevisit;
  34006. for (var i = 0; i < nodesToRevisit.length; i++) {
  34007. var node = nodesToRevisit[i];
  34008. // Remove any reference nodes from the currrent refset so they
  34009. // aren't skipped when we revist them.
  34010. if (isRef(node)) {
  34011. this.refSet.remove(node);
  34012. }
  34013. }
  34014. this._walk(nodesToVisit);
  34015. }.bind(this), this.capability.reject);
  34016. return;
  34017. }
  34018. // Everything is loaded.
  34019. this.refSet = null;
  34020. this.capability.resolve();
  34021. }
  34022. };
  34023. return ObjectLoader;
  34024. })();
  34025. exports.Catalog = Catalog;
  34026. exports.ObjectLoader = ObjectLoader;
  34027. exports.XRef = XRef;
  34028. exports.FileSpec = FileSpec;
  34029. }));
  34030. (function (root, factory) {
  34031. {
  34032. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  34033. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  34034. root.pdfjsCoreColorSpace);
  34035. }
  34036. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  34037. coreColorSpace) {
  34038. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  34039. var MissingDataException = sharedUtil.MissingDataException;
  34040. var Util = sharedUtil.Util;
  34041. var assert = sharedUtil.assert;
  34042. var error = sharedUtil.error;
  34043. var info = sharedUtil.info;
  34044. var warn = sharedUtil.warn;
  34045. var isStream = corePrimitives.isStream;
  34046. var PDFFunction = coreFunction.PDFFunction;
  34047. var ColorSpace = coreColorSpace.ColorSpace;
  34048. var ShadingType = {
  34049. FUNCTION_BASED: 1,
  34050. AXIAL: 2,
  34051. RADIAL: 3,
  34052. FREE_FORM_MESH: 4,
  34053. LATTICE_FORM_MESH: 5,
  34054. COONS_PATCH_MESH: 6,
  34055. TENSOR_PATCH_MESH: 7
  34056. };
  34057. var Pattern = (function PatternClosure() {
  34058. // Constructor should define this.getPattern
  34059. function Pattern() {
  34060. error('should not call Pattern constructor');
  34061. }
  34062. Pattern.prototype = {
  34063. // Input: current Canvas context
  34064. // Output: the appropriate fillStyle or strokeStyle
  34065. getPattern: function Pattern_getPattern(ctx) {
  34066. error('Should not call Pattern.getStyle: ' + ctx);
  34067. }
  34068. };
  34069. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  34070. res, handler) {
  34071. var dict = isStream(shading) ? shading.dict : shading;
  34072. var type = dict.get('ShadingType');
  34073. try {
  34074. switch (type) {
  34075. case ShadingType.AXIAL:
  34076. case ShadingType.RADIAL:
  34077. // Both radial and axial shadings are handled by RadialAxial shading.
  34078. return new Shadings.RadialAxial(dict, matrix, xref, res);
  34079. case ShadingType.FREE_FORM_MESH:
  34080. case ShadingType.LATTICE_FORM_MESH:
  34081. case ShadingType.COONS_PATCH_MESH:
  34082. case ShadingType.TENSOR_PATCH_MESH:
  34083. return new Shadings.Mesh(shading, matrix, xref, res);
  34084. default:
  34085. throw new Error('Unsupported ShadingType: ' + type);
  34086. }
  34087. } catch (ex) {
  34088. if (ex instanceof MissingDataException) {
  34089. throw ex;
  34090. }
  34091. handler.send('UnsupportedFeature',
  34092. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  34093. warn(ex);
  34094. return new Shadings.Dummy();
  34095. }
  34096. };
  34097. return Pattern;
  34098. })();
  34099. var Shadings = {};
  34100. // A small number to offset the first/last color stops so we can insert ones to
  34101. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  34102. Shadings.SMALL_NUMBER = 1e-6;
  34103. // Radial and axial shading have very similar implementations
  34104. // If needed, the implementations can be broken into two classes
  34105. Shadings.RadialAxial = (function RadialAxialClosure() {
  34106. function RadialAxial(dict, matrix, xref, res) {
  34107. this.matrix = matrix;
  34108. this.coordsArr = dict.getArray('Coords');
  34109. this.shadingType = dict.get('ShadingType');
  34110. this.type = 'Pattern';
  34111. var cs = dict.get('ColorSpace', 'CS');
  34112. cs = ColorSpace.parse(cs, xref, res);
  34113. this.cs = cs;
  34114. var t0 = 0.0, t1 = 1.0;
  34115. if (dict.has('Domain')) {
  34116. var domainArr = dict.getArray('Domain');
  34117. t0 = domainArr[0];
  34118. t1 = domainArr[1];
  34119. }
  34120. var extendStart = false, extendEnd = false;
  34121. if (dict.has('Extend')) {
  34122. var extendArr = dict.getArray('Extend');
  34123. extendStart = extendArr[0];
  34124. extendEnd = extendArr[1];
  34125. }
  34126. if (this.shadingType === ShadingType.RADIAL &&
  34127. (!extendStart || !extendEnd)) {
  34128. // Radial gradient only currently works if either circle is fully within
  34129. // the other circle.
  34130. var x1 = this.coordsArr[0];
  34131. var y1 = this.coordsArr[1];
  34132. var r1 = this.coordsArr[2];
  34133. var x2 = this.coordsArr[3];
  34134. var y2 = this.coordsArr[4];
  34135. var r2 = this.coordsArr[5];
  34136. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  34137. if (r1 <= r2 + distance &&
  34138. r2 <= r1 + distance) {
  34139. warn('Unsupported radial gradient.');
  34140. }
  34141. }
  34142. this.extendStart = extendStart;
  34143. this.extendEnd = extendEnd;
  34144. var fnObj = dict.get('Function');
  34145. var fn = PDFFunction.parseArray(xref, fnObj);
  34146. // 10 samples seems good enough for now, but probably won't work
  34147. // if there are sharp color changes. Ideally, we would implement
  34148. // the spec faithfully and add lossless optimizations.
  34149. var diff = t1 - t0;
  34150. var step = diff / 10;
  34151. var colorStops = this.colorStops = [];
  34152. // Protect against bad domains so we don't end up in an infinte loop below.
  34153. if (t0 >= t1 || step <= 0) {
  34154. // Acrobat doesn't seem to handle these cases so we'll ignore for
  34155. // now.
  34156. info('Bad shading domain.');
  34157. return;
  34158. }
  34159. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  34160. var rgbColor;
  34161. for (var i = t0; i <= t1; i += step) {
  34162. ratio[0] = i;
  34163. fn(ratio, 0, color, 0);
  34164. rgbColor = cs.getRgb(color, 0);
  34165. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  34166. colorStops.push([(i - t0) / diff, cssColor]);
  34167. }
  34168. var background = 'transparent';
  34169. if (dict.has('Background')) {
  34170. rgbColor = cs.getRgb(dict.get('Background'), 0);
  34171. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  34172. }
  34173. if (!extendStart) {
  34174. // Insert a color stop at the front and offset the first real color stop
  34175. // so it doesn't conflict with the one we insert.
  34176. colorStops.unshift([0, background]);
  34177. colorStops[1][0] += Shadings.SMALL_NUMBER;
  34178. }
  34179. if (!extendEnd) {
  34180. // Same idea as above in extendStart but for the end.
  34181. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  34182. colorStops.push([1, background]);
  34183. }
  34184. this.colorStops = colorStops;
  34185. }
  34186. RadialAxial.prototype = {
  34187. getIR: function RadialAxial_getIR() {
  34188. var coordsArr = this.coordsArr;
  34189. var shadingType = this.shadingType;
  34190. var type, p0, p1, r0, r1;
  34191. if (shadingType === ShadingType.AXIAL) {
  34192. p0 = [coordsArr[0], coordsArr[1]];
  34193. p1 = [coordsArr[2], coordsArr[3]];
  34194. r0 = null;
  34195. r1 = null;
  34196. type = 'axial';
  34197. } else if (shadingType === ShadingType.RADIAL) {
  34198. p0 = [coordsArr[0], coordsArr[1]];
  34199. p1 = [coordsArr[3], coordsArr[4]];
  34200. r0 = coordsArr[2];
  34201. r1 = coordsArr[5];
  34202. type = 'radial';
  34203. } else {
  34204. error('getPattern type unknown: ' + shadingType);
  34205. }
  34206. var matrix = this.matrix;
  34207. if (matrix) {
  34208. p0 = Util.applyTransform(p0, matrix);
  34209. p1 = Util.applyTransform(p1, matrix);
  34210. if (shadingType === ShadingType.RADIAL) {
  34211. var scale = Util.singularValueDecompose2dScale(matrix);
  34212. r0 *= scale[0];
  34213. r1 *= scale[1];
  34214. }
  34215. }
  34216. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  34217. }
  34218. };
  34219. return RadialAxial;
  34220. })();
  34221. // All mesh shading. For now, they will be presented as set of the triangles
  34222. // to be drawn on the canvas and rgb color for each vertex.
  34223. Shadings.Mesh = (function MeshClosure() {
  34224. function MeshStreamReader(stream, context) {
  34225. this.stream = stream;
  34226. this.context = context;
  34227. this.buffer = 0;
  34228. this.bufferLength = 0;
  34229. var numComps = context.numComps;
  34230. this.tmpCompsBuf = new Float32Array(numComps);
  34231. var csNumComps = context.colorSpace.numComps;
  34232. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  34233. this.tmpCompsBuf;
  34234. }
  34235. MeshStreamReader.prototype = {
  34236. get hasData() {
  34237. if (this.stream.end) {
  34238. return this.stream.pos < this.stream.end;
  34239. }
  34240. if (this.bufferLength > 0) {
  34241. return true;
  34242. }
  34243. var nextByte = this.stream.getByte();
  34244. if (nextByte < 0) {
  34245. return false;
  34246. }
  34247. this.buffer = nextByte;
  34248. this.bufferLength = 8;
  34249. return true;
  34250. },
  34251. readBits: function MeshStreamReader_readBits(n) {
  34252. var buffer = this.buffer;
  34253. var bufferLength = this.bufferLength;
  34254. if (n === 32) {
  34255. if (bufferLength === 0) {
  34256. return ((this.stream.getByte() << 24) |
  34257. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  34258. this.stream.getByte()) >>> 0;
  34259. }
  34260. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  34261. (this.stream.getByte() << 8) | this.stream.getByte();
  34262. var nextByte = this.stream.getByte();
  34263. this.buffer = nextByte & ((1 << bufferLength) - 1);
  34264. return ((buffer << (8 - bufferLength)) |
  34265. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  34266. }
  34267. if (n === 8 && bufferLength === 0) {
  34268. return this.stream.getByte();
  34269. }
  34270. while (bufferLength < n) {
  34271. buffer = (buffer << 8) | this.stream.getByte();
  34272. bufferLength += 8;
  34273. }
  34274. bufferLength -= n;
  34275. this.bufferLength = bufferLength;
  34276. this.buffer = buffer & ((1 << bufferLength) - 1);
  34277. return buffer >> bufferLength;
  34278. },
  34279. align: function MeshStreamReader_align() {
  34280. this.buffer = 0;
  34281. this.bufferLength = 0;
  34282. },
  34283. readFlag: function MeshStreamReader_readFlag() {
  34284. return this.readBits(this.context.bitsPerFlag);
  34285. },
  34286. readCoordinate: function MeshStreamReader_readCoordinate() {
  34287. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  34288. var xi = this.readBits(bitsPerCoordinate);
  34289. var yi = this.readBits(bitsPerCoordinate);
  34290. var decode = this.context.decode;
  34291. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  34292. 2.3283064365386963e-10; // 2 ^ -32
  34293. return [
  34294. xi * scale * (decode[1] - decode[0]) + decode[0],
  34295. yi * scale * (decode[3] - decode[2]) + decode[2]
  34296. ];
  34297. },
  34298. readComponents: function MeshStreamReader_readComponents() {
  34299. var numComps = this.context.numComps;
  34300. var bitsPerComponent = this.context.bitsPerComponent;
  34301. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  34302. 2.3283064365386963e-10; // 2 ^ -32
  34303. var decode = this.context.decode;
  34304. var components = this.tmpCompsBuf;
  34305. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  34306. var ci = this.readBits(bitsPerComponent);
  34307. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  34308. }
  34309. var color = this.tmpCsCompsBuf;
  34310. if (this.context.colorFn) {
  34311. this.context.colorFn(components, 0, color, 0);
  34312. }
  34313. return this.context.colorSpace.getRgb(color, 0);
  34314. }
  34315. };
  34316. function decodeType4Shading(mesh, reader) {
  34317. var coords = mesh.coords;
  34318. var colors = mesh.colors;
  34319. var operators = [];
  34320. var ps = []; // not maintaining cs since that will match ps
  34321. var verticesLeft = 0; // assuming we have all data to start a new triangle
  34322. while (reader.hasData) {
  34323. var f = reader.readFlag();
  34324. var coord = reader.readCoordinate();
  34325. var color = reader.readComponents();
  34326. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  34327. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  34328. switch (f) {
  34329. case 0:
  34330. verticesLeft = 3;
  34331. break;
  34332. case 1:
  34333. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  34334. verticesLeft = 1;
  34335. break;
  34336. case 2:
  34337. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  34338. verticesLeft = 1;
  34339. break;
  34340. }
  34341. operators.push(f);
  34342. }
  34343. ps.push(coords.length);
  34344. coords.push(coord);
  34345. colors.push(color);
  34346. verticesLeft--;
  34347. reader.align();
  34348. }
  34349. mesh.figures.push({
  34350. type: 'triangles',
  34351. coords: new Int32Array(ps),
  34352. colors: new Int32Array(ps),
  34353. });
  34354. }
  34355. function decodeType5Shading(mesh, reader, verticesPerRow) {
  34356. var coords = mesh.coords;
  34357. var colors = mesh.colors;
  34358. var ps = []; // not maintaining cs since that will match ps
  34359. while (reader.hasData) {
  34360. var coord = reader.readCoordinate();
  34361. var color = reader.readComponents();
  34362. ps.push(coords.length);
  34363. coords.push(coord);
  34364. colors.push(color);
  34365. }
  34366. mesh.figures.push({
  34367. type: 'lattice',
  34368. coords: new Int32Array(ps),
  34369. colors: new Int32Array(ps),
  34370. verticesPerRow: verticesPerRow
  34371. });
  34372. }
  34373. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  34374. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  34375. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  34376. var getB = (function getBClosure() {
  34377. function buildB(count) {
  34378. var lut = [];
  34379. for (var i = 0; i <= count; i++) {
  34380. var t = i / count, t_ = 1 - t;
  34381. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  34382. 3 * t * t * t_, t * t * t]));
  34383. }
  34384. return lut;
  34385. }
  34386. var cache = [];
  34387. return function getB(count) {
  34388. if (!cache[count]) {
  34389. cache[count] = buildB(count);
  34390. }
  34391. return cache[count];
  34392. };
  34393. })();
  34394. function buildFigureFromPatch(mesh, index) {
  34395. var figure = mesh.figures[index];
  34396. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  34397. var coords = mesh.coords, colors = mesh.colors;
  34398. var pi = figure.coords;
  34399. var ci = figure.colors;
  34400. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  34401. coords[pi[12]][0], coords[pi[15]][0]);
  34402. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  34403. coords[pi[12]][1], coords[pi[15]][1]);
  34404. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  34405. coords[pi[12]][0], coords[pi[15]][0]);
  34406. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  34407. coords[pi[12]][1], coords[pi[15]][1]);
  34408. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  34409. (mesh.bounds[2] - mesh.bounds[0]));
  34410. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  34411. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  34412. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  34413. (mesh.bounds[3] - mesh.bounds[1]));
  34414. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  34415. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  34416. var verticesPerRow = splitXBy + 1;
  34417. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  34418. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  34419. var k = 0;
  34420. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  34421. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  34422. c2 = colors[ci[2]], c3 = colors[ci[3]];
  34423. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  34424. for (var row = 0; row <= splitYBy; row++) {
  34425. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  34426. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  34427. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  34428. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  34429. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  34430. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  34431. for (var col = 0; col <= splitXBy; col++, k++) {
  34432. if ((row === 0 || row === splitYBy) &&
  34433. (col === 0 || col === splitXBy)) {
  34434. continue;
  34435. }
  34436. var x = 0, y = 0;
  34437. var q = 0;
  34438. for (var i = 0; i <= 3; i++) {
  34439. for (var j = 0; j <= 3; j++, q++) {
  34440. var m = bRow[row][i] * bCol[col][j];
  34441. x += coords[pi[q]][0] * m;
  34442. y += coords[pi[q]][1] * m;
  34443. }
  34444. }
  34445. figureCoords[k] = coords.length;
  34446. coords.push([x, y]);
  34447. figureColors[k] = colors.length;
  34448. var newColor = new Uint8Array(3);
  34449. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  34450. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  34451. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  34452. colors.push(newColor);
  34453. }
  34454. }
  34455. figureCoords[0] = pi[0];
  34456. figureColors[0] = ci[0];
  34457. figureCoords[splitXBy] = pi[3];
  34458. figureColors[splitXBy] = ci[1];
  34459. figureCoords[verticesPerRow * splitYBy] = pi[12];
  34460. figureColors[verticesPerRow * splitYBy] = ci[2];
  34461. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  34462. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  34463. mesh.figures[index] = {
  34464. type: 'lattice',
  34465. coords: figureCoords,
  34466. colors: figureColors,
  34467. verticesPerRow: verticesPerRow
  34468. };
  34469. }
  34470. function decodeType6Shading(mesh, reader) {
  34471. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  34472. var coords = mesh.coords;
  34473. var colors = mesh.colors;
  34474. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  34475. var cs = new Int32Array(4); // c00, c30, c03, c33
  34476. while (reader.hasData) {
  34477. var f = reader.readFlag();
  34478. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  34479. var i, ii;
  34480. var pi = coords.length;
  34481. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  34482. coords.push(reader.readCoordinate());
  34483. }
  34484. var ci = colors.length;
  34485. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  34486. colors.push(reader.readComponents());
  34487. }
  34488. var tmp1, tmp2, tmp3, tmp4;
  34489. switch (f) {
  34490. case 0:
  34491. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  34492. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  34493. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  34494. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  34495. cs[2] = ci + 1; cs[3] = ci + 2;
  34496. cs[0] = ci; cs[1] = ci + 3;
  34497. break;
  34498. case 1:
  34499. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  34500. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34501. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  34502. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  34503. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34504. tmp1 = cs[2]; tmp2 = cs[3];
  34505. cs[2] = tmp2; cs[3] = ci;
  34506. cs[0] = tmp1; cs[1] = ci + 1;
  34507. break;
  34508. case 2:
  34509. tmp1 = ps[15];
  34510. tmp2 = ps[11];
  34511. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34512. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  34513. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  34514. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34515. tmp1 = cs[3];
  34516. cs[2] = cs[1]; cs[3] = ci;
  34517. cs[0] = tmp1; cs[1] = ci + 1;
  34518. break;
  34519. case 3:
  34520. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34521. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  34522. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  34523. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34524. cs[2] = cs[0]; cs[3] = ci;
  34525. cs[0] = cs[1]; cs[1] = ci + 1;
  34526. break;
  34527. }
  34528. // set p11, p12, p21, p22
  34529. ps[5] = coords.length;
  34530. coords.push([
  34531. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  34532. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  34533. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  34534. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  34535. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  34536. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  34537. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  34538. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  34539. ]);
  34540. ps[6] = coords.length;
  34541. coords.push([
  34542. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  34543. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  34544. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  34545. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  34546. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  34547. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  34548. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  34549. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  34550. ]);
  34551. ps[9] = coords.length;
  34552. coords.push([
  34553. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  34554. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  34555. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  34556. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  34557. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  34558. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  34559. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  34560. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  34561. ]);
  34562. ps[10] = coords.length;
  34563. coords.push([
  34564. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  34565. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  34566. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  34567. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  34568. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  34569. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  34570. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  34571. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  34572. ]);
  34573. mesh.figures.push({
  34574. type: 'patch',
  34575. coords: new Int32Array(ps), // making copies of ps and cs
  34576. colors: new Int32Array(cs)
  34577. });
  34578. }
  34579. }
  34580. function decodeType7Shading(mesh, reader) {
  34581. var coords = mesh.coords;
  34582. var colors = mesh.colors;
  34583. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  34584. var cs = new Int32Array(4); // c00, c30, c03, c33
  34585. while (reader.hasData) {
  34586. var f = reader.readFlag();
  34587. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  34588. var i, ii;
  34589. var pi = coords.length;
  34590. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  34591. coords.push(reader.readCoordinate());
  34592. }
  34593. var ci = colors.length;
  34594. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  34595. colors.push(reader.readComponents());
  34596. }
  34597. var tmp1, tmp2, tmp3, tmp4;
  34598. switch (f) {
  34599. case 0:
  34600. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  34601. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  34602. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  34603. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  34604. cs[2] = ci + 1; cs[3] = ci + 2;
  34605. cs[0] = ci; cs[1] = ci + 3;
  34606. break;
  34607. case 1:
  34608. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  34609. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34610. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  34611. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  34612. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34613. tmp1 = cs[2]; tmp2 = cs[3];
  34614. cs[2] = tmp2; cs[3] = ci;
  34615. cs[0] = tmp1; cs[1] = ci + 1;
  34616. break;
  34617. case 2:
  34618. tmp1 = ps[15];
  34619. tmp2 = ps[11];
  34620. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34621. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  34622. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  34623. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34624. tmp1 = cs[3];
  34625. cs[2] = cs[1]; cs[3] = ci;
  34626. cs[0] = tmp1; cs[1] = ci + 1;
  34627. break;
  34628. case 3:
  34629. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34630. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  34631. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  34632. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34633. cs[2] = cs[0]; cs[3] = ci;
  34634. cs[0] = cs[1]; cs[1] = ci + 1;
  34635. break;
  34636. }
  34637. mesh.figures.push({
  34638. type: 'patch',
  34639. coords: new Int32Array(ps), // making copies of ps and cs
  34640. colors: new Int32Array(cs)
  34641. });
  34642. }
  34643. }
  34644. function updateBounds(mesh) {
  34645. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  34646. maxX = minX, maxY = minY;
  34647. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  34648. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  34649. minX = minX > x ? x : minX;
  34650. minY = minY > y ? y : minY;
  34651. maxX = maxX < x ? x : maxX;
  34652. maxY = maxY < y ? y : maxY;
  34653. }
  34654. mesh.bounds = [minX, minY, maxX, maxY];
  34655. }
  34656. function packData(mesh) {
  34657. var i, ii, j, jj;
  34658. var coords = mesh.coords;
  34659. var coordsPacked = new Float32Array(coords.length * 2);
  34660. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  34661. var xy = coords[i];
  34662. coordsPacked[j++] = xy[0];
  34663. coordsPacked[j++] = xy[1];
  34664. }
  34665. mesh.coords = coordsPacked;
  34666. var colors = mesh.colors;
  34667. var colorsPacked = new Uint8Array(colors.length * 3);
  34668. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  34669. var c = colors[i];
  34670. colorsPacked[j++] = c[0];
  34671. colorsPacked[j++] = c[1];
  34672. colorsPacked[j++] = c[2];
  34673. }
  34674. mesh.colors = colorsPacked;
  34675. var figures = mesh.figures;
  34676. for (i = 0, ii = figures.length; i < ii; i++) {
  34677. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  34678. for (j = 0, jj = ps.length; j < jj; j++) {
  34679. ps[j] *= 2;
  34680. cs[j] *= 3;
  34681. }
  34682. }
  34683. }
  34684. function Mesh(stream, matrix, xref, res) {
  34685. assert(isStream(stream), 'Mesh data is not a stream');
  34686. var dict = stream.dict;
  34687. this.matrix = matrix;
  34688. this.shadingType = dict.get('ShadingType');
  34689. this.type = 'Pattern';
  34690. this.bbox = dict.getArray('BBox');
  34691. var cs = dict.get('ColorSpace', 'CS');
  34692. cs = ColorSpace.parse(cs, xref, res);
  34693. this.cs = cs;
  34694. this.background = dict.has('Background') ?
  34695. cs.getRgb(dict.get('Background'), 0) : null;
  34696. var fnObj = dict.get('Function');
  34697. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  34698. this.coords = [];
  34699. this.colors = [];
  34700. this.figures = [];
  34701. var decodeContext = {
  34702. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  34703. bitsPerComponent: dict.get('BitsPerComponent'),
  34704. bitsPerFlag: dict.get('BitsPerFlag'),
  34705. decode: dict.getArray('Decode'),
  34706. colorFn: fn,
  34707. colorSpace: cs,
  34708. numComps: fn ? 1 : cs.numComps
  34709. };
  34710. var reader = new MeshStreamReader(stream, decodeContext);
  34711. var patchMesh = false;
  34712. switch (this.shadingType) {
  34713. case ShadingType.FREE_FORM_MESH:
  34714. decodeType4Shading(this, reader);
  34715. break;
  34716. case ShadingType.LATTICE_FORM_MESH:
  34717. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  34718. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  34719. decodeType5Shading(this, reader, verticesPerRow);
  34720. break;
  34721. case ShadingType.COONS_PATCH_MESH:
  34722. decodeType6Shading(this, reader);
  34723. patchMesh = true;
  34724. break;
  34725. case ShadingType.TENSOR_PATCH_MESH:
  34726. decodeType7Shading(this, reader);
  34727. patchMesh = true;
  34728. break;
  34729. default:
  34730. error('Unsupported mesh type.');
  34731. break;
  34732. }
  34733. if (patchMesh) {
  34734. // dirty bounds calculation for determining, how dense shall be triangles
  34735. updateBounds(this);
  34736. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  34737. buildFigureFromPatch(this, i);
  34738. }
  34739. }
  34740. // calculate bounds
  34741. updateBounds(this);
  34742. packData(this);
  34743. }
  34744. Mesh.prototype = {
  34745. getIR: function Mesh_getIR() {
  34746. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  34747. this.bounds, this.matrix, this.bbox, this.background];
  34748. }
  34749. };
  34750. return Mesh;
  34751. })();
  34752. Shadings.Dummy = (function DummyClosure() {
  34753. function Dummy() {
  34754. this.type = 'Pattern';
  34755. }
  34756. Dummy.prototype = {
  34757. getIR: function Dummy_getIR() {
  34758. return ['Dummy'];
  34759. }
  34760. };
  34761. return Dummy;
  34762. })();
  34763. function getTilingPatternIR(operatorList, dict, args) {
  34764. var matrix = dict.getArray('Matrix');
  34765. var bbox = dict.getArray('BBox');
  34766. var xstep = dict.get('XStep');
  34767. var ystep = dict.get('YStep');
  34768. var paintType = dict.get('PaintType');
  34769. var tilingType = dict.get('TilingType');
  34770. return [
  34771. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  34772. paintType, tilingType
  34773. ];
  34774. }
  34775. exports.Pattern = Pattern;
  34776. exports.getTilingPatternIR = getTilingPatternIR;
  34777. }));
  34778. (function (root, factory) {
  34779. {
  34780. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  34781. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  34782. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  34783. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  34784. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi,
  34785. root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts,
  34786. root.pdfjsCoreUnicode, root.pdfjsCoreGlyphList);
  34787. }
  34788. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  34789. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  34790. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi,
  34791. coreEncodings, coreStandardFonts, coreUnicode,
  34792. coreGlyphList) {
  34793. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  34794. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  34795. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  34796. var ImageKind = sharedUtil.ImageKind;
  34797. var OPS = sharedUtil.OPS;
  34798. var TextRenderingMode = sharedUtil.TextRenderingMode;
  34799. var Util = sharedUtil.Util;
  34800. var assert = sharedUtil.assert;
  34801. var createPromiseCapability = sharedUtil.createPromiseCapability;
  34802. var error = sharedUtil.error;
  34803. var info = sharedUtil.info;
  34804. var isArray = sharedUtil.isArray;
  34805. var isNum = sharedUtil.isNum;
  34806. var isString = sharedUtil.isString;
  34807. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  34808. var warn = sharedUtil.warn;
  34809. var Dict = corePrimitives.Dict;
  34810. var Name = corePrimitives.Name;
  34811. var isCmd = corePrimitives.isCmd;
  34812. var isDict = corePrimitives.isDict;
  34813. var isName = corePrimitives.isName;
  34814. var isRef = corePrimitives.isRef;
  34815. var isStream = corePrimitives.isStream;
  34816. var DecodeStream = coreStream.DecodeStream;
  34817. var JpegStream = coreStream.JpegStream;
  34818. var Stream = coreStream.Stream;
  34819. var Lexer = coreParser.Lexer;
  34820. var Parser = coreParser.Parser;
  34821. var isEOF = coreParser.isEOF;
  34822. var PDFImage = coreImage.PDFImage;
  34823. var ColorSpace = coreColorSpace.ColorSpace;
  34824. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  34825. var ErrorFont = coreFonts.ErrorFont;
  34826. var FontFlags = coreFonts.FontFlags;
  34827. var Font = coreFonts.Font;
  34828. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  34829. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  34830. var getFontType = coreFonts.getFontType;
  34831. var isPDFFunction = coreFunction.isPDFFunction;
  34832. var PDFFunction = coreFunction.PDFFunction;
  34833. var Pattern = corePattern.Pattern;
  34834. var getTilingPatternIR = corePattern.getTilingPatternIR;
  34835. var CMapFactory = coreCMap.CMapFactory;
  34836. var IdentityCMap = coreCMap.IdentityCMap;
  34837. var getMetrics = coreMetrics.getMetrics;
  34838. var bidi = coreBidi.bidi;
  34839. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  34840. var StandardEncoding = coreEncodings.StandardEncoding;
  34841. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  34842. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  34843. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  34844. var getEncoding = coreEncodings.getEncoding;
  34845. var getStdFontMap = coreStandardFonts.getStdFontMap;
  34846. var getSerifFonts = coreStandardFonts.getSerifFonts;
  34847. var getSymbolsFonts = coreStandardFonts.getSymbolsFonts;
  34848. var getNormalizedUnicodes = coreUnicode.getNormalizedUnicodes;
  34849. var reverseIfRtl = coreUnicode.reverseIfRtl;
  34850. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  34851. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  34852. var PartialEvaluator = (function PartialEvaluatorClosure() {
  34853. var DefaultPartialEvaluatorOptions = {
  34854. forceDataSchema: false,
  34855. maxImageSize: -1,
  34856. disableFontFace: false,
  34857. cMapOptions: { url: null, packed: false }
  34858. };
  34859. function NativeImageDecoder(xref, resources, handler, forceDataSchema) {
  34860. this.xref = xref;
  34861. this.resources = resources;
  34862. this.handler = handler;
  34863. this.forceDataSchema = forceDataSchema;
  34864. }
  34865. NativeImageDecoder.prototype = {
  34866. canDecode: function (image) {
  34867. return image instanceof JpegStream &&
  34868. NativeImageDecoder.isDecodable(image, this.xref, this.resources);
  34869. },
  34870. decode: function (image) {
  34871. // For natively supported JPEGs send them to the main thread for decoding.
  34872. var dict = image.dict;
  34873. var colorSpace = dict.get('ColorSpace', 'CS');
  34874. colorSpace = ColorSpace.parse(colorSpace, this.xref, this.resources);
  34875. var numComps = colorSpace.numComps;
  34876. var decodePromise = this.handler.sendWithPromise('JpegDecode',
  34877. [image.getIR(this.forceDataSchema), numComps]);
  34878. return decodePromise.then(function (message) {
  34879. var data = message.data;
  34880. return new Stream(data, 0, data.length, image.dict);
  34881. });
  34882. }
  34883. };
  34884. /**
  34885. * Checks if the image can be decoded and displayed by the browser without any
  34886. * further processing such as color space conversions.
  34887. */
  34888. NativeImageDecoder.isSupported =
  34889. function NativeImageDecoder_isSupported(image, xref, res) {
  34890. var dict = image.dict;
  34891. if (dict.has('DecodeParms') || dict.has('DP')) {
  34892. return false;
  34893. }
  34894. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  34895. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  34896. cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  34897. };
  34898. /**
  34899. * Checks if the image can be decoded by the browser.
  34900. */
  34901. NativeImageDecoder.isDecodable =
  34902. function NativeImageDecoder_isDecodable(image, xref, res) {
  34903. var dict = image.dict;
  34904. if (dict.has('DecodeParms') || dict.has('DP')) {
  34905. return false;
  34906. }
  34907. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  34908. return (cs.numComps === 1 || cs.numComps === 3) &&
  34909. cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  34910. };
  34911. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  34912. uniquePrefix, idCounters, fontCache, options) {
  34913. this.pdfManager = pdfManager;
  34914. this.xref = xref;
  34915. this.handler = handler;
  34916. this.pageIndex = pageIndex;
  34917. this.uniquePrefix = uniquePrefix;
  34918. this.idCounters = idCounters;
  34919. this.fontCache = fontCache;
  34920. this.options = options || DefaultPartialEvaluatorOptions;
  34921. }
  34922. // Trying to minimize Date.now() usage and check every 100 time
  34923. var TIME_SLOT_DURATION_MS = 20;
  34924. var CHECK_TIME_EVERY = 100;
  34925. function TimeSlotManager() {
  34926. this.reset();
  34927. }
  34928. TimeSlotManager.prototype = {
  34929. check: function TimeSlotManager_check() {
  34930. if (++this.checked < CHECK_TIME_EVERY) {
  34931. return false;
  34932. }
  34933. this.checked = 0;
  34934. return this.endTime <= Date.now();
  34935. },
  34936. reset: function TimeSlotManager_reset() {
  34937. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  34938. this.checked = 0;
  34939. }
  34940. };
  34941. var deferred = Promise.resolve();
  34942. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  34943. PartialEvaluator.prototype = {
  34944. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  34945. if (!isDict(resources)) {
  34946. return false;
  34947. }
  34948. var processed = Object.create(null);
  34949. if (resources.objId) {
  34950. processed[resources.objId] = true;
  34951. }
  34952. var nodes = [resources], xref = this.xref;
  34953. while (nodes.length) {
  34954. var key, i, ii;
  34955. var node = nodes.shift();
  34956. // First check the current resources for blend modes.
  34957. var graphicStates = node.get('ExtGState');
  34958. if (isDict(graphicStates)) {
  34959. var graphicStatesKeys = graphicStates.getKeys();
  34960. for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
  34961. key = graphicStatesKeys[i];
  34962. var graphicState = graphicStates.get(key);
  34963. var bm = graphicState.get('BM');
  34964. if (isName(bm) && bm.name !== 'Normal') {
  34965. return true;
  34966. }
  34967. }
  34968. }
  34969. // Descend into the XObjects to look for more resources and blend modes.
  34970. var xObjects = node.get('XObject');
  34971. if (!isDict(xObjects)) {
  34972. continue;
  34973. }
  34974. var xObjectsKeys = xObjects.getKeys();
  34975. for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
  34976. key = xObjectsKeys[i];
  34977. var xObject = xObjects.getRaw(key);
  34978. if (isRef(xObject)) {
  34979. if (processed[xObject.toString()]) {
  34980. // The XObject has already been processed, and by avoiding a
  34981. // redundant `xref.fetch` we can *significantly* reduce the load
  34982. // time for badly generated PDF files (fixes issue6961.pdf).
  34983. continue;
  34984. }
  34985. xObject = xref.fetch(xObject);
  34986. }
  34987. if (!isStream(xObject)) {
  34988. continue;
  34989. }
  34990. if (xObject.dict.objId) {
  34991. if (processed[xObject.dict.objId]) {
  34992. // stream has objId and is processed already
  34993. continue;
  34994. }
  34995. processed[xObject.dict.objId] = true;
  34996. }
  34997. var xResources = xObject.dict.get('Resources');
  34998. // Checking objId to detect an infinite loop.
  34999. if (isDict(xResources) &&
  35000. (!xResources.objId || !processed[xResources.objId])) {
  35001. nodes.push(xResources);
  35002. if (xResources.objId) {
  35003. processed[xResources.objId] = true;
  35004. }
  35005. }
  35006. }
  35007. }
  35008. return false;
  35009. },
  35010. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  35011. xobj, smask,
  35012. operatorList,
  35013. task,
  35014. initialState) {
  35015. var matrix = xobj.dict.getArray('Matrix');
  35016. var bbox = xobj.dict.getArray('BBox');
  35017. var group = xobj.dict.get('Group');
  35018. if (group) {
  35019. var groupOptions = {
  35020. matrix: matrix,
  35021. bbox: bbox,
  35022. smask: smask,
  35023. isolated: false,
  35024. knockout: false
  35025. };
  35026. var groupSubtype = group.get('S');
  35027. var colorSpace;
  35028. if (isName(groupSubtype, 'Transparency')) {
  35029. groupOptions.isolated = (group.get('I') || false);
  35030. groupOptions.knockout = (group.get('K') || false);
  35031. colorSpace = (group.has('CS') ?
  35032. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  35033. }
  35034. if (smask && smask.backdrop) {
  35035. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  35036. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  35037. }
  35038. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  35039. }
  35040. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  35041. return this.getOperatorList(xobj, task,
  35042. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  35043. then(function () {
  35044. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  35045. if (group) {
  35046. operatorList.addOp(OPS.endGroup, [groupOptions]);
  35047. }
  35048. });
  35049. },
  35050. buildPaintImageXObject:
  35051. function PartialEvaluator_buildPaintImageXObject(resources, image,
  35052. inline, operatorList,
  35053. cacheKey, imageCache) {
  35054. var self = this;
  35055. var dict = image.dict;
  35056. var w = dict.get('Width', 'W');
  35057. var h = dict.get('Height', 'H');
  35058. if (!(w && isNum(w)) || !(h && isNum(h))) {
  35059. warn('Image dimensions are missing, or not numbers.');
  35060. return;
  35061. }
  35062. var maxImageSize = this.options.maxImageSize;
  35063. if (maxImageSize !== -1 && w * h > maxImageSize) {
  35064. warn('Image exceeded maximum allowed size and was removed.');
  35065. return;
  35066. }
  35067. var imageMask = (dict.get('ImageMask', 'IM') || false);
  35068. var imgData, args;
  35069. if (imageMask) {
  35070. // This depends on a tmpCanvas being filled with the
  35071. // current fillStyle, such that processing the pixel
  35072. // data can't be done here. Instead of creating a
  35073. // complete PDFImage, only read the information needed
  35074. // for later.
  35075. var width = dict.get('Width', 'W');
  35076. var height = dict.get('Height', 'H');
  35077. var bitStrideLength = (width + 7) >> 3;
  35078. var imgArray = image.getBytes(bitStrideLength * height);
  35079. var decode = dict.getArray('Decode', 'D');
  35080. var inverseDecode = (!!decode && decode[0] > 0);
  35081. imgData = PDFImage.createMask(imgArray, width, height,
  35082. image instanceof DecodeStream,
  35083. inverseDecode);
  35084. imgData.cached = true;
  35085. args = [imgData];
  35086. operatorList.addOp(OPS.paintImageMaskXObject, args);
  35087. if (cacheKey) {
  35088. imageCache[cacheKey] = {
  35089. fn: OPS.paintImageMaskXObject,
  35090. args: args
  35091. };
  35092. }
  35093. return;
  35094. }
  35095. var softMask = (dict.get('SMask', 'SM') || false);
  35096. var mask = (dict.get('Mask') || false);
  35097. var SMALL_IMAGE_DIMENSIONS = 200;
  35098. // Inlining small images into the queue as RGB data
  35099. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  35100. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  35101. var imageObj = new PDFImage(this.xref, resources, image,
  35102. inline, null, null);
  35103. // We force the use of RGBA_32BPP images here, because we can't handle
  35104. // any other kind.
  35105. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  35106. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  35107. return;
  35108. }
  35109. // If there is no imageMask, create the PDFImage and a lot
  35110. // of image processing can be done here.
  35111. var uniquePrefix = (this.uniquePrefix || '');
  35112. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  35113. operatorList.addDependency(objId);
  35114. args = [objId, w, h];
  35115. if (!softMask && !mask && image instanceof JpegStream &&
  35116. NativeImageDecoder.isSupported(image, this.xref, resources)) {
  35117. // These JPEGs don't need any more processing so we can just send it.
  35118. operatorList.addOp(OPS.paintJpegXObject, args);
  35119. this.handler.send('obj',
  35120. [objId, this.pageIndex, 'JpegStream',
  35121. image.getIR(this.options.forceDataSchema)]);
  35122. return;
  35123. }
  35124. // Creates native image decoder only if a JPEG image or mask is present.
  35125. var nativeImageDecoder = null;
  35126. if (image instanceof JpegStream || mask instanceof JpegStream ||
  35127. softMask instanceof JpegStream) {
  35128. nativeImageDecoder = new NativeImageDecoder(self.xref, resources,
  35129. self.handler, self.options.forceDataSchema);
  35130. }
  35131. PDFImage.buildImage(self.handler, self.xref, resources, image, inline,
  35132. nativeImageDecoder).
  35133. then(function(imageObj) {
  35134. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  35135. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  35136. [imgData.data.buffer]);
  35137. }).then(undefined, function (reason) {
  35138. warn('Unable to decode image: ' + reason);
  35139. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  35140. });
  35141. operatorList.addOp(OPS.paintImageXObject, args);
  35142. if (cacheKey) {
  35143. imageCache[cacheKey] = {
  35144. fn: OPS.paintImageXObject,
  35145. args: args
  35146. };
  35147. }
  35148. },
  35149. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  35150. operatorList, task,
  35151. stateManager) {
  35152. var smaskContent = smask.get('G');
  35153. var smaskOptions = {
  35154. subtype: smask.get('S').name,
  35155. backdrop: smask.get('BC')
  35156. };
  35157. // The SMask might have a alpha/luminosity value transfer function --
  35158. // we will build a map of integer values in range 0..255 to be fast.
  35159. var transferObj = smask.get('TR');
  35160. if (isPDFFunction(transferObj)) {
  35161. var transferFn = PDFFunction.parse(this.xref, transferObj);
  35162. var transferMap = new Uint8Array(256);
  35163. var tmp = new Float32Array(1);
  35164. for (var i = 0; i < 256; i++) {
  35165. tmp[0] = i / 255;
  35166. transferFn(tmp, 0, tmp, 0);
  35167. transferMap[i] = (tmp[0] * 255) | 0;
  35168. }
  35169. smaskOptions.transferMap = transferMap;
  35170. }
  35171. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  35172. operatorList, task, stateManager.state.clone());
  35173. },
  35174. handleTilingType:
  35175. function PartialEvaluator_handleTilingType(fn, args, resources,
  35176. pattern, patternDict,
  35177. operatorList, task) {
  35178. // Create an IR of the pattern code.
  35179. var tilingOpList = new OperatorList();
  35180. // Merge the available resources, to prevent issues when the patternDict
  35181. // is missing some /Resources entries (fixes issue6541.pdf).
  35182. var resourcesArray = [patternDict.get('Resources'), resources];
  35183. var patternResources = Dict.merge(this.xref, resourcesArray);
  35184. return this.getOperatorList(pattern, task, patternResources,
  35185. tilingOpList).then(function () {
  35186. // Add the dependencies to the parent operator list so they are
  35187. // resolved before sub operator list is executed synchronously.
  35188. operatorList.addDependencies(tilingOpList.dependencies);
  35189. operatorList.addOp(fn, getTilingPatternIR({
  35190. fnArray: tilingOpList.fnArray,
  35191. argsArray: tilingOpList.argsArray
  35192. }, patternDict, args));
  35193. });
  35194. },
  35195. handleSetFont:
  35196. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  35197. operatorList, task, state) {
  35198. // TODO(mack): Not needed?
  35199. var fontName;
  35200. if (fontArgs) {
  35201. fontArgs = fontArgs.slice();
  35202. fontName = fontArgs[0].name;
  35203. }
  35204. var self = this;
  35205. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  35206. function (translated) {
  35207. if (!translated.font.isType3Font) {
  35208. return translated;
  35209. }
  35210. return translated.loadType3Data(self, resources, operatorList, task).
  35211. then(function () {
  35212. return translated;
  35213. }, function (reason) {
  35214. // Error in the font data -- sending unsupported feature notification.
  35215. self.handler.send('UnsupportedFeature',
  35216. {featureId: UNSUPPORTED_FEATURES.font});
  35217. return new TranslatedFont('g_font_error',
  35218. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  35219. });
  35220. }).then(function (translated) {
  35221. state.font = translated.font;
  35222. translated.send(self.handler);
  35223. return translated.loadedName;
  35224. });
  35225. },
  35226. handleText: function PartialEvaluator_handleText(chars, state) {
  35227. var font = state.font;
  35228. var glyphs = font.charsToGlyphs(chars);
  35229. var isAddToPathSet = !!(state.textRenderingMode &
  35230. TextRenderingMode.ADD_TO_PATH_FLAG);
  35231. if (font.data && (isAddToPathSet || this.options.disableFontFace)) {
  35232. var buildPath = function (fontChar) {
  35233. if (!font.renderer.hasBuiltPath(fontChar)) {
  35234. var path = font.renderer.getPathJs(fontChar);
  35235. this.handler.send('commonobj', [
  35236. font.loadedName + '_path_' + fontChar,
  35237. 'FontPath',
  35238. path
  35239. ]);
  35240. }
  35241. }.bind(this);
  35242. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  35243. var glyph = glyphs[i];
  35244. buildPath(glyph.fontChar);
  35245. // If the glyph has an accent we need to build a path for its
  35246. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  35247. var accent = glyph.accent;
  35248. if (accent && accent.fontChar) {
  35249. buildPath(accent.fontChar);
  35250. }
  35251. }
  35252. }
  35253. return glyphs;
  35254. },
  35255. setGState: function PartialEvaluator_setGState(resources, gState,
  35256. operatorList, task,
  35257. xref, stateManager) {
  35258. // This array holds the converted/processed state data.
  35259. var gStateObj = [];
  35260. var gStateKeys = gState.getKeys();
  35261. var self = this;
  35262. var promise = Promise.resolve();
  35263. for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
  35264. var key = gStateKeys[i];
  35265. var value = gState.get(key);
  35266. switch (key) {
  35267. case 'Type':
  35268. break;
  35269. case 'LW':
  35270. case 'LC':
  35271. case 'LJ':
  35272. case 'ML':
  35273. case 'D':
  35274. case 'RI':
  35275. case 'FL':
  35276. case 'CA':
  35277. case 'ca':
  35278. gStateObj.push([key, value]);
  35279. break;
  35280. case 'Font':
  35281. promise = promise.then(function () {
  35282. return self.handleSetFont(resources, null, value[0], operatorList,
  35283. task, stateManager.state).
  35284. then(function (loadedName) {
  35285. operatorList.addDependency(loadedName);
  35286. gStateObj.push([key, [loadedName, value[1]]]);
  35287. });
  35288. });
  35289. break;
  35290. case 'BM':
  35291. gStateObj.push([key, value]);
  35292. break;
  35293. case 'SMask':
  35294. if (isName(value, 'None')) {
  35295. gStateObj.push([key, false]);
  35296. break;
  35297. }
  35298. if (isDict(value)) {
  35299. promise = promise.then(function (dict) {
  35300. return self.handleSMask(dict, resources, operatorList,
  35301. task, stateManager);
  35302. }.bind(this, value));
  35303. gStateObj.push([key, true]);
  35304. } else {
  35305. warn('Unsupported SMask type');
  35306. }
  35307. break;
  35308. // Only generate info log messages for the following since
  35309. // they are unlikely to have a big impact on the rendering.
  35310. case 'OP':
  35311. case 'op':
  35312. case 'OPM':
  35313. case 'BG':
  35314. case 'BG2':
  35315. case 'UCR':
  35316. case 'UCR2':
  35317. case 'TR':
  35318. case 'TR2':
  35319. case 'HT':
  35320. case 'SM':
  35321. case 'SA':
  35322. case 'AIS':
  35323. case 'TK':
  35324. // TODO implement these operators.
  35325. info('graphic state operator ' + key);
  35326. break;
  35327. default:
  35328. info('Unknown graphic state operator ' + key);
  35329. break;
  35330. }
  35331. }
  35332. return promise.then(function () {
  35333. if (gStateObj.length > 0) {
  35334. operatorList.addOp(OPS.setGState, [gStateObj]);
  35335. }
  35336. });
  35337. },
  35338. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  35339. resources) {
  35340. function errorFont() {
  35341. return Promise.resolve(new TranslatedFont('g_font_error',
  35342. new ErrorFont('Font ' + fontName + ' is not available'), font));
  35343. }
  35344. var fontRef;
  35345. if (font) { // Loading by ref.
  35346. assert(isRef(font));
  35347. fontRef = font;
  35348. } else { // Loading by name.
  35349. var fontRes = resources.get('Font');
  35350. if (fontRes) {
  35351. fontRef = fontRes.getRaw(fontName);
  35352. } else {
  35353. warn('fontRes not available');
  35354. return errorFont();
  35355. }
  35356. }
  35357. if (!fontRef) {
  35358. warn('fontRef not available');
  35359. return errorFont();
  35360. }
  35361. if (this.fontCache.has(fontRef)) {
  35362. return this.fontCache.get(fontRef);
  35363. }
  35364. font = xref.fetchIfRef(fontRef);
  35365. if (!isDict(font)) {
  35366. return errorFont();
  35367. }
  35368. // We are holding `font.translated` references just for `fontRef`s that
  35369. // are not actually `Ref`s, but rather `Dict`s. See explanation below.
  35370. if (font.translated) {
  35371. return font.translated;
  35372. }
  35373. var fontCapability = createPromiseCapability();
  35374. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  35375. var descriptor = preEvaluatedFont.descriptor;
  35376. var fontRefIsRef = isRef(fontRef), fontID;
  35377. if (fontRefIsRef) {
  35378. fontID = fontRef.toString();
  35379. }
  35380. if (isDict(descriptor)) {
  35381. if (!descriptor.fontAliases) {
  35382. descriptor.fontAliases = Object.create(null);
  35383. }
  35384. var fontAliases = descriptor.fontAliases;
  35385. var hash = preEvaluatedFont.hash;
  35386. if (fontAliases[hash]) {
  35387. var aliasFontRef = fontAliases[hash].aliasRef;
  35388. if (fontRefIsRef && aliasFontRef &&
  35389. this.fontCache.has(aliasFontRef)) {
  35390. this.fontCache.putAlias(fontRef, aliasFontRef);
  35391. return this.fontCache.get(fontRef);
  35392. }
  35393. } else {
  35394. fontAliases[hash] = {
  35395. fontID: Font.getFontID()
  35396. };
  35397. }
  35398. if (fontRefIsRef) {
  35399. fontAliases[hash].aliasRef = fontRef;
  35400. }
  35401. fontID = fontAliases[hash].fontID;
  35402. }
  35403. // Workaround for bad PDF generators that reference fonts incorrectly,
  35404. // where `fontRef` is a `Dict` rather than a `Ref` (fixes bug946506.pdf).
  35405. // In this case we should not put the font into `this.fontCache` (which is
  35406. // a `RefSetCache`), since it's not meaningful to use a `Dict` as a key.
  35407. //
  35408. // However, if we don't cache the font it's not possible to remove it
  35409. // when `cleanup` is triggered from the API, which causes issues on
  35410. // subsequent rendering operations (see issue7403.pdf).
  35411. // A simple workaround would be to just not hold `font.translated`
  35412. // references in this case, but this would force us to unnecessarily load
  35413. // the same fonts over and over.
  35414. //
  35415. // Instead, we cheat a bit by attempting to use a modified `fontID` as a
  35416. // key in `this.fontCache`, to allow the font to be cached.
  35417. // NOTE: This works because `RefSetCache` calls `toString()` on provided
  35418. // keys. Also, since `fontRef` is used when getting cached fonts,
  35419. // we'll not accidentally match fonts cached with the `fontID`.
  35420. if (fontRefIsRef) {
  35421. this.fontCache.put(fontRef, fontCapability.promise);
  35422. } else {
  35423. if (!fontID) {
  35424. fontID = (this.uniquePrefix || 'F_') + (++this.idCounters.obj);
  35425. }
  35426. this.fontCache.put('id_' + fontID, fontCapability.promise);
  35427. }
  35428. assert(fontID, 'The "fontID" must be defined.');
  35429. // Keep track of each font we translated so the caller can
  35430. // load them asynchronously before calling display on a page.
  35431. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + fontID;
  35432. font.translated = fontCapability.promise;
  35433. // TODO move promises into translate font
  35434. var translatedPromise;
  35435. try {
  35436. translatedPromise = this.translateFont(preEvaluatedFont, xref);
  35437. } catch (e) {
  35438. translatedPromise = Promise.reject(e);
  35439. }
  35440. var self = this;
  35441. translatedPromise.then(function (translatedFont) {
  35442. if (translatedFont.fontType !== undefined) {
  35443. var xrefFontStats = xref.stats.fontTypes;
  35444. xrefFontStats[translatedFont.fontType] = true;
  35445. }
  35446. fontCapability.resolve(new TranslatedFont(font.loadedName,
  35447. translatedFont, font));
  35448. }, function (reason) {
  35449. // TODO fontCapability.reject?
  35450. // Error in the font data -- sending unsupported feature notification.
  35451. self.handler.send('UnsupportedFeature',
  35452. {featureId: UNSUPPORTED_FEATURES.font});
  35453. try {
  35454. // error, but it's still nice to have font type reported
  35455. var descriptor = preEvaluatedFont.descriptor;
  35456. var fontFile3 = descriptor && descriptor.get('FontFile3');
  35457. var subtype = fontFile3 && fontFile3.get('Subtype');
  35458. var fontType = getFontType(preEvaluatedFont.type,
  35459. subtype && subtype.name);
  35460. var xrefFontStats = xref.stats.fontTypes;
  35461. xrefFontStats[fontType] = true;
  35462. } catch (ex) { }
  35463. fontCapability.resolve(new TranslatedFont(font.loadedName,
  35464. new ErrorFont(reason instanceof Error ? reason.message : reason),
  35465. font));
  35466. });
  35467. return fontCapability.promise;
  35468. },
  35469. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  35470. var lastIndex = operatorList.length - 1;
  35471. if (!args) {
  35472. args = [];
  35473. }
  35474. if (lastIndex < 0 ||
  35475. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  35476. operatorList.addOp(OPS.constructPath, [[fn], args]);
  35477. } else {
  35478. var opArgs = operatorList.argsArray[lastIndex];
  35479. opArgs[0].push(fn);
  35480. Array.prototype.push.apply(opArgs[1], args);
  35481. }
  35482. },
  35483. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  35484. cs, patterns, resources, task, xref) {
  35485. // compile tiling patterns
  35486. var patternName = args[args.length - 1];
  35487. // SCN/scn applies patterns along with normal colors
  35488. var pattern;
  35489. if (isName(patternName) &&
  35490. (pattern = patterns.get(patternName.name))) {
  35491. var dict = (isStream(pattern) ? pattern.dict : pattern);
  35492. var typeNum = dict.get('PatternType');
  35493. if (typeNum === TILING_PATTERN) {
  35494. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  35495. return this.handleTilingType(fn, color, resources, pattern,
  35496. dict, operatorList, task);
  35497. } else if (typeNum === SHADING_PATTERN) {
  35498. var shading = dict.get('Shading');
  35499. var matrix = dict.getArray('Matrix');
  35500. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  35501. this.handler);
  35502. operatorList.addOp(fn, pattern.getIR());
  35503. return Promise.resolve();
  35504. } else {
  35505. return Promise.reject('Unknown PatternType: ' + typeNum);
  35506. }
  35507. }
  35508. // TODO shall we fail here?
  35509. operatorList.addOp(fn, args);
  35510. return Promise.resolve();
  35511. },
  35512. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  35513. task,
  35514. resources,
  35515. operatorList,
  35516. initialState) {
  35517. var self = this;
  35518. var xref = this.xref;
  35519. var imageCache = Object.create(null);
  35520. assert(operatorList);
  35521. resources = (resources || Dict.empty);
  35522. var xobjs = (resources.get('XObject') || Dict.empty);
  35523. var patterns = (resources.get('Pattern') || Dict.empty);
  35524. var stateManager = new StateManager(initialState || new EvalState());
  35525. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  35526. var timeSlotManager = new TimeSlotManager();
  35527. return new Promise(function promiseBody(resolve, reject) {
  35528. var next = function (promise) {
  35529. promise.then(function () {
  35530. try {
  35531. promiseBody(resolve, reject);
  35532. } catch (ex) {
  35533. reject(ex);
  35534. }
  35535. }, reject);
  35536. };
  35537. task.ensureNotTerminated();
  35538. timeSlotManager.reset();
  35539. var stop, operation = {}, i, ii, cs;
  35540. while (!(stop = timeSlotManager.check())) {
  35541. // The arguments parsed by read() are used beyond this loop, so we
  35542. // cannot reuse the same array on each iteration. Therefore we pass
  35543. // in |null| as the initial value (see the comment on
  35544. // EvaluatorPreprocessor_read() for why).
  35545. operation.args = null;
  35546. if (!(preprocessor.read(operation))) {
  35547. break;
  35548. }
  35549. var args = operation.args;
  35550. var fn = operation.fn;
  35551. switch (fn | 0) {
  35552. case OPS.paintXObject:
  35553. if (args[0].code) {
  35554. break;
  35555. }
  35556. // eagerly compile XForm objects
  35557. var name = args[0].name;
  35558. if (!name) {
  35559. warn('XObject must be referred to by name.');
  35560. continue;
  35561. }
  35562. if (imageCache[name] !== undefined) {
  35563. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  35564. args = null;
  35565. continue;
  35566. }
  35567. var xobj = xobjs.get(name);
  35568. if (xobj) {
  35569. assert(isStream(xobj), 'XObject should be a stream');
  35570. var type = xobj.dict.get('Subtype');
  35571. assert(isName(type), 'XObject should have a Name subtype');
  35572. if (type.name === 'Form') {
  35573. stateManager.save();
  35574. next(self.buildFormXObject(resources, xobj, null,
  35575. operatorList, task,
  35576. stateManager.state.clone()).
  35577. then(function () {
  35578. stateManager.restore();
  35579. }));
  35580. return;
  35581. } else if (type.name === 'Image') {
  35582. self.buildPaintImageXObject(resources, xobj, false,
  35583. operatorList, name, imageCache);
  35584. args = null;
  35585. continue;
  35586. } else if (type.name === 'PS') {
  35587. // PostScript XObjects are unused when viewing documents.
  35588. // See section 4.7.1 of Adobe's PDF reference.
  35589. info('Ignored XObject subtype PS');
  35590. continue;
  35591. } else {
  35592. error('Unhandled XObject subtype ' + type.name);
  35593. }
  35594. }
  35595. break;
  35596. case OPS.setFont:
  35597. var fontSize = args[1];
  35598. // eagerly collect all fonts
  35599. next(self.handleSetFont(resources, args, null, operatorList,
  35600. task, stateManager.state).
  35601. then(function (loadedName) {
  35602. operatorList.addDependency(loadedName);
  35603. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  35604. }));
  35605. return;
  35606. case OPS.endInlineImage:
  35607. var cacheKey = args[0].cacheKey;
  35608. if (cacheKey) {
  35609. var cacheEntry = imageCache[cacheKey];
  35610. if (cacheEntry !== undefined) {
  35611. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  35612. args = null;
  35613. continue;
  35614. }
  35615. }
  35616. self.buildPaintImageXObject(resources, args[0], true,
  35617. operatorList, cacheKey, imageCache);
  35618. args = null;
  35619. continue;
  35620. case OPS.showText:
  35621. args[0] = self.handleText(args[0], stateManager.state);
  35622. break;
  35623. case OPS.showSpacedText:
  35624. var arr = args[0];
  35625. var combinedGlyphs = [];
  35626. var arrLength = arr.length;
  35627. var state = stateManager.state;
  35628. for (i = 0; i < arrLength; ++i) {
  35629. var arrItem = arr[i];
  35630. if (isString(arrItem)) {
  35631. Array.prototype.push.apply(combinedGlyphs,
  35632. self.handleText(arrItem, state));
  35633. } else if (isNum(arrItem)) {
  35634. combinedGlyphs.push(arrItem);
  35635. }
  35636. }
  35637. args[0] = combinedGlyphs;
  35638. fn = OPS.showText;
  35639. break;
  35640. case OPS.nextLineShowText:
  35641. operatorList.addOp(OPS.nextLine);
  35642. args[0] = self.handleText(args[0], stateManager.state);
  35643. fn = OPS.showText;
  35644. break;
  35645. case OPS.nextLineSetSpacingShowText:
  35646. operatorList.addOp(OPS.nextLine);
  35647. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  35648. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  35649. args[0] = self.handleText(args[0], stateManager.state);
  35650. fn = OPS.showText;
  35651. break;
  35652. case OPS.setTextRenderingMode:
  35653. stateManager.state.textRenderingMode = args[0];
  35654. break;
  35655. case OPS.setFillColorSpace:
  35656. stateManager.state.fillColorSpace =
  35657. ColorSpace.parse(args[0], xref, resources);
  35658. continue;
  35659. case OPS.setStrokeColorSpace:
  35660. stateManager.state.strokeColorSpace =
  35661. ColorSpace.parse(args[0], xref, resources);
  35662. continue;
  35663. case OPS.setFillColor:
  35664. cs = stateManager.state.fillColorSpace;
  35665. args = cs.getRgb(args, 0);
  35666. fn = OPS.setFillRGBColor;
  35667. break;
  35668. case OPS.setStrokeColor:
  35669. cs = stateManager.state.strokeColorSpace;
  35670. args = cs.getRgb(args, 0);
  35671. fn = OPS.setStrokeRGBColor;
  35672. break;
  35673. case OPS.setFillGray:
  35674. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  35675. args = ColorSpace.singletons.gray.getRgb(args, 0);
  35676. fn = OPS.setFillRGBColor;
  35677. break;
  35678. case OPS.setStrokeGray:
  35679. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  35680. args = ColorSpace.singletons.gray.getRgb(args, 0);
  35681. fn = OPS.setStrokeRGBColor;
  35682. break;
  35683. case OPS.setFillCMYKColor:
  35684. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  35685. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  35686. fn = OPS.setFillRGBColor;
  35687. break;
  35688. case OPS.setStrokeCMYKColor:
  35689. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  35690. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  35691. fn = OPS.setStrokeRGBColor;
  35692. break;
  35693. case OPS.setFillRGBColor:
  35694. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  35695. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  35696. break;
  35697. case OPS.setStrokeRGBColor:
  35698. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  35699. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  35700. break;
  35701. case OPS.setFillColorN:
  35702. cs = stateManager.state.fillColorSpace;
  35703. if (cs.name === 'Pattern') {
  35704. next(self.handleColorN(operatorList, OPS.setFillColorN, args,
  35705. cs, patterns, resources, task, xref));
  35706. return;
  35707. }
  35708. args = cs.getRgb(args, 0);
  35709. fn = OPS.setFillRGBColor;
  35710. break;
  35711. case OPS.setStrokeColorN:
  35712. cs = stateManager.state.strokeColorSpace;
  35713. if (cs.name === 'Pattern') {
  35714. next(self.handleColorN(operatorList, OPS.setStrokeColorN, args,
  35715. cs, patterns, resources, task, xref));
  35716. return;
  35717. }
  35718. args = cs.getRgb(args, 0);
  35719. fn = OPS.setStrokeRGBColor;
  35720. break;
  35721. case OPS.shadingFill:
  35722. var shadingRes = resources.get('Shading');
  35723. if (!shadingRes) {
  35724. error('No shading resource found');
  35725. }
  35726. var shading = shadingRes.get(args[0].name);
  35727. if (!shading) {
  35728. error('No shading object found');
  35729. }
  35730. var shadingFill = Pattern.parseShading(shading, null, xref,
  35731. resources, self.handler);
  35732. var patternIR = shadingFill.getIR();
  35733. args = [patternIR];
  35734. fn = OPS.shadingFill;
  35735. break;
  35736. case OPS.setGState:
  35737. var dictName = args[0];
  35738. var extGState = resources.get('ExtGState');
  35739. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  35740. break;
  35741. }
  35742. var gState = extGState.get(dictName.name);
  35743. next(self.setGState(resources, gState, operatorList, task, xref,
  35744. stateManager));
  35745. return;
  35746. case OPS.moveTo:
  35747. case OPS.lineTo:
  35748. case OPS.curveTo:
  35749. case OPS.curveTo2:
  35750. case OPS.curveTo3:
  35751. case OPS.closePath:
  35752. self.buildPath(operatorList, fn, args);
  35753. continue;
  35754. case OPS.rectangle:
  35755. self.buildPath(operatorList, fn, args);
  35756. continue;
  35757. case OPS.markPoint:
  35758. case OPS.markPointProps:
  35759. case OPS.beginMarkedContent:
  35760. case OPS.beginMarkedContentProps:
  35761. case OPS.endMarkedContent:
  35762. case OPS.beginCompat:
  35763. case OPS.endCompat:
  35764. // Ignore operators where the corresponding handlers are known to
  35765. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  35766. // serialization errors and is also a bit more efficient.
  35767. // We could also try to serialize all objects in a general way,
  35768. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  35769. // but doing so is meaningless without knowing the semantics.
  35770. continue;
  35771. default:
  35772. // Note: Ignore the operator if it has `Dict` arguments, since
  35773. // those are non-serializable, otherwise postMessage will throw
  35774. // "An object could not be cloned.".
  35775. if (args !== null) {
  35776. for (i = 0, ii = args.length; i < ii; i++) {
  35777. if (args[i] instanceof Dict) {
  35778. break;
  35779. }
  35780. }
  35781. if (i < ii) {
  35782. warn('getOperatorList - ignoring operator: ' + fn);
  35783. continue;
  35784. }
  35785. }
  35786. }
  35787. operatorList.addOp(fn, args);
  35788. }
  35789. if (stop) {
  35790. next(deferred);
  35791. return;
  35792. }
  35793. // Some PDFs don't close all restores inside object/form.
  35794. // Closing those for them.
  35795. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  35796. operatorList.addOp(OPS.restore, []);
  35797. }
  35798. resolve();
  35799. });
  35800. },
  35801. getTextContent:
  35802. function PartialEvaluator_getTextContent(stream, task, resources,
  35803. stateManager,
  35804. normalizeWhitespace,
  35805. combineTextItems) {
  35806. stateManager = (stateManager || new StateManager(new TextState()));
  35807. var WhitespaceRegexp = /\s/g;
  35808. var textContent = {
  35809. items: [],
  35810. styles: Object.create(null)
  35811. };
  35812. var textContentItem = {
  35813. initialized: false,
  35814. str: [],
  35815. width: 0,
  35816. height: 0,
  35817. vertical: false,
  35818. lastAdvanceWidth: 0,
  35819. lastAdvanceHeight: 0,
  35820. textAdvanceScale: 0,
  35821. spaceWidth: 0,
  35822. fakeSpaceMin: Infinity,
  35823. fakeMultiSpaceMin: Infinity,
  35824. fakeMultiSpaceMax: -0,
  35825. textRunBreakAllowed: false,
  35826. transform: null,
  35827. fontName: null
  35828. };
  35829. var SPACE_FACTOR = 0.3;
  35830. var MULTI_SPACE_FACTOR = 1.5;
  35831. var MULTI_SPACE_FACTOR_MAX = 4;
  35832. var self = this;
  35833. var xref = this.xref;
  35834. resources = (xref.fetchIfRef(resources) || Dict.empty);
  35835. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  35836. var xobjs = null;
  35837. var xobjsCache = Object.create(null);
  35838. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  35839. var textState;
  35840. function ensureTextContentItem() {
  35841. if (textContentItem.initialized) {
  35842. return textContentItem;
  35843. }
  35844. var font = textState.font;
  35845. if (!(font.loadedName in textContent.styles)) {
  35846. textContent.styles[font.loadedName] = {
  35847. fontFamily: font.fallbackName,
  35848. ascent: font.ascent,
  35849. descent: font.descent,
  35850. vertical: font.vertical
  35851. };
  35852. }
  35853. textContentItem.fontName = font.loadedName;
  35854. // 9.4.4 Text Space Details
  35855. var tsm = [textState.fontSize * textState.textHScale, 0,
  35856. 0, textState.fontSize,
  35857. 0, textState.textRise];
  35858. if (font.isType3Font &&
  35859. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  35860. textState.fontSize === 1) {
  35861. var glyphHeight = font.bbox[3] - font.bbox[1];
  35862. if (glyphHeight > 0) {
  35863. glyphHeight = glyphHeight * textState.fontMatrix[3];
  35864. tsm[3] *= glyphHeight;
  35865. }
  35866. }
  35867. var trm = Util.transform(textState.ctm,
  35868. Util.transform(textState.textMatrix, tsm));
  35869. textContentItem.transform = trm;
  35870. if (!font.vertical) {
  35871. textContentItem.width = 0;
  35872. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  35873. textContentItem.vertical = false;
  35874. } else {
  35875. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  35876. textContentItem.height = 0;
  35877. textContentItem.vertical = true;
  35878. }
  35879. var a = textState.textLineMatrix[0];
  35880. var b = textState.textLineMatrix[1];
  35881. var scaleLineX = Math.sqrt(a * a + b * b);
  35882. a = textState.ctm[0];
  35883. b = textState.ctm[1];
  35884. var scaleCtmX = Math.sqrt(a * a + b * b);
  35885. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  35886. textContentItem.lastAdvanceWidth = 0;
  35887. textContentItem.lastAdvanceHeight = 0;
  35888. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  35889. if (spaceWidth) {
  35890. textContentItem.spaceWidth = spaceWidth;
  35891. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  35892. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  35893. textContentItem.fakeMultiSpaceMax =
  35894. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  35895. // It's okay for monospace fonts to fake as much space as needed.
  35896. textContentItem.textRunBreakAllowed = !font.isMonospace;
  35897. } else {
  35898. textContentItem.spaceWidth = 0;
  35899. textContentItem.fakeSpaceMin = Infinity;
  35900. textContentItem.fakeMultiSpaceMin = Infinity;
  35901. textContentItem.fakeMultiSpaceMax = 0;
  35902. textContentItem.textRunBreakAllowed = false;
  35903. }
  35904. textContentItem.initialized = true;
  35905. return textContentItem;
  35906. }
  35907. function replaceWhitespace(str) {
  35908. // Replaces all whitespaces with standard spaces (0x20), to avoid
  35909. // alignment issues between the textLayer and the canvas if the text
  35910. // contains e.g. tabs (fixes issue6612.pdf).
  35911. var i = 0, ii = str.length, code;
  35912. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  35913. i++;
  35914. }
  35915. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  35916. }
  35917. function runBidiTransform(textChunk) {
  35918. var str = textChunk.str.join('');
  35919. var bidiResult = bidi(str, -1, textChunk.vertical);
  35920. return {
  35921. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  35922. bidiResult.str),
  35923. dir: bidiResult.dir,
  35924. width: textChunk.width,
  35925. height: textChunk.height,
  35926. transform: textChunk.transform,
  35927. fontName: textChunk.fontName
  35928. };
  35929. }
  35930. function handleSetFont(fontName, fontRef) {
  35931. return self.loadFont(fontName, fontRef, xref, resources).
  35932. then(function (translated) {
  35933. textState.font = translated.font;
  35934. textState.fontMatrix = translated.font.fontMatrix ||
  35935. FONT_IDENTITY_MATRIX;
  35936. });
  35937. }
  35938. function buildTextContentItem(chars) {
  35939. var font = textState.font;
  35940. var textChunk = ensureTextContentItem();
  35941. var width = 0;
  35942. var height = 0;
  35943. var glyphs = font.charsToGlyphs(chars);
  35944. var defaultVMetrics = font.defaultVMetrics;
  35945. for (var i = 0; i < glyphs.length; i++) {
  35946. var glyph = glyphs[i];
  35947. var vMetricX = null;
  35948. var vMetricY = null;
  35949. var glyphWidth = null;
  35950. if (font.vertical) {
  35951. if (glyph.vmetric) {
  35952. glyphWidth = glyph.vmetric[0];
  35953. vMetricX = glyph.vmetric[1];
  35954. vMetricY = glyph.vmetric[2];
  35955. } else {
  35956. glyphWidth = glyph.width;
  35957. vMetricX = glyph.width * 0.5;
  35958. vMetricY = defaultVMetrics[2];
  35959. }
  35960. } else {
  35961. glyphWidth = glyph.width;
  35962. }
  35963. var glyphUnicode = glyph.unicode;
  35964. var NormalizedUnicodes = getNormalizedUnicodes();
  35965. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  35966. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  35967. }
  35968. glyphUnicode = reverseIfRtl(glyphUnicode);
  35969. // The following will calculate the x and y of the individual glyphs.
  35970. // if (font.vertical) {
  35971. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  35972. // textState.fontMatrix[0];
  35973. // tsm[5] -= vMetricY * textState.fontSize *
  35974. // textState.fontMatrix[0];
  35975. // }
  35976. // var trm = Util.transform(textState.textMatrix, tsm);
  35977. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  35978. // var x = pt[0];
  35979. // var y = pt[1];
  35980. var charSpacing = textState.charSpacing;
  35981. if (glyph.isSpace) {
  35982. var wordSpacing = textState.wordSpacing;
  35983. charSpacing += wordSpacing;
  35984. if (wordSpacing > 0) {
  35985. addFakeSpaces(wordSpacing, textChunk.str);
  35986. }
  35987. }
  35988. var tx = 0;
  35989. var ty = 0;
  35990. if (!font.vertical) {
  35991. var w0 = glyphWidth * textState.fontMatrix[0];
  35992. tx = (w0 * textState.fontSize + charSpacing) *
  35993. textState.textHScale;
  35994. width += tx;
  35995. } else {
  35996. var w1 = glyphWidth * textState.fontMatrix[0];
  35997. ty = w1 * textState.fontSize + charSpacing;
  35998. height += ty;
  35999. }
  36000. textState.translateTextMatrix(tx, ty);
  36001. textChunk.str.push(glyphUnicode);
  36002. }
  36003. if (!font.vertical) {
  36004. textChunk.lastAdvanceWidth = width;
  36005. textChunk.width += width * textChunk.textAdvanceScale;
  36006. } else {
  36007. textChunk.lastAdvanceHeight = height;
  36008. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  36009. }
  36010. return textChunk;
  36011. }
  36012. function addFakeSpaces(width, strBuf) {
  36013. if (width < textContentItem.fakeSpaceMin) {
  36014. return;
  36015. }
  36016. if (width < textContentItem.fakeMultiSpaceMin) {
  36017. strBuf.push(' ');
  36018. return;
  36019. }
  36020. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  36021. while (fakeSpaces-- > 0) {
  36022. strBuf.push(' ');
  36023. }
  36024. }
  36025. function flushTextContentItem() {
  36026. if (!textContentItem.initialized) {
  36027. return;
  36028. }
  36029. textContent.items.push(runBidiTransform(textContentItem));
  36030. textContentItem.initialized = false;
  36031. textContentItem.str.length = 0;
  36032. }
  36033. var timeSlotManager = new TimeSlotManager();
  36034. return new Promise(function promiseBody(resolve, reject) {
  36035. var next = function (promise) {
  36036. promise.then(function () {
  36037. try {
  36038. promiseBody(resolve, reject);
  36039. } catch (ex) {
  36040. reject(ex);
  36041. }
  36042. }, reject);
  36043. };
  36044. task.ensureNotTerminated();
  36045. timeSlotManager.reset();
  36046. var stop, operation = {}, args = [];
  36047. while (!(stop = timeSlotManager.check())) {
  36048. // The arguments parsed by read() are not used beyond this loop, so
  36049. // we can reuse the same array on every iteration, thus avoiding
  36050. // unnecessary allocations.
  36051. args.length = 0;
  36052. operation.args = args;
  36053. if (!(preprocessor.read(operation))) {
  36054. break;
  36055. }
  36056. textState = stateManager.state;
  36057. var fn = operation.fn;
  36058. args = operation.args;
  36059. var advance, diff;
  36060. switch (fn | 0) {
  36061. case OPS.setFont:
  36062. // Optimization to ignore multiple identical Tf commands.
  36063. var fontNameArg = args[0].name, fontSizeArg = args[1];
  36064. if (textState.font && fontNameArg === textState.fontName &&
  36065. fontSizeArg === textState.fontSize) {
  36066. break;
  36067. }
  36068. flushTextContentItem();
  36069. textState.fontName = fontNameArg;
  36070. textState.fontSize = fontSizeArg;
  36071. next(handleSetFont(fontNameArg, null));
  36072. return;
  36073. case OPS.setTextRise:
  36074. flushTextContentItem();
  36075. textState.textRise = args[0];
  36076. break;
  36077. case OPS.setHScale:
  36078. flushTextContentItem();
  36079. textState.textHScale = args[0] / 100;
  36080. break;
  36081. case OPS.setLeading:
  36082. flushTextContentItem();
  36083. textState.leading = args[0];
  36084. break;
  36085. case OPS.moveText:
  36086. // Optimization to treat same line movement as advance
  36087. var isSameTextLine = !textState.font ? false :
  36088. ((textState.font.vertical ? args[0] : args[1]) === 0);
  36089. advance = args[0] - args[1];
  36090. if (combineTextItems &&
  36091. isSameTextLine && textContentItem.initialized &&
  36092. advance > 0 &&
  36093. advance <= textContentItem.fakeMultiSpaceMax) {
  36094. textState.translateTextLineMatrix(args[0], args[1]);
  36095. textContentItem.width +=
  36096. (args[0] - textContentItem.lastAdvanceWidth);
  36097. textContentItem.height +=
  36098. (args[1] - textContentItem.lastAdvanceHeight);
  36099. diff = (args[0] - textContentItem.lastAdvanceWidth) -
  36100. (args[1] - textContentItem.lastAdvanceHeight);
  36101. addFakeSpaces(diff, textContentItem.str);
  36102. break;
  36103. }
  36104. flushTextContentItem();
  36105. textState.translateTextLineMatrix(args[0], args[1]);
  36106. textState.textMatrix = textState.textLineMatrix.slice();
  36107. break;
  36108. case OPS.setLeadingMoveText:
  36109. flushTextContentItem();
  36110. textState.leading = -args[1];
  36111. textState.translateTextLineMatrix(args[0], args[1]);
  36112. textState.textMatrix = textState.textLineMatrix.slice();
  36113. break;
  36114. case OPS.nextLine:
  36115. flushTextContentItem();
  36116. textState.carriageReturn();
  36117. break;
  36118. case OPS.setTextMatrix:
  36119. // Optimization to treat same line movement as advance.
  36120. advance = textState.calcTextLineMatrixAdvance(
  36121. args[0], args[1], args[2], args[3], args[4], args[5]);
  36122. if (combineTextItems &&
  36123. advance !== null && textContentItem.initialized &&
  36124. advance.value > 0 &&
  36125. advance.value <= textContentItem.fakeMultiSpaceMax) {
  36126. textState.translateTextLineMatrix(advance.width,
  36127. advance.height);
  36128. textContentItem.width +=
  36129. (advance.width - textContentItem.lastAdvanceWidth);
  36130. textContentItem.height +=
  36131. (advance.height - textContentItem.lastAdvanceHeight);
  36132. diff = (advance.width - textContentItem.lastAdvanceWidth) -
  36133. (advance.height - textContentItem.lastAdvanceHeight);
  36134. addFakeSpaces(diff, textContentItem.str);
  36135. break;
  36136. }
  36137. flushTextContentItem();
  36138. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  36139. args[4], args[5]);
  36140. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  36141. args[4], args[5]);
  36142. break;
  36143. case OPS.setCharSpacing:
  36144. textState.charSpacing = args[0];
  36145. break;
  36146. case OPS.setWordSpacing:
  36147. textState.wordSpacing = args[0];
  36148. break;
  36149. case OPS.beginText:
  36150. flushTextContentItem();
  36151. textState.textMatrix = IDENTITY_MATRIX.slice();
  36152. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  36153. break;
  36154. case OPS.showSpacedText:
  36155. var items = args[0];
  36156. var offset;
  36157. for (var j = 0, jj = items.length; j < jj; j++) {
  36158. if (typeof items[j] === 'string') {
  36159. buildTextContentItem(items[j]);
  36160. } else {
  36161. ensureTextContentItem();
  36162. // PDF Specification 5.3.2 states:
  36163. // The number is expressed in thousandths of a unit of text
  36164. // space.
  36165. // This amount is subtracted from the current horizontal or
  36166. // vertical coordinate, depending on the writing mode.
  36167. // In the default coordinate system, a positive adjustment
  36168. // has the effect of moving the next glyph painted either to
  36169. // the left or down by the given amount.
  36170. advance = items[j] * textState.fontSize / 1000;
  36171. var breakTextRun = false;
  36172. if (textState.font.vertical) {
  36173. offset = advance *
  36174. (textState.textHScale * textState.textMatrix[2] +
  36175. textState.textMatrix[3]);
  36176. textState.translateTextMatrix(0, advance);
  36177. breakTextRun = textContentItem.textRunBreakAllowed &&
  36178. advance > textContentItem.fakeMultiSpaceMax;
  36179. if (!breakTextRun) {
  36180. // Value needs to be added to height to paint down.
  36181. textContentItem.height += offset;
  36182. }
  36183. } else {
  36184. advance = -advance;
  36185. offset = advance * (
  36186. textState.textHScale * textState.textMatrix[0] +
  36187. textState.textMatrix[1]);
  36188. textState.translateTextMatrix(advance, 0);
  36189. breakTextRun = textContentItem.textRunBreakAllowed &&
  36190. advance > textContentItem.fakeMultiSpaceMax;
  36191. if (!breakTextRun) {
  36192. // Value needs to be subtracted from width to paint left.
  36193. textContentItem.width += offset;
  36194. }
  36195. }
  36196. if (breakTextRun) {
  36197. flushTextContentItem();
  36198. } else if (advance > 0) {
  36199. addFakeSpaces(advance, textContentItem.str);
  36200. }
  36201. }
  36202. }
  36203. break;
  36204. case OPS.showText:
  36205. buildTextContentItem(args[0]);
  36206. break;
  36207. case OPS.nextLineShowText:
  36208. flushTextContentItem();
  36209. textState.carriageReturn();
  36210. buildTextContentItem(args[0]);
  36211. break;
  36212. case OPS.nextLineSetSpacingShowText:
  36213. flushTextContentItem();
  36214. textState.wordSpacing = args[0];
  36215. textState.charSpacing = args[1];
  36216. textState.carriageReturn();
  36217. buildTextContentItem(args[2]);
  36218. break;
  36219. case OPS.paintXObject:
  36220. flushTextContentItem();
  36221. if (args[0].code) {
  36222. break;
  36223. }
  36224. if (!xobjs) {
  36225. xobjs = (resources.get('XObject') || Dict.empty);
  36226. }
  36227. var name = args[0].name;
  36228. if (xobjsCache.key === name) {
  36229. if (xobjsCache.texts) {
  36230. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  36231. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  36232. }
  36233. break;
  36234. }
  36235. var xobj = xobjs.get(name);
  36236. if (!xobj) {
  36237. break;
  36238. }
  36239. assert(isStream(xobj), 'XObject should be a stream');
  36240. var type = xobj.dict.get('Subtype');
  36241. assert(isName(type), 'XObject should have a Name subtype');
  36242. if ('Form' !== type.name) {
  36243. xobjsCache.key = name;
  36244. xobjsCache.texts = null;
  36245. break;
  36246. }
  36247. stateManager.save();
  36248. var matrix = xobj.dict.getArray('Matrix');
  36249. if (isArray(matrix) && matrix.length === 6) {
  36250. stateManager.transform(matrix);
  36251. }
  36252. next(self.getTextContent(xobj, task,
  36253. xobj.dict.get('Resources') || resources, stateManager,
  36254. normalizeWhitespace, combineTextItems).then(
  36255. function (formTextContent) {
  36256. Util.appendToArray(textContent.items, formTextContent.items);
  36257. Util.extendObj(textContent.styles, formTextContent.styles);
  36258. stateManager.restore();
  36259. xobjsCache.key = name;
  36260. xobjsCache.texts = formTextContent;
  36261. }));
  36262. return;
  36263. case OPS.setGState:
  36264. flushTextContentItem();
  36265. var dictName = args[0];
  36266. var extGState = resources.get('ExtGState');
  36267. if (!isDict(extGState) || !isName(dictName)) {
  36268. break;
  36269. }
  36270. var gState = extGState.get(dictName.name);
  36271. if (!isDict(gState)) {
  36272. break;
  36273. }
  36274. var gStateFont = gState.get('Font');
  36275. if (gStateFont) {
  36276. textState.fontName = null;
  36277. textState.fontSize = gStateFont[1];
  36278. next(handleSetFont(null, gStateFont[0]));
  36279. return;
  36280. }
  36281. break;
  36282. } // switch
  36283. } // while
  36284. if (stop) {
  36285. next(deferred);
  36286. return;
  36287. }
  36288. flushTextContentItem();
  36289. resolve(textContent);
  36290. });
  36291. },
  36292. extractDataStructures:
  36293. function PartialEvaluator_extractDataStructures(dict, baseDict,
  36294. xref, properties) {
  36295. // 9.10.2
  36296. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  36297. var toUnicodePromise = toUnicode ?
  36298. this.readToUnicode(toUnicode) : Promise.resolve(undefined);
  36299. if (properties.composite) {
  36300. // CIDSystemInfo helps to match CID to glyphs
  36301. var cidSystemInfo = dict.get('CIDSystemInfo');
  36302. if (isDict(cidSystemInfo)) {
  36303. properties.cidSystemInfo = {
  36304. registry: cidSystemInfo.get('Registry'),
  36305. ordering: cidSystemInfo.get('Ordering'),
  36306. supplement: cidSystemInfo.get('Supplement')
  36307. };
  36308. }
  36309. var cidToGidMap = dict.get('CIDToGIDMap');
  36310. if (isStream(cidToGidMap)) {
  36311. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  36312. }
  36313. }
  36314. // Based on 9.6.6 of the spec the encoding can come from multiple places
  36315. // and depends on the font type. The base encoding and differences are
  36316. // read here, but the encoding that is actually used is chosen during
  36317. // glyph mapping in the font.
  36318. // TODO: Loading the built in encoding in the font would allow the
  36319. // differences to be merged in here not require us to hold on to it.
  36320. var differences = [];
  36321. var baseEncodingName = null;
  36322. var encoding;
  36323. if (dict.has('Encoding')) {
  36324. encoding = dict.get('Encoding');
  36325. if (isDict(encoding)) {
  36326. baseEncodingName = encoding.get('BaseEncoding');
  36327. baseEncodingName = (isName(baseEncodingName) ?
  36328. baseEncodingName.name : null);
  36329. // Load the differences between the base and original
  36330. if (encoding.has('Differences')) {
  36331. var diffEncoding = encoding.get('Differences');
  36332. var index = 0;
  36333. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  36334. var data = xref.fetchIfRef(diffEncoding[j]);
  36335. if (isNum(data)) {
  36336. index = data;
  36337. } else if (isName(data)) {
  36338. differences[index++] = data.name;
  36339. } else {
  36340. error('Invalid entry in \'Differences\' array: ' + data);
  36341. }
  36342. }
  36343. }
  36344. } else if (isName(encoding)) {
  36345. baseEncodingName = encoding.name;
  36346. } else {
  36347. error('Encoding is not a Name nor a Dict');
  36348. }
  36349. // According to table 114 if the encoding is a named encoding it must be
  36350. // one of these predefined encodings.
  36351. if ((baseEncodingName !== 'MacRomanEncoding' &&
  36352. baseEncodingName !== 'MacExpertEncoding' &&
  36353. baseEncodingName !== 'WinAnsiEncoding')) {
  36354. baseEncodingName = null;
  36355. }
  36356. }
  36357. if (baseEncodingName) {
  36358. properties.defaultEncoding = getEncoding(baseEncodingName).slice();
  36359. } else {
  36360. encoding = (properties.type === 'TrueType' ?
  36361. WinAnsiEncoding : StandardEncoding);
  36362. // The Symbolic attribute can be misused for regular fonts
  36363. // Heuristic: we have to check if the font is a standard one also
  36364. if (!!(properties.flags & FontFlags.Symbolic)) {
  36365. encoding = MacRomanEncoding;
  36366. if (!properties.file) {
  36367. if (/Symbol/i.test(properties.name)) {
  36368. encoding = SymbolSetEncoding;
  36369. } else if (/Dingbats/i.test(properties.name)) {
  36370. encoding = ZapfDingbatsEncoding;
  36371. }
  36372. }
  36373. }
  36374. properties.defaultEncoding = encoding;
  36375. }
  36376. properties.differences = differences;
  36377. properties.baseEncodingName = baseEncodingName;
  36378. properties.hasEncoding = !!baseEncodingName || differences.length > 0;
  36379. properties.dict = dict;
  36380. return toUnicodePromise.then(function(toUnicode) {
  36381. properties.toUnicode = toUnicode;
  36382. return this.buildToUnicode(properties);
  36383. }.bind(this)).then(function (toUnicode) {
  36384. properties.toUnicode = toUnicode;
  36385. return properties;
  36386. });
  36387. },
  36388. /**
  36389. * Builds a char code to unicode map based on section 9.10 of the spec.
  36390. * @param {Object} properties Font properties object.
  36391. * @return {Promise} A Promise that is resolved with a
  36392. * {ToUnicodeMap|IdentityToUnicodeMap} object.
  36393. */
  36394. buildToUnicode: function PartialEvaluator_buildToUnicode(properties) {
  36395. properties.hasIncludedToUnicodeMap =
  36396. !!properties.toUnicode && properties.toUnicode.length > 0;
  36397. // Section 9.10.2 Mapping Character Codes to Unicode Values
  36398. if (properties.hasIncludedToUnicodeMap) {
  36399. return Promise.resolve(properties.toUnicode);
  36400. }
  36401. // According to the spec if the font is a simple font we should only map
  36402. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  36403. // the differences array only contains adobe standard or symbol set names,
  36404. // in pratice it seems better to always try to create a toUnicode
  36405. // map based of the default encoding.
  36406. var toUnicode, charcode, glyphName;
  36407. if (!properties.composite /* is simple font */) {
  36408. toUnicode = [];
  36409. var encoding = properties.defaultEncoding.slice();
  36410. var baseEncodingName = properties.baseEncodingName;
  36411. // Merge in the differences array.
  36412. var differences = properties.differences;
  36413. for (charcode in differences) {
  36414. glyphName = differences[charcode];
  36415. if (glyphName === '.notdef') {
  36416. // Skip .notdef to prevent rendering errors, e.g. boxes appearing
  36417. // where there should be spaces (fixes issue5256.pdf).
  36418. continue;
  36419. }
  36420. encoding[charcode] = glyphName;
  36421. }
  36422. var glyphsUnicodeMap = getGlyphsUnicode();
  36423. for (charcode in encoding) {
  36424. // a) Map the character code to a character name.
  36425. glyphName = encoding[charcode];
  36426. // b) Look up the character name in the Adobe Glyph List (see the
  36427. // Bibliography) to obtain the corresponding Unicode value.
  36428. if (glyphName === '') {
  36429. continue;
  36430. } else if (glyphsUnicodeMap[glyphName] === undefined) {
  36431. // (undocumented) c) Few heuristics to recognize unknown glyphs
  36432. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  36433. var code = 0;
  36434. switch (glyphName[0]) {
  36435. case 'G': // Gxx glyph
  36436. if (glyphName.length === 3) {
  36437. code = parseInt(glyphName.substr(1), 16);
  36438. }
  36439. break;
  36440. case 'g': // g00xx glyph
  36441. if (glyphName.length === 5) {
  36442. code = parseInt(glyphName.substr(1), 16);
  36443. }
  36444. break;
  36445. case 'C': // Cddd glyph
  36446. case 'c': // cddd glyph
  36447. if (glyphName.length >= 3) {
  36448. code = +glyphName.substr(1);
  36449. }
  36450. break;
  36451. default:
  36452. // 'uniXXXX'/'uXXXX{XX}' glyphs
  36453. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  36454. if (unicode !== -1) {
  36455. code = unicode;
  36456. }
  36457. }
  36458. if (code) {
  36459. // If |baseEncodingName| is one the predefined encodings,
  36460. // and |code| equals |charcode|, using the glyph defined in the
  36461. // baseEncoding seems to yield a better |toUnicode| mapping
  36462. // (fixes issue 5070).
  36463. if (baseEncodingName && code === +charcode) {
  36464. var baseEncoding = getEncoding(baseEncodingName);
  36465. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  36466. toUnicode[charcode] =
  36467. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  36468. continue;
  36469. }
  36470. }
  36471. toUnicode[charcode] = String.fromCharCode(code);
  36472. }
  36473. continue;
  36474. }
  36475. toUnicode[charcode] =
  36476. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  36477. }
  36478. return Promise.resolve(new ToUnicodeMap(toUnicode));
  36479. }
  36480. // If the font is a composite font that uses one of the predefined CMaps
  36481. // listed in Table 118 (except Identity–H and Identity–V) or whose
  36482. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  36483. // Adobe-Korea1 character collection:
  36484. if (properties.composite && (
  36485. (properties.cMap.builtInCMap &&
  36486. !(properties.cMap instanceof IdentityCMap)) ||
  36487. (properties.cidSystemInfo.registry === 'Adobe' &&
  36488. (properties.cidSystemInfo.ordering === 'GB1' ||
  36489. properties.cidSystemInfo.ordering === 'CNS1' ||
  36490. properties.cidSystemInfo.ordering === 'Japan1' ||
  36491. properties.cidSystemInfo.ordering === 'Korea1')))) {
  36492. // Then:
  36493. // a) Map the character code to a character identifier (CID) according
  36494. // to the font’s CMap.
  36495. // b) Obtain the registry and ordering of the character collection used
  36496. // by the font’s CMap (for example, Adobe and Japan1) from its
  36497. // CIDSystemInfo dictionary.
  36498. var registry = properties.cidSystemInfo.registry;
  36499. var ordering = properties.cidSystemInfo.ordering;
  36500. // c) Construct a second CMap name by concatenating the registry and
  36501. // ordering obtained in step (b) in the format registry–ordering–UCS2
  36502. // (for example, Adobe–Japan1–UCS2).
  36503. var ucs2CMapName = Name.get(registry + '-' + ordering + '-UCS2');
  36504. // d) Obtain the CMap with the name constructed in step (c) (available
  36505. // from the ASN Web site; see the Bibliography).
  36506. return CMapFactory.create(ucs2CMapName, this.options.cMapOptions,
  36507. null).then(
  36508. function (ucs2CMap) {
  36509. var cMap = properties.cMap;
  36510. toUnicode = [];
  36511. cMap.forEach(function(charcode, cid) {
  36512. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  36513. // e) Map the CID obtained in step (a) according to the CMap
  36514. // obtained in step (d), producing a Unicode value.
  36515. var ucs2 = ucs2CMap.lookup(cid);
  36516. if (ucs2) {
  36517. toUnicode[charcode] =
  36518. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  36519. ucs2.charCodeAt(1));
  36520. }
  36521. });
  36522. return new ToUnicodeMap(toUnicode);
  36523. });
  36524. }
  36525. // The viewer's choice, just use an identity map.
  36526. return Promise.resolve(new IdentityToUnicodeMap(properties.firstChar,
  36527. properties.lastChar));
  36528. },
  36529. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  36530. var cmapObj = toUnicode;
  36531. if (isName(cmapObj)) {
  36532. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
  36533. function (cmap) {
  36534. if (cmap instanceof IdentityCMap) {
  36535. return new IdentityToUnicodeMap(0, 0xFFFF);
  36536. }
  36537. return new ToUnicodeMap(cmap.getMap());
  36538. });
  36539. } else if (isStream(cmapObj)) {
  36540. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
  36541. function (cmap) {
  36542. if (cmap instanceof IdentityCMap) {
  36543. return new IdentityToUnicodeMap(0, 0xFFFF);
  36544. }
  36545. var map = new Array(cmap.length);
  36546. // Convert UTF-16BE
  36547. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  36548. // to iterate over all keys.
  36549. cmap.forEach(function(charCode, token) {
  36550. var str = [];
  36551. for (var k = 0; k < token.length; k += 2) {
  36552. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  36553. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  36554. str.push(w1);
  36555. continue;
  36556. }
  36557. k += 2;
  36558. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  36559. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  36560. }
  36561. map[charCode] = String.fromCharCode.apply(String, str);
  36562. });
  36563. return new ToUnicodeMap(map);
  36564. });
  36565. }
  36566. return Promise.resolve(null);
  36567. },
  36568. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  36569. // Extract the encoding from the CIDToGIDMap
  36570. var glyphsData = cidToGidStream.getBytes();
  36571. // Set encoding 0 to later verify the font has an encoding
  36572. var result = [];
  36573. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  36574. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  36575. if (glyphID === 0) {
  36576. continue;
  36577. }
  36578. var code = j >> 1;
  36579. result[code] = glyphID;
  36580. }
  36581. return result;
  36582. },
  36583. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  36584. descriptor,
  36585. properties) {
  36586. var glyphsWidths = [];
  36587. var defaultWidth = 0;
  36588. var glyphsVMetrics = [];
  36589. var defaultVMetrics;
  36590. var i, ii, j, jj, start, code, widths;
  36591. if (properties.composite) {
  36592. defaultWidth = dict.get('DW') || 1000;
  36593. widths = dict.get('W');
  36594. if (widths) {
  36595. for (i = 0, ii = widths.length; i < ii; i++) {
  36596. start = widths[i++];
  36597. code = xref.fetchIfRef(widths[i]);
  36598. if (isArray(code)) {
  36599. for (j = 0, jj = code.length; j < jj; j++) {
  36600. glyphsWidths[start++] = code[j];
  36601. }
  36602. } else {
  36603. var width = widths[++i];
  36604. for (j = start; j <= code; j++) {
  36605. glyphsWidths[j] = width;
  36606. }
  36607. }
  36608. }
  36609. }
  36610. if (properties.vertical) {
  36611. var vmetrics = (dict.get('DW2') || [880, -1000]);
  36612. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  36613. vmetrics = dict.get('W2');
  36614. if (vmetrics) {
  36615. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  36616. start = vmetrics[i++];
  36617. code = xref.fetchIfRef(vmetrics[i]);
  36618. if (isArray(code)) {
  36619. for (j = 0, jj = code.length; j < jj; j++) {
  36620. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  36621. }
  36622. } else {
  36623. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  36624. for (j = start; j <= code; j++) {
  36625. glyphsVMetrics[j] = vmetric;
  36626. }
  36627. }
  36628. }
  36629. }
  36630. }
  36631. } else {
  36632. var firstChar = properties.firstChar;
  36633. widths = dict.get('Widths');
  36634. if (widths) {
  36635. j = firstChar;
  36636. for (i = 0, ii = widths.length; i < ii; i++) {
  36637. glyphsWidths[j++] = widths[i];
  36638. }
  36639. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  36640. } else {
  36641. // Trying get the BaseFont metrics (see comment above).
  36642. var baseFontName = dict.get('BaseFont');
  36643. if (isName(baseFontName)) {
  36644. var metrics = this.getBaseFontMetrics(baseFontName.name);
  36645. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  36646. properties);
  36647. defaultWidth = metrics.defaultWidth;
  36648. }
  36649. }
  36650. }
  36651. // Heuristic: detection of monospace font by checking all non-zero widths
  36652. var isMonospace = true;
  36653. var firstWidth = defaultWidth;
  36654. for (var glyph in glyphsWidths) {
  36655. var glyphWidth = glyphsWidths[glyph];
  36656. if (!glyphWidth) {
  36657. continue;
  36658. }
  36659. if (!firstWidth) {
  36660. firstWidth = glyphWidth;
  36661. continue;
  36662. }
  36663. if (firstWidth !== glyphWidth) {
  36664. isMonospace = false;
  36665. break;
  36666. }
  36667. }
  36668. if (isMonospace) {
  36669. properties.flags |= FontFlags.FixedPitch;
  36670. }
  36671. properties.defaultWidth = defaultWidth;
  36672. properties.widths = glyphsWidths;
  36673. properties.defaultVMetrics = defaultVMetrics;
  36674. properties.vmetrics = glyphsVMetrics;
  36675. },
  36676. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  36677. // Simulating descriptor flags attribute
  36678. var fontNameWoStyle = baseFontName.split('-')[0];
  36679. return (fontNameWoStyle in getSerifFonts()) ||
  36680. (fontNameWoStyle.search(/serif/gi) !== -1);
  36681. },
  36682. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  36683. var defaultWidth = 0;
  36684. var widths = [];
  36685. var monospace = false;
  36686. var stdFontMap = getStdFontMap();
  36687. var lookupName = (stdFontMap[name] || name);
  36688. var Metrics = getMetrics();
  36689. if (!(lookupName in Metrics)) {
  36690. // Use default fonts for looking up font metrics if the passed
  36691. // font is not a base font
  36692. if (this.isSerifFont(name)) {
  36693. lookupName = 'Times-Roman';
  36694. } else {
  36695. lookupName = 'Helvetica';
  36696. }
  36697. }
  36698. var glyphWidths = Metrics[lookupName];
  36699. if (isNum(glyphWidths)) {
  36700. defaultWidth = glyphWidths;
  36701. monospace = true;
  36702. } else {
  36703. widths = glyphWidths(); // expand lazy widths array
  36704. }
  36705. return {
  36706. defaultWidth: defaultWidth,
  36707. monospace: monospace,
  36708. widths: widths
  36709. };
  36710. },
  36711. buildCharCodeToWidth:
  36712. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  36713. properties) {
  36714. var widths = Object.create(null);
  36715. var differences = properties.differences;
  36716. var encoding = properties.defaultEncoding;
  36717. for (var charCode = 0; charCode < 256; charCode++) {
  36718. if (charCode in differences &&
  36719. widthsByGlyphName[differences[charCode]]) {
  36720. widths[charCode] = widthsByGlyphName[differences[charCode]];
  36721. continue;
  36722. }
  36723. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  36724. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  36725. continue;
  36726. }
  36727. }
  36728. return widths;
  36729. },
  36730. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  36731. var baseDict = dict;
  36732. var type = dict.get('Subtype');
  36733. assert(isName(type), 'invalid font Subtype');
  36734. var composite = false;
  36735. var uint8array;
  36736. if (type.name === 'Type0') {
  36737. // If font is a composite
  36738. // - get the descendant font
  36739. // - set the type according to the descendant font
  36740. // - get the FontDescriptor from the descendant font
  36741. var df = dict.get('DescendantFonts');
  36742. if (!df) {
  36743. error('Descendant fonts are not specified');
  36744. }
  36745. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  36746. type = dict.get('Subtype');
  36747. assert(isName(type), 'invalid font Subtype');
  36748. composite = true;
  36749. }
  36750. var descriptor = dict.get('FontDescriptor');
  36751. if (descriptor) {
  36752. var hash = new MurmurHash3_64();
  36753. var encoding = baseDict.getRaw('Encoding');
  36754. if (isName(encoding)) {
  36755. hash.update(encoding.name);
  36756. } else if (isRef(encoding)) {
  36757. hash.update(encoding.toString());
  36758. } else if (isDict(encoding)) {
  36759. var keys = encoding.getKeys();
  36760. for (var i = 0, ii = keys.length; i < ii; i++) {
  36761. var entry = encoding.getRaw(keys[i]);
  36762. if (isName(entry)) {
  36763. hash.update(entry.name);
  36764. } else if (isRef(entry)) {
  36765. hash.update(entry.toString());
  36766. } else if (isArray(entry)) { // 'Differences' entry.
  36767. // Ideally we should check the contents of the array, but to avoid
  36768. // parsing it here and then again in |extractDataStructures|,
  36769. // we only use the array length for now (fixes bug1157493.pdf).
  36770. hash.update(entry.length.toString());
  36771. }
  36772. }
  36773. }
  36774. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  36775. if (isStream(toUnicode)) {
  36776. var stream = toUnicode.str || toUnicode;
  36777. uint8array = stream.buffer ?
  36778. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  36779. new Uint8Array(stream.bytes.buffer,
  36780. stream.start, stream.end - stream.start);
  36781. hash.update(uint8array);
  36782. } else if (isName(toUnicode)) {
  36783. hash.update(toUnicode.name);
  36784. }
  36785. var widths = dict.get('Widths') || baseDict.get('Widths');
  36786. if (widths) {
  36787. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  36788. hash.update(uint8array);
  36789. }
  36790. }
  36791. return {
  36792. descriptor: descriptor,
  36793. dict: dict,
  36794. baseDict: baseDict,
  36795. composite: composite,
  36796. type: type.name,
  36797. hash: hash ? hash.hexdigest() : ''
  36798. };
  36799. },
  36800. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  36801. xref) {
  36802. var baseDict = preEvaluatedFont.baseDict;
  36803. var dict = preEvaluatedFont.dict;
  36804. var composite = preEvaluatedFont.composite;
  36805. var descriptor = preEvaluatedFont.descriptor;
  36806. var type = preEvaluatedFont.type;
  36807. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  36808. var cMapOptions = this.options.cMapOptions;
  36809. var properties;
  36810. if (!descriptor) {
  36811. if (type === 'Type3') {
  36812. // FontDescriptor is only required for Type3 fonts when the document
  36813. // is a tagged pdf. Create a barbebones one to get by.
  36814. descriptor = new Dict(null);
  36815. descriptor.set('FontName', Name.get(type));
  36816. descriptor.set('FontBBox', dict.getArray('FontBBox'));
  36817. } else {
  36818. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  36819. // FontDescriptor was not required.
  36820. // This case is here for compatibility.
  36821. var baseFontName = dict.get('BaseFont');
  36822. if (!isName(baseFontName)) {
  36823. error('Base font is not specified');
  36824. }
  36825. // Using base font name as a font name.
  36826. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  36827. var metrics = this.getBaseFontMetrics(baseFontName);
  36828. // Simulating descriptor flags attribute
  36829. var fontNameWoStyle = baseFontName.split('-')[0];
  36830. var flags =
  36831. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  36832. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  36833. (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic :
  36834. FontFlags.Nonsymbolic);
  36835. properties = {
  36836. type: type,
  36837. name: baseFontName,
  36838. widths: metrics.widths,
  36839. defaultWidth: metrics.defaultWidth,
  36840. flags: flags,
  36841. firstChar: 0,
  36842. lastChar: maxCharIndex
  36843. };
  36844. return this.extractDataStructures(dict, dict, xref, properties).then(
  36845. function (properties) {
  36846. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  36847. properties);
  36848. return new Font(baseFontName, null, properties);
  36849. }.bind(this));
  36850. }
  36851. }
  36852. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  36853. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  36854. // to ignore this rule when a variant of a standard font is used.
  36855. // TODO Fill the width array depending on which of the base font this is
  36856. // a variant.
  36857. var firstChar = (dict.get('FirstChar') || 0);
  36858. var lastChar = (dict.get('LastChar') || maxCharIndex);
  36859. var fontName = descriptor.get('FontName');
  36860. var baseFont = dict.get('BaseFont');
  36861. // Some bad PDFs have a string as the font name.
  36862. if (isString(fontName)) {
  36863. fontName = Name.get(fontName);
  36864. }
  36865. if (isString(baseFont)) {
  36866. baseFont = Name.get(baseFont);
  36867. }
  36868. if (type !== 'Type3') {
  36869. var fontNameStr = fontName && fontName.name;
  36870. var baseFontStr = baseFont && baseFont.name;
  36871. if (fontNameStr !== baseFontStr) {
  36872. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  36873. '" but should be the same as the Font\'s BaseFont "' +
  36874. baseFontStr + '"');
  36875. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  36876. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  36877. if (fontNameStr && baseFontStr &&
  36878. baseFontStr.indexOf(fontNameStr) === 0) {
  36879. fontName = baseFont;
  36880. }
  36881. }
  36882. }
  36883. fontName = (fontName || baseFont);
  36884. assert(isName(fontName), 'invalid font name');
  36885. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  36886. if (fontFile) {
  36887. if (fontFile.dict) {
  36888. var subtype = fontFile.dict.get('Subtype');
  36889. if (subtype) {
  36890. subtype = subtype.name;
  36891. }
  36892. var length1 = fontFile.dict.get('Length1');
  36893. var length2 = fontFile.dict.get('Length2');
  36894. var length3 = fontFile.dict.get('Length3');
  36895. }
  36896. }
  36897. properties = {
  36898. type: type,
  36899. name: fontName.name,
  36900. subtype: subtype,
  36901. file: fontFile,
  36902. length1: length1,
  36903. length2: length2,
  36904. length3: length3,
  36905. loadedName: baseDict.loadedName,
  36906. composite: composite,
  36907. wideChars: composite,
  36908. fixedPitch: false,
  36909. fontMatrix: (dict.getArray('FontMatrix') || FONT_IDENTITY_MATRIX),
  36910. firstChar: firstChar || 0,
  36911. lastChar: (lastChar || maxCharIndex),
  36912. bbox: descriptor.getArray('FontBBox'),
  36913. ascent: descriptor.get('Ascent'),
  36914. descent: descriptor.get('Descent'),
  36915. xHeight: descriptor.get('XHeight'),
  36916. capHeight: descriptor.get('CapHeight'),
  36917. flags: descriptor.get('Flags'),
  36918. italicAngle: descriptor.get('ItalicAngle'),
  36919. coded: false
  36920. };
  36921. var cMapPromise;
  36922. if (composite) {
  36923. var cidEncoding = baseDict.get('Encoding');
  36924. if (isName(cidEncoding)) {
  36925. properties.cidEncoding = cidEncoding.name;
  36926. }
  36927. cMapPromise = CMapFactory.create(cidEncoding, cMapOptions, null).then(
  36928. function (cMap) {
  36929. properties.cMap = cMap;
  36930. properties.vertical = properties.cMap.vertical;
  36931. });
  36932. } else {
  36933. cMapPromise = Promise.resolve(undefined);
  36934. }
  36935. return cMapPromise.then(function () {
  36936. return this.extractDataStructures(dict, baseDict, xref, properties);
  36937. }.bind(this)).then(function (properties) {
  36938. this.extractWidths(dict, xref, descriptor, properties);
  36939. if (type === 'Type3') {
  36940. properties.isType3Font = true;
  36941. }
  36942. return new Font(fontName.name, fontFile, properties);
  36943. }.bind(this));
  36944. }
  36945. };
  36946. return PartialEvaluator;
  36947. })();
  36948. var TranslatedFont = (function TranslatedFontClosure() {
  36949. function TranslatedFont(loadedName, font, dict) {
  36950. this.loadedName = loadedName;
  36951. this.font = font;
  36952. this.dict = dict;
  36953. this.type3Loaded = null;
  36954. this.sent = false;
  36955. }
  36956. TranslatedFont.prototype = {
  36957. send: function (handler) {
  36958. if (this.sent) {
  36959. return;
  36960. }
  36961. var fontData = this.font.exportData();
  36962. handler.send('commonobj', [
  36963. this.loadedName,
  36964. 'Font',
  36965. fontData
  36966. ]);
  36967. this.sent = true;
  36968. },
  36969. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  36970. assert(this.font.isType3Font);
  36971. if (this.type3Loaded) {
  36972. return this.type3Loaded;
  36973. }
  36974. var translatedFont = this.font;
  36975. var loadCharProcsPromise = Promise.resolve();
  36976. var charProcs = this.dict.get('CharProcs');
  36977. var fontResources = this.dict.get('Resources') || resources;
  36978. var charProcKeys = charProcs.getKeys();
  36979. var charProcOperatorList = Object.create(null);
  36980. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  36981. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  36982. var glyphStream = charProcs.get(key);
  36983. var operatorList = new OperatorList();
  36984. return evaluator.getOperatorList(glyphStream, task, fontResources,
  36985. operatorList).then(function () {
  36986. charProcOperatorList[key] = operatorList.getIR();
  36987. // Add the dependencies to the parent operator list so they are
  36988. // resolved before sub operator list is executed synchronously.
  36989. parentOperatorList.addDependencies(operatorList.dependencies);
  36990. }, function (reason) {
  36991. warn('Type3 font resource \"' + key + '\" is not available');
  36992. var operatorList = new OperatorList();
  36993. charProcOperatorList[key] = operatorList.getIR();
  36994. });
  36995. }.bind(this, charProcKeys[i]));
  36996. }
  36997. this.type3Loaded = loadCharProcsPromise.then(function () {
  36998. translatedFont.charProcOperatorList = charProcOperatorList;
  36999. });
  37000. return this.type3Loaded;
  37001. }
  37002. };
  37003. return TranslatedFont;
  37004. })();
  37005. var OperatorList = (function OperatorListClosure() {
  37006. var CHUNK_SIZE = 1000;
  37007. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  37008. function getTransfers(queue) {
  37009. var transfers = [];
  37010. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  37011. for (var i = 0, ii = queue.length; i < ii; i++) {
  37012. switch (fnArray[i]) {
  37013. case OPS.paintInlineImageXObject:
  37014. case OPS.paintInlineImageXObjectGroup:
  37015. case OPS.paintImageMaskXObject:
  37016. var arg = argsArray[i][0]; // first param in imgData
  37017. if (!arg.cached) {
  37018. transfers.push(arg.data.buffer);
  37019. }
  37020. break;
  37021. }
  37022. }
  37023. return transfers;
  37024. }
  37025. function OperatorList(intent, messageHandler, pageIndex) {
  37026. this.messageHandler = messageHandler;
  37027. this.fnArray = [];
  37028. this.argsArray = [];
  37029. this.dependencies = Object.create(null);
  37030. this._totalLength = 0;
  37031. this.pageIndex = pageIndex;
  37032. this.intent = intent;
  37033. }
  37034. OperatorList.prototype = {
  37035. get length() {
  37036. return this.argsArray.length;
  37037. },
  37038. /**
  37039. * @returns {number} The total length of the entire operator list,
  37040. * since `this.length === 0` after flushing.
  37041. */
  37042. get totalLength() {
  37043. return (this._totalLength + this.length);
  37044. },
  37045. addOp: function(fn, args) {
  37046. this.fnArray.push(fn);
  37047. this.argsArray.push(args);
  37048. if (this.messageHandler) {
  37049. if (this.fnArray.length >= CHUNK_SIZE) {
  37050. this.flush();
  37051. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  37052. (fn === OPS.restore || fn === OPS.endText)) {
  37053. // heuristic to flush on boundary of restore or endText
  37054. this.flush();
  37055. }
  37056. }
  37057. },
  37058. addDependency: function(dependency) {
  37059. if (dependency in this.dependencies) {
  37060. return;
  37061. }
  37062. this.dependencies[dependency] = true;
  37063. this.addOp(OPS.dependency, [dependency]);
  37064. },
  37065. addDependencies: function(dependencies) {
  37066. for (var key in dependencies) {
  37067. this.addDependency(key);
  37068. }
  37069. },
  37070. addOpList: function(opList) {
  37071. Util.extendObj(this.dependencies, opList.dependencies);
  37072. for (var i = 0, ii = opList.length; i < ii; i++) {
  37073. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  37074. }
  37075. },
  37076. getIR: function() {
  37077. return {
  37078. fnArray: this.fnArray,
  37079. argsArray: this.argsArray,
  37080. length: this.length
  37081. };
  37082. },
  37083. flush: function(lastChunk) {
  37084. if (this.intent !== 'oplist') {
  37085. new QueueOptimizer().optimize(this);
  37086. }
  37087. var transfers = getTransfers(this);
  37088. var length = this.length;
  37089. this._totalLength += length;
  37090. this.messageHandler.send('RenderPageChunk', {
  37091. operatorList: {
  37092. fnArray: this.fnArray,
  37093. argsArray: this.argsArray,
  37094. lastChunk: lastChunk,
  37095. length: length
  37096. },
  37097. pageIndex: this.pageIndex,
  37098. intent: this.intent
  37099. }, transfers);
  37100. this.dependencies = Object.create(null);
  37101. this.fnArray.length = 0;
  37102. this.argsArray.length = 0;
  37103. }
  37104. };
  37105. return OperatorList;
  37106. })();
  37107. var StateManager = (function StateManagerClosure() {
  37108. function StateManager(initialState) {
  37109. this.state = initialState;
  37110. this.stateStack = [];
  37111. }
  37112. StateManager.prototype = {
  37113. save: function () {
  37114. var old = this.state;
  37115. this.stateStack.push(this.state);
  37116. this.state = old.clone();
  37117. },
  37118. restore: function () {
  37119. var prev = this.stateStack.pop();
  37120. if (prev) {
  37121. this.state = prev;
  37122. }
  37123. },
  37124. transform: function (args) {
  37125. this.state.ctm = Util.transform(this.state.ctm, args);
  37126. }
  37127. };
  37128. return StateManager;
  37129. })();
  37130. var TextState = (function TextStateClosure() {
  37131. function TextState() {
  37132. this.ctm = new Float32Array(IDENTITY_MATRIX);
  37133. this.fontName = null;
  37134. this.fontSize = 0;
  37135. this.font = null;
  37136. this.fontMatrix = FONT_IDENTITY_MATRIX;
  37137. this.textMatrix = IDENTITY_MATRIX.slice();
  37138. this.textLineMatrix = IDENTITY_MATRIX.slice();
  37139. this.charSpacing = 0;
  37140. this.wordSpacing = 0;
  37141. this.leading = 0;
  37142. this.textHScale = 1;
  37143. this.textRise = 0;
  37144. }
  37145. TextState.prototype = {
  37146. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  37147. var m = this.textMatrix;
  37148. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  37149. },
  37150. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  37151. var m = this.textLineMatrix;
  37152. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  37153. },
  37154. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  37155. var m = this.textMatrix;
  37156. m[4] = m[0] * x + m[2] * y + m[4];
  37157. m[5] = m[1] * x + m[3] * y + m[5];
  37158. },
  37159. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  37160. var m = this.textLineMatrix;
  37161. m[4] = m[0] * x + m[2] * y + m[4];
  37162. m[5] = m[1] * x + m[3] * y + m[5];
  37163. },
  37164. calcTextLineMatrixAdvance:
  37165. function TextState_calcTextLineMatrixAdvance(a, b, c, d, e, f) {
  37166. var font = this.font;
  37167. if (!font) {
  37168. return null;
  37169. }
  37170. var m = this.textLineMatrix;
  37171. if (!(a === m[0] && b === m[1] && c === m[2] && d === m[3])) {
  37172. return null;
  37173. }
  37174. var txDiff = e - m[4], tyDiff = f - m[5];
  37175. if ((font.vertical && txDiff !== 0) || (!font.vertical && tyDiff !== 0)) {
  37176. return null;
  37177. }
  37178. var tx, ty, denominator = a * d - b * c;
  37179. if (font.vertical) {
  37180. tx = -tyDiff * c / denominator;
  37181. ty = tyDiff * a / denominator;
  37182. } else {
  37183. tx = txDiff * d / denominator;
  37184. ty = -txDiff * b / denominator;
  37185. }
  37186. return { width: tx, height: ty, value: (font.vertical ? ty : tx), };
  37187. },
  37188. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  37189. // 9.4.4 Text Space Details
  37190. var tsm = [this.fontSize * this.textHScale, 0,
  37191. 0, this.fontSize,
  37192. 0, this.textRise];
  37193. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  37194. },
  37195. carriageReturn: function TextState_carriageReturn() {
  37196. this.translateTextLineMatrix(0, -this.leading);
  37197. this.textMatrix = this.textLineMatrix.slice();
  37198. },
  37199. clone: function TextState_clone() {
  37200. var clone = Object.create(this);
  37201. clone.textMatrix = this.textMatrix.slice();
  37202. clone.textLineMatrix = this.textLineMatrix.slice();
  37203. clone.fontMatrix = this.fontMatrix.slice();
  37204. return clone;
  37205. }
  37206. };
  37207. return TextState;
  37208. })();
  37209. var EvalState = (function EvalStateClosure() {
  37210. function EvalState() {
  37211. this.ctm = new Float32Array(IDENTITY_MATRIX);
  37212. this.font = null;
  37213. this.textRenderingMode = TextRenderingMode.FILL;
  37214. this.fillColorSpace = ColorSpace.singletons.gray;
  37215. this.strokeColorSpace = ColorSpace.singletons.gray;
  37216. }
  37217. EvalState.prototype = {
  37218. clone: function CanvasExtraState_clone() {
  37219. return Object.create(this);
  37220. },
  37221. };
  37222. return EvalState;
  37223. })();
  37224. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  37225. // Specifies properties for each command
  37226. //
  37227. // If variableArgs === true: [0, `numArgs`] expected
  37228. // If variableArgs === false: exactly `numArgs` expected
  37229. var getOPMap = getLookupTableFactory(function (t) {
  37230. // Graphic state
  37231. t['w'] = { id: OPS.setLineWidth, numArgs: 1, variableArgs: false };
  37232. t['J'] = { id: OPS.setLineCap, numArgs: 1, variableArgs: false };
  37233. t['j'] = { id: OPS.setLineJoin, numArgs: 1, variableArgs: false };
  37234. t['M'] = { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false };
  37235. t['d'] = { id: OPS.setDash, numArgs: 2, variableArgs: false };
  37236. t['ri'] = { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false };
  37237. t['i'] = { id: OPS.setFlatness, numArgs: 1, variableArgs: false };
  37238. t['gs'] = { id: OPS.setGState, numArgs: 1, variableArgs: false };
  37239. t['q'] = { id: OPS.save, numArgs: 0, variableArgs: false };
  37240. t['Q'] = { id: OPS.restore, numArgs: 0, variableArgs: false };
  37241. t['cm'] = { id: OPS.transform, numArgs: 6, variableArgs: false };
  37242. // Path
  37243. t['m'] = { id: OPS.moveTo, numArgs: 2, variableArgs: false };
  37244. t['l'] = { id: OPS.lineTo, numArgs: 2, variableArgs: false };
  37245. t['c'] = { id: OPS.curveTo, numArgs: 6, variableArgs: false };
  37246. t['v'] = { id: OPS.curveTo2, numArgs: 4, variableArgs: false };
  37247. t['y'] = { id: OPS.curveTo3, numArgs: 4, variableArgs: false };
  37248. t['h'] = { id: OPS.closePath, numArgs: 0, variableArgs: false };
  37249. t['re'] = { id: OPS.rectangle, numArgs: 4, variableArgs: false };
  37250. t['S'] = { id: OPS.stroke, numArgs: 0, variableArgs: false };
  37251. t['s'] = { id: OPS.closeStroke, numArgs: 0, variableArgs: false };
  37252. t['f'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  37253. t['F'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  37254. t['f*'] = { id: OPS.eoFill, numArgs: 0, variableArgs: false };
  37255. t['B'] = { id: OPS.fillStroke, numArgs: 0, variableArgs: false };
  37256. t['B*'] = { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false };
  37257. t['b'] = { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false };
  37258. t['b*'] = { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false };
  37259. t['n'] = { id: OPS.endPath, numArgs: 0, variableArgs: false };
  37260. // Clipping
  37261. t['W'] = { id: OPS.clip, numArgs: 0, variableArgs: false };
  37262. t['W*'] = { id: OPS.eoClip, numArgs: 0, variableArgs: false };
  37263. // Text
  37264. t['BT'] = { id: OPS.beginText, numArgs: 0, variableArgs: false };
  37265. t['ET'] = { id: OPS.endText, numArgs: 0, variableArgs: false };
  37266. t['Tc'] = { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false };
  37267. t['Tw'] = { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false };
  37268. t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false };
  37269. t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false };
  37270. t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false };
  37271. t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false };
  37272. t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false };
  37273. t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false };
  37274. t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false };
  37275. t['Tm'] = { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false };
  37276. t['T*'] = { id: OPS.nextLine, numArgs: 0, variableArgs: false };
  37277. t['Tj'] = { id: OPS.showText, numArgs: 1, variableArgs: false };
  37278. t['TJ'] = { id: OPS.showSpacedText, numArgs: 1, variableArgs: false };
  37279. t['\''] = { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false };
  37280. t['"'] = { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  37281. variableArgs: false };
  37282. // Type3 fonts
  37283. t['d0'] = { id: OPS.setCharWidth, numArgs: 2, variableArgs: false };
  37284. t['d1'] = { id: OPS.setCharWidthAndBounds, numArgs: 6,
  37285. variableArgs: false };
  37286. // Color
  37287. t['CS'] = { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false };
  37288. t['cs'] = { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false };
  37289. t['SC'] = { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true };
  37290. t['SCN'] = { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true };
  37291. t['sc'] = { id: OPS.setFillColor, numArgs: 4, variableArgs: true };
  37292. t['scn'] = { id: OPS.setFillColorN, numArgs: 33, variableArgs: true };
  37293. t['G'] = { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false };
  37294. t['g'] = { id: OPS.setFillGray, numArgs: 1, variableArgs: false };
  37295. t['RG'] = { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false };
  37296. t['rg'] = { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false };
  37297. t['K'] = { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false };
  37298. t['k'] = { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false };
  37299. // Shading
  37300. t['sh'] = { id: OPS.shadingFill, numArgs: 1, variableArgs: false };
  37301. // Images
  37302. t['BI'] = { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false };
  37303. t['ID'] = { id: OPS.beginImageData, numArgs: 0, variableArgs: false };
  37304. t['EI'] = { id: OPS.endInlineImage, numArgs: 1, variableArgs: false };
  37305. // XObjects
  37306. t['Do'] = { id: OPS.paintXObject, numArgs: 1, variableArgs: false };
  37307. t['MP'] = { id: OPS.markPoint, numArgs: 1, variableArgs: false };
  37308. t['DP'] = { id: OPS.markPointProps, numArgs: 2, variableArgs: false };
  37309. t['BMC'] = { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false };
  37310. t['BDC'] = { id: OPS.beginMarkedContentProps, numArgs: 2,
  37311. variableArgs: false };
  37312. t['EMC'] = { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false };
  37313. // Compatibility
  37314. t['BX'] = { id: OPS.beginCompat, numArgs: 0, variableArgs: false };
  37315. t['EX'] = { id: OPS.endCompat, numArgs: 0, variableArgs: false };
  37316. // (reserved partial commands for the lexer)
  37317. t['BM'] = null;
  37318. t['BD'] = null;
  37319. t['true'] = null;
  37320. t['fa'] = null;
  37321. t['fal'] = null;
  37322. t['fals'] = null;
  37323. t['false'] = null;
  37324. t['nu'] = null;
  37325. t['nul'] = null;
  37326. t['null'] = null;
  37327. });
  37328. function EvaluatorPreprocessor(stream, xref, stateManager) {
  37329. this.opMap = getOPMap();
  37330. // TODO(mduan): pass array of knownCommands rather than this.opMap
  37331. // dictionary
  37332. this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
  37333. this.stateManager = stateManager;
  37334. this.nonProcessedArgs = [];
  37335. }
  37336. EvaluatorPreprocessor.prototype = {
  37337. get savedStatesDepth() {
  37338. return this.stateManager.stateStack.length;
  37339. },
  37340. // |operation| is an object with two fields:
  37341. //
  37342. // - |fn| is an out param.
  37343. //
  37344. // - |args| is an inout param. On entry, it should have one of two values.
  37345. //
  37346. // - An empty array. This indicates that the caller is providing the
  37347. // array in which the args will be stored in. The caller should use
  37348. // this value if it can reuse a single array for each call to read().
  37349. //
  37350. // - |null|. This indicates that the caller needs this function to create
  37351. // the array in which any args are stored in. If there are zero args,
  37352. // this function will leave |operation.args| as |null| (thus avoiding
  37353. // allocations that would occur if we used an empty array to represent
  37354. // zero arguments). Otherwise, it will replace |null| with a new array
  37355. // containing the arguments. The caller should use this value if it
  37356. // cannot reuse an array for each call to read().
  37357. //
  37358. // These two modes are present because this function is very hot and so
  37359. // avoiding allocations where possible is worthwhile.
  37360. //
  37361. read: function EvaluatorPreprocessor_read(operation) {
  37362. var args = operation.args;
  37363. while (true) {
  37364. var obj = this.parser.getObj();
  37365. if (isCmd(obj)) {
  37366. var cmd = obj.cmd;
  37367. // Check that the command is valid
  37368. var opSpec = this.opMap[cmd];
  37369. if (!opSpec) {
  37370. warn('Unknown command "' + cmd + '"');
  37371. continue;
  37372. }
  37373. var fn = opSpec.id;
  37374. var numArgs = opSpec.numArgs;
  37375. var argsLength = args !== null ? args.length : 0;
  37376. if (!opSpec.variableArgs) {
  37377. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  37378. if (argsLength !== numArgs) {
  37379. var nonProcessedArgs = this.nonProcessedArgs;
  37380. while (argsLength > numArgs) {
  37381. nonProcessedArgs.push(args.shift());
  37382. argsLength--;
  37383. }
  37384. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  37385. if (!args) {
  37386. args = [];
  37387. }
  37388. args.unshift(nonProcessedArgs.pop());
  37389. argsLength++;
  37390. }
  37391. }
  37392. if (argsLength < numArgs) {
  37393. // If we receive too few args, it's not possible to possible
  37394. // to execute the command, so skip the command
  37395. info('Command ' + fn + ': because expected ' +
  37396. numArgs + ' args, but received ' + argsLength +
  37397. ' args; skipping');
  37398. args = null;
  37399. continue;
  37400. }
  37401. } else if (argsLength > numArgs) {
  37402. info('Command ' + fn + ': expected [0,' + numArgs +
  37403. '] args, but received ' + argsLength + ' args');
  37404. }
  37405. // TODO figure out how to type-check vararg functions
  37406. this.preprocessCommand(fn, args);
  37407. operation.fn = fn;
  37408. operation.args = args;
  37409. return true;
  37410. } else {
  37411. if (isEOF(obj)) {
  37412. return false; // no more commands
  37413. }
  37414. // argument
  37415. if (obj !== null) {
  37416. if (!args) {
  37417. args = [];
  37418. }
  37419. args.push(obj);
  37420. assert(args.length <= 33, 'Too many arguments');
  37421. }
  37422. }
  37423. }
  37424. },
  37425. preprocessCommand:
  37426. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  37427. switch (fn | 0) {
  37428. case OPS.save:
  37429. this.stateManager.save();
  37430. break;
  37431. case OPS.restore:
  37432. this.stateManager.restore();
  37433. break;
  37434. case OPS.transform:
  37435. this.stateManager.transform(args);
  37436. break;
  37437. }
  37438. }
  37439. };
  37440. return EvaluatorPreprocessor;
  37441. })();
  37442. var QueueOptimizer = (function QueueOptimizerClosure() {
  37443. function addState(parentState, pattern, fn) {
  37444. var state = parentState;
  37445. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  37446. var item = pattern[i];
  37447. state = (state[item] || (state[item] = []));
  37448. }
  37449. state[pattern[pattern.length - 1]] = fn;
  37450. }
  37451. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  37452. argsArray) {
  37453. // Handles special case of mainly LaTeX documents which use image masks to
  37454. // draw lines with the current fill style.
  37455. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  37456. // have been found at iFirstSave.
  37457. var iFirstPIMXO = iFirstSave + 2;
  37458. for (var i = 0; i < count; i++) {
  37459. var arg = argsArray[iFirstPIMXO + 4 * i];
  37460. var imageMask = arg.length === 1 && arg[0];
  37461. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  37462. (!imageMask.data.length ||
  37463. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  37464. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  37465. continue;
  37466. }
  37467. break;
  37468. }
  37469. return count - i;
  37470. }
  37471. var InitialState = [];
  37472. // This replaces (save, transform, paintInlineImageXObject, restore)+
  37473. // sequences with one |paintInlineImageXObjectGroup| operation.
  37474. addState(InitialState,
  37475. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  37476. function foundInlineImageGroup(context) {
  37477. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  37478. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  37479. var MAX_WIDTH = 1000;
  37480. var IMAGE_PADDING = 1;
  37481. var fnArray = context.fnArray, argsArray = context.argsArray;
  37482. var curr = context.iCurr;
  37483. var iFirstSave = curr - 3;
  37484. var iFirstTransform = curr - 2;
  37485. var iFirstPIIXO = curr - 1;
  37486. // Look for the quartets.
  37487. var i = iFirstSave + 4;
  37488. var ii = fnArray.length;
  37489. while (i + 3 < ii) {
  37490. if (fnArray[i] !== OPS.save ||
  37491. fnArray[i + 1] !== OPS.transform ||
  37492. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  37493. fnArray[i + 3] !== OPS.restore) {
  37494. break; // ops don't match
  37495. }
  37496. i += 4;
  37497. }
  37498. // At this point, i is the index of the first op past the last valid
  37499. // quartet.
  37500. var count = Math.min((i - iFirstSave) / 4,
  37501. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  37502. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  37503. return i;
  37504. }
  37505. // assuming that heights of those image is too small (~1 pixel)
  37506. // packing as much as possible by lines
  37507. var maxX = 0;
  37508. var map = [], maxLineHeight = 0;
  37509. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  37510. var q;
  37511. for (q = 0; q < count; q++) {
  37512. var transform = argsArray[iFirstTransform + (q << 2)];
  37513. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  37514. if (currentX + img.width > MAX_WIDTH) {
  37515. // starting new line
  37516. maxX = Math.max(maxX, currentX);
  37517. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  37518. currentX = 0;
  37519. maxLineHeight = 0;
  37520. }
  37521. map.push({
  37522. transform: transform,
  37523. x: currentX, y: currentY,
  37524. w: img.width, h: img.height
  37525. });
  37526. currentX += img.width + 2 * IMAGE_PADDING;
  37527. maxLineHeight = Math.max(maxLineHeight, img.height);
  37528. }
  37529. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  37530. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  37531. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  37532. var imgRowSize = imgWidth << 2;
  37533. for (q = 0; q < count; q++) {
  37534. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  37535. // Copy image by lines and extends pixels into padding.
  37536. var rowSize = map[q].w << 2;
  37537. var dataOffset = 0;
  37538. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  37539. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  37540. for (var k = 0, kk = map[q].h; k < kk; k++) {
  37541. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  37542. dataOffset += rowSize;
  37543. offset += imgRowSize;
  37544. }
  37545. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  37546. while (offset >= 0) {
  37547. data[offset - 4] = data[offset];
  37548. data[offset - 3] = data[offset + 1];
  37549. data[offset - 2] = data[offset + 2];
  37550. data[offset - 1] = data[offset + 3];
  37551. data[offset + rowSize] = data[offset + rowSize - 4];
  37552. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  37553. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  37554. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  37555. offset -= imgRowSize;
  37556. }
  37557. }
  37558. // Replace queue items.
  37559. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  37560. argsArray.splice(iFirstSave, count * 4,
  37561. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  37562. data: imgData }, map]);
  37563. return iFirstSave + 1;
  37564. });
  37565. // This replaces (save, transform, paintImageMaskXObject, restore)+
  37566. // sequences with one |paintImageMaskXObjectGroup| or one
  37567. // |paintImageMaskXObjectRepeat| operation.
  37568. addState(InitialState,
  37569. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  37570. function foundImageMaskGroup(context) {
  37571. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  37572. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  37573. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  37574. var fnArray = context.fnArray, argsArray = context.argsArray;
  37575. var curr = context.iCurr;
  37576. var iFirstSave = curr - 3;
  37577. var iFirstTransform = curr - 2;
  37578. var iFirstPIMXO = curr - 1;
  37579. // Look for the quartets.
  37580. var i = iFirstSave + 4;
  37581. var ii = fnArray.length;
  37582. while (i + 3 < ii) {
  37583. if (fnArray[i] !== OPS.save ||
  37584. fnArray[i + 1] !== OPS.transform ||
  37585. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  37586. fnArray[i + 3] !== OPS.restore) {
  37587. break; // ops don't match
  37588. }
  37589. i += 4;
  37590. }
  37591. // At this point, i is the index of the first op past the last valid
  37592. // quartet.
  37593. var count = (i - iFirstSave) / 4;
  37594. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  37595. argsArray);
  37596. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  37597. return i;
  37598. }
  37599. var q;
  37600. var isSameImage = false;
  37601. var iTransform, transformArgs;
  37602. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  37603. if (argsArray[iFirstTransform][1] === 0 &&
  37604. argsArray[iFirstTransform][2] === 0) {
  37605. isSameImage = true;
  37606. var firstTransformArg0 = argsArray[iFirstTransform][0];
  37607. var firstTransformArg3 = argsArray[iFirstTransform][3];
  37608. iTransform = iFirstTransform + 4;
  37609. var iPIMXO = iFirstPIMXO + 4;
  37610. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  37611. transformArgs = argsArray[iTransform];
  37612. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  37613. transformArgs[0] !== firstTransformArg0 ||
  37614. transformArgs[1] !== 0 ||
  37615. transformArgs[2] !== 0 ||
  37616. transformArgs[3] !== firstTransformArg3) {
  37617. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  37618. isSameImage = false;
  37619. } else {
  37620. count = q;
  37621. }
  37622. break; // different image or transform
  37623. }
  37624. }
  37625. }
  37626. if (isSameImage) {
  37627. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  37628. var positions = new Float32Array(count * 2);
  37629. iTransform = iFirstTransform;
  37630. for (q = 0; q < count; q++, iTransform += 4) {
  37631. transformArgs = argsArray[iTransform];
  37632. positions[(q << 1)] = transformArgs[4];
  37633. positions[(q << 1) + 1] = transformArgs[5];
  37634. }
  37635. // Replace queue items.
  37636. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  37637. argsArray.splice(iFirstSave, count * 4,
  37638. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  37639. } else {
  37640. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  37641. var images = [];
  37642. for (q = 0; q < count; q++) {
  37643. transformArgs = argsArray[iFirstTransform + (q << 2)];
  37644. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  37645. images.push({ data: maskParams.data, width: maskParams.width,
  37646. height: maskParams.height,
  37647. transform: transformArgs });
  37648. }
  37649. // Replace queue items.
  37650. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  37651. argsArray.splice(iFirstSave, count * 4, [images]);
  37652. }
  37653. return iFirstSave + 1;
  37654. });
  37655. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  37656. // with one paintImageXObjectRepeat operation, if the |transform| and
  37657. // |paintImageXObjectRepeat| ops are appropriate.
  37658. addState(InitialState,
  37659. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  37660. function (context) {
  37661. var MIN_IMAGES_IN_BLOCK = 3;
  37662. var MAX_IMAGES_IN_BLOCK = 1000;
  37663. var fnArray = context.fnArray, argsArray = context.argsArray;
  37664. var curr = context.iCurr;
  37665. var iFirstSave = curr - 3;
  37666. var iFirstTransform = curr - 2;
  37667. var iFirstPIXO = curr - 1;
  37668. var iFirstRestore = curr;
  37669. if (argsArray[iFirstTransform][1] !== 0 ||
  37670. argsArray[iFirstTransform][2] !== 0) {
  37671. return iFirstRestore + 1; // transform has the wrong form
  37672. }
  37673. // Look for the quartets.
  37674. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  37675. var firstTransformArg0 = argsArray[iFirstTransform][0];
  37676. var firstTransformArg3 = argsArray[iFirstTransform][3];
  37677. var i = iFirstSave + 4;
  37678. var ii = fnArray.length;
  37679. while (i + 3 < ii) {
  37680. if (fnArray[i] !== OPS.save ||
  37681. fnArray[i + 1] !== OPS.transform ||
  37682. fnArray[i + 2] !== OPS.paintImageXObject ||
  37683. fnArray[i + 3] !== OPS.restore) {
  37684. break; // ops don't match
  37685. }
  37686. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  37687. argsArray[i + 1][1] !== 0 ||
  37688. argsArray[i + 1][2] !== 0 ||
  37689. argsArray[i + 1][3] !== firstTransformArg3) {
  37690. break; // transforms don't match
  37691. }
  37692. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  37693. break; // images don't match
  37694. }
  37695. i += 4;
  37696. }
  37697. // At this point, i is the index of the first op past the last valid
  37698. // quartet.
  37699. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  37700. if (count < MIN_IMAGES_IN_BLOCK) {
  37701. return i;
  37702. }
  37703. // Extract the (x,y) positions from all of the matching transforms.
  37704. var positions = new Float32Array(count * 2);
  37705. var iTransform = iFirstTransform;
  37706. for (var q = 0; q < count; q++, iTransform += 4) {
  37707. var transformArgs = argsArray[iTransform];
  37708. positions[(q << 1)] = transformArgs[4];
  37709. positions[(q << 1) + 1] = transformArgs[5];
  37710. }
  37711. // Replace queue items.
  37712. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  37713. positions];
  37714. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  37715. argsArray.splice(iFirstSave, count * 4, args);
  37716. return iFirstSave + 1;
  37717. });
  37718. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  37719. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  37720. // sequences, if the font for each one is the same.
  37721. addState(InitialState,
  37722. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  37723. function (context) {
  37724. var MIN_CHARS_IN_BLOCK = 3;
  37725. var MAX_CHARS_IN_BLOCK = 1000;
  37726. var fnArray = context.fnArray, argsArray = context.argsArray;
  37727. var curr = context.iCurr;
  37728. var iFirstBeginText = curr - 4;
  37729. var iFirstSetFont = curr - 3;
  37730. var iFirstSetTextMatrix = curr - 2;
  37731. var iFirstShowText = curr - 1;
  37732. var iFirstEndText = curr;
  37733. // Look for the quintets.
  37734. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  37735. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  37736. var i = iFirstBeginText + 5;
  37737. var ii = fnArray.length;
  37738. while (i + 4 < ii) {
  37739. if (fnArray[i] !== OPS.beginText ||
  37740. fnArray[i + 1] !== OPS.setFont ||
  37741. fnArray[i + 2] !== OPS.setTextMatrix ||
  37742. fnArray[i + 3] !== OPS.showText ||
  37743. fnArray[i + 4] !== OPS.endText) {
  37744. break; // ops don't match
  37745. }
  37746. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  37747. argsArray[i + 1][1] !== firstSetFontArg1) {
  37748. break; // fonts don't match
  37749. }
  37750. i += 5;
  37751. }
  37752. // At this point, i is the index of the first op past the last valid
  37753. // quintet.
  37754. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  37755. if (count < MIN_CHARS_IN_BLOCK) {
  37756. return i;
  37757. }
  37758. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  37759. // showText, endText), include that as well. (E.g. <something> might be
  37760. // |dependency|.)
  37761. var iFirst = iFirstBeginText;
  37762. if (iFirstBeginText >= 4 &&
  37763. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  37764. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  37765. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  37766. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  37767. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  37768. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  37769. count++;
  37770. iFirst -= 5;
  37771. }
  37772. // Remove (endText, beginText, setFont) trios.
  37773. var iEndText = iFirst + 4;
  37774. for (var q = 1; q < count; q++) {
  37775. fnArray.splice(iEndText, 3);
  37776. argsArray.splice(iEndText, 3);
  37777. iEndText += 2;
  37778. }
  37779. return iEndText + 1;
  37780. });
  37781. function QueueOptimizer() {}
  37782. QueueOptimizer.prototype = {
  37783. optimize: function QueueOptimizer_optimize(queue) {
  37784. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  37785. var context = {
  37786. iCurr: 0,
  37787. fnArray: fnArray,
  37788. argsArray: argsArray
  37789. };
  37790. var state;
  37791. var i = 0, ii = fnArray.length;
  37792. while (i < ii) {
  37793. state = (state || InitialState)[fnArray[i]];
  37794. if (typeof state === 'function') { // we found some handler
  37795. context.iCurr = i;
  37796. // state() returns the index of the first non-matching op (if we
  37797. // didn't match) or the first op past the modified ops (if we did
  37798. // match and replace).
  37799. i = state(context);
  37800. state = undefined; // reset the state machine
  37801. ii = context.fnArray.length;
  37802. } else {
  37803. i++;
  37804. }
  37805. }
  37806. }
  37807. };
  37808. return QueueOptimizer;
  37809. })();
  37810. exports.OperatorList = OperatorList;
  37811. exports.PartialEvaluator = PartialEvaluator;
  37812. }));
  37813. (function (root, factory) {
  37814. {
  37815. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  37816. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  37817. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  37818. }
  37819. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  37820. coreColorSpace, coreObj, coreEvaluator) {
  37821. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  37822. var AnnotationFieldFlag = sharedUtil.AnnotationFieldFlag;
  37823. var AnnotationFlag = sharedUtil.AnnotationFlag;
  37824. var AnnotationType = sharedUtil.AnnotationType;
  37825. var OPS = sharedUtil.OPS;
  37826. var Util = sharedUtil.Util;
  37827. var isBool = sharedUtil.isBool;
  37828. var isString = sharedUtil.isString;
  37829. var isArray = sharedUtil.isArray;
  37830. var isInt = sharedUtil.isInt;
  37831. var isValidUrl = sharedUtil.isValidUrl;
  37832. var stringToBytes = sharedUtil.stringToBytes;
  37833. var stringToPDFString = sharedUtil.stringToPDFString;
  37834. var stringToUTF8String = sharedUtil.stringToUTF8String;
  37835. var warn = sharedUtil.warn;
  37836. var Dict = corePrimitives.Dict;
  37837. var isDict = corePrimitives.isDict;
  37838. var isName = corePrimitives.isName;
  37839. var isRef = corePrimitives.isRef;
  37840. var Stream = coreStream.Stream;
  37841. var ColorSpace = coreColorSpace.ColorSpace;
  37842. var ObjectLoader = coreObj.ObjectLoader;
  37843. var FileSpec = coreObj.FileSpec;
  37844. var OperatorList = coreEvaluator.OperatorList;
  37845. /**
  37846. * @class
  37847. * @alias AnnotationFactory
  37848. */
  37849. function AnnotationFactory() {}
  37850. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  37851. /**
  37852. * @param {XRef} xref
  37853. * @param {Object} ref
  37854. * @param {string} uniquePrefix
  37855. * @param {Object} idCounters
  37856. * @returns {Annotation}
  37857. */
  37858. create: function AnnotationFactory_create(xref, ref,
  37859. uniquePrefix, idCounters) {
  37860. var dict = xref.fetchIfRef(ref);
  37861. if (!isDict(dict)) {
  37862. return;
  37863. }
  37864. var id = isRef(ref) ? ref.toString() :
  37865. 'annot_' + (uniquePrefix || '') + (++idCounters.obj);
  37866. // Determine the annotation's subtype.
  37867. var subtype = dict.get('Subtype');
  37868. subtype = isName(subtype) ? subtype.name : null;
  37869. // Return the right annotation object based on the subtype and field type.
  37870. var parameters = {
  37871. xref: xref,
  37872. dict: dict,
  37873. ref: isRef(ref) ? ref : null,
  37874. subtype: subtype,
  37875. id: id,
  37876. };
  37877. switch (subtype) {
  37878. case 'Link':
  37879. return new LinkAnnotation(parameters);
  37880. case 'Text':
  37881. return new TextAnnotation(parameters);
  37882. case 'Widget':
  37883. var fieldType = Util.getInheritableProperty(dict, 'FT');
  37884. fieldType = isName(fieldType) ? fieldType.name : null;
  37885. switch (fieldType) {
  37886. case 'Tx':
  37887. return new TextWidgetAnnotation(parameters);
  37888. }
  37889. warn('Unimplemented widget field type "' + fieldType + '", ' +
  37890. 'falling back to base field type.');
  37891. return new WidgetAnnotation(parameters);
  37892. case 'Popup':
  37893. return new PopupAnnotation(parameters);
  37894. case 'Highlight':
  37895. return new HighlightAnnotation(parameters);
  37896. case 'Underline':
  37897. return new UnderlineAnnotation(parameters);
  37898. case 'Squiggly':
  37899. return new SquigglyAnnotation(parameters);
  37900. case 'StrikeOut':
  37901. return new StrikeOutAnnotation(parameters);
  37902. case 'FileAttachment':
  37903. return new FileAttachmentAnnotation(parameters);
  37904. default:
  37905. if (!subtype) {
  37906. warn('Annotation is missing the required /Subtype.');
  37907. } else {
  37908. warn('Unimplemented annotation type "' + subtype + '", ' +
  37909. 'falling back to base annotation.');
  37910. }
  37911. return new Annotation(parameters);
  37912. }
  37913. }
  37914. };
  37915. var Annotation = (function AnnotationClosure() {
  37916. // 12.5.5: Algorithm: Appearance streams
  37917. function getTransformMatrix(rect, bbox, matrix) {
  37918. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  37919. var minX = bounds[0];
  37920. var minY = bounds[1];
  37921. var maxX = bounds[2];
  37922. var maxY = bounds[3];
  37923. if (minX === maxX || minY === maxY) {
  37924. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  37925. // just apply the transform for rect
  37926. return [1, 0, 0, 1, rect[0], rect[1]];
  37927. }
  37928. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  37929. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  37930. return [
  37931. xRatio,
  37932. 0,
  37933. 0,
  37934. yRatio,
  37935. rect[0] - minX * xRatio,
  37936. rect[1] - minY * yRatio
  37937. ];
  37938. }
  37939. function getDefaultAppearance(dict) {
  37940. var appearanceState = dict.get('AP');
  37941. if (!isDict(appearanceState)) {
  37942. return;
  37943. }
  37944. var appearance;
  37945. var appearances = appearanceState.get('N');
  37946. if (isDict(appearances)) {
  37947. var as = dict.get('AS');
  37948. if (as && appearances.has(as.name)) {
  37949. appearance = appearances.get(as.name);
  37950. }
  37951. } else {
  37952. appearance = appearances;
  37953. }
  37954. return appearance;
  37955. }
  37956. function Annotation(params) {
  37957. var dict = params.dict;
  37958. this.setFlags(dict.get('F'));
  37959. this.setRectangle(dict.getArray('Rect'));
  37960. this.setColor(dict.getArray('C'));
  37961. this.setBorderStyle(dict);
  37962. this.appearance = getDefaultAppearance(dict);
  37963. // Expose public properties using a data object.
  37964. this.data = {};
  37965. this.data.id = params.id;
  37966. this.data.subtype = params.subtype;
  37967. this.data.annotationFlags = this.flags;
  37968. this.data.rect = this.rectangle;
  37969. this.data.color = this.color;
  37970. this.data.borderStyle = this.borderStyle;
  37971. this.data.hasAppearance = !!this.appearance;
  37972. }
  37973. Annotation.prototype = {
  37974. /**
  37975. * @private
  37976. */
  37977. _hasFlag: function Annotation_hasFlag(flags, flag) {
  37978. return !!(flags & flag);
  37979. },
  37980. /**
  37981. * @private
  37982. */
  37983. _isViewable: function Annotation_isViewable(flags) {
  37984. return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
  37985. !this._hasFlag(flags, AnnotationFlag.HIDDEN) &&
  37986. !this._hasFlag(flags, AnnotationFlag.NOVIEW);
  37987. },
  37988. /**
  37989. * @private
  37990. */
  37991. _isPrintable: function AnnotationFlag_isPrintable(flags) {
  37992. return this._hasFlag(flags, AnnotationFlag.PRINT) &&
  37993. !this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
  37994. !this._hasFlag(flags, AnnotationFlag.HIDDEN);
  37995. },
  37996. /**
  37997. * @return {boolean}
  37998. */
  37999. get viewable() {
  38000. if (this.flags === 0) {
  38001. return true;
  38002. }
  38003. return this._isViewable(this.flags);
  38004. },
  38005. /**
  38006. * @return {boolean}
  38007. */
  38008. get printable() {
  38009. if (this.flags === 0) {
  38010. return false;
  38011. }
  38012. return this._isPrintable(this.flags);
  38013. },
  38014. /**
  38015. * Set the flags.
  38016. *
  38017. * @public
  38018. * @memberof Annotation
  38019. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  38020. * characteristics
  38021. * @see {@link shared/util.js}
  38022. */
  38023. setFlags: function Annotation_setFlags(flags) {
  38024. this.flags = (isInt(flags) && flags > 0) ? flags : 0;
  38025. },
  38026. /**
  38027. * Check if a provided flag is set.
  38028. *
  38029. * @public
  38030. * @memberof Annotation
  38031. * @param {number} flag - Hexadecimal representation for an annotation
  38032. * characteristic
  38033. * @return {boolean}
  38034. * @see {@link shared/util.js}
  38035. */
  38036. hasFlag: function Annotation_hasFlag(flag) {
  38037. return this._hasFlag(this.flags, flag);
  38038. },
  38039. /**
  38040. * Set the rectangle.
  38041. *
  38042. * @public
  38043. * @memberof Annotation
  38044. * @param {Array} rectangle - The rectangle array with exactly four entries
  38045. */
  38046. setRectangle: function Annotation_setRectangle(rectangle) {
  38047. if (isArray(rectangle) && rectangle.length === 4) {
  38048. this.rectangle = Util.normalizeRect(rectangle);
  38049. } else {
  38050. this.rectangle = [0, 0, 0, 0];
  38051. }
  38052. },
  38053. /**
  38054. * Set the color and take care of color space conversion.
  38055. *
  38056. * @public
  38057. * @memberof Annotation
  38058. * @param {Array} color - The color array containing either 0
  38059. * (transparent), 1 (grayscale), 3 (RGB) or
  38060. * 4 (CMYK) elements
  38061. */
  38062. setColor: function Annotation_setColor(color) {
  38063. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  38064. if (!isArray(color)) {
  38065. this.color = rgbColor;
  38066. return;
  38067. }
  38068. switch (color.length) {
  38069. case 0: // Transparent, which we indicate with a null value
  38070. this.color = null;
  38071. break;
  38072. case 1: // Convert grayscale to RGB
  38073. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  38074. this.color = rgbColor;
  38075. break;
  38076. case 3: // Convert RGB percentages to RGB
  38077. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  38078. this.color = rgbColor;
  38079. break;
  38080. case 4: // Convert CMYK to RGB
  38081. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  38082. this.color = rgbColor;
  38083. break;
  38084. default:
  38085. this.color = rgbColor;
  38086. break;
  38087. }
  38088. },
  38089. /**
  38090. * Set the border style (as AnnotationBorderStyle object).
  38091. *
  38092. * @public
  38093. * @memberof Annotation
  38094. * @param {Dict} borderStyle - The border style dictionary
  38095. */
  38096. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  38097. this.borderStyle = new AnnotationBorderStyle();
  38098. if (!isDict(borderStyle)) {
  38099. return;
  38100. }
  38101. if (borderStyle.has('BS')) {
  38102. var dict = borderStyle.get('BS');
  38103. var dictType = dict.get('Type');
  38104. if (!dictType || isName(dictType, 'Border')) {
  38105. this.borderStyle.setWidth(dict.get('W'));
  38106. this.borderStyle.setStyle(dict.get('S'));
  38107. this.borderStyle.setDashArray(dict.getArray('D'));
  38108. }
  38109. } else if (borderStyle.has('Border')) {
  38110. var array = borderStyle.getArray('Border');
  38111. if (isArray(array) && array.length >= 3) {
  38112. this.borderStyle.setHorizontalCornerRadius(array[0]);
  38113. this.borderStyle.setVerticalCornerRadius(array[1]);
  38114. this.borderStyle.setWidth(array[2]);
  38115. if (array.length === 4) { // Dash array available
  38116. this.borderStyle.setDashArray(array[3]);
  38117. }
  38118. }
  38119. } else {
  38120. // There are no border entries in the dictionary. According to the
  38121. // specification, we should draw a solid border of width 1 in that
  38122. // case, but Adobe Reader did not implement that part of the
  38123. // specification and instead draws no border at all, so we do the same.
  38124. // See also https://github.com/mozilla/pdf.js/issues/6179.
  38125. this.borderStyle.setWidth(0);
  38126. }
  38127. },
  38128. /**
  38129. * Prepare the annotation for working with a popup in the display layer.
  38130. *
  38131. * @private
  38132. * @memberof Annotation
  38133. * @param {Dict} dict - The annotation's data dictionary
  38134. */
  38135. _preparePopup: function Annotation_preparePopup(dict) {
  38136. if (!dict.has('C')) {
  38137. // Fall back to the default background color.
  38138. this.data.color = null;
  38139. }
  38140. this.data.hasPopup = dict.has('Popup');
  38141. this.data.title = stringToPDFString(dict.get('T') || '');
  38142. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  38143. },
  38144. loadResources: function Annotation_loadResources(keys) {
  38145. return new Promise(function (resolve, reject) {
  38146. this.appearance.dict.getAsync('Resources').then(function (resources) {
  38147. if (!resources) {
  38148. resolve();
  38149. return;
  38150. }
  38151. var objectLoader = new ObjectLoader(resources.map,
  38152. keys,
  38153. resources.xref);
  38154. objectLoader.load().then(function() {
  38155. resolve(resources);
  38156. }, reject);
  38157. }, reject);
  38158. }.bind(this));
  38159. },
  38160. getOperatorList: function Annotation_getOperatorList(evaluator, task,
  38161. renderForms) {
  38162. if (!this.appearance) {
  38163. return Promise.resolve(new OperatorList());
  38164. }
  38165. var data = this.data;
  38166. var appearanceDict = this.appearance.dict;
  38167. var resourcesPromise = this.loadResources([
  38168. 'ExtGState',
  38169. 'ColorSpace',
  38170. 'Pattern',
  38171. 'Shading',
  38172. 'XObject',
  38173. 'Font'
  38174. // ProcSet
  38175. // Properties
  38176. ]);
  38177. var bbox = appearanceDict.getArray('BBox') || [0, 0, 1, 1];
  38178. var matrix = appearanceDict.getArray('Matrix') || [1, 0, 0, 1, 0 ,0];
  38179. var transform = getTransformMatrix(data.rect, bbox, matrix);
  38180. var self = this;
  38181. return resourcesPromise.then(function(resources) {
  38182. var opList = new OperatorList();
  38183. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  38184. return evaluator.getOperatorList(self.appearance, task,
  38185. resources, opList).
  38186. then(function () {
  38187. opList.addOp(OPS.endAnnotation, []);
  38188. self.appearance.reset();
  38189. return opList;
  38190. });
  38191. });
  38192. }
  38193. };
  38194. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  38195. annotations, opList, partialEvaluator, task, intent, renderForms) {
  38196. var annotationPromises = [];
  38197. for (var i = 0, n = annotations.length; i < n; ++i) {
  38198. if ((intent === 'display' && annotations[i].viewable) ||
  38199. (intent === 'print' && annotations[i].printable)) {
  38200. annotationPromises.push(
  38201. annotations[i].getOperatorList(partialEvaluator, task, renderForms));
  38202. }
  38203. }
  38204. return Promise.all(annotationPromises).then(function(operatorLists) {
  38205. opList.addOp(OPS.beginAnnotations, []);
  38206. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  38207. opList.addOpList(operatorLists[i]);
  38208. }
  38209. opList.addOp(OPS.endAnnotations, []);
  38210. });
  38211. };
  38212. return Annotation;
  38213. })();
  38214. /**
  38215. * Contains all data regarding an annotation's border style.
  38216. *
  38217. * @class
  38218. */
  38219. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  38220. /**
  38221. * @constructor
  38222. * @private
  38223. */
  38224. function AnnotationBorderStyle() {
  38225. this.width = 1;
  38226. this.style = AnnotationBorderStyleType.SOLID;
  38227. this.dashArray = [3];
  38228. this.horizontalCornerRadius = 0;
  38229. this.verticalCornerRadius = 0;
  38230. }
  38231. AnnotationBorderStyle.prototype = {
  38232. /**
  38233. * Set the width.
  38234. *
  38235. * @public
  38236. * @memberof AnnotationBorderStyle
  38237. * @param {integer} width - The width
  38238. */
  38239. setWidth: function AnnotationBorderStyle_setWidth(width) {
  38240. if (width === (width | 0)) {
  38241. this.width = width;
  38242. }
  38243. },
  38244. /**
  38245. * Set the style.
  38246. *
  38247. * @public
  38248. * @memberof AnnotationBorderStyle
  38249. * @param {Object} style - The style object
  38250. * @see {@link shared/util.js}
  38251. */
  38252. setStyle: function AnnotationBorderStyle_setStyle(style) {
  38253. if (!style) {
  38254. return;
  38255. }
  38256. switch (style.name) {
  38257. case 'S':
  38258. this.style = AnnotationBorderStyleType.SOLID;
  38259. break;
  38260. case 'D':
  38261. this.style = AnnotationBorderStyleType.DASHED;
  38262. break;
  38263. case 'B':
  38264. this.style = AnnotationBorderStyleType.BEVELED;
  38265. break;
  38266. case 'I':
  38267. this.style = AnnotationBorderStyleType.INSET;
  38268. break;
  38269. case 'U':
  38270. this.style = AnnotationBorderStyleType.UNDERLINE;
  38271. break;
  38272. default:
  38273. break;
  38274. }
  38275. },
  38276. /**
  38277. * Set the dash array.
  38278. *
  38279. * @public
  38280. * @memberof AnnotationBorderStyle
  38281. * @param {Array} dashArray - The dash array with at least one element
  38282. */
  38283. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  38284. // We validate the dash array, but we do not use it because CSS does not
  38285. // allow us to change spacing of dashes. For more information, visit
  38286. // http://www.w3.org/TR/css3-background/#the-border-style.
  38287. if (isArray(dashArray) && dashArray.length > 0) {
  38288. // According to the PDF specification: the elements in a dashArray
  38289. // shall be numbers that are nonnegative and not all equal to zero.
  38290. var isValid = true;
  38291. var allZeros = true;
  38292. for (var i = 0, len = dashArray.length; i < len; i++) {
  38293. var element = dashArray[i];
  38294. var validNumber = (+element >= 0);
  38295. if (!validNumber) {
  38296. isValid = false;
  38297. break;
  38298. } else if (element > 0) {
  38299. allZeros = false;
  38300. }
  38301. }
  38302. if (isValid && !allZeros) {
  38303. this.dashArray = dashArray;
  38304. } else {
  38305. this.width = 0; // Adobe behavior when the array is invalid.
  38306. }
  38307. } else if (dashArray) {
  38308. this.width = 0; // Adobe behavior when the array is invalid.
  38309. }
  38310. },
  38311. /**
  38312. * Set the horizontal corner radius (from a Border dictionary).
  38313. *
  38314. * @public
  38315. * @memberof AnnotationBorderStyle
  38316. * @param {integer} radius - The horizontal corner radius
  38317. */
  38318. setHorizontalCornerRadius:
  38319. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  38320. if (radius === (radius | 0)) {
  38321. this.horizontalCornerRadius = radius;
  38322. }
  38323. },
  38324. /**
  38325. * Set the vertical corner radius (from a Border dictionary).
  38326. *
  38327. * @public
  38328. * @memberof AnnotationBorderStyle
  38329. * @param {integer} radius - The vertical corner radius
  38330. */
  38331. setVerticalCornerRadius:
  38332. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  38333. if (radius === (radius | 0)) {
  38334. this.verticalCornerRadius = radius;
  38335. }
  38336. }
  38337. };
  38338. return AnnotationBorderStyle;
  38339. })();
  38340. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  38341. function WidgetAnnotation(params) {
  38342. Annotation.call(this, params);
  38343. var dict = params.dict;
  38344. var data = this.data;
  38345. data.annotationType = AnnotationType.WIDGET;
  38346. data.fieldValue = stringToPDFString(
  38347. Util.getInheritableProperty(dict, 'V') || '');
  38348. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  38349. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  38350. var fieldType = Util.getInheritableProperty(dict, 'FT');
  38351. data.fieldType = isName(fieldType) ? fieldType.name : null;
  38352. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  38353. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff');
  38354. if (!isInt(data.fieldFlags) || data.fieldFlags < 0) {
  38355. data.fieldFlags = 0;
  38356. }
  38357. // Hide signatures because we cannot validate them.
  38358. if (data.fieldType === 'Sig') {
  38359. this.setFlags(AnnotationFlag.HIDDEN);
  38360. }
  38361. // Building the full field name by collecting the field and
  38362. // its ancestors 'T' data and joining them using '.'.
  38363. var fieldName = [];
  38364. var namedItem = dict;
  38365. var ref = params.ref;
  38366. while (namedItem) {
  38367. var parent = namedItem.get('Parent');
  38368. var parentRef = namedItem.getRaw('Parent');
  38369. var name = namedItem.get('T');
  38370. if (name) {
  38371. fieldName.unshift(stringToPDFString(name));
  38372. } else if (parent && ref) {
  38373. // The field name is absent, that means more than one field
  38374. // with the same name may exist. Replacing the empty name
  38375. // with the '`' plus index in the parent's 'Kids' array.
  38376. // This is not in the PDF spec but necessary to id the
  38377. // the input controls.
  38378. var kids = parent.get('Kids');
  38379. var j, jj;
  38380. for (j = 0, jj = kids.length; j < jj; j++) {
  38381. var kidRef = kids[j];
  38382. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  38383. break;
  38384. }
  38385. }
  38386. fieldName.unshift('`' + j);
  38387. }
  38388. namedItem = parent;
  38389. ref = parentRef;
  38390. }
  38391. data.fullName = fieldName.join('.');
  38392. }
  38393. Util.inherit(WidgetAnnotation, Annotation, {
  38394. /**
  38395. * Check if a provided field flag is set.
  38396. *
  38397. * @public
  38398. * @memberof WidgetAnnotation
  38399. * @param {number} flag - Hexadecimal representation for an annotation
  38400. * field characteristic
  38401. * @return {boolean}
  38402. * @see {@link shared/util.js}
  38403. */
  38404. hasFieldFlag: function WidgetAnnotation_hasFieldFlag(flag) {
  38405. return !!(this.data.fieldFlags & flag);
  38406. },
  38407. });
  38408. return WidgetAnnotation;
  38409. })();
  38410. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  38411. function TextWidgetAnnotation(params) {
  38412. WidgetAnnotation.call(this, params);
  38413. // Determine the alignment of text in the field.
  38414. var alignment = Util.getInheritableProperty(params.dict, 'Q');
  38415. if (!isInt(alignment) || alignment < 0 || alignment > 2) {
  38416. alignment = null;
  38417. }
  38418. this.data.textAlignment = alignment;
  38419. // Determine the maximum length of text in the field.
  38420. var maximumLength = Util.getInheritableProperty(params.dict, 'MaxLen');
  38421. if (!isInt(maximumLength) || maximumLength < 0) {
  38422. maximumLength = null;
  38423. }
  38424. this.data.maxLen = maximumLength;
  38425. // Process field flags for the display layer.
  38426. this.data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
  38427. this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
  38428. this.data.comb = this.hasFieldFlag(AnnotationFieldFlag.COMB) &&
  38429. !this.hasFieldFlag(AnnotationFieldFlag.MULTILINE) &&
  38430. !this.hasFieldFlag(AnnotationFieldFlag.PASSWORD) &&
  38431. !this.hasFieldFlag(AnnotationFieldFlag.FILESELECT) &&
  38432. this.data.maxLen !== null;
  38433. }
  38434. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  38435. getOperatorList:
  38436. function TextWidgetAnnotation_getOperatorList(evaluator, task,
  38437. renderForms) {
  38438. var operatorList = new OperatorList();
  38439. // Do not render form elements on the canvas when interactive forms are
  38440. // enabled. The display layer is responsible for rendering them instead.
  38441. if (renderForms) {
  38442. return Promise.resolve(operatorList);
  38443. }
  38444. if (this.appearance) {
  38445. return Annotation.prototype.getOperatorList.call(this, evaluator, task,
  38446. renderForms);
  38447. }
  38448. // Even if there is an appearance stream, ignore it. This is the
  38449. // behaviour used by Adobe Reader.
  38450. if (!this.data.defaultAppearance) {
  38451. return Promise.resolve(operatorList);
  38452. }
  38453. var stream = new Stream(stringToBytes(this.data.defaultAppearance));
  38454. return evaluator.getOperatorList(stream, task, this.fieldResources,
  38455. operatorList).
  38456. then(function () {
  38457. return operatorList;
  38458. });
  38459. }
  38460. });
  38461. return TextWidgetAnnotation;
  38462. })();
  38463. var TextAnnotation = (function TextAnnotationClosure() {
  38464. var DEFAULT_ICON_SIZE = 22; // px
  38465. function TextAnnotation(parameters) {
  38466. Annotation.call(this, parameters);
  38467. this.data.annotationType = AnnotationType.TEXT;
  38468. if (this.data.hasAppearance) {
  38469. this.data.name = 'NoIcon';
  38470. } else {
  38471. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  38472. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  38473. this.data.name = parameters.dict.has('Name') ?
  38474. parameters.dict.get('Name').name : 'Note';
  38475. }
  38476. this._preparePopup(parameters.dict);
  38477. }
  38478. Util.inherit(TextAnnotation, Annotation, {});
  38479. return TextAnnotation;
  38480. })();
  38481. var LinkAnnotation = (function LinkAnnotationClosure() {
  38482. function LinkAnnotation(params) {
  38483. Annotation.call(this, params);
  38484. var dict = params.dict;
  38485. var data = this.data;
  38486. data.annotationType = AnnotationType.LINK;
  38487. var action = dict.get('A'), url, dest;
  38488. if (action && isDict(action)) {
  38489. var linkType = action.get('S').name;
  38490. switch (linkType) {
  38491. case 'URI':
  38492. url = action.get('URI');
  38493. if (isName(url)) {
  38494. // Some bad PDFs do not put parentheses around relative URLs.
  38495. url = '/' + url.name;
  38496. } else if (url) {
  38497. url = addDefaultProtocolToUrl(url);
  38498. }
  38499. // TODO: pdf spec mentions urls can be relative to a Base
  38500. // entry in the dictionary.
  38501. break;
  38502. case 'GoTo':
  38503. dest = action.get('D');
  38504. break;
  38505. case 'GoToR':
  38506. var urlDict = action.get('F');
  38507. if (isDict(urlDict)) {
  38508. // We assume that we found a FileSpec dictionary
  38509. // and fetch the URL without checking any further.
  38510. url = urlDict.get('F') || null;
  38511. } else if (isString(urlDict)) {
  38512. url = urlDict;
  38513. }
  38514. // NOTE: the destination is relative to the *remote* document.
  38515. var remoteDest = action.get('D');
  38516. if (remoteDest) {
  38517. if (isName(remoteDest)) {
  38518. remoteDest = remoteDest.name;
  38519. }
  38520. if (isString(url)) {
  38521. var baseUrl = url.split('#')[0];
  38522. if (isString(remoteDest)) {
  38523. // In practice, a named destination may contain only a number.
  38524. // If that happens, use the '#nameddest=' form to avoid the link
  38525. // redirecting to a page, instead of the correct destination.
  38526. url = baseUrl + '#' +
  38527. (/^\d+$/.test(remoteDest) ? 'nameddest=' : '') + remoteDest;
  38528. } else if (isArray(remoteDest)) {
  38529. url = baseUrl + '#' + JSON.stringify(remoteDest);
  38530. }
  38531. }
  38532. }
  38533. // The 'NewWindow' property, equal to `LinkTarget.BLANK`.
  38534. var newWindow = action.get('NewWindow');
  38535. if (isBool(newWindow)) {
  38536. data.newWindow = newWindow;
  38537. }
  38538. break;
  38539. case 'Named':
  38540. data.action = action.get('N').name;
  38541. break;
  38542. default:
  38543. warn('unrecognized link type: ' + linkType);
  38544. }
  38545. } else if (dict.has('Dest')) { // Simple destination link.
  38546. dest = dict.get('Dest');
  38547. }
  38548. if (url) {
  38549. if (isValidUrl(url, /* allowRelative = */ false)) {
  38550. data.url = tryConvertUrlEncoding(url);
  38551. }
  38552. }
  38553. if (dest) {
  38554. data.dest = isName(dest) ? dest.name : dest;
  38555. }
  38556. }
  38557. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  38558. function addDefaultProtocolToUrl(url) {
  38559. if (isString(url) && url.indexOf('www.') === 0) {
  38560. return ('http://' + url);
  38561. }
  38562. return url;
  38563. }
  38564. function tryConvertUrlEncoding(url) {
  38565. // According to ISO 32000-1:2008, section 12.6.4.7, URIs should be encoded
  38566. // in 7-bit ASCII. Some bad PDFs use UTF-8 encoding, see Bugzilla 1122280.
  38567. try {
  38568. return stringToUTF8String(url);
  38569. } catch (e) {
  38570. return url;
  38571. }
  38572. }
  38573. Util.inherit(LinkAnnotation, Annotation, {});
  38574. return LinkAnnotation;
  38575. })();
  38576. var PopupAnnotation = (function PopupAnnotationClosure() {
  38577. function PopupAnnotation(parameters) {
  38578. Annotation.call(this, parameters);
  38579. this.data.annotationType = AnnotationType.POPUP;
  38580. var dict = parameters.dict;
  38581. var parentItem = dict.get('Parent');
  38582. if (!parentItem) {
  38583. warn('Popup annotation has a missing or invalid parent annotation.');
  38584. return;
  38585. }
  38586. this.data.parentId = dict.getRaw('Parent').toString();
  38587. this.data.title = stringToPDFString(parentItem.get('T') || '');
  38588. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  38589. if (!parentItem.has('C')) {
  38590. // Fall back to the default background color.
  38591. this.data.color = null;
  38592. } else {
  38593. this.setColor(parentItem.getArray('C'));
  38594. this.data.color = this.color;
  38595. }
  38596. // If the Popup annotation is not viewable, but the parent annotation is,
  38597. // that is most likely a bug. Fallback to inherit the flags from the parent
  38598. // annotation (this is consistent with the behaviour in Adobe Reader).
  38599. if (!this.viewable) {
  38600. var parentFlags = parentItem.get('F');
  38601. if (this._isViewable(parentFlags)) {
  38602. this.setFlags(parentFlags);
  38603. }
  38604. }
  38605. }
  38606. Util.inherit(PopupAnnotation, Annotation, {});
  38607. return PopupAnnotation;
  38608. })();
  38609. var HighlightAnnotation = (function HighlightAnnotationClosure() {
  38610. function HighlightAnnotation(parameters) {
  38611. Annotation.call(this, parameters);
  38612. this.data.annotationType = AnnotationType.HIGHLIGHT;
  38613. this._preparePopup(parameters.dict);
  38614. // PDF viewers completely ignore any border styles.
  38615. this.data.borderStyle.setWidth(0);
  38616. }
  38617. Util.inherit(HighlightAnnotation, Annotation, {});
  38618. return HighlightAnnotation;
  38619. })();
  38620. var UnderlineAnnotation = (function UnderlineAnnotationClosure() {
  38621. function UnderlineAnnotation(parameters) {
  38622. Annotation.call(this, parameters);
  38623. this.data.annotationType = AnnotationType.UNDERLINE;
  38624. this._preparePopup(parameters.dict);
  38625. // PDF viewers completely ignore any border styles.
  38626. this.data.borderStyle.setWidth(0);
  38627. }
  38628. Util.inherit(UnderlineAnnotation, Annotation, {});
  38629. return UnderlineAnnotation;
  38630. })();
  38631. var SquigglyAnnotation = (function SquigglyAnnotationClosure() {
  38632. function SquigglyAnnotation(parameters) {
  38633. Annotation.call(this, parameters);
  38634. this.data.annotationType = AnnotationType.SQUIGGLY;
  38635. this._preparePopup(parameters.dict);
  38636. // PDF viewers completely ignore any border styles.
  38637. this.data.borderStyle.setWidth(0);
  38638. }
  38639. Util.inherit(SquigglyAnnotation, Annotation, {});
  38640. return SquigglyAnnotation;
  38641. })();
  38642. var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() {
  38643. function StrikeOutAnnotation(parameters) {
  38644. Annotation.call(this, parameters);
  38645. this.data.annotationType = AnnotationType.STRIKEOUT;
  38646. this._preparePopup(parameters.dict);
  38647. // PDF viewers completely ignore any border styles.
  38648. this.data.borderStyle.setWidth(0);
  38649. }
  38650. Util.inherit(StrikeOutAnnotation, Annotation, {});
  38651. return StrikeOutAnnotation;
  38652. })();
  38653. var FileAttachmentAnnotation = (function FileAttachmentAnnotationClosure() {
  38654. function FileAttachmentAnnotation(parameters) {
  38655. Annotation.call(this, parameters);
  38656. var file = new FileSpec(parameters.dict.get('FS'), parameters.xref);
  38657. this.data.annotationType = AnnotationType.FILEATTACHMENT;
  38658. this.data.file = file.serializable;
  38659. this._preparePopup(parameters.dict);
  38660. }
  38661. Util.inherit(FileAttachmentAnnotation, Annotation, {});
  38662. return FileAttachmentAnnotation;
  38663. })();
  38664. exports.Annotation = Annotation;
  38665. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  38666. exports.AnnotationFactory = AnnotationFactory;
  38667. }));
  38668. (function (root, factory) {
  38669. {
  38670. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  38671. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  38672. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  38673. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  38674. }
  38675. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  38676. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  38677. var MissingDataException = sharedUtil.MissingDataException;
  38678. var Util = sharedUtil.Util;
  38679. var assert = sharedUtil.assert;
  38680. var error = sharedUtil.error;
  38681. var info = sharedUtil.info;
  38682. var isArray = sharedUtil.isArray;
  38683. var isArrayBuffer = sharedUtil.isArrayBuffer;
  38684. var isString = sharedUtil.isString;
  38685. var shadow = sharedUtil.shadow;
  38686. var stringToBytes = sharedUtil.stringToBytes;
  38687. var stringToPDFString = sharedUtil.stringToPDFString;
  38688. var warn = sharedUtil.warn;
  38689. var isSpace = sharedUtil.isSpace;
  38690. var Dict = corePrimitives.Dict;
  38691. var isDict = corePrimitives.isDict;
  38692. var isName = corePrimitives.isName;
  38693. var isStream = corePrimitives.isStream;
  38694. var NullStream = coreStream.NullStream;
  38695. var Stream = coreStream.Stream;
  38696. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  38697. var Catalog = coreObj.Catalog;
  38698. var ObjectLoader = coreObj.ObjectLoader;
  38699. var XRef = coreObj.XRef;
  38700. var Linearization = coreParser.Linearization;
  38701. var calculateMD5 = coreCrypto.calculateMD5;
  38702. var OperatorList = coreEvaluator.OperatorList;
  38703. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  38704. var Annotation = coreAnnotation.Annotation;
  38705. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  38706. var Page = (function PageClosure() {
  38707. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  38708. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  38709. this.pdfManager = pdfManager;
  38710. this.pageIndex = pageIndex;
  38711. this.pageDict = pageDict;
  38712. this.xref = xref;
  38713. this.ref = ref;
  38714. this.fontCache = fontCache;
  38715. this.uniquePrefix = 'p' + this.pageIndex + '_';
  38716. this.idCounters = {
  38717. obj: 0
  38718. };
  38719. this.evaluatorOptions = pdfManager.evaluatorOptions;
  38720. this.resourcesPromise = null;
  38721. }
  38722. Page.prototype = {
  38723. getPageProp: function Page_getPageProp(key) {
  38724. return this.pageDict.get(key);
  38725. },
  38726. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  38727. var dict = this.pageDict, valueArray = null, loopCount = 0;
  38728. var MAX_LOOP_COUNT = 100;
  38729. // Always walk up the entire parent chain, to be able to find
  38730. // e.g. \Resources placed on multiple levels of the tree.
  38731. while (dict) {
  38732. var value = dict.get(key);
  38733. if (value) {
  38734. if (!valueArray) {
  38735. valueArray = [];
  38736. }
  38737. valueArray.push(value);
  38738. }
  38739. if (++loopCount > MAX_LOOP_COUNT) {
  38740. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  38741. break;
  38742. }
  38743. dict = dict.get('Parent');
  38744. }
  38745. if (!valueArray) {
  38746. return Dict.empty;
  38747. }
  38748. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  38749. loopCount > MAX_LOOP_COUNT) {
  38750. return valueArray[0];
  38751. }
  38752. return Dict.merge(this.xref, valueArray);
  38753. },
  38754. get content() {
  38755. return this.getPageProp('Contents');
  38756. },
  38757. get resources() {
  38758. // For robustness: The spec states that a \Resources entry has to be
  38759. // present, but can be empty. Some document omit it still, in this case
  38760. // we return an empty dictionary.
  38761. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  38762. },
  38763. get mediaBox() {
  38764. var obj = this.getInheritedPageProp('MediaBox');
  38765. // Reset invalid media box to letter size.
  38766. if (!isArray(obj) || obj.length !== 4) {
  38767. obj = LETTER_SIZE_MEDIABOX;
  38768. }
  38769. return shadow(this, 'mediaBox', obj);
  38770. },
  38771. get view() {
  38772. var mediaBox = this.mediaBox;
  38773. var cropBox = this.getInheritedPageProp('CropBox');
  38774. if (!isArray(cropBox) || cropBox.length !== 4) {
  38775. return shadow(this, 'view', mediaBox);
  38776. }
  38777. // From the spec, 6th ed., p.963:
  38778. // "The crop, bleed, trim, and art boxes should not ordinarily
  38779. // extend beyond the boundaries of the media box. If they do, they are
  38780. // effectively reduced to their intersection with the media box."
  38781. cropBox = Util.intersect(cropBox, mediaBox);
  38782. if (!cropBox) {
  38783. return shadow(this, 'view', mediaBox);
  38784. }
  38785. return shadow(this, 'view', cropBox);
  38786. },
  38787. get rotate() {
  38788. var rotate = this.getInheritedPageProp('Rotate') || 0;
  38789. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  38790. if (rotate % 90 !== 0) {
  38791. rotate = 0;
  38792. } else if (rotate >= 360) {
  38793. rotate = rotate % 360;
  38794. } else if (rotate < 0) {
  38795. // The spec doesn't cover negatives, assume its counterclockwise
  38796. // rotation. The following is the other implementation of modulo.
  38797. rotate = ((rotate % 360) + 360) % 360;
  38798. }
  38799. return shadow(this, 'rotate', rotate);
  38800. },
  38801. getContentStream: function Page_getContentStream() {
  38802. var content = this.content;
  38803. var stream;
  38804. if (isArray(content)) {
  38805. // fetching items
  38806. var xref = this.xref;
  38807. var i, n = content.length;
  38808. var streams = [];
  38809. for (i = 0; i < n; ++i) {
  38810. streams.push(xref.fetchIfRef(content[i]));
  38811. }
  38812. stream = new StreamsSequenceStream(streams);
  38813. } else if (isStream(content)) {
  38814. stream = content;
  38815. } else {
  38816. // replacing non-existent page content with empty one
  38817. stream = new NullStream();
  38818. }
  38819. return stream;
  38820. },
  38821. loadResources: function Page_loadResources(keys) {
  38822. if (!this.resourcesPromise) {
  38823. // TODO: add async getInheritedPageProp and remove this.
  38824. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  38825. }
  38826. return this.resourcesPromise.then(function resourceSuccess() {
  38827. var objectLoader = new ObjectLoader(this.resources.map,
  38828. keys,
  38829. this.xref);
  38830. return objectLoader.load();
  38831. }.bind(this));
  38832. },
  38833. getOperatorList: function Page_getOperatorList(handler, task, intent,
  38834. renderInteractiveForms) {
  38835. var self = this;
  38836. var pdfManager = this.pdfManager;
  38837. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  38838. []);
  38839. var resourcesPromise = this.loadResources([
  38840. 'ExtGState',
  38841. 'ColorSpace',
  38842. 'Pattern',
  38843. 'Shading',
  38844. 'XObject',
  38845. 'Font'
  38846. // ProcSet
  38847. // Properties
  38848. ]);
  38849. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  38850. handler, this.pageIndex,
  38851. this.uniquePrefix,
  38852. this.idCounters,
  38853. this.fontCache,
  38854. this.evaluatorOptions);
  38855. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  38856. var pageListPromise = dataPromises.then(function(data) {
  38857. var contentStream = data[0];
  38858. var opList = new OperatorList(intent, handler, self.pageIndex);
  38859. handler.send('StartRenderPage', {
  38860. transparency: partialEvaluator.hasBlendModes(self.resources),
  38861. pageIndex: self.pageIndex,
  38862. intent: intent
  38863. });
  38864. return partialEvaluator.getOperatorList(contentStream, task,
  38865. self.resources, opList).then(function () {
  38866. return opList;
  38867. });
  38868. });
  38869. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  38870. return Promise.all([pageListPromise, annotationsPromise]).then(
  38871. function(datas) {
  38872. var pageOpList = datas[0];
  38873. var annotations = datas[1];
  38874. if (annotations.length === 0) {
  38875. pageOpList.flush(true);
  38876. return pageOpList;
  38877. }
  38878. var annotationsReadyPromise = Annotation.appendToOperatorList(
  38879. annotations, pageOpList, partialEvaluator, task, intent,
  38880. renderInteractiveForms);
  38881. return annotationsReadyPromise.then(function () {
  38882. pageOpList.flush(true);
  38883. return pageOpList;
  38884. });
  38885. });
  38886. },
  38887. extractTextContent: function Page_extractTextContent(task,
  38888. normalizeWhitespace,
  38889. combineTextItems) {
  38890. var handler = {
  38891. on: function nullHandlerOn() {},
  38892. send: function nullHandlerSend() {}
  38893. };
  38894. var self = this;
  38895. var pdfManager = this.pdfManager;
  38896. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  38897. []);
  38898. var resourcesPromise = this.loadResources([
  38899. 'ExtGState',
  38900. 'XObject',
  38901. 'Font'
  38902. ]);
  38903. var dataPromises = Promise.all([contentStreamPromise,
  38904. resourcesPromise]);
  38905. return dataPromises.then(function(data) {
  38906. var contentStream = data[0];
  38907. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  38908. handler, self.pageIndex,
  38909. self.uniquePrefix,
  38910. self.idCounters,
  38911. self.fontCache,
  38912. self.evaluatorOptions);
  38913. return partialEvaluator.getTextContent(contentStream,
  38914. task,
  38915. self.resources,
  38916. /* stateManager = */ null,
  38917. normalizeWhitespace,
  38918. combineTextItems);
  38919. });
  38920. },
  38921. getAnnotationsData: function Page_getAnnotationsData(intent) {
  38922. var annotations = this.annotations;
  38923. var annotationsData = [];
  38924. for (var i = 0, n = annotations.length; i < n; ++i) {
  38925. if (intent) {
  38926. if (!(intent === 'display' && annotations[i].viewable) &&
  38927. !(intent === 'print' && annotations[i].printable)) {
  38928. continue;
  38929. }
  38930. }
  38931. annotationsData.push(annotations[i].data);
  38932. }
  38933. return annotationsData;
  38934. },
  38935. get annotations() {
  38936. var annotations = [];
  38937. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  38938. var annotationFactory = new AnnotationFactory();
  38939. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  38940. var annotationRef = annotationRefs[i];
  38941. var annotation = annotationFactory.create(this.xref, annotationRef,
  38942. this.uniquePrefix,
  38943. this.idCounters);
  38944. if (annotation) {
  38945. annotations.push(annotation);
  38946. }
  38947. }
  38948. return shadow(this, 'annotations', annotations);
  38949. }
  38950. };
  38951. return Page;
  38952. })();
  38953. /**
  38954. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  38955. * `PDFDoc`, this one doesn't have any job management code.
  38956. * Right now there exists one PDFDocument on the main thread + one object
  38957. * for each worker. If there is no worker support enabled, there are two
  38958. * `PDFDocument` objects on the main thread created.
  38959. */
  38960. var PDFDocument = (function PDFDocumentClosure() {
  38961. var FINGERPRINT_FIRST_BYTES = 1024;
  38962. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  38963. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  38964. function PDFDocument(pdfManager, arg, password) {
  38965. if (isStream(arg)) {
  38966. init.call(this, pdfManager, arg, password);
  38967. } else if (isArrayBuffer(arg)) {
  38968. init.call(this, pdfManager, new Stream(arg), password);
  38969. } else {
  38970. error('PDFDocument: Unknown argument type');
  38971. }
  38972. }
  38973. function init(pdfManager, stream, password) {
  38974. assert(stream.length > 0, 'stream must have data');
  38975. this.pdfManager = pdfManager;
  38976. this.stream = stream;
  38977. var xref = new XRef(this.stream, password, pdfManager);
  38978. this.xref = xref;
  38979. }
  38980. function find(stream, needle, limit, backwards) {
  38981. var pos = stream.pos;
  38982. var end = stream.end;
  38983. var strBuf = [];
  38984. if (pos + limit > end) {
  38985. limit = end - pos;
  38986. }
  38987. for (var n = 0; n < limit; ++n) {
  38988. strBuf.push(String.fromCharCode(stream.getByte()));
  38989. }
  38990. var str = strBuf.join('');
  38991. stream.pos = pos;
  38992. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  38993. if (index === -1) {
  38994. return false; /* not found */
  38995. }
  38996. stream.pos += index;
  38997. return true; /* found */
  38998. }
  38999. var DocumentInfoValidators = {
  39000. get entries() {
  39001. // Lazily build this since all the validation functions below are not
  39002. // defined until after this file loads.
  39003. return shadow(this, 'entries', {
  39004. Title: isString,
  39005. Author: isString,
  39006. Subject: isString,
  39007. Keywords: isString,
  39008. Creator: isString,
  39009. Producer: isString,
  39010. CreationDate: isString,
  39011. ModDate: isString,
  39012. Trapped: isName
  39013. });
  39014. }
  39015. };
  39016. PDFDocument.prototype = {
  39017. parse: function PDFDocument_parse(recoveryMode) {
  39018. this.setup(recoveryMode);
  39019. var version = this.catalog.catDict.get('Version');
  39020. if (isName(version)) {
  39021. this.pdfFormatVersion = version.name;
  39022. }
  39023. try {
  39024. // checking if AcroForm is present
  39025. this.acroForm = this.catalog.catDict.get('AcroForm');
  39026. if (this.acroForm) {
  39027. this.xfa = this.acroForm.get('XFA');
  39028. var fields = this.acroForm.get('Fields');
  39029. if ((!fields || !isArray(fields) || fields.length === 0) &&
  39030. !this.xfa) {
  39031. // no fields and no XFA -- not a form (?)
  39032. this.acroForm = null;
  39033. }
  39034. }
  39035. } catch (ex) {
  39036. info('Something wrong with AcroForm entry');
  39037. this.acroForm = null;
  39038. }
  39039. },
  39040. get linearization() {
  39041. var linearization = null;
  39042. if (this.stream.length) {
  39043. try {
  39044. linearization = Linearization.create(this.stream);
  39045. } catch (err) {
  39046. if (err instanceof MissingDataException) {
  39047. throw err;
  39048. }
  39049. info(err);
  39050. }
  39051. }
  39052. // shadow the prototype getter with a data property
  39053. return shadow(this, 'linearization', linearization);
  39054. },
  39055. get startXRef() {
  39056. var stream = this.stream;
  39057. var startXRef = 0;
  39058. var linearization = this.linearization;
  39059. if (linearization) {
  39060. // Find end of first obj.
  39061. stream.reset();
  39062. if (find(stream, 'endobj', 1024)) {
  39063. startXRef = stream.pos + 6;
  39064. }
  39065. } else {
  39066. // Find startxref by jumping backward from the end of the file.
  39067. var step = 1024;
  39068. var found = false, pos = stream.end;
  39069. while (!found && pos > 0) {
  39070. pos -= step - 'startxref'.length;
  39071. if (pos < 0) {
  39072. pos = 0;
  39073. }
  39074. stream.pos = pos;
  39075. found = find(stream, 'startxref', step, true);
  39076. }
  39077. if (found) {
  39078. stream.skip(9);
  39079. var ch;
  39080. do {
  39081. ch = stream.getByte();
  39082. } while (isSpace(ch));
  39083. var str = '';
  39084. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  39085. str += String.fromCharCode(ch);
  39086. ch = stream.getByte();
  39087. }
  39088. startXRef = parseInt(str, 10);
  39089. if (isNaN(startXRef)) {
  39090. startXRef = 0;
  39091. }
  39092. }
  39093. }
  39094. // shadow the prototype getter with a data property
  39095. return shadow(this, 'startXRef', startXRef);
  39096. },
  39097. get mainXRefEntriesOffset() {
  39098. var mainXRefEntriesOffset = 0;
  39099. var linearization = this.linearization;
  39100. if (linearization) {
  39101. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  39102. }
  39103. // shadow the prototype getter with a data property
  39104. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  39105. },
  39106. // Find the header, remove leading garbage and setup the stream
  39107. // starting from the header.
  39108. checkHeader: function PDFDocument_checkHeader() {
  39109. var stream = this.stream;
  39110. stream.reset();
  39111. if (find(stream, '%PDF-', 1024)) {
  39112. // Found the header, trim off any garbage before it.
  39113. stream.moveStart();
  39114. // Reading file format version
  39115. var MAX_VERSION_LENGTH = 12;
  39116. var version = '', ch;
  39117. while ((ch = stream.getByte()) > 0x20) { // SPACE
  39118. if (version.length >= MAX_VERSION_LENGTH) {
  39119. break;
  39120. }
  39121. version += String.fromCharCode(ch);
  39122. }
  39123. if (!this.pdfFormatVersion) {
  39124. // removing "%PDF-"-prefix
  39125. this.pdfFormatVersion = version.substring(5);
  39126. }
  39127. return;
  39128. }
  39129. // May not be a PDF file, continue anyway.
  39130. },
  39131. parseStartXRef: function PDFDocument_parseStartXRef() {
  39132. var startXRef = this.startXRef;
  39133. this.xref.setStartXRef(startXRef);
  39134. },
  39135. setup: function PDFDocument_setup(recoveryMode) {
  39136. this.xref.parse(recoveryMode);
  39137. var self = this;
  39138. var pageFactory = {
  39139. createPage: function (pageIndex, dict, ref, fontCache) {
  39140. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  39141. fontCache);
  39142. }
  39143. };
  39144. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  39145. },
  39146. get numPages() {
  39147. var linearization = this.linearization;
  39148. var num = linearization ? linearization.numPages : this.catalog.numPages;
  39149. // shadow the prototype getter
  39150. return shadow(this, 'numPages', num);
  39151. },
  39152. get documentInfo() {
  39153. var docInfo = {
  39154. PDFFormatVersion: this.pdfFormatVersion,
  39155. IsAcroFormPresent: !!this.acroForm,
  39156. IsXFAPresent: !!this.xfa
  39157. };
  39158. var infoDict;
  39159. try {
  39160. infoDict = this.xref.trailer.get('Info');
  39161. } catch (err) {
  39162. info('The document information dictionary is invalid.');
  39163. }
  39164. if (infoDict) {
  39165. var validEntries = DocumentInfoValidators.entries;
  39166. // Only fill the document info with valid entries from the spec.
  39167. for (var key in validEntries) {
  39168. if (infoDict.has(key)) {
  39169. var value = infoDict.get(key);
  39170. // Make sure the value conforms to the spec.
  39171. if (validEntries[key](value)) {
  39172. docInfo[key] = (typeof value !== 'string' ?
  39173. value : stringToPDFString(value));
  39174. } else {
  39175. info('Bad value in document info for "' + key + '"');
  39176. }
  39177. }
  39178. }
  39179. }
  39180. return shadow(this, 'documentInfo', docInfo);
  39181. },
  39182. get fingerprint() {
  39183. var xref = this.xref, hash, fileID = '';
  39184. var idArray = xref.trailer.get('ID');
  39185. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  39186. idArray[0] !== EMPTY_FINGERPRINT) {
  39187. hash = stringToBytes(idArray[0]);
  39188. } else {
  39189. if (this.stream.ensureRange) {
  39190. this.stream.ensureRange(0,
  39191. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  39192. }
  39193. hash = calculateMD5(this.stream.bytes.subarray(0,
  39194. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  39195. }
  39196. for (var i = 0, n = hash.length; i < n; i++) {
  39197. var hex = hash[i].toString(16);
  39198. fileID += hex.length === 1 ? '0' + hex : hex;
  39199. }
  39200. return shadow(this, 'fingerprint', fileID);
  39201. },
  39202. getPage: function PDFDocument_getPage(pageIndex) {
  39203. return this.catalog.getPage(pageIndex);
  39204. },
  39205. cleanup: function PDFDocument_cleanup() {
  39206. return this.catalog.cleanup();
  39207. }
  39208. };
  39209. return PDFDocument;
  39210. })();
  39211. exports.Page = Page;
  39212. exports.PDFDocument = PDFDocument;
  39213. }));
  39214. (function (root, factory) {
  39215. {
  39216. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  39217. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  39218. root.pdfjsCoreDocument);
  39219. }
  39220. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  39221. coreDocument) {
  39222. var NotImplementedException = sharedUtil.NotImplementedException;
  39223. var MissingDataException = sharedUtil.MissingDataException;
  39224. var createPromiseCapability = sharedUtil.createPromiseCapability;
  39225. var Util = sharedUtil.Util;
  39226. var Stream = coreStream.Stream;
  39227. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  39228. var PDFDocument = coreDocument.PDFDocument;
  39229. var BasePdfManager = (function BasePdfManagerClosure() {
  39230. function BasePdfManager() {
  39231. throw new Error('Cannot initialize BaseManagerManager');
  39232. }
  39233. BasePdfManager.prototype = {
  39234. get docId() {
  39235. return this._docId;
  39236. },
  39237. onLoadedStream: function BasePdfManager_onLoadedStream() {
  39238. throw new NotImplementedException();
  39239. },
  39240. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  39241. return this.ensure(this.pdfDocument, prop, args);
  39242. },
  39243. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  39244. return this.ensure(this.pdfDocument.xref, prop, args);
  39245. },
  39246. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  39247. return this.ensure(this.pdfDocument.catalog, prop, args);
  39248. },
  39249. getPage: function BasePdfManager_getPage(pageIndex) {
  39250. return this.pdfDocument.getPage(pageIndex);
  39251. },
  39252. cleanup: function BasePdfManager_cleanup() {
  39253. return this.pdfDocument.cleanup();
  39254. },
  39255. ensure: function BasePdfManager_ensure(obj, prop, args) {
  39256. return new NotImplementedException();
  39257. },
  39258. requestRange: function BasePdfManager_requestRange(begin, end) {
  39259. return new NotImplementedException();
  39260. },
  39261. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  39262. return new NotImplementedException();
  39263. },
  39264. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  39265. return new NotImplementedException();
  39266. },
  39267. updatePassword: function BasePdfManager_updatePassword(password) {
  39268. this.pdfDocument.xref.password = this.password = password;
  39269. if (this._passwordChangedCapability) {
  39270. this._passwordChangedCapability.resolve();
  39271. }
  39272. },
  39273. passwordChanged: function BasePdfManager_passwordChanged() {
  39274. this._passwordChangedCapability = createPromiseCapability();
  39275. return this._passwordChangedCapability.promise;
  39276. },
  39277. terminate: function BasePdfManager_terminate() {
  39278. return new NotImplementedException();
  39279. }
  39280. };
  39281. return BasePdfManager;
  39282. })();
  39283. var LocalPdfManager = (function LocalPdfManagerClosure() {
  39284. function LocalPdfManager(docId, data, password, evaluatorOptions) {
  39285. this._docId = docId;
  39286. this.evaluatorOptions = evaluatorOptions;
  39287. var stream = new Stream(data);
  39288. this.pdfDocument = new PDFDocument(this, stream, password);
  39289. this._loadedStreamCapability = createPromiseCapability();
  39290. this._loadedStreamCapability.resolve(stream);
  39291. }
  39292. Util.inherit(LocalPdfManager, BasePdfManager, {
  39293. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  39294. return new Promise(function (resolve, reject) {
  39295. try {
  39296. var value = obj[prop];
  39297. var result;
  39298. if (typeof value === 'function') {
  39299. result = value.apply(obj, args);
  39300. } else {
  39301. result = value;
  39302. }
  39303. resolve(result);
  39304. } catch (e) {
  39305. reject(e);
  39306. }
  39307. });
  39308. },
  39309. requestRange: function LocalPdfManager_requestRange(begin, end) {
  39310. return Promise.resolve();
  39311. },
  39312. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  39313. return;
  39314. },
  39315. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  39316. return this._loadedStreamCapability.promise;
  39317. },
  39318. terminate: function LocalPdfManager_terminate() {
  39319. return;
  39320. }
  39321. });
  39322. return LocalPdfManager;
  39323. })();
  39324. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  39325. function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions) {
  39326. this._docId = docId;
  39327. this.msgHandler = args.msgHandler;
  39328. this.evaluatorOptions = evaluatorOptions;
  39329. var params = {
  39330. msgHandler: args.msgHandler,
  39331. url: args.url,
  39332. length: args.length,
  39333. disableAutoFetch: args.disableAutoFetch,
  39334. rangeChunkSize: args.rangeChunkSize
  39335. };
  39336. this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
  39337. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  39338. args.password);
  39339. }
  39340. Util.inherit(NetworkPdfManager, BasePdfManager, {
  39341. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  39342. var pdfManager = this;
  39343. return new Promise(function (resolve, reject) {
  39344. function ensureHelper() {
  39345. try {
  39346. var result;
  39347. var value = obj[prop];
  39348. if (typeof value === 'function') {
  39349. result = value.apply(obj, args);
  39350. } else {
  39351. result = value;
  39352. }
  39353. resolve(result);
  39354. } catch(e) {
  39355. if (!(e instanceof MissingDataException)) {
  39356. reject(e);
  39357. return;
  39358. }
  39359. pdfManager.streamManager.requestRange(e.begin, e.end).
  39360. then(ensureHelper, reject);
  39361. }
  39362. }
  39363. ensureHelper();
  39364. });
  39365. },
  39366. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  39367. return this.streamManager.requestRange(begin, end);
  39368. },
  39369. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  39370. this.streamManager.requestAllChunks();
  39371. },
  39372. sendProgressiveData:
  39373. function NetworkPdfManager_sendProgressiveData(chunk) {
  39374. this.streamManager.onReceiveData({ chunk: chunk });
  39375. },
  39376. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  39377. return this.streamManager.onLoadedStream();
  39378. },
  39379. terminate: function NetworkPdfManager_terminate() {
  39380. this.streamManager.abort();
  39381. }
  39382. });
  39383. return NetworkPdfManager;
  39384. })();
  39385. exports.LocalPdfManager = LocalPdfManager;
  39386. exports.NetworkPdfManager = NetworkPdfManager;
  39387. }));
  39388. (function (root, factory) {
  39389. {
  39390. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  39391. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager);
  39392. }
  39393. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager) {
  39394. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  39395. var InvalidPDFException = sharedUtil.InvalidPDFException;
  39396. var MessageHandler = sharedUtil.MessageHandler;
  39397. var MissingPDFException = sharedUtil.MissingPDFException;
  39398. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  39399. var PasswordException = sharedUtil.PasswordException;
  39400. var PasswordResponses = sharedUtil.PasswordResponses;
  39401. var UnknownErrorException = sharedUtil.UnknownErrorException;
  39402. var XRefParseException = sharedUtil.XRefParseException;
  39403. var arrayByteLength = sharedUtil.arrayByteLength;
  39404. var arraysToBytes = sharedUtil.arraysToBytes;
  39405. var assert = sharedUtil.assert;
  39406. var createPromiseCapability = sharedUtil.createPromiseCapability;
  39407. var error = sharedUtil.error;
  39408. var info = sharedUtil.info;
  39409. var warn = sharedUtil.warn;
  39410. var setVerbosityLevel = sharedUtil.setVerbosityLevel;
  39411. var Ref = corePrimitives.Ref;
  39412. var LocalPdfManager = corePdfManager.LocalPdfManager;
  39413. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  39414. var globalScope = sharedUtil.globalScope;
  39415. var WorkerTask = (function WorkerTaskClosure() {
  39416. function WorkerTask(name) {
  39417. this.name = name;
  39418. this.terminated = false;
  39419. this._capability = createPromiseCapability();
  39420. }
  39421. WorkerTask.prototype = {
  39422. get finished() {
  39423. return this._capability.promise;
  39424. },
  39425. finish: function () {
  39426. this._capability.resolve();
  39427. },
  39428. terminate: function () {
  39429. this.terminated = true;
  39430. },
  39431. ensureNotTerminated: function () {
  39432. if (this.terminated) {
  39433. throw new Error('Worker task was terminated');
  39434. }
  39435. }
  39436. };
  39437. return WorkerTask;
  39438. })();
  39439. /** @implements {IPDFStream} */
  39440. var PDFWorkerStream = (function PDFWorkerStreamClosure() {
  39441. function PDFWorkerStream(params, msgHandler) {
  39442. this._queuedChunks = [];
  39443. var initialData = params.initialData;
  39444. if (initialData && initialData.length > 0) {
  39445. this._queuedChunks.push(initialData);
  39446. }
  39447. this._msgHandler = msgHandler;
  39448. this._isRangeSupported = !(params.disableRange);
  39449. this._isStreamingSupported = !(params.disableStream);
  39450. this._contentLength = params.length;
  39451. this._fullRequestReader = null;
  39452. this._rangeReaders = [];
  39453. msgHandler.on('OnDataRange', this._onReceiveData.bind(this));
  39454. msgHandler.on('OnDataProgress', this._onProgress.bind(this));
  39455. }
  39456. PDFWorkerStream.prototype = {
  39457. _onReceiveData: function PDFWorkerStream_onReceiveData(args) {
  39458. if (args.begin === undefined) {
  39459. if (this._fullRequestReader) {
  39460. this._fullRequestReader._enqueue(args.chunk);
  39461. } else {
  39462. this._queuedChunks.push(args.chunk);
  39463. }
  39464. } else {
  39465. var found = this._rangeReaders.some(function (rangeReader) {
  39466. if (rangeReader._begin !== args.begin) {
  39467. return false;
  39468. }
  39469. rangeReader._enqueue(args.chunk);
  39470. return true;
  39471. });
  39472. assert(found);
  39473. }
  39474. },
  39475. _onProgress: function PDFWorkerStream_onProgress(evt) {
  39476. if (this._rangeReaders.length > 0) {
  39477. // Reporting to first range reader.
  39478. var firstReader = this._rangeReaders[0];
  39479. if (firstReader.onProgress) {
  39480. firstReader.onProgress({loaded: evt.loaded});
  39481. }
  39482. }
  39483. },
  39484. _removeRangeReader: function PDFWorkerStream_removeRangeReader(reader) {
  39485. var i = this._rangeReaders.indexOf(reader);
  39486. if (i >= 0) {
  39487. this._rangeReaders.splice(i, 1);
  39488. }
  39489. },
  39490. getFullReader: function PDFWorkerStream_getFullReader() {
  39491. assert(!this._fullRequestReader);
  39492. var queuedChunks = this._queuedChunks;
  39493. this._queuedChunks = null;
  39494. return new PDFWorkerStreamReader(this, queuedChunks);
  39495. },
  39496. getRangeReader: function PDFWorkerStream_getRangeReader(begin, end) {
  39497. var reader = new PDFWorkerStreamRangeReader(this, begin, end);
  39498. this._msgHandler.send('RequestDataRange', { begin: begin, end: end });
  39499. this._rangeReaders.push(reader);
  39500. return reader;
  39501. },
  39502. cancelAllRequests: function PDFWorkerStream_cancelAllRequests(reason) {
  39503. if (this._fullRequestReader) {
  39504. this._fullRequestReader.cancel(reason);
  39505. }
  39506. var readers = this._rangeReaders.slice(0);
  39507. readers.forEach(function (rangeReader) {
  39508. rangeReader.cancel(reason);
  39509. });
  39510. }
  39511. };
  39512. /** @implements {IPDFStreamReader} */
  39513. function PDFWorkerStreamReader(stream, queuedChunks) {
  39514. this._stream = stream;
  39515. this._done = false;
  39516. this._queuedChunks = queuedChunks || [];
  39517. this._requests = [];
  39518. this._headersReady = Promise.resolve();
  39519. stream._fullRequestReader = this;
  39520. this.onProgress = null; // not used
  39521. }
  39522. PDFWorkerStreamReader.prototype = {
  39523. _enqueue: function PDFWorkerStreamReader_enqueue(chunk) {
  39524. if (this._done) {
  39525. return; // ignore new data
  39526. }
  39527. if (this._requests.length > 0) {
  39528. var requestCapability = this._requests.shift();
  39529. requestCapability.resolve({value: chunk, done: false});
  39530. return;
  39531. }
  39532. this._queuedChunks.push(chunk);
  39533. },
  39534. get headersReady() {
  39535. return this._headersReady;
  39536. },
  39537. get isRangeSupported() {
  39538. return this._stream._isRangeSupported;
  39539. },
  39540. get isStreamingSupported() {
  39541. return this._stream._isStreamingSupported;
  39542. },
  39543. get contentLength() {
  39544. return this._stream._contentLength;
  39545. },
  39546. read: function PDFWorkerStreamReader_read() {
  39547. if (this._queuedChunks.length > 0) {
  39548. var chunk = this._queuedChunks.shift();
  39549. return Promise.resolve({value: chunk, done: false});
  39550. }
  39551. if (this._done) {
  39552. return Promise.resolve({value: undefined, done: true});
  39553. }
  39554. var requestCapability = createPromiseCapability();
  39555. this._requests.push(requestCapability);
  39556. return requestCapability.promise;
  39557. },
  39558. cancel: function PDFWorkerStreamReader_cancel(reason) {
  39559. this._done = true;
  39560. this._requests.forEach(function (requestCapability) {
  39561. requestCapability.resolve({value: undefined, done: true});
  39562. });
  39563. this._requests = [];
  39564. }
  39565. };
  39566. /** @implements {IPDFStreamRangeReader} */
  39567. function PDFWorkerStreamRangeReader(stream, begin, end) {
  39568. this._stream = stream;
  39569. this._begin = begin;
  39570. this._end = end;
  39571. this._queuedChunk = null;
  39572. this._requests = [];
  39573. this._done = false;
  39574. this.onProgress = null;
  39575. }
  39576. PDFWorkerStreamRangeReader.prototype = {
  39577. _enqueue: function PDFWorkerStreamRangeReader_enqueue(chunk) {
  39578. if (this._done) {
  39579. return; // ignore new data
  39580. }
  39581. if (this._requests.length === 0) {
  39582. this._queuedChunk = chunk;
  39583. } else {
  39584. var requestsCapability = this._requests.shift();
  39585. requestsCapability.resolve({value: chunk, done: false});
  39586. this._requests.forEach(function (requestCapability) {
  39587. requestCapability.resolve({value: undefined, done: true});
  39588. });
  39589. this._requests = [];
  39590. }
  39591. this._done = true;
  39592. this._stream._removeRangeReader(this);
  39593. },
  39594. get isStreamingSupported() {
  39595. return false;
  39596. },
  39597. read: function PDFWorkerStreamRangeReader_read() {
  39598. if (this._queuedChunk) {
  39599. return Promise.resolve({value: this._queuedChunk, done: false});
  39600. }
  39601. if (this._done) {
  39602. return Promise.resolve({value: undefined, done: true});
  39603. }
  39604. var requestCapability = createPromiseCapability();
  39605. this._requests.push(requestCapability);
  39606. return requestCapability.promise;
  39607. },
  39608. cancel: function PDFWorkerStreamRangeReader_cancel(reason) {
  39609. this._done = true;
  39610. this._requests.forEach(function (requestCapability) {
  39611. requestCapability.resolve({value: undefined, done: true});
  39612. });
  39613. this._requests = [];
  39614. this._stream._removeRangeReader(this);
  39615. }
  39616. };
  39617. return PDFWorkerStream;
  39618. })();
  39619. /** @type IPDFStream */
  39620. var PDFNetworkStream;
  39621. /**
  39622. * Sets PDFNetworkStream class to be used as alternative PDF data transport.
  39623. * @param {IPDFStream} cls - the PDF data transport.
  39624. */
  39625. function setPDFNetworkStreamClass(cls) {
  39626. PDFNetworkStream = cls;
  39627. }
  39628. var WorkerMessageHandler = {
  39629. setup: function wphSetup(handler, port) {
  39630. var testMessageProcessed = false;
  39631. handler.on('test', function wphSetupTest(data) {
  39632. if (testMessageProcessed) {
  39633. return; // we already processed 'test' message once
  39634. }
  39635. testMessageProcessed = true;
  39636. // check if Uint8Array can be sent to worker
  39637. if (!(data instanceof Uint8Array)) {
  39638. handler.send('test', 'main', false);
  39639. return;
  39640. }
  39641. // making sure postMessage transfers are working
  39642. var supportTransfers = data[0] === 255;
  39643. handler.postMessageTransfers = supportTransfers;
  39644. // check if the response property is supported by xhr
  39645. var xhr = new XMLHttpRequest();
  39646. var responseExists = 'response' in xhr;
  39647. // check if the property is actually implemented
  39648. try {
  39649. var dummy = xhr.responseType;
  39650. } catch (e) {
  39651. responseExists = false;
  39652. }
  39653. if (!responseExists) {
  39654. handler.send('test', false);
  39655. return;
  39656. }
  39657. handler.send('test', {
  39658. supportTypedArray: true,
  39659. supportTransfers: supportTransfers
  39660. });
  39661. });
  39662. handler.on('configure', function wphConfigure(data) {
  39663. setVerbosityLevel(data.verbosity);
  39664. });
  39665. handler.on('GetDocRequest', function wphSetupDoc(data) {
  39666. return WorkerMessageHandler.createDocumentHandler(data, port);
  39667. });
  39668. },
  39669. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  39670. // This context is actually holds references on pdfManager and handler,
  39671. // until the latter is destroyed.
  39672. var pdfManager;
  39673. var terminated = false;
  39674. var cancelXHRs = null;
  39675. var WorkerTasks = [];
  39676. var docId = docParams.docId;
  39677. var workerHandlerName = docParams.docId + '_worker';
  39678. var handler = new MessageHandler(workerHandlerName, docId, port);
  39679. // Ensure that postMessage transfers are correctly enabled/disabled,
  39680. // to prevent "DataCloneError" in older versions of IE (see issue 6957).
  39681. handler.postMessageTransfers = docParams.postMessageTransfers;
  39682. function ensureNotTerminated() {
  39683. if (terminated) {
  39684. throw new Error('Worker was terminated');
  39685. }
  39686. }
  39687. function startWorkerTask(task) {
  39688. WorkerTasks.push(task);
  39689. }
  39690. function finishWorkerTask(task) {
  39691. task.finish();
  39692. var i = WorkerTasks.indexOf(task);
  39693. WorkerTasks.splice(i, 1);
  39694. }
  39695. function loadDocument(recoveryMode) {
  39696. var loadDocumentCapability = createPromiseCapability();
  39697. var parseSuccess = function parseSuccess() {
  39698. var numPagesPromise = pdfManager.ensureDoc('numPages');
  39699. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  39700. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  39701. Promise.all([numPagesPromise, fingerprintPromise,
  39702. encryptedPromise]).then(function onDocReady(results) {
  39703. var doc = {
  39704. numPages: results[0],
  39705. fingerprint: results[1],
  39706. encrypted: !!results[2],
  39707. };
  39708. loadDocumentCapability.resolve(doc);
  39709. },
  39710. parseFailure);
  39711. };
  39712. var parseFailure = function parseFailure(e) {
  39713. loadDocumentCapability.reject(e);
  39714. };
  39715. pdfManager.ensureDoc('checkHeader', []).then(function() {
  39716. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  39717. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  39718. parseSuccess, parseFailure);
  39719. }, parseFailure);
  39720. }, parseFailure);
  39721. return loadDocumentCapability.promise;
  39722. }
  39723. function getPdfManager(data, evaluatorOptions) {
  39724. var pdfManagerCapability = createPromiseCapability();
  39725. var pdfManager;
  39726. var source = data.source;
  39727. if (source.data) {
  39728. try {
  39729. pdfManager = new LocalPdfManager(docId, source.data, source.password,
  39730. evaluatorOptions);
  39731. pdfManagerCapability.resolve(pdfManager);
  39732. } catch (ex) {
  39733. pdfManagerCapability.reject(ex);
  39734. }
  39735. return pdfManagerCapability.promise;
  39736. }
  39737. var pdfStream;
  39738. try {
  39739. if (source.chunkedViewerLoading) {
  39740. pdfStream = new PDFWorkerStream(source, handler);
  39741. } else {
  39742. assert(PDFNetworkStream, 'pdfjs/core/network module is not loaded');
  39743. pdfStream = new PDFNetworkStream(data);
  39744. }
  39745. } catch (ex) {
  39746. pdfManagerCapability.reject(ex);
  39747. return pdfManagerCapability.promise;
  39748. }
  39749. var fullRequest = pdfStream.getFullReader();
  39750. fullRequest.headersReady.then(function () {
  39751. if (!fullRequest.isStreamingSupported ||
  39752. !fullRequest.isRangeSupported) {
  39753. // If stream or range are disabled, it's our only way to report
  39754. // loading progress.
  39755. fullRequest.onProgress = function (evt) {
  39756. handler.send('DocProgress', {
  39757. loaded: evt.loaded,
  39758. total: evt.total
  39759. });
  39760. };
  39761. }
  39762. if (!fullRequest.isRangeSupported) {
  39763. return;
  39764. }
  39765. // We don't need auto-fetch when streaming is enabled.
  39766. var disableAutoFetch = source.disableAutoFetch ||
  39767. fullRequest.isStreamingSupported;
  39768. pdfManager = new NetworkPdfManager(docId, pdfStream, {
  39769. msgHandler: handler,
  39770. url: source.url,
  39771. password: source.password,
  39772. length: fullRequest.contentLength,
  39773. disableAutoFetch: disableAutoFetch,
  39774. rangeChunkSize: source.rangeChunkSize
  39775. }, evaluatorOptions);
  39776. pdfManagerCapability.resolve(pdfManager);
  39777. cancelXHRs = null;
  39778. }).catch(function (reason) {
  39779. pdfManagerCapability.reject(reason);
  39780. cancelXHRs = null;
  39781. });
  39782. var cachedChunks = [], loaded = 0;
  39783. var flushChunks = function () {
  39784. var pdfFile = arraysToBytes(cachedChunks);
  39785. if (source.length && pdfFile.length !== source.length) {
  39786. warn('reported HTTP length is different from actual');
  39787. }
  39788. // the data is array, instantiating directly from it
  39789. try {
  39790. pdfManager = new LocalPdfManager(docId, pdfFile, source.password,
  39791. evaluatorOptions);
  39792. pdfManagerCapability.resolve(pdfManager);
  39793. } catch (ex) {
  39794. pdfManagerCapability.reject(ex);
  39795. }
  39796. cachedChunks = [];
  39797. };
  39798. var readPromise = new Promise(function (resolve, reject) {
  39799. var readChunk = function (chunk) {
  39800. try {
  39801. ensureNotTerminated();
  39802. if (chunk.done) {
  39803. if (!pdfManager) {
  39804. flushChunks();
  39805. }
  39806. cancelXHRs = null;
  39807. return;
  39808. }
  39809. var data = chunk.value;
  39810. loaded += arrayByteLength(data);
  39811. if (!fullRequest.isStreamingSupported) {
  39812. handler.send('DocProgress', {
  39813. loaded: loaded,
  39814. total: Math.max(loaded, fullRequest.contentLength || 0)
  39815. });
  39816. }
  39817. if (pdfManager) {
  39818. pdfManager.sendProgressiveData(data);
  39819. } else {
  39820. cachedChunks.push(data);
  39821. }
  39822. fullRequest.read().then(readChunk, reject);
  39823. } catch (e) {
  39824. reject(e);
  39825. }
  39826. };
  39827. fullRequest.read().then(readChunk, reject);
  39828. });
  39829. readPromise.catch(function (e) {
  39830. pdfManagerCapability.reject(e);
  39831. cancelXHRs = null;
  39832. });
  39833. cancelXHRs = function () {
  39834. pdfStream.cancelAllRequests('abort');
  39835. };
  39836. return pdfManagerCapability.promise;
  39837. }
  39838. var setupDoc = function(data) {
  39839. var onSuccess = function(doc) {
  39840. ensureNotTerminated();
  39841. handler.send('GetDoc', { pdfInfo: doc });
  39842. };
  39843. var onFailure = function(e) {
  39844. if (e instanceof PasswordException) {
  39845. if (e.code === PasswordResponses.NEED_PASSWORD) {
  39846. handler.send('NeedPassword', e);
  39847. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  39848. handler.send('IncorrectPassword', e);
  39849. }
  39850. } else if (e instanceof InvalidPDFException) {
  39851. handler.send('InvalidPDF', e);
  39852. } else if (e instanceof MissingPDFException) {
  39853. handler.send('MissingPDF', e);
  39854. } else if (e instanceof UnexpectedResponseException) {
  39855. handler.send('UnexpectedResponse', e);
  39856. } else {
  39857. handler.send('UnknownError',
  39858. new UnknownErrorException(e.message, e.toString()));
  39859. }
  39860. };
  39861. ensureNotTerminated();
  39862. var cMapOptions = {
  39863. url: data.cMapUrl === undefined ? null : data.cMapUrl,
  39864. packed: data.cMapPacked === true
  39865. };
  39866. var evaluatorOptions = {
  39867. forceDataSchema: data.disableCreateObjectURL,
  39868. maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize,
  39869. disableFontFace: data.disableFontFace,
  39870. cMapOptions: cMapOptions
  39871. };
  39872. getPdfManager(data, evaluatorOptions).then(function (newPdfManager) {
  39873. if (terminated) {
  39874. // We were in a process of setting up the manager, but it got
  39875. // terminated in the middle.
  39876. newPdfManager.terminate();
  39877. throw new Error('Worker was terminated');
  39878. }
  39879. pdfManager = newPdfManager;
  39880. handler.send('PDFManagerReady', null);
  39881. pdfManager.onLoadedStream().then(function(stream) {
  39882. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  39883. });
  39884. }).then(function pdfManagerReady() {
  39885. ensureNotTerminated();
  39886. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  39887. ensureNotTerminated();
  39888. // Try again with recoveryMode == true
  39889. if (!(ex instanceof XRefParseException)) {
  39890. if (ex instanceof PasswordException) {
  39891. // after password exception prepare to receive a new password
  39892. // to repeat loading
  39893. pdfManager.passwordChanged().then(pdfManagerReady);
  39894. }
  39895. onFailure(ex);
  39896. return;
  39897. }
  39898. pdfManager.requestLoadedStream();
  39899. pdfManager.onLoadedStream().then(function() {
  39900. ensureNotTerminated();
  39901. loadDocument(true).then(onSuccess, onFailure);
  39902. });
  39903. }, onFailure);
  39904. }, onFailure);
  39905. };
  39906. handler.on('GetPage', function wphSetupGetPage(data) {
  39907. return pdfManager.getPage(data.pageIndex).then(function(page) {
  39908. var rotatePromise = pdfManager.ensure(page, 'rotate');
  39909. var refPromise = pdfManager.ensure(page, 'ref');
  39910. var viewPromise = pdfManager.ensure(page, 'view');
  39911. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  39912. function(results) {
  39913. return {
  39914. rotate: results[0],
  39915. ref: results[1],
  39916. view: results[2]
  39917. };
  39918. });
  39919. });
  39920. });
  39921. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  39922. var ref = new Ref(data.ref.num, data.ref.gen);
  39923. var catalog = pdfManager.pdfDocument.catalog;
  39924. return catalog.getPageIndex(ref);
  39925. });
  39926. handler.on('GetDestinations',
  39927. function wphSetupGetDestinations(data) {
  39928. return pdfManager.ensureCatalog('destinations');
  39929. }
  39930. );
  39931. handler.on('GetDestination',
  39932. function wphSetupGetDestination(data) {
  39933. return pdfManager.ensureCatalog('getDestination', [data.id]);
  39934. }
  39935. );
  39936. handler.on('GetPageLabels',
  39937. function wphSetupGetPageLabels(data) {
  39938. return pdfManager.ensureCatalog('pageLabels');
  39939. }
  39940. );
  39941. handler.on('GetAttachments',
  39942. function wphSetupGetAttachments(data) {
  39943. return pdfManager.ensureCatalog('attachments');
  39944. }
  39945. );
  39946. handler.on('GetJavaScript',
  39947. function wphSetupGetJavaScript(data) {
  39948. return pdfManager.ensureCatalog('javaScript');
  39949. }
  39950. );
  39951. handler.on('GetOutline',
  39952. function wphSetupGetOutline(data) {
  39953. return pdfManager.ensureCatalog('documentOutline');
  39954. }
  39955. );
  39956. handler.on('GetMetadata',
  39957. function wphSetupGetMetadata(data) {
  39958. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  39959. pdfManager.ensureCatalog('metadata')]);
  39960. }
  39961. );
  39962. handler.on('GetData', function wphSetupGetData(data) {
  39963. pdfManager.requestLoadedStream();
  39964. return pdfManager.onLoadedStream().then(function(stream) {
  39965. return stream.bytes;
  39966. });
  39967. });
  39968. handler.on('GetStats',
  39969. function wphSetupGetStats(data) {
  39970. return pdfManager.pdfDocument.xref.stats;
  39971. }
  39972. );
  39973. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  39974. pdfManager.updatePassword(data);
  39975. });
  39976. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  39977. return pdfManager.getPage(data.pageIndex).then(function(page) {
  39978. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  39979. });
  39980. });
  39981. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  39982. var pageIndex = data.pageIndex;
  39983. pdfManager.getPage(pageIndex).then(function(page) {
  39984. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  39985. startWorkerTask(task);
  39986. var pageNum = pageIndex + 1;
  39987. var start = Date.now();
  39988. // Pre compile the pdf page and fetch the fonts/images.
  39989. page.getOperatorList(handler, task, data.intent,
  39990. data.renderInteractiveForms).then(
  39991. function(operatorList) {
  39992. finishWorkerTask(task);
  39993. info('page=' + pageNum + ' - getOperatorList: time=' +
  39994. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  39995. }, function(e) {
  39996. finishWorkerTask(task);
  39997. if (task.terminated) {
  39998. return; // ignoring errors from the terminated thread
  39999. }
  40000. // For compatibility with older behavior, generating unknown
  40001. // unsupported feature notification on errors.
  40002. handler.send('UnsupportedFeature',
  40003. {featureId: UNSUPPORTED_FEATURES.unknown});
  40004. var minimumStackMessage =
  40005. 'worker.js: while trying to getPage() and getOperatorList()';
  40006. var wrappedException;
  40007. // Turn the error into an obj that can be serialized
  40008. if (typeof e === 'string') {
  40009. wrappedException = {
  40010. message: e,
  40011. stack: minimumStackMessage
  40012. };
  40013. } else if (typeof e === 'object') {
  40014. wrappedException = {
  40015. message: e.message || e.toString(),
  40016. stack: e.stack || minimumStackMessage
  40017. };
  40018. } else {
  40019. wrappedException = {
  40020. message: 'Unknown exception type: ' + (typeof e),
  40021. stack: minimumStackMessage
  40022. };
  40023. }
  40024. handler.send('PageError', {
  40025. pageNum: pageNum,
  40026. error: wrappedException,
  40027. intent: data.intent
  40028. });
  40029. });
  40030. });
  40031. }, this);
  40032. handler.on('GetTextContent', function wphExtractText(data) {
  40033. var pageIndex = data.pageIndex;
  40034. var normalizeWhitespace = data.normalizeWhitespace;
  40035. var combineTextItems = data.combineTextItems;
  40036. return pdfManager.getPage(pageIndex).then(function(page) {
  40037. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  40038. startWorkerTask(task);
  40039. var pageNum = pageIndex + 1;
  40040. var start = Date.now();
  40041. return page.extractTextContent(task, normalizeWhitespace,
  40042. combineTextItems).then(
  40043. function(textContent) {
  40044. finishWorkerTask(task);
  40045. info('text indexing: page=' + pageNum + ' - time=' +
  40046. (Date.now() - start) + 'ms');
  40047. return textContent;
  40048. }, function (reason) {
  40049. finishWorkerTask(task);
  40050. if (task.terminated) {
  40051. return; // ignoring errors from the terminated thread
  40052. }
  40053. throw reason;
  40054. });
  40055. });
  40056. });
  40057. handler.on('Cleanup', function wphCleanup(data) {
  40058. return pdfManager.cleanup();
  40059. });
  40060. handler.on('Terminate', function wphTerminate(data) {
  40061. terminated = true;
  40062. if (pdfManager) {
  40063. pdfManager.terminate();
  40064. pdfManager = null;
  40065. }
  40066. if (cancelXHRs) {
  40067. cancelXHRs();
  40068. }
  40069. var waitOn = [];
  40070. WorkerTasks.forEach(function (task) {
  40071. waitOn.push(task.finished);
  40072. task.terminate();
  40073. });
  40074. return Promise.all(waitOn).then(function () {
  40075. // Notice that even if we destroying handler, resolved response promise
  40076. // must be sent back.
  40077. handler.destroy();
  40078. handler = null;
  40079. });
  40080. });
  40081. handler.on('Ready', function wphReady(data) {
  40082. setupDoc(docParams);
  40083. docParams = null; // we don't need docParams anymore -- saving memory.
  40084. });
  40085. return workerHandlerName;
  40086. }
  40087. };
  40088. function initializeWorker() {
  40089. if (!('console' in globalScope)) {
  40090. var consoleTimer = {};
  40091. var workerConsole = {
  40092. log: function log() {
  40093. var args = Array.prototype.slice.call(arguments);
  40094. globalScope.postMessage({
  40095. targetName: 'main',
  40096. action: 'console_log',
  40097. data: args
  40098. });
  40099. },
  40100. error: function error() {
  40101. var args = Array.prototype.slice.call(arguments);
  40102. globalScope.postMessage({
  40103. targetName: 'main',
  40104. action: 'console_error',
  40105. data: args
  40106. });
  40107. throw 'pdf.js execution error';
  40108. },
  40109. time: function time(name) {
  40110. consoleTimer[name] = Date.now();
  40111. },
  40112. timeEnd: function timeEnd(name) {
  40113. var time = consoleTimer[name];
  40114. if (!time) {
  40115. error('Unknown timer name ' + name);
  40116. }
  40117. this.log('Timer:', name, Date.now() - time);
  40118. }
  40119. };
  40120. globalScope.console = workerConsole;
  40121. }
  40122. var handler = new MessageHandler('worker', 'main', self);
  40123. WorkerMessageHandler.setup(handler, self);
  40124. handler.send('ready', null);
  40125. }
  40126. // Worker thread (and not node.js)?
  40127. if (typeof window === 'undefined' &&
  40128. !(typeof module !== 'undefined' && module.require)) {
  40129. initializeWorker();
  40130. }
  40131. exports.setPDFNetworkStreamClass = setPDFNetworkStreamClass;
  40132. exports.WorkerTask = WorkerTask;
  40133. exports.WorkerMessageHandler = WorkerMessageHandler;
  40134. }));
  40135. var NetworkManager = (function NetworkManagerClosure() {
  40136. var OK_RESPONSE = 200;
  40137. var PARTIAL_CONTENT_RESPONSE = 206;
  40138. function NetworkManager(url, args) {
  40139. this.url = url;
  40140. args = args || {};
  40141. this.isHttp = /^https?:/i.test(url);
  40142. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  40143. this.withCredentials = args.withCredentials || false;
  40144. this.getXhr = args.getXhr ||
  40145. function NetworkManager_getXhr() {
  40146. return new XMLHttpRequest();
  40147. };
  40148. this.currXhrId = 0;
  40149. this.pendingRequests = Object.create(null);
  40150. this.loadedRequests = Object.create(null);
  40151. }
  40152. function getArrayBuffer(xhr) {
  40153. var data = xhr.response;
  40154. if (typeof data !== 'string') {
  40155. return data;
  40156. }
  40157. var length = data.length;
  40158. var array = new Uint8Array(length);
  40159. for (var i = 0; i < length; i++) {
  40160. array[i] = data.charCodeAt(i) & 0xFF;
  40161. }
  40162. return array.buffer;
  40163. }
  40164. var supportsMozChunked = (function supportsMozChunkedClosure() {
  40165. try {
  40166. var x = new XMLHttpRequest();
  40167. // Firefox 37- required .open() to be called before setting responseType.
  40168. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  40169. // Even though the URL is not visited, .open() could fail if the URL is
  40170. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  40171. // When this error occurs, this feature detection method will mistakenly
  40172. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  40173. x.open('GET', 'https://example.com');
  40174. x.responseType = 'moz-chunked-arraybuffer';
  40175. return x.responseType === 'moz-chunked-arraybuffer';
  40176. } catch (e) {
  40177. return false;
  40178. }
  40179. })();
  40180. NetworkManager.prototype = {
  40181. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  40182. var args = {
  40183. begin: begin,
  40184. end: end
  40185. };
  40186. for (var prop in listeners) {
  40187. args[prop] = listeners[prop];
  40188. }
  40189. return this.request(args);
  40190. },
  40191. requestFull: function NetworkManager_requestFull(listeners) {
  40192. return this.request(listeners);
  40193. },
  40194. request: function NetworkManager_request(args) {
  40195. var xhr = this.getXhr();
  40196. var xhrId = this.currXhrId++;
  40197. var pendingRequest = this.pendingRequests[xhrId] = {
  40198. xhr: xhr
  40199. };
  40200. xhr.open('GET', this.url);
  40201. xhr.withCredentials = this.withCredentials;
  40202. for (var property in this.httpHeaders) {
  40203. var value = this.httpHeaders[property];
  40204. if (typeof value === 'undefined') {
  40205. continue;
  40206. }
  40207. xhr.setRequestHeader(property, value);
  40208. }
  40209. if (this.isHttp && 'begin' in args && 'end' in args) {
  40210. var rangeStr = args.begin + '-' + (args.end - 1);
  40211. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  40212. pendingRequest.expectedStatus = 206;
  40213. } else {
  40214. pendingRequest.expectedStatus = 200;
  40215. }
  40216. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  40217. if (useMozChunkedLoading) {
  40218. xhr.responseType = 'moz-chunked-arraybuffer';
  40219. pendingRequest.onProgressiveData = args.onProgressiveData;
  40220. pendingRequest.mozChunked = true;
  40221. } else {
  40222. xhr.responseType = 'arraybuffer';
  40223. }
  40224. if (args.onError) {
  40225. xhr.onerror = function(evt) {
  40226. args.onError(xhr.status);
  40227. };
  40228. }
  40229. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  40230. xhr.onprogress = this.onProgress.bind(this, xhrId);
  40231. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  40232. pendingRequest.onDone = args.onDone;
  40233. pendingRequest.onError = args.onError;
  40234. pendingRequest.onProgress = args.onProgress;
  40235. xhr.send(null);
  40236. return xhrId;
  40237. },
  40238. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  40239. var pendingRequest = this.pendingRequests[xhrId];
  40240. if (!pendingRequest) {
  40241. // Maybe abortRequest was called...
  40242. return;
  40243. }
  40244. if (pendingRequest.mozChunked) {
  40245. var chunk = getArrayBuffer(pendingRequest.xhr);
  40246. pendingRequest.onProgressiveData(chunk);
  40247. }
  40248. var onProgress = pendingRequest.onProgress;
  40249. if (onProgress) {
  40250. onProgress(evt);
  40251. }
  40252. },
  40253. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  40254. var pendingRequest = this.pendingRequests[xhrId];
  40255. if (!pendingRequest) {
  40256. // Maybe abortRequest was called...
  40257. return;
  40258. }
  40259. var xhr = pendingRequest.xhr;
  40260. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  40261. pendingRequest.onHeadersReceived();
  40262. delete pendingRequest.onHeadersReceived;
  40263. }
  40264. if (xhr.readyState !== 4) {
  40265. return;
  40266. }
  40267. if (!(xhrId in this.pendingRequests)) {
  40268. // The XHR request might have been aborted in onHeadersReceived()
  40269. // callback, in which case we should abort request
  40270. return;
  40271. }
  40272. delete this.pendingRequests[xhrId];
  40273. // success status == 0 can be on ftp, file and other protocols
  40274. if (xhr.status === 0 && this.isHttp) {
  40275. if (pendingRequest.onError) {
  40276. pendingRequest.onError(xhr.status);
  40277. }
  40278. return;
  40279. }
  40280. var xhrStatus = xhr.status || OK_RESPONSE;
  40281. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  40282. // "A server MAY ignore the Range header". This means it's possible to
  40283. // get a 200 rather than a 206 response from a range request.
  40284. var ok_response_on_range_request =
  40285. xhrStatus === OK_RESPONSE &&
  40286. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  40287. if (!ok_response_on_range_request &&
  40288. xhrStatus !== pendingRequest.expectedStatus) {
  40289. if (pendingRequest.onError) {
  40290. pendingRequest.onError(xhr.status);
  40291. }
  40292. return;
  40293. }
  40294. this.loadedRequests[xhrId] = true;
  40295. var chunk = getArrayBuffer(xhr);
  40296. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  40297. var rangeHeader = xhr.getResponseHeader('Content-Range');
  40298. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  40299. var begin = parseInt(matches[1], 10);
  40300. pendingRequest.onDone({
  40301. begin: begin,
  40302. chunk: chunk
  40303. });
  40304. } else if (pendingRequest.onProgressiveData) {
  40305. pendingRequest.onDone(null);
  40306. } else if (chunk) {
  40307. pendingRequest.onDone({
  40308. begin: 0,
  40309. chunk: chunk
  40310. });
  40311. } else if (pendingRequest.onError) {
  40312. pendingRequest.onError(xhr.status);
  40313. }
  40314. },
  40315. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  40316. for (var xhrId in this.pendingRequests) {
  40317. return true;
  40318. }
  40319. return false;
  40320. },
  40321. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  40322. return this.pendingRequests[xhrId].xhr;
  40323. },
  40324. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  40325. return !!(this.pendingRequests[xhrId].onProgressiveData);
  40326. },
  40327. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  40328. return xhrId in this.pendingRequests;
  40329. },
  40330. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  40331. return xhrId in this.loadedRequests;
  40332. },
  40333. abortAllRequests: function NetworkManager_abortAllRequests() {
  40334. for (var xhrId in this.pendingRequests) {
  40335. this.abortRequest(xhrId | 0);
  40336. }
  40337. },
  40338. abortRequest: function NetworkManager_abortRequest(xhrId) {
  40339. var xhr = this.pendingRequests[xhrId].xhr;
  40340. delete this.pendingRequests[xhrId];
  40341. xhr.abort();
  40342. }
  40343. };
  40344. return NetworkManager;
  40345. })();
  40346. (function (root, factory) {
  40347. {
  40348. factory((root.pdfjsCoreNetwork = {}), root.pdfjsSharedUtil,
  40349. root.pdfjsCoreWorker);
  40350. }
  40351. }(this, function (exports, sharedUtil, coreWorker) {
  40352. var assert = sharedUtil.assert;
  40353. var createPromiseCapability = sharedUtil.createPromiseCapability;
  40354. var isInt = sharedUtil.isInt;
  40355. var MissingPDFException = sharedUtil.MissingPDFException;
  40356. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  40357. /** @implements {IPDFStream} */
  40358. function PDFNetworkStream(options) {
  40359. this._options = options;
  40360. var source = options.source;
  40361. this._manager = new NetworkManager(source.url, {
  40362. httpHeaders: source.httpHeaders,
  40363. withCredentials: source.withCredentials
  40364. });
  40365. this._rangeChunkSize = source.rangeChunkSize;
  40366. this._fullRequestReader = null;
  40367. this._rangeRequestReaders = [];
  40368. }
  40369. PDFNetworkStream.prototype = {
  40370. _onRangeRequestReaderClosed:
  40371. function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
  40372. var i = this._rangeRequestReaders.indexOf(reader);
  40373. if (i >= 0) {
  40374. this._rangeRequestReaders.splice(i, 1);
  40375. }
  40376. },
  40377. getFullReader: function PDFNetworkStream_getFullReader() {
  40378. assert(!this._fullRequestReader);
  40379. this._fullRequestReader =
  40380. new PDFNetworkStreamFullRequestReader(this._manager, this._options);
  40381. return this._fullRequestReader;
  40382. },
  40383. getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
  40384. var reader = new PDFNetworkStreamRangeRequestReader(this._manager,
  40385. begin, end);
  40386. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  40387. this._rangeRequestReaders.push(reader);
  40388. return reader;
  40389. },
  40390. cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
  40391. if (this._fullRequestReader) {
  40392. this._fullRequestReader.cancel(reason);
  40393. }
  40394. var readers = this._rangeRequestReaders.slice(0);
  40395. readers.forEach(function (reader) {
  40396. reader.cancel(reason);
  40397. });
  40398. }
  40399. };
  40400. /** @implements {IPDFStreamReader} */
  40401. function PDFNetworkStreamFullRequestReader(manager, options) {
  40402. this._manager = manager;
  40403. var source = options.source;
  40404. var args = {
  40405. onHeadersReceived: this._onHeadersReceived.bind(this),
  40406. onProgressiveData: source.disableStream ? null :
  40407. this._onProgressiveData.bind(this),
  40408. onDone: this._onDone.bind(this),
  40409. onError: this._onError.bind(this),
  40410. onProgress: this._onProgress.bind(this)
  40411. };
  40412. this._url = source.url;
  40413. this._fullRequestId = manager.requestFull(args);
  40414. this._headersReceivedCapability = createPromiseCapability();
  40415. this._disableRange = options.disableRange || false;
  40416. this._contentLength = source.length; // optional
  40417. this._rangeChunkSize = source.rangeChunkSize;
  40418. if (!this._rangeChunkSize && !this._disableRange) {
  40419. this._disableRange = true;
  40420. }
  40421. this._isStreamingSupported = false;
  40422. this._isRangeSupported = false;
  40423. this._cachedChunks = [];
  40424. this._requests = [];
  40425. this._done = false;
  40426. this._storedError = undefined;
  40427. this.onProgress = null;
  40428. }
  40429. PDFNetworkStreamFullRequestReader.prototype = {
  40430. _validateRangeRequestCapabilities: function
  40431. PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() {
  40432. if (this._disableRange) {
  40433. return false;
  40434. }
  40435. var networkManager = this._manager;
  40436. var fullRequestXhrId = this._fullRequestId;
  40437. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  40438. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  40439. return false;
  40440. }
  40441. var contentEncoding =
  40442. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  40443. if (contentEncoding !== 'identity') {
  40444. return false;
  40445. }
  40446. var length = fullRequestXhr.getResponseHeader('Content-Length');
  40447. length = parseInt(length, 10);
  40448. if (!isInt(length)) {
  40449. return false;
  40450. }
  40451. this._contentLength = length; // setting right content length
  40452. if (length <= 2 * this._rangeChunkSize) {
  40453. // The file size is smaller than the size of two chunks, so it does
  40454. // not make any sense to abort the request and retry with a range
  40455. // request.
  40456. return false;
  40457. }
  40458. return true;
  40459. },
  40460. _onHeadersReceived:
  40461. function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
  40462. if (this._validateRangeRequestCapabilities()) {
  40463. this._isRangeSupported = true;
  40464. }
  40465. var networkManager = this._manager;
  40466. var fullRequestXhrId = this._fullRequestId;
  40467. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  40468. // We can continue fetching when progressive loading is enabled,
  40469. // and we don't need the autoFetch feature.
  40470. this._isStreamingSupported = true;
  40471. } else if (this._isRangeSupported) {
  40472. // NOTE: by cancelling the full request, and then issuing range
  40473. // requests, there will be an issue for sites where you can only
  40474. // request the pdf once. However, if this is the case, then the
  40475. // server should not be returning that it can support range
  40476. // requests.
  40477. networkManager.abortRequest(fullRequestXhrId);
  40478. }
  40479. this._headersReceivedCapability.resolve();
  40480. },
  40481. _onProgressiveData:
  40482. function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
  40483. if (this._requests.length > 0) {
  40484. var requestCapability = this._requests.shift();
  40485. requestCapability.resolve({value: chunk, done: false});
  40486. } else {
  40487. this._cachedChunks.push(chunk);
  40488. }
  40489. },
  40490. _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
  40491. if (args) {
  40492. this._onProgressiveData(args.chunk);
  40493. }
  40494. this._done = true;
  40495. if (this._cachedChunks.length > 0) {
  40496. return;
  40497. }
  40498. this._requests.forEach(function (requestCapability) {
  40499. requestCapability.resolve({value: undefined, done: true});
  40500. });
  40501. this._requests = [];
  40502. },
  40503. _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
  40504. var url = this._url;
  40505. var exception;
  40506. if (status === 404 || status === 0 && /^file:/.test(url)) {
  40507. exception = new MissingPDFException('Missing PDF "' + url + '".');
  40508. } else {
  40509. exception = new UnexpectedResponseException(
  40510. 'Unexpected server response (' + status +
  40511. ') while retrieving PDF "' + url + '".', status);
  40512. }
  40513. this._storedError = exception;
  40514. this._headersReceivedCapability.reject(exception);
  40515. this._requests.forEach(function (requestCapability) {
  40516. requestCapability.reject(exception);
  40517. });
  40518. this._requests = [];
  40519. this._cachedChunks = [];
  40520. },
  40521. _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
  40522. if (this.onProgress) {
  40523. this.onProgress({
  40524. loaded: data.loaded,
  40525. total: data.lengthComputable ? data.total : this._contentLength
  40526. });
  40527. }
  40528. },
  40529. get isRangeSupported() {
  40530. return this._isRangeSupported;
  40531. },
  40532. get isStreamingSupported() {
  40533. return this._isStreamingSupported;
  40534. },
  40535. get contentLength() {
  40536. return this._contentLength;
  40537. },
  40538. get headersReady() {
  40539. return this._headersReceivedCapability.promise;
  40540. },
  40541. read: function PDFNetworkStreamFullRequestReader_read() {
  40542. if (this._storedError) {
  40543. return Promise.reject(this._storedError);
  40544. }
  40545. if (this._cachedChunks.length > 0) {
  40546. var chunk = this._cachedChunks.shift();
  40547. return Promise.resolve(chunk);
  40548. }
  40549. if (this._done) {
  40550. return Promise.resolve({value: undefined, done: true});
  40551. }
  40552. var requestCapability = createPromiseCapability();
  40553. this._requests.push(requestCapability);
  40554. return requestCapability.promise;
  40555. },
  40556. cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
  40557. this._done = true;
  40558. this._headersReceivedCapability.reject(reason);
  40559. this._requests.forEach(function (requestCapability) {
  40560. requestCapability.resolve({value: undefined, done: true});
  40561. });
  40562. this._requests = [];
  40563. if (this._manager.isPendingRequest(this._fullRequestId)) {
  40564. this._manager.abortRequest(this._fullRequestId);
  40565. }
  40566. this._fullRequestReader = null;
  40567. }
  40568. };
  40569. /** @implements {IPDFStreamRangeReader} */
  40570. function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
  40571. this._manager = manager;
  40572. var args = {
  40573. onDone: this._onDone.bind(this),
  40574. onProgress: this._onProgress.bind(this)
  40575. };
  40576. this._requestId = manager.requestRange(begin, end, args);
  40577. this._requests = [];
  40578. this._queuedChunk = null;
  40579. this._done = false;
  40580. this.onProgress = null;
  40581. this.onClosed = null;
  40582. }
  40583. PDFNetworkStreamRangeRequestReader.prototype = {
  40584. _close: function PDFNetworkStreamRangeRequestReader_close() {
  40585. if (this.onClosed) {
  40586. this.onClosed(this);
  40587. }
  40588. },
  40589. _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
  40590. var chunk = data.chunk;
  40591. if (this._requests.length > 0) {
  40592. var requestCapability = this._requests.shift();
  40593. requestCapability.resolve({value: chunk, done: false});
  40594. } else {
  40595. this._queuedChunk = chunk;
  40596. }
  40597. this._done = true;
  40598. this._requests.forEach(function (requestCapability) {
  40599. requestCapability.resolve({value: undefined, done: true});
  40600. });
  40601. this._requests = [];
  40602. this._close();
  40603. },
  40604. _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
  40605. if (!this.isStreamingSupported && this.onProgress) {
  40606. this.onProgress({
  40607. loaded: evt.loaded
  40608. });
  40609. }
  40610. },
  40611. get isStreamingSupported() {
  40612. return false; // TODO allow progressive range bytes loading
  40613. },
  40614. read: function PDFNetworkStreamRangeRequestReader_read() {
  40615. if (this._queuedChunk !== null) {
  40616. var chunk = this._queuedChunk;
  40617. this._queuedChunk = null;
  40618. return Promise.resolve({value: chunk, done: false});
  40619. }
  40620. if (this._done) {
  40621. return Promise.resolve({value: undefined, done: true});
  40622. }
  40623. var requestCapability = createPromiseCapability();
  40624. this._requests.push(requestCapability);
  40625. return requestCapability.promise;
  40626. },
  40627. cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
  40628. this._done = true;
  40629. this._requests.forEach(function (requestCapability) {
  40630. requestCapability.resolve({value: undefined, done: true});
  40631. });
  40632. this._requests = [];
  40633. if (this._manager.isPendingRequest(this._requestId)) {
  40634. this._manager.abortRequest(this._requestId);
  40635. }
  40636. this._close();
  40637. }
  40638. };
  40639. coreWorker.setPDFNetworkStreamClass(PDFNetworkStream);
  40640. exports.PDFNetworkStream = PDFNetworkStream;
  40641. exports.NetworkManager = NetworkManager;
  40642. }));
  40643. }).call(pdfjsLibs);
  40644. exports.WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
  40645. }));